aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/platform_specific
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2022-12-02 00:07:31 +0100
committerGitHub <noreply@github.com>2022-12-02 00:07:31 +0100
commit7f3ea9cf512a613d42422a2dde959165976b48bd (patch)
treeb9db5a5f0f8382063e61b0c42d75ab90c95b8bbe /src-tauri/src/platform_specific
parent0ffbf9762dd10a1cf327901afa3792128f04b892 (diff)
downloadFlightCore-7f3ea9cf512a613d42422a2dde959165976b48bd.tar.gz
FlightCore-7f3ea9cf512a613d42422a2dde959165976b48bd.zip
fix: Stop opening PS to get Origin game path (#99)
Now using a library instead of calling a PowerShell command should prevent the PowerShell window from opening.
Diffstat (limited to 'src-tauri/src/platform_specific')
-rw-r--r--src-tauri/src/platform_specific/windows.rs53
1 files changed, 25 insertions, 28 deletions
diff --git a/src-tauri/src/platform_specific/windows.rs b/src-tauri/src/platform_specific/windows.rs
index 2803bf05..ad2ba6df 100644
--- a/src-tauri/src/platform_specific/windows.rs
+++ b/src-tauri/src/platform_specific/windows.rs
@@ -1,39 +1,36 @@
/// Windows specific code
-use powershell_script::PsScriptBuilder;
-use regex::Regex;
-
use anyhow::{anyhow, Result};
use crate::check_is_valid_game_path;
+const TITANFALL2_ORIGIN_IDS: [&str; 2] = ["Origin.OFR.50.0001452", "Origin.OFR.50.0001456"];
+
/// Runs a powershell command and parses output to get Titanfall2 install location on Origin
pub fn origin_install_location_detection() -> Result<String, anyhow::Error> {
- dbg!();
-
- // Run PowerShell command to get Titanfall2 Origin install path
- let ps = PsScriptBuilder::new()
- .no_profile(true)
- .non_interactive(true)
- .hidden(false)
- .print_commands(false)
- .build();
- let output = ps.run(r#"Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Respawn\Titanfall2\ -Name "Install Dir""#).unwrap();
-
- // Get command output as string
- let string = output.stdout().unwrap();
-
- // Regex the result out and return value accordingly
- let regex = Regex::new(r"(?m)Install Dir.+: (.+)\r\n").unwrap();
- let mut result = regex.captures_iter(&string);
- match result.next() {
- Some(mat) => {
- let game_path = mat.get(1).map_or("", |m| m.as_str());
- println!("{}", game_path);
- match check_is_valid_game_path(game_path) {
- Ok(()) => return Ok(game_path.to_owned()),
- Err(err) => Err(err),
+ // Iterate over known Titanfall2 Origin IDs
+ for origin_id in TITANFALL2_ORIGIN_IDS {
+ match game_scanner::origin::find(origin_id) {
+ // Origin ID found as installed game
+ Ok(game) => {
+ if game.path.is_some() {
+ let game_path = game.path.unwrap();
+ let game_path_str = game_path.to_str().unwrap();
+ match check_is_valid_game_path(game_path_str) {
+ Ok(()) => {
+ return Ok(game_path_str.to_string());
+ }
+ Err(err) => {
+ println!("{}", err.to_string());
+ continue; // Not a valid game path
+ }
+ }
+ }
+ }
+ Err(err) => {
+ println!("Couldn't find {origin_id}: {err}")
}
}
- None => Err(anyhow!("No Origin install path found")),
}
+
+ Err(anyhow!("No Origin install path found"))
}