Skip to content
This repository was archived by the owner on Apr 21, 2023. It is now read-only.

Commit 6efcdfb

Browse files
committed
Add naive game path detection
1 parent 7b1b9a2 commit 6efcdfb

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/app.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::time;
22

3-
use self::util::{apply_launcher_pr, apply_mods_pr};
3+
use self::util::{apply_launcher_pr, apply_mods_pr, find_game_install_path};
44
use self_update::cargo_crate_version;
55

66
mod util;
@@ -96,6 +96,25 @@ impl eframe::App for TemplateApp {
9696

9797
ui.label("Titanfall2 install location:");
9898
ui.text_edit_singleline(game_install_path);
99+
if ui.button("Try detect install path").clicked() {
100+
match find_game_install_path() {
101+
Ok(found_install_path) => {
102+
println!("Found install at {}", found_install_path);
103+
*game_install_path = found_install_path;
104+
}
105+
Err(err) => {
106+
println!("{}", err);
107+
egui::Frame::popup(ui.style()).show(ui, |ui| {
108+
ui.label(
109+
egui::RichText::new(format!("Error: {}", err))
110+
.color(egui::Color32::RED),
111+
);
112+
});
113+
114+
*value = 1;
115+
}
116+
}
117+
}
99118

100119
ui.label(""); // simple spacer
101120

src/app/util.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,28 @@ fn check_game_path(game_install_path: &str) -> Result<(), anyhow::Error> {
347347
Ok(())
348348
}
349349

350+
/// Tries to find the game install location. In its current form it only checks a few hardcoded locations
351+
pub fn find_game_install_path() -> Result<String, anyhow::Error> {
352+
// List of predefined install locations
353+
// Parsing VDF for Steam and Windows registry for Origin would be nicer
354+
// but requires a lot more investigation on how to do that exactly.
355+
let potential_locations = [
356+
"C:\\Program Files (x86)\\Steam\\steamapps\\common\\Titanfall2", // Default Steam
357+
"C:\\Program Files (x86)\\Origin Games\\Titanfall2", // Default Origin
358+
"C:\\Program Files\\EA Games\\Titanfall2", // Default EA Play
359+
];
360+
361+
for location in potential_locations {
362+
// Check if valid folder and valid Titanfall2 install path
363+
if std::path::Path::new(location).exists() && check_game_path(location).is_ok() {
364+
return Ok(location.to_string());
365+
}
366+
}
367+
return Err(anyhow!(
368+
"Could not auto-detect game install location! Please enter it manually."
369+
));
370+
}
371+
350372
pub fn apply_launcher_pr(
351373
pr_number: i64,
352374
game_install_path: &str,

0 commit comments

Comments
 (0)