Compare commits
5 Commits
v0.1.0
...
91579d333e
| Author | SHA1 | Date | |
|---|---|---|---|
| 91579d333e | |||
| 0b940aea70 | |||
| 86d1e176d4 | |||
| b6221643e2 | |||
| 3150019b76 |
@@ -1,7 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "town-of-us-updater"
|
name = "town-of-us-updater"
|
||||||
version = "0.1.0"
|
version = "1.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
build = "src/build.rs"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
@@ -12,3 +13,8 @@ fs_extra = "1.2.0"
|
|||||||
dirs = "4.0.0"
|
dirs = "4.0.0"
|
||||||
reqwest = {version = "0.11.11", features = ["blocking"]}
|
reqwest = {version = "0.11.11", features = ["blocking"]}
|
||||||
iui = "0.3.0"
|
iui = "0.3.0"
|
||||||
|
serde_json = "1.0"
|
||||||
|
tokio = {version="1", features=["full"]}
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embed-resource = "1.6"
|
||||||
|
|||||||
BIN
assets/icon.ico
Normal file
BIN
assets/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 142 KiB |
BIN
assets/logo.png
Normal file
BIN
assets/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
1
assets/main.rc
Normal file
1
assets/main.rc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1 ICON "icon.ico"
|
||||||
5
src/build.rs
Normal file
5
src/build.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
extern crate embed_resource;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
embed_resource::compile("assets/main.rc");
|
||||||
|
}
|
||||||
201
src/main.rs
201
src/main.rs
@@ -1,5 +1,6 @@
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use std::thread;
|
||||||
use std::*;
|
use std::*;
|
||||||
|
|
||||||
use fs_extra::{copy_items, dir};
|
use fs_extra::{copy_items, dir};
|
||||||
@@ -9,6 +10,7 @@ use regex::Regex;
|
|||||||
|
|
||||||
static AMONG_US_APPID: &'static str = "945360";
|
static AMONG_US_APPID: &'static str = "945360";
|
||||||
|
|
||||||
|
#[derive(Ord, PartialOrd, Eq, PartialEq)]
|
||||||
struct AmongUsVersion {
|
struct AmongUsVersion {
|
||||||
year: i32,
|
year: i32,
|
||||||
month: i32,
|
month: i32,
|
||||||
@@ -61,7 +63,61 @@ fn unmod_among_us_folder(folder_path: &Path) {
|
|||||||
fs::remove_dir_all(mono_path).unwrap_or_default();
|
fs::remove_dir_all(mono_path).unwrap_or_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
async fn get_latest_updater_version() -> Result<(String, String), reqwest::Error> {
|
||||||
|
let version = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
let mut cur_vers = version.split('.');
|
||||||
|
let major_ver = cur_vers.next().unwrap().parse::<i32>().unwrap();
|
||||||
|
let minor_ver = cur_vers.next().unwrap().parse::<i32>().unwrap();
|
||||||
|
let patch_ver = cur_vers.next().unwrap().parse::<i32>().unwrap();
|
||||||
|
|
||||||
|
let body =
|
||||||
|
reqwest::get("https://git.dormedas.com/api/v1/repos/dormedas/town-of-us-updater/releases");
|
||||||
|
let root: serde_json::Value = serde_json::from_str(&body.await?.text().await?).unwrap();
|
||||||
|
|
||||||
|
for i in root.as_array().unwrap() {
|
||||||
|
let tag_name = i["tag_name"].as_str().unwrap();
|
||||||
|
if let Some(trimmed_str) = tag_name.strip_prefix('v') {
|
||||||
|
let mut vers = trimmed_str.split('.');
|
||||||
|
let tag_major_ver = vers.next().unwrap().parse::<i32>().unwrap();
|
||||||
|
let tag_minor_ver = vers.next().unwrap().parse::<i32>().unwrap();
|
||||||
|
let tag_patch_ver = vers.next().unwrap().parse::<i32>().unwrap();
|
||||||
|
if tag_major_ver > major_ver
|
||||||
|
|| (tag_major_ver == major_ver && tag_minor_ver > minor_ver)
|
||||||
|
|| (tag_major_ver == major_ver
|
||||||
|
&& tag_minor_ver == minor_ver
|
||||||
|
&& tag_patch_ver > patch_ver)
|
||||||
|
{
|
||||||
|
println!("New version of the updater detected!");
|
||||||
|
}
|
||||||
|
println!("{}", trimmed_str);
|
||||||
|
} else {
|
||||||
|
let mut vers = tag_name.split('.');
|
||||||
|
let tag_major_ver = vers.next().unwrap().parse::<i32>().unwrap();
|
||||||
|
let tag_minor_ver = vers.next().unwrap().parse::<i32>().unwrap();
|
||||||
|
let tag_patch_ver = vers.next().unwrap().parse::<i32>().unwrap();
|
||||||
|
if tag_major_ver > major_ver
|
||||||
|
|| (tag_major_ver == major_ver && tag_minor_ver > minor_ver)
|
||||||
|
|| (tag_major_ver == major_ver
|
||||||
|
&& tag_minor_ver == minor_ver
|
||||||
|
&& tag_patch_ver > patch_ver)
|
||||||
|
{
|
||||||
|
println!("New version of the updater detected!");
|
||||||
|
}
|
||||||
|
println!("{}", i["tag_name"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((String::from("no"), String::from("yes")))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let version = env!("CARGO_PKG_VERSION");
|
||||||
|
println!("Updater Version: {}", version);
|
||||||
|
get_latest_updater_version().await.unwrap();
|
||||||
|
//let _version_check_thread_handle = thread::spawn(move || get_latest_updater_version());
|
||||||
|
|
||||||
// CREATE PROGRAM DIRECTORY
|
// CREATE PROGRAM DIRECTORY
|
||||||
let mut data_path = dirs::data_dir().unwrap();
|
let mut data_path = dirs::data_dir().unwrap();
|
||||||
data_path.push("town-of-us-updater");
|
data_path.push("town-of-us-updater");
|
||||||
@@ -79,28 +135,42 @@ 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();
|
||||||
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 {
|
} 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 folder_opt = detect_among_us_folder();
|
||||||
let open_window = win.open_file(&ui);
|
if folder_opt.is_some() {
|
||||||
// println!("{}", open_window.unwrap().to_str().unwrap());
|
among_us_folder.push(folder_opt.unwrap());
|
||||||
among_us_folder = open_window.unwrap().clone();
|
} else {
|
||||||
among_us_folder.pop();
|
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());
|
println!("Among Us Folder: {}", among_us_folder.to_str().unwrap());
|
||||||
@@ -108,15 +178,22 @@ fn main() {
|
|||||||
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, bool) =
|
let ver_url: (String, String, bool) =
|
||||||
determine_town_of_us_url(among_us_version.clone()).unwrap();
|
determine_town_of_us_url(among_us_version.to_string().clone())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let version_smash = format!("{}-{}", among_us_version.clone(), ver_url.0.clone());
|
let version_smash = format!(
|
||||||
|
"{}-{}",
|
||||||
|
among_us_version.to_string().clone(),
|
||||||
|
ver_url.0.clone()
|
||||||
|
);
|
||||||
let new_installed_path: path::PathBuf =
|
let new_installed_path: path::PathBuf =
|
||||||
[installs_path.to_str().unwrap(), version_smash.as_str()]
|
[installs_path.to_str().unwrap(), version_smash.as_str()]
|
||||||
.iter()
|
.iter()
|
||||||
.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(),
|
||||||
@@ -134,7 +211,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()
|
||||||
);
|
);
|
||||||
@@ -149,8 +226,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()
|
||||||
@@ -186,12 +263,22 @@ fn main() {
|
|||||||
|
|
||||||
match install_iter {
|
match install_iter {
|
||||||
Ok(iter) => {
|
Ok(iter) => {
|
||||||
let mut collection: Vec<Result<fs::DirEntry, io::Error>> = iter.collect();
|
let mut collection: Vec<Result<fs::DirEntry, std::io::Error>> = iter.collect();
|
||||||
collection.reverse();
|
collection.reverse();
|
||||||
for i in collection {
|
for i in collection {
|
||||||
// for i in iter {
|
// for i in iter {
|
||||||
let existing_ver_smash = i.unwrap().file_name();
|
let existing_ver_smash = i.unwrap().file_name();
|
||||||
let mut button = Button::new(&ui, existing_ver_smash.clone().to_str().unwrap());
|
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 mut button = Button::new(&ui, button_string.as_str());
|
||||||
button.on_clicked(&ui, {
|
button.on_clicked(&ui, {
|
||||||
let ui = ui.clone();
|
let ui = ui.clone();
|
||||||
let installs_path = installs_path.clone();
|
let installs_path = installs_path.clone();
|
||||||
@@ -201,16 +288,28 @@ fn main() {
|
|||||||
new_path.push(existing_ver_smash.clone());
|
new_path.push(existing_ver_smash.clone());
|
||||||
println!("{}", new_path.clone().to_str().unwrap());
|
println!("{}", new_path.clone().to_str().unwrap());
|
||||||
attempt_run_among_us(&new_path);
|
attempt_run_among_us(&new_path);
|
||||||
btn.set_text(&ui, "Launching...");
|
btn.set_text(&ui, "Launching Among Us...");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
vbox.append(&ui, button, LayoutStrategy::Stretchy);
|
group_vbox.append(&ui, button, LayoutStrategy::Stretchy);
|
||||||
|
group.set_child(&ui, group_vbox);
|
||||||
|
vbox.append(&ui, group, LayoutStrategy::Stretchy);
|
||||||
println!("{}", existing_ver_smash.clone().to_str().unwrap());
|
println!("{}", existing_ver_smash.clone().to_str().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
win.set_child(&ui, vbox);
|
win.set_child(&ui, vbox);
|
||||||
win.show(&ui);
|
win.show(&ui);
|
||||||
ui.main();
|
ui.main();
|
||||||
@@ -231,21 +330,22 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns (Version, URL)
|
// Returns (Version, URL)
|
||||||
fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String, bool)> {
|
async fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String, bool)> {
|
||||||
let markdown = reqwest::blocking::get(
|
let markdown =
|
||||||
"https://raw.githubusercontent.com/eDonnes124/Town-Of-Us-R/master/README.md",
|
reqwest::get("https://raw.githubusercontent.com/eDonnes124/Town-Of-Us-R/master/README.md")
|
||||||
)
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.text()
|
.text()
|
||||||
.unwrap();
|
.await
|
||||||
|
.unwrap();
|
||||||
let mut line = markdown.find(&among_us_version);
|
let mut line = markdown.find(&among_us_version);
|
||||||
let mut line_offset = 0;
|
let mut line_offset = 0;
|
||||||
let mut official_compatibility = false;
|
let mut official_compatibility = false;
|
||||||
if line.is_some() {
|
if line.is_some() {
|
||||||
println!("Found official version!");
|
println!("Found sanctioned version!");
|
||||||
official_compatibility = true;
|
official_compatibility = true;
|
||||||
} else {
|
} else {
|
||||||
println!("Official version cannot be determined, installing experimental latest...");
|
println!("Sanctioned version cannot be determined, installing experimental latest...");
|
||||||
line = markdown.find("[Download]");
|
line = markdown.find("[Download]");
|
||||||
line_offset = 15;
|
line_offset = 15;
|
||||||
// println!("At this point, there are two options:");
|
// println!("At this point, there are two options:");
|
||||||
@@ -273,7 +373,7 @@ fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String,
|
|||||||
let captures = url_regex.captures(splits.1).unwrap();
|
let captures = url_regex.captures(splits.1).unwrap();
|
||||||
let capture = captures.get(captures.len() - 1).unwrap();
|
let capture = captures.get(captures.len() - 1).unwrap();
|
||||||
let url = splits.1.get(capture.start()..capture.end()).unwrap();
|
let url = splits.1.get(capture.start()..capture.end()).unwrap();
|
||||||
println!("Official URL is: {}", url);
|
println!("Mod URL is: {}", url);
|
||||||
let ver_regex = Regex::new(r#"\| (v\d\.\d\.\d) \|"#).unwrap();
|
let ver_regex = Regex::new(r#"\| (v\d\.\d\.\d) \|"#).unwrap();
|
||||||
let ver_captures = ver_regex.captures(splits.1).unwrap();
|
let ver_captures = ver_regex.captures(splits.1).unwrap();
|
||||||
let ver_capture = ver_captures.get(ver_captures.len() - 1).unwrap();
|
let ver_capture = ver_captures.get(ver_captures.len() - 1).unwrap();
|
||||||
@@ -281,11 +381,11 @@ fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String,
|
|||||||
.1
|
.1
|
||||||
.get(ver_capture.start()..ver_capture.end())
|
.get(ver_capture.start()..ver_capture.end())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("Matching version is: {}", ver);
|
println!("Installing version: {}", ver);
|
||||||
Some((String::from(ver), String::from(url), official_compatibility))
|
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<AmongUsVersion> {
|
||||||
let asset_file = format!("{}\\Among Us_Data\\globalgamemanagers", folder_root);
|
let asset_file = format!("{}\\Among Us_Data\\globalgamemanagers", folder_root);
|
||||||
|
|
||||||
const TARGET_BYTES_LEN: usize = 16;
|
const TARGET_BYTES_LEN: usize = 16;
|
||||||
@@ -324,20 +424,18 @@ fn determine_among_us_version(folder_root: String) -> Option<String> {
|
|||||||
// offset -= 1;
|
// offset -= 1;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
println!(
|
// println!(
|
||||||
"|{}|",
|
// "|{}|",
|
||||||
str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap()
|
// str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap()
|
||||||
);
|
// );
|
||||||
let ver = AmongUsVersion::from(
|
let ver = AmongUsVersion::from(
|
||||||
str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap(),
|
str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap(),
|
||||||
);
|
);
|
||||||
println!("AmongUsVersion: {}", ver);
|
println!("AmongUsVersion: {}", ver);
|
||||||
Some(String::from(
|
Some(ver)
|
||||||
str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap(),
|
// Some(String::from(
|
||||||
))
|
// str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap(),
|
||||||
//println!("{}", bytes_str);
|
// ))
|
||||||
|
|
||||||
//None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_folder_to_target<T: AsRef<path::Path>>(source: T, dest: T) {
|
fn copy_folder_to_target<T: AsRef<path::Path>>(source: T, dest: T) {
|
||||||
@@ -358,6 +456,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, ©_opts).unwrap();
|
fs_extra::dir::copy(source, dest, ©_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");
|
||||||
|
|||||||
Reference in New Issue
Block a user