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,20 +99,30 @@ fn main() {
vbox.set_padded(&ui, true); vbox.set_padded(&ui, true);
let mut button = Button::new(&ui, "Button"); // let mut button = Button::new(&ui, "Button");
button.on_clicked(&ui, { // button.on_clicked(&ui, {
let ui = ui.clone(); // let ui = ui.clone();
move |btn| { // move |btn| {
let folder_opt = detect_among_us_folder(); // let folder_opt = detect_among_us_folder();
if folder_opt.is_some() { // if folder_opt.is_some() {
btn.set_text(&ui, "Amogus"); // btn.set_text(&ui, "Amogus");
ui.quit(); // ui.quit();
} // }
} // }
}); // });
// DETERMINE AMONG US VERSION
let folder_opt = detect_among_us_folder();
let mut among_us_folder = path::PathBuf::new(); let mut among_us_folder = path::PathBuf::new();
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 {
let folder_opt = detect_among_us_folder();
if folder_opt.is_some() { if folder_opt.is_some() {
among_us_folder.push(folder_opt.unwrap()); among_us_folder.push(folder_opt.unwrap());
} else { } else {
@@ -120,8 +130,12 @@ fn main() {
let open_window = win.open_file(&ui); let open_window = win.open_file(&ui);
// println!("{}", open_window.unwrap().to_str().unwrap()); // 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();
}
println!("Among Us Folder: {}", among_us_folder.to_str().unwrap()); println!("Among Us Folder: {}", among_us_folder.to_str().unwrap());
@@ -141,6 +155,7 @@ fn main() {
.collect(); .collect();
if !path::Path::exists(&new_installed_path) { if !path::Path::exists(&new_installed_path) {
println!("Copying Among Us to separate location...");
copy_folder_to_target( copy_folder_to_target(
among_us_folder.to_str().unwrap(), among_us_folder.to_str().unwrap(),
installs_path.to_str().unwrap(), installs_path.to_str().unwrap(),
@@ -158,7 +173,7 @@ fn main() {
unmod_among_us_folder(&among_us_path); unmod_among_us_folder(&among_us_path);
println!( println!(
"Rename {} to {}", "Renaming {} to {}",
among_us_path.to_str().unwrap(), among_us_path.to_str().unwrap(),
new_installed_path.to_str().unwrap() new_installed_path.to_str().unwrap()
); );
@@ -173,8 +188,8 @@ fn main() {
download_path.push(downloaded_filename.clone()); download_path.push(downloaded_filename.clone());
if !path::Path::exists(&download_path) { if !path::Path::exists(&download_path) {
println!("{:?}", download_path); // println!("{:?}", download_path);
println!("Downloading Town of Us [{}]", ver_url.1.clone()); println!("Downloading Town of Us... [{}]", ver_url.1.clone());
let zip = reqwest::blocking::get(ver_url.1.clone()) let zip = reqwest::blocking::get(ver_url.1.clone())
.unwrap() .unwrap()
.bytes() .bytes()
@@ -386,6 +401,7 @@ fn copy_folder_contents_to_target<T: AsRef<path::Path>>(source: T, dest: T) {
copy_opts.content_only = true; copy_opts.content_only = true;
fs_extra::dir::copy(source, dest, &copy_opts).unwrap(); fs_extra::dir::copy(source, dest, &copy_opts).unwrap();
} }
fn detect_among_us_folder() -> Option<String> { fn detect_among_us_folder() -> Option<String> {
let library_folder = let library_folder =
fs::read_to_string("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf"); fs::read_to_string("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf");