Latest changes
This commit is contained in:
128
src/main.rs
128
src/main.rs
@@ -79,33 +79,6 @@ fn main() {
|
||||
|
||||
vbox.set_padded(&ui, true);
|
||||
|
||||
// Find existing installs, make buttons for them
|
||||
let install_iter = fs::read_dir(installs_path.clone());
|
||||
|
||||
match install_iter {
|
||||
Ok(iter) => {
|
||||
for i in iter {
|
||||
let existing_ver_smash = i.unwrap().file_name();
|
||||
let mut button = Button::new(&ui, existing_ver_smash.clone().to_str().unwrap());
|
||||
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, "Amogus");
|
||||
}
|
||||
});
|
||||
vbox.append(&ui, button, LayoutStrategy::Compact);
|
||||
println!("{}", existing_ver_smash.clone().to_str().unwrap());
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
let mut button = Button::new(&ui, "Button");
|
||||
button.on_clicked(&ui, {
|
||||
let ui = ui.clone();
|
||||
@@ -128,18 +101,14 @@ fn main() {
|
||||
// println!("{}", open_window.unwrap().to_str().unwrap());
|
||||
among_us_folder = open_window.unwrap().clone();
|
||||
among_us_folder.pop();
|
||||
// vbox.append(&ui, button, LayoutStrategy::Compact);
|
||||
// win.set_child(&ui, vbox);
|
||||
|
||||
// win.show(&ui);
|
||||
// ui.main();
|
||||
}
|
||||
|
||||
println!("Among Us Folder: {}", among_us_folder.to_str().unwrap());
|
||||
|
||||
let among_us_version =
|
||||
determine_among_us_version(String::from(among_us_folder.to_str().unwrap())).unwrap();
|
||||
let ver_url: (String, String) = determine_town_of_us_url(among_us_version.clone()).unwrap();
|
||||
let ver_url: (String, String, bool) =
|
||||
determine_town_of_us_url(among_us_version.clone()).unwrap();
|
||||
|
||||
let version_smash = format!("{}-{}", among_us_version.clone(), ver_url.0.clone());
|
||||
let new_installed_path: path::PathBuf =
|
||||
@@ -157,6 +126,10 @@ fn main() {
|
||||
.iter()
|
||||
.collect();
|
||||
|
||||
if !among_us_path.to_str().unwrap().contains("Among Us") {
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
// Un-mod whatever we found if it's modded
|
||||
unmod_among_us_folder(&among_us_path);
|
||||
|
||||
@@ -208,6 +181,39 @@ fn main() {
|
||||
println!("Modded install already found");
|
||||
}
|
||||
|
||||
// Find existing installs, make buttons for them
|
||||
let install_iter = fs::read_dir(installs_path.clone());
|
||||
|
||||
match install_iter {
|
||||
Ok(iter) => {
|
||||
let mut collection: Vec<Result<fs::DirEntry, io::Error>> = iter.collect();
|
||||
collection.reverse();
|
||||
for i in collection {
|
||||
// for i in iter {
|
||||
let existing_ver_smash = i.unwrap().file_name();
|
||||
let mut button = Button::new(&ui, existing_ver_smash.clone().to_str().unwrap());
|
||||
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...");
|
||||
}
|
||||
});
|
||||
vbox.append(&ui, button, LayoutStrategy::Stretchy);
|
||||
println!("{}", existing_ver_smash.clone().to_str().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(());
|
||||
@@ -215,17 +221,17 @@ fn main() {
|
||||
// Copy Among Us Out
|
||||
// Create destination path
|
||||
|
||||
let executable_path: path::PathBuf = [new_installed_path.to_str().unwrap(), "Among Us.exe"]
|
||||
.iter()
|
||||
.collect();
|
||||
// let executable_path: path::PathBuf = [new_installed_path.to_str().unwrap(), "Among Us.exe"]
|
||||
// .iter()
|
||||
// .collect();
|
||||
|
||||
std::process::Command::new(executable_path.to_str().unwrap())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
// std::process::Command::new(executable_path.to_str().unwrap())
|
||||
// .spawn()
|
||||
// .unwrap();
|
||||
}
|
||||
|
||||
// Returns (Version, URL)
|
||||
fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String)> {
|
||||
fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String, bool)> {
|
||||
let markdown = reqwest::blocking::get(
|
||||
"https://raw.githubusercontent.com/eDonnes124/Town-Of-Us-R/master/README.md",
|
||||
)
|
||||
@@ -233,29 +239,35 @@ fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String)
|
||||
.text()
|
||||
.unwrap();
|
||||
let mut line = markdown.find(&among_us_version);
|
||||
let mut line_offset = 0;
|
||||
let mut official_compatibility = false;
|
||||
if line.is_some() {
|
||||
println!("Found official version!");
|
||||
official_compatibility = true;
|
||||
} else {
|
||||
println!("Official version cannot be determined.");
|
||||
println!("At this point, there are two options:");
|
||||
println!(" [1] Revert Among Us to public-previous in Steam THEN select this option.");
|
||||
println!(" [2] Attempt to use the latest version of Town of Us anyway");
|
||||
let mut input = String::new();
|
||||
io::stdin().read_line(&mut input).unwrap();
|
||||
match input.trim() {
|
||||
"1" => {
|
||||
println!("Re-attempting...");
|
||||
return None;
|
||||
}
|
||||
"2" => {
|
||||
println!("Continuing...");
|
||||
println!("Official version cannot be determined, installing experimental latest...");
|
||||
line = markdown.find("[Download]");
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
line_offset = 15;
|
||||
// println!("At this point, there are two options:");
|
||||
// println!(" [1] Revert Among Us to public-previous in Steam THEN select this option.");
|
||||
// println!(" [2] Attempt to use the latest version of Town of Us anyway");
|
||||
// let mut input = String::new();
|
||||
// io::stdin().read_line(&mut input).unwrap();
|
||||
// match input.trim() {
|
||||
// "1" => {
|
||||
// println!("Re-attempting...");
|
||||
// return None;
|
||||
// }
|
||||
// "2" => {
|
||||
// println!("Continuing...");
|
||||
// line = markdown.find("[Download]");
|
||||
// line_offset = 15;
|
||||
// }
|
||||
// _ => return None,
|
||||
// };
|
||||
}
|
||||
// 100% scientific "-15" here to get the correct version since we find to [Download] above which is after the version number for that line
|
||||
let splits = markdown.split_at(line.unwrap() - 15);
|
||||
let splits = markdown.split_at(line.unwrap() - line_offset);
|
||||
// println!("{}", splits.1);
|
||||
let url_regex = Regex::new(r#"\(([\w\d:/\.\-]+)\)\s|\n"#).unwrap();
|
||||
let captures = url_regex.captures(splits.1).unwrap();
|
||||
@@ -270,7 +282,7 @@ fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String)
|
||||
.get(ver_capture.start()..ver_capture.end())
|
||||
.unwrap();
|
||||
println!("Matching version is: {}", ver);
|
||||
Some((String::from(ver), String::from(url)))
|
||||
Some((String::from(ver), String::from(url), official_compatibility))
|
||||
}
|
||||
|
||||
fn determine_among_us_version(folder_root: String) -> Option<String> {
|
||||
|
||||
Reference in New Issue
Block a user