Updated version check logic. Still un-implemented

This commit is contained in:
2022-07-26 22:12:30 -07:00
parent 86d1e176d4
commit 0b940aea70

View File

@@ -1,5 +1,6 @@
use std::path::{Path, PathBuf};
use std::str;
use std::thread;
use std::*;
use fs_extra::{copy_items, dir};
@@ -63,14 +64,49 @@ fn unmod_among_us_folder(folder_path: &Path) {
}
fn get_latest_updater_version() -> (String, String) {
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::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"]);
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"]);
}
}
(String::from("no"), String::from("yes"))
@@ -79,8 +115,7 @@ fn get_latest_updater_version() -> (String, String) {
fn main() {
let version = env!("CARGO_PKG_VERSION");
println!("Updater Version: {}", version);
//get_latest_updater_version();
let _version_check_thread_handle = thread::spawn(move || get_latest_updater_version());
// CREATE PROGRAM DIRECTORY
let mut data_path = dirs::data_dir().unwrap();
@@ -256,6 +291,16 @@ fn main() {
_ => (),
}
// 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.show(&ui);
ui.main();