diff --git a/Cargo.toml b/Cargo.toml index 76770a1..7490e5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "town-of-us-updater" -version = "0.1.0" +version = "1.0.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -12,3 +12,4 @@ fs_extra = "1.2.0" dirs = "4.0.0" reqwest = {version = "0.11.11", features = ["blocking"]} iui = "0.3.0" +serde_json = "1.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 18e1a5d..c90367c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,12 +9,23 @@ use regex::Regex; static AMONG_US_APPID: &'static str = "945360"; +#[derive(Ord, PartialOrd, Eq, PartialEq)] struct AmongUsVersion { year: i32, month: i32, day: i32, } +// impl Ord for AmongUsVersion { +// fn cmp(&self, other: &Self) -> Ordering { +// (self.year, self.month, self.day).cmp(&(other.year, other.month, other.day)) +// } +// } + +// impl PartialOrd for AmongUsVersion { +// fn partial_cmp(&self, other: &Self) -> Option {} +// } + impl fmt::Display for AmongUsVersion { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}.{}.{}", self.year, self.month, self.day) @@ -61,7 +72,26 @@ fn unmod_among_us_folder(folder_path: &Path) { fs::remove_dir_all(mono_path).unwrap_or_default(); } +fn get_latest_updater_version() -> (String, String) { + let body = reqwest::blocking::get( + "https://git.dormedas.com/api/v1/repos/dormedas/town-of-us-updater/releases", + ); + + let root: serde_json::Value = serde_json::from_str(&body.unwrap().text().unwrap()).unwrap(); + + for i in root.as_array().unwrap() { + println!("{}", i["id"]); + } + + (String::from("no"), String::from("yes")) +} + fn main() { + let version = env!("CARGO_PKG_VERSION"); + println!("Program Version: {}", version); + + get_latest_updater_version(); + // CREATE PROGRAM DIRECTORY let mut data_path = dirs::data_dir().unwrap(); data_path.push("town-of-us-updater"); @@ -108,9 +138,13 @@ fn main() { let among_us_version = determine_among_us_version(String::from(among_us_folder.to_str().unwrap())).unwrap(); 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()).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 = [installs_path.to_str().unwrap(), version_smash.as_str()] .iter() @@ -186,7 +220,7 @@ fn main() { match install_iter { Ok(iter) => { - let mut collection: Vec> = iter.collect(); + let mut collection: Vec> = iter.collect(); collection.reverse(); for i in collection { // for i in iter { @@ -285,7 +319,7 @@ fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String, Some((String::from(ver), String::from(url), official_compatibility)) } -fn determine_among_us_version(folder_root: String) -> Option { +fn determine_among_us_version(folder_root: String) -> Option { let asset_file = format!("{}\\Among Us_Data\\globalgamemanagers", folder_root); const TARGET_BYTES_LEN: usize = 16; @@ -332,12 +366,10 @@ fn determine_among_us_version(folder_root: String) -> Option { str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap(), ); println!("AmongUsVersion: {}", ver); - Some(String::from( - str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap(), - )) - //println!("{}", bytes_str); - - //None + Some(ver) + // Some(String::from( + // str::from_utf8(file_bytes.get(file_index..file_index + offset).unwrap()).unwrap(), + // )) } fn copy_folder_to_target>(source: T, dest: T) {