More improved messaging, added folder detection caching

This commit is contained in:
2022-07-26 20:37:00 -07:00
parent b6221643e2
commit 86d1e176d4

View File

@@ -99,28 +99,42 @@ fn main() {
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();
}
}
});
// 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 folder_opt = detect_among_us_folder();
let mut among_us_folder = path::PathBuf::new();
if folder_opt.is_some() {
among_us_folder.push(folder_opt.unwrap());
let mut existing_file_path = data_path.clone();
existing_file_path.push("existing_among_us_dir.txt");
let existing_found_folder = fs::read_to_string(existing_file_path.clone());
if existing_found_folder.is_ok() {
among_us_folder.push(existing_found_folder.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);
// println!("{}", open_window.unwrap().to_str().unwrap());
among_us_folder = open_window.unwrap().clone();
among_us_folder.pop();
let folder_opt = detect_among_us_folder();
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);
// println!("{}", open_window.unwrap().to_str().unwrap());
among_us_folder = open_window.unwrap().clone();
// Pop the selected file off the end of the path
among_us_folder.pop();
}
fs::write(existing_file_path, among_us_folder.to_str().unwrap()).unwrap();
}
println!("Among Us Folder: {}", among_us_folder.to_str().unwrap());
@@ -141,6 +155,7 @@ fn main() {
.collect();
if !path::Path::exists(&new_installed_path) {
println!("Copying Among Us to separate location...");
copy_folder_to_target(
among_us_folder.to_str().unwrap(),
installs_path.to_str().unwrap(),
@@ -158,7 +173,7 @@ fn main() {
unmod_among_us_folder(&among_us_path);
println!(
"Rename {} to {}",
"Renaming {} to {}",
among_us_path.to_str().unwrap(),
new_installed_path.to_str().unwrap()
);
@@ -173,8 +188,8 @@ fn main() {
download_path.push(downloaded_filename.clone());
if !path::Path::exists(&download_path) {
println!("{:?}", download_path);
println!("Downloading Town of Us [{}]", ver_url.1.clone());
// println!("{:?}", download_path);
println!("Downloading Town of Us... [{}]", ver_url.1.clone());
let zip = reqwest::blocking::get(ver_url.1.clone())
.unwrap()
.bytes()
@@ -386,6 +401,7 @@ fn copy_folder_contents_to_target<T: AsRef<path::Path>>(source: T, dest: T) {
copy_opts.content_only = true;
fs_extra::dir::copy(source, dest, &copy_opts).unwrap();
}
fn detect_among_us_folder() -> Option<String> {
let library_folder =
fs::read_to_string("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf");