From cdeb14a23af570614d468a9f166adaa8ae9fc845 Mon Sep 17 00:00:00 2001 From: djkato Date: Mon, 24 Apr 2023 16:47:06 +0200 Subject: [PATCH] ui, add download options --- src/main.rs | 144 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 100 insertions(+), 44 deletions(-) diff --git a/src/main.rs b/src/main.rs index c1deba6..054e539 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,33 +10,56 @@ use version_compare::Version; use walkdir::WalkDir; fn main() -> Result<(), eframe::Error> { - let mut installed_apps = list_installed_adobe_programs(); - let online_apps = find_updates(&installed_apps); - compare_versions(&mut installed_apps, online_apps); - create_ui(installed_apps) + let mut installed_apps = find_local_programs(); + /*let mut installed_apps: Vec = vec![ + LocalFoundApp { + name: "Adobe After Effects".to_owned(), + version: "1.0.0".to_owned(), + newest_online: None, + }, + LocalFoundApp { + name: "Adobe Premiere Pro".to_owned(), + version: "1.0.0".to_owned(), + newest_online: None, + }, + LocalFoundApp { + name: "Adobe Photoshop".to_owned(), + version: "1.0.0".to_owned(), + newest_online: None, + }, + ];*/ + let mut online_apps = find_online_programs(&installed_apps); + compare_versions(&mut installed_apps, &mut online_apps); + create_ui(installed_apps, online_apps) } -fn create_ui(installed_apps: Vec) -> Result<(), eframe::Error> { +fn create_ui( + installed_apps: Vec, + online_apps: Vec, +) -> Result<(), eframe::Error> { //egui let options = NativeOptions { initial_window_size: Some(egui::vec2(320.0, 240.0)), ..Default::default() }; let app = Box::new(IsaApp { - app_list: installed_apps, - ..Default::default() + local_app_list: installed_apps, + online_app_list: online_apps, }); run_native("Adobe checker", options, Box::new(|_cc| app)) } /* GUI */ #[derive(Default)] struct IsaApp { - app_list: Vec, + local_app_list: Vec, + online_app_list: Vec, } impl App for IsaApp { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { - for local_app in self.app_list.iter() { + ui.heading("Updates"); + ui.separator(); + for local_app in self.local_app_list.iter() { ui.horizontal(|ui| { ui.label(format!("{}:", &local_app.name)); if local_app.newest_online.is_some() { @@ -60,15 +83,33 @@ impl App for IsaApp { } }); } + ui.add_space(20.0); + ui.heading("Online found apps"); + ui.separator(); + egui::ScrollArea::vertical().show(ui, |ui| { + for online_app in self.online_app_list.iter() { + ui.horizontal(|ui| { + ui.label(format!( + "{}, version: {} ", + online_app.name, &online_app.version + )); + ui.hyperlink_to("download", &online_app.magnet); + ui.add_space(ui.available_width()); + }); + } + }); }); } } /* COMPARE VERS */ -fn compare_versions(installed_apps: &mut Vec, online_apps: Vec) { +fn compare_versions( + installed_apps: &mut Vec, + online_apps: &mut Vec, +) { for local_app in installed_apps.iter_mut() { for online_app in online_apps.iter() { - if local_app.name == online_app.name { + if online_app.name.contains(&local_app.name) { if local_app.newest_online.is_none() { if Version::from(&local_app.version) < Version::from(&online_app.version) { local_app.newest_online = Some(online_app.clone()); @@ -86,9 +127,11 @@ fn compare_versions(installed_apps: &mut Vec, online_apps: Vec) -> Vec { - let version_regex = Regex::new(r"\(v.*?\)").unwrap(); +fn find_online_programs(app_list: &Vec) -> Vec { + let version_brackets_regex = Regex::new(r"\(v.*?\)").unwrap(); + let version_bare_regex = Regex::new(r"v[.\d]* ").unwrap(); let magnet_regex = Regex::new(r#"href="magnet:\?xt.*?""#).unwrap(); + let name_regex = Regex::new(r#"Adobe .*"#).unwrap(); //if temp is missing make it, delete previous tracker.php file if there is one match std::fs::read_dir("./temp") { Ok(_) => std::fs::remove_file("./temp/tracker.php").unwrap_or_else(|_e| ()), @@ -110,41 +153,54 @@ fn find_updates(app_list: &Vec) -> Vec { println!(""); let website_file = fs::read_to_string("./temp/tracker.php").unwrap(); for (web_line_i, web_line) in website_file.lines().enumerate() { - for app_name in app_list { - if web_line - .to_ascii_lowercase() - .contains(&app_name.name.to_ascii_lowercase()) - { - let mut version = "".to_owned(); - if let Some(res) = version_regex.find(web_line) { - version = web_line - .get(res.start() + 2..res.end() - 1) - .unwrap() - .to_string(); + if web_line.to_ascii_lowercase().contains("adobe") { + let mut version = "".to_owned(); + let mut name = "".to_owned(); + if let Some(res) = name_regex.find(web_line) { + name = web_line + .get(res.start() + 3..res.end() - 5) + .unwrap() + .to_string(); + } + if let Some(res) = version_brackets_regex.find(web_line) { + version = web_line + .get(res.start() + 2..res.end() - 1) + .unwrap() + .to_string(); + if version.contains("") { + version.pop(); + version.pop(); + version.pop(); + version.pop(); + version.pop(); } + } else if let Some(res) = version_bare_regex.find(&web_line) { + version = web_line + .get(res.start() + 1..res.end() - 1) + .unwrap() + .to_string(); + version = version.trim().to_string(); + } - let mut magnet = "".to_string(); - for magnet_web_line in website_file.lines().skip(web_line_i) { - if magnet_web_line.contains("href=\"magnet:?") { - if let Some(magnet_res) = magnet_regex.find(magnet_web_line) { - magnet = magnet_web_line - .get(magnet_res.start() + 6..magnet_res.end() - 1) - .unwrap() - .to_owned(); - break; - } + let mut magnet = "".to_string(); + for magnet_web_line in website_file.lines().skip(web_line_i) { + if magnet_web_line.contains("href=\"magnet:?") { + if let Some(magnet_res) = magnet_regex.find(magnet_web_line) { + magnet = magnet_web_line + .get(magnet_res.start() + 6..magnet_res.end() - 1) + .unwrap() + .to_owned(); + break; } } - println!( - "App: {}\nVersion: {}\nMagnet:{}\n", - &app_name.name, &version, magnet - ); - online_apps.push(OnlineFoundApp { - name: app_name.name.clone(), - version, - magnet, - }); } + println!("App: {}\nVersion: {}\nMagnet:{}\n", &name, &version, magnet); + let mut online_app = OnlineFoundApp { + name, + magnet, + version, + }; + online_apps.push(online_app.clone()); } } }; @@ -152,7 +208,7 @@ fn find_updates(app_list: &Vec) -> Vec { } /* FILE BROWSER */ -fn list_installed_adobe_programs() -> Vec { +fn find_local_programs() -> Vec { let version_regex = Regex::new(r#""\{\w*-\d*\.\d.*?-64-"#).unwrap(); let mut apps = Vec::new(); for directory_res in WalkDir::new(r"C:\Program Files\Adobe").max_depth(1) {