Skip to content

Commit

Permalink
ui, add download options
Browse files Browse the repository at this point in the history
  • Loading branch information
djkato committed Apr 24, 2023
1 parent b99b669 commit cdeb14a
Showing 1 changed file with 100 additions and 44 deletions.
144 changes: 100 additions & 44 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LocalFoundApp> = 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<LocalFoundApp>) -> Result<(), eframe::Error> {
fn create_ui(
installed_apps: Vec<LocalFoundApp>,
online_apps: Vec<OnlineFoundApp>,
) -> 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<LocalFoundApp>,
local_app_list: Vec<LocalFoundApp>,
online_app_list: Vec<OnlineFoundApp>,
}
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() {
Expand All @@ -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<LocalFoundApp>, online_apps: Vec<OnlineFoundApp>) {
fn compare_versions(
installed_apps: &mut Vec<LocalFoundApp>,
online_apps: &mut Vec<OnlineFoundApp>,
) {
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());
Expand All @@ -86,9 +127,11 @@ fn compare_versions(installed_apps: &mut Vec<LocalFoundApp>, online_apps: Vec<On
}

/* SCAPER */
fn find_updates(app_list: &Vec<LocalFoundApp>) -> Vec<OnlineFoundApp> {
let version_regex = Regex::new(r"\(v.*?\)").unwrap();
fn find_online_programs(app_list: &Vec<LocalFoundApp>) -> Vec<OnlineFoundApp> {
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#"<b>Adobe .*<wbr>"#).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| ()),
Expand All @@ -110,49 +153,62 @@ fn find_updates(app_list: &Vec<LocalFoundApp>) -> Vec<OnlineFoundApp> {
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("<wbr>") {
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());
}
}
};
online_apps
}

/* FILE BROWSER */
fn list_installed_adobe_programs() -> Vec<LocalFoundApp> {
fn find_local_programs() -> Vec<LocalFoundApp> {
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) {
Expand Down

0 comments on commit cdeb14a

Please sign in to comment.