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

@@ -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<Ordering> {}
// }
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<Result<fs::DirEntry, io::Error>> = iter.collect();
let mut collection: Vec<Result<fs::DirEntry, std::io::Error>> = 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<String> {
fn determine_among_us_version(folder_root: String) -> Option<AmongUsVersion> {
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<String> {
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<T: AsRef<path::Path>>(source: T, dest: T) {