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);
|
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");
|
let mut button = Button::new(&ui, "Button");
|
||||||
button.on_clicked(&ui, {
|
button.on_clicked(&ui, {
|
||||||
let ui = ui.clone();
|
let ui = ui.clone();
|
||||||
@@ -128,18 +101,14 @@ fn main() {
|
|||||||
// 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();
|
||||||
among_us_folder.pop();
|
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());
|
println!("Among Us Folder: {}", among_us_folder.to_str().unwrap());
|
||||||
|
|
||||||
let among_us_version =
|
let among_us_version =
|
||||||
determine_among_us_version(String::from(among_us_folder.to_str().unwrap())).unwrap();
|
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 version_smash = format!("{}-{}", among_us_version.clone(), ver_url.0.clone());
|
||||||
let new_installed_path: path::PathBuf =
|
let new_installed_path: path::PathBuf =
|
||||||
@@ -157,6 +126,10 @@ fn main() {
|
|||||||
.iter()
|
.iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
if !among_us_path.to_str().unwrap().contains("Among Us") {
|
||||||
|
process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
// Un-mod whatever we found if it's modded
|
// Un-mod whatever we found if it's modded
|
||||||
unmod_among_us_folder(&among_us_path);
|
unmod_among_us_folder(&among_us_path);
|
||||||
|
|
||||||
@@ -208,6 +181,39 @@ fn main() {
|
|||||||
println!("Modded install already found");
|
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();
|
// let mut install_folder_path = installs_path.clone();
|
||||||
// install_folder_path.push(version_smash);
|
// install_folder_path.push(version_smash);
|
||||||
// fs::create_dir(install_folder_path.clone()).unwrap_or(());
|
// fs::create_dir(install_folder_path.clone()).unwrap_or(());
|
||||||
@@ -215,17 +221,17 @@ fn main() {
|
|||||||
// Copy Among Us Out
|
// Copy Among Us Out
|
||||||
// Create destination path
|
// Create destination path
|
||||||
|
|
||||||
let executable_path: path::PathBuf = [new_installed_path.to_str().unwrap(), "Among Us.exe"]
|
// let executable_path: path::PathBuf = [new_installed_path.to_str().unwrap(), "Among Us.exe"]
|
||||||
.iter()
|
// .iter()
|
||||||
.collect();
|
// .collect();
|
||||||
|
|
||||||
std::process::Command::new(executable_path.to_str().unwrap())
|
// std::process::Command::new(executable_path.to_str().unwrap())
|
||||||
.spawn()
|
// .spawn()
|
||||||
.unwrap();
|
// .unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns (Version, URL)
|
// 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(
|
let markdown = reqwest::blocking::get(
|
||||||
"https://raw.githubusercontent.com/eDonnes124/Town-Of-Us-R/master/README.md",
|
"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()
|
.text()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut line = markdown.find(&among_us_version);
|
let mut line = markdown.find(&among_us_version);
|
||||||
|
let mut line_offset = 0;
|
||||||
|
let mut official_compatibility = false;
|
||||||
if line.is_some() {
|
if line.is_some() {
|
||||||
println!("Found official version!");
|
println!("Found official version!");
|
||||||
|
official_compatibility = true;
|
||||||
} else {
|
} else {
|
||||||
println!("Official version cannot be determined.");
|
println!("Official version cannot be determined, installing experimental latest...");
|
||||||
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 = markdown.find("[Download]");
|
||||||
}
|
line_offset = 15;
|
||||||
_ => return None,
|
// 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
|
// 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);
|
// println!("{}", splits.1);
|
||||||
let url_regex = Regex::new(r#"\(([\w\d:/\.\-]+)\)\s|\n"#).unwrap();
|
let url_regex = Regex::new(r#"\(([\w\d:/\.\-]+)\)\s|\n"#).unwrap();
|
||||||
let captures = url_regex.captures(splits.1).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())
|
.get(ver_capture.start()..ver_capture.end())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("Matching version is: {}", ver);
|
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> {
|
fn determine_among_us_version(folder_root: String) -> Option<String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user