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

Commit

Permalink
Add naive game path detection
Browse files Browse the repository at this point in the history
  • Loading branch information
GeckoEidechse committed Aug 9, 2022
1 parent 7b1b9a2 commit 6efcdfb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions src/app/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, anyhow::Error> {
// 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,
Expand Down

0 comments on commit 6efcdfb

Please sign in to comment.