Compare commits
4 Commits
91579d333e
...
9132afe917
| Author | SHA1 | Date | |
|---|---|---|---|
| 9132afe917 | |||
| ebad7cb893 | |||
| b4c22cdc48 | |||
| 54b2b8b117 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/target
|
||||
Cargo.lock
|
||||
|
||||
@@ -15,6 +15,7 @@ reqwest = {version = "0.11.11", features = ["blocking"]}
|
||||
iui = "0.3.0"
|
||||
serde_json = "1.0"
|
||||
tokio = {version="1", features=["full"]}
|
||||
druid = "0.7.0"
|
||||
|
||||
[build-dependencies]
|
||||
embed-resource = "1.6"
|
||||
|
||||
BIN
assets/logo.png
BIN
assets/logo.png
Binary file not shown.
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 42 KiB |
196
src/main.rs
196
src/main.rs
@@ -1,13 +1,24 @@
|
||||
use std::cell::RefCell;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::rc::Rc;
|
||||
use std::str;
|
||||
use std::thread;
|
||||
use std::*;
|
||||
|
||||
use druid::widget::*;
|
||||
use druid::{
|
||||
commands, AppDelegate, AppLauncher, Application, Data, DelegateCtx, Env, FileDialogOptions,
|
||||
Handled, Target, WidgetExt, WindowDesc,
|
||||
};
|
||||
use fs_extra::{copy_items, dir};
|
||||
use iui::controls::{Button, Group, Label, VerticalBox};
|
||||
use iui::prelude::*;
|
||||
use regex::Regex;
|
||||
|
||||
struct Delegate;
|
||||
|
||||
#[derive(Data, Clone)]
|
||||
struct AppData {
|
||||
pub among_us_path: Rc<RefCell<String>>,
|
||||
}
|
||||
|
||||
static AMONG_US_APPID: &'static str = "945360";
|
||||
|
||||
#[derive(Ord, PartialOrd, Eq, PartialEq)]
|
||||
@@ -111,9 +122,39 @@ async fn get_latest_updater_version() -> Result<(String, String), reqwest::Error
|
||||
Ok((String::from("no"), String::from("yes")))
|
||||
}
|
||||
|
||||
impl AppDelegate<AppData> for Delegate {
|
||||
fn command(
|
||||
&mut self,
|
||||
_ctx: &mut DelegateCtx,
|
||||
_target: Target,
|
||||
cmd: &druid::Command,
|
||||
data: &mut AppData,
|
||||
_env: &Env,
|
||||
) -> Handled {
|
||||
if let Some(file_info) = cmd.get(commands::OPEN_FILE) {
|
||||
println!("{:?}", file_info);
|
||||
let among_us_folder = file_info.path();
|
||||
let mut buf = among_us_folder.to_path_buf();
|
||||
buf.pop();
|
||||
let mut borrow = data.among_us_path.borrow_mut();
|
||||
*borrow = String::from(buf.to_str().unwrap());
|
||||
|
||||
// Pop the selected file off the end of the path
|
||||
// among_us_folder.pop();
|
||||
println!("{}", buf.to_str().unwrap());
|
||||
println!("Handled!");
|
||||
Application::global().quit();
|
||||
return Handled::Yes;
|
||||
}
|
||||
Handled::No
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let version = env!("CARGO_PKG_VERSION");
|
||||
let title_string: String = format!("Town of Us Updater - {}", version);
|
||||
|
||||
println!("Updater Version: {}", version);
|
||||
get_latest_updater_version().await.unwrap();
|
||||
//let _version_check_thread_handle = thread::spawn(move || get_latest_updater_version());
|
||||
@@ -127,26 +168,6 @@ async fn main() {
|
||||
installs_path.push("installs");
|
||||
fs::create_dir(installs_path.clone()).unwrap_or(());
|
||||
|
||||
let ui = UI::init().expect("UI failed to init");
|
||||
|
||||
let mut win = Window::new(&ui, "Town of Us Updater", 600, 400, WindowType::NoMenubar);
|
||||
|
||||
let mut vbox = VerticalBox::new(&ui);
|
||||
|
||||
vbox.set_padded(&ui, true);
|
||||
|
||||
// let mut button = Button::new(&ui, "Button");
|
||||
// button.on_clicked(&ui, {
|
||||
// let ui = ui.clone();
|
||||
// move |btn| {
|
||||
// let folder_opt = detect_among_us_folder();
|
||||
// if folder_opt.is_some() {
|
||||
// btn.set_text(&ui, "Amogus");
|
||||
// ui.quit();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// DETERMINE AMONG US VERSION
|
||||
|
||||
let mut among_us_folder = path::PathBuf::new();
|
||||
@@ -162,13 +183,37 @@ async fn main() {
|
||||
if folder_opt.is_some() {
|
||||
among_us_folder.push(folder_opt.unwrap());
|
||||
} else {
|
||||
win.modal_msg(&ui, "Find Among Us", "On the following Open File dialog, navigate to your Among Us folder and select Among Us.exe");
|
||||
let open_window = win.open_file(&ui);
|
||||
let path_rc = Rc::new(RefCell::new(String::from("")));
|
||||
let data: AppData = AppData {
|
||||
among_us_path: path_rc.clone(),
|
||||
};
|
||||
let open_button = Button::new("Locate Among Us").fix_height(45.0).on_click(
|
||||
move |ctx, _: &mut AppData, _| {
|
||||
ctx.submit_command(
|
||||
druid::commands::SHOW_OPEN_PANEL.with(FileDialogOptions::new()),
|
||||
);
|
||||
},
|
||||
);
|
||||
let flex: Flex<AppData> = Flex::column().with_flex_child(open_button, 1.0);
|
||||
let open_dialog = WindowDesc::new(|| flex)
|
||||
.title("Among Us Not Found!")
|
||||
.window_size((400.0, 400.0));
|
||||
AppLauncher::with_window(open_dialog)
|
||||
.delegate(Delegate)
|
||||
.launch(data)
|
||||
.unwrap_or_default();
|
||||
|
||||
among_us_folder = path::PathBuf::from(Rc::try_unwrap(path_rc).unwrap().take());
|
||||
|
||||
println!("{}", among_us_folder.to_str().unwrap());
|
||||
|
||||
// win.modal_msg(&ui, "Find Among Us", "On the following Open File dialog, navigate to your Among Us folder and select Among Us.exe");
|
||||
// let open_window = win.open_file(&ui);
|
||||
// println!("{}", open_window.unwrap().to_str().unwrap());
|
||||
among_us_folder = open_window.unwrap().clone();
|
||||
// among_us_folder = open_window.unwrap().clone();
|
||||
|
||||
// Pop the selected file off the end of the path
|
||||
among_us_folder.pop();
|
||||
// among_us_folder.pop();
|
||||
}
|
||||
fs::write(existing_file_path, among_us_folder.to_str().unwrap()).unwrap();
|
||||
}
|
||||
@@ -228,9 +273,11 @@ async fn main() {
|
||||
if !path::Path::exists(&download_path) {
|
||||
// println!("{:?}", download_path);
|
||||
println!("Downloading Town of Us... [{}]", ver_url.1.clone());
|
||||
let zip = reqwest::blocking::get(ver_url.1.clone())
|
||||
let zip = reqwest::get(ver_url.1.clone())
|
||||
.await
|
||||
.unwrap()
|
||||
.bytes()
|
||||
.await
|
||||
.unwrap();
|
||||
fs::write(download_path.clone(), zip).unwrap();
|
||||
}
|
||||
@@ -260,59 +307,80 @@ async fn main() {
|
||||
|
||||
// Find existing installs, make buttons for them
|
||||
let install_iter = fs::read_dir(installs_path.clone());
|
||||
let mut root_column: druid::widget::Flex<u32> = druid::widget::Flex::column();
|
||||
|
||||
match install_iter {
|
||||
Ok(iter) => {
|
||||
if let Ok(iter) = install_iter {
|
||||
let mut collection: Vec<Result<fs::DirEntry, std::io::Error>> = iter.collect();
|
||||
collection.reverse();
|
||||
|
||||
// Iterate first to find labels:
|
||||
|
||||
let mut flexbox_array: Vec<druid::widget::Flex<u32>> = Vec::new();
|
||||
let mut auv_array: Vec<String> = Vec::new();
|
||||
|
||||
for i in &collection {
|
||||
let existing_ver_smash = i.as_ref().unwrap().file_name();
|
||||
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split("-");
|
||||
let auv = ver_smash_split.next().unwrap();
|
||||
if !auv_array.contains(&auv.to_string()) {
|
||||
let label_text = format!("Among Us {}", auv);
|
||||
let flex: druid::widget::Flex<u32> = druid::widget::Flex::column()
|
||||
.with_flex_child(
|
||||
druid::widget::Label::new(label_text.as_str()).with_text_size(24.0),
|
||||
1.0,
|
||||
)
|
||||
.with_default_spacer();
|
||||
flexbox_array.push(flex);
|
||||
auv_array.push(auv.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
for i in collection {
|
||||
// for i in iter {
|
||||
let existing_ver_smash = i.unwrap().file_name();
|
||||
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split("-");
|
||||
let auv = ver_smash_split.next().unwrap();
|
||||
let button_string: String = format!(
|
||||
"Among Us {} Town of Us {}",
|
||||
auv,
|
||||
ver_smash_split.next().unwrap()
|
||||
);
|
||||
let mut group_vbox = VerticalBox::new(&ui);
|
||||
let mut group = Group::new(&ui, auv.clone());
|
||||
let button_string: String = format!("Town of Us {}", ver_smash_split.next().unwrap());
|
||||
|
||||
let mut button = Button::new(&ui, button_string.as_str());
|
||||
button.on_clicked(&ui, {
|
||||
let ui = ui.clone();
|
||||
let installs_path = installs_path.clone();
|
||||
let existing_ver_smash = existing_ver_smash.clone();
|
||||
move |btn| {
|
||||
let mut new_path = installs_path.clone();
|
||||
new_path.push(existing_ver_smash.clone());
|
||||
println!("{}", new_path.clone().to_str().unwrap());
|
||||
attempt_run_among_us(&new_path);
|
||||
btn.set_text(&ui, "Launching Among Us...");
|
||||
}
|
||||
let mut index = 0;
|
||||
for j in &auv_array {
|
||||
if j == auv {
|
||||
let mut clone = installs_path.clone();
|
||||
clone.push(existing_ver_smash.clone());
|
||||
|
||||
let fybutton = druid::widget::Button::new(button_string.as_str())
|
||||
.fix_height(45.0)
|
||||
.on_click(move |_, _: &mut u32, _| {
|
||||
attempt_run_among_us(&clone);
|
||||
});
|
||||
group_vbox.append(&ui, button, LayoutStrategy::Stretchy);
|
||||
group.set_child(&ui, group_vbox);
|
||||
vbox.append(&ui, group, LayoutStrategy::Stretchy);
|
||||
|
||||
flexbox_array
|
||||
.get_mut(index)
|
||||
.unwrap()
|
||||
.add_flex_child(fybutton, 1.0);
|
||||
|
||||
println!("{}", existing_ver_smash.clone().to_str().unwrap());
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
for i in flexbox_array {
|
||||
root_column.add_flex_child(i, 1.0);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
// println!("Checking for updater updates...");
|
||||
// let vals: (String, String) = version_check_thread_handle.join().unwrap();
|
||||
// let mut update_button = Button::new(&ui, "Check for New Version");
|
||||
// update_button.on_clicked(&ui, {
|
||||
// let ui = ui.clone();
|
||||
// move |btn| {}
|
||||
// });
|
||||
|
||||
// vbox.append(&ui, update_button, LayoutStrategy::Stretchy);
|
||||
println!("Launching main window...");
|
||||
|
||||
let main_window = WindowDesc::new(|| root_column)
|
||||
.title(title_string)
|
||||
.window_size((400.0, 400.0));
|
||||
let app_launcher = AppLauncher::with_window(main_window);
|
||||
let external_handler = app_launcher.get_external_handle();
|
||||
app_launcher.launch(1).unwrap();
|
||||
// AppLauncher::with_window(main_window).launch(1).unwrap();
|
||||
|
||||
win.set_child(&ui, vbox);
|
||||
win.show(&ui);
|
||||
ui.main();
|
||||
// let mut install_folder_path = installs_path.clone();
|
||||
// install_folder_path.push(version_smash);
|
||||
// fs::create_dir(install_folder_path.clone()).unwrap_or(());
|
||||
@@ -381,7 +449,7 @@ async fn determine_town_of_us_url(among_us_version: String) -> Option<(String, S
|
||||
.1
|
||||
.get(ver_capture.start()..ver_capture.end())
|
||||
.unwrap();
|
||||
println!("Installing version: {}", ver);
|
||||
println!("Installing Town of Us version: {}", ver);
|
||||
Some((String::from(ver), String::from(url), official_compatibility))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user