Bumped version to 1.0.0, started work on update infrastructure

This commit is contained in:
2022-07-20 09:26:22 -07:00
parent 179a2a321d
commit 3150019b76
2 changed files with 44 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "town-of-us-updater" name = "town-of-us-updater"
version = "0.1.0" version = "1.0.0"
edition = "2021" edition = "2021"
# 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 +12,4 @@ 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"

View File

@@ -9,12 +9,23 @@ 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,
day: 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<Ordering> {}
// }
impl fmt::Display for AmongUsVersion { impl fmt::Display for AmongUsVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}.{}", self.year, self.month, self.day) 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(); 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() { fn main() {
let version = env!("CARGO_PKG_VERSION");
println!("Program Version: {}", version);
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");
@@ -108,9 +138,13 @@ 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()).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()
@@ -186,7 +220,7 @@ 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 {
@@ -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)) 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;
@@ -332,12 +366,10 @@ fn determine_among_us_version(folder_root: String) -> Option<String> {
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) {