diff --git a/src/app.rs b/src/app.rs index 946438f..b9c1f8a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,6 +1,6 @@ use core::time; -use self::util::{apply_launcher_pr, apply_mods_pr}; +use self::util::{apply_launcher_pr, apply_mods_pr, find_game_install_path}; use self_update::cargo_crate_version; mod util; @@ -96,6 +96,25 @@ impl eframe::App for TemplateApp { ui.label("Titanfall2 install location:"); ui.text_edit_singleline(game_install_path); + if ui.button("Try detect install path").clicked() { + match find_game_install_path() { + Ok(found_install_path) => { + println!("Found install at {}", found_install_path); + *game_install_path = found_install_path; + } + Err(err) => { + println!("{}", err); + egui::Frame::popup(ui.style()).show(ui, |ui| { + ui.label( + egui::RichText::new(format!("Error: {}", err)) + .color(egui::Color32::RED), + ); + }); + + *value = 1; + } + } + } ui.label(""); // simple spacer diff --git a/src/app/util.rs b/src/app/util.rs index c6b9746..a6c8227 100644 --- a/src/app/util.rs +++ b/src/app/util.rs @@ -347,6 +347,28 @@ fn check_game_path(game_install_path: &str) -> Result<(), anyhow::Error> { Ok(()) } +/// Tries to find the game install location. In its current form it only checks a few hardcoded locations +pub fn find_game_install_path() -> Result { + // List of predefined install locations + // Parsing VDF for Steam and Windows registry for Origin would be nicer + // but requires a lot more investigation on how to do that exactly. + let potential_locations = [ + "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Titanfall2", // Default Steam + "C:\\Program Files (x86)\\Origin Games\\Titanfall2", // Default Origin + "C:\\Program Files\\EA Games\\Titanfall2", // Default EA Play + ]; + + for location in potential_locations { + // Check if valid folder and valid Titanfall2 install path + if std::path::Path::new(location).exists() && check_game_path(location).is_ok() { + return Ok(location.to_string()); + } + } + return Err(anyhow!( + "Could not auto-detect game install location! Please enter it manually." + )); +} + pub fn apply_launcher_pr( pr_number: i64, game_install_path: &str,