diff options
author | Rémy Raes <contact@remyraes.com> | 2022-09-24 19:01:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-24 19:01:33 +0200 |
commit | 5bf2254204692066fbd5774097b1e3fbc33d0157 (patch) | |
tree | 73652a5b6b0245aa81a9ce30451165207ac868f5 /src-tauri/src/platform_specific | |
parent | bdba63fa033a9f98d63951ec0cf9109f7949f444 (diff) | |
parent | 94979acb5d62fc5a0498b8d0170308511972fbb7 (diff) | |
download | FlightCore-5bf2254204692066fbd5774097b1e3fbc33d0157.tar.gz FlightCore-5bf2254204692066fbd5774097b1e3fbc33d0157.zip |
Merge branch 'GeckoEidechse:main' into feat/new-ui
Diffstat (limited to 'src-tauri/src/platform_specific')
-rw-r--r-- | src-tauri/src/platform_specific/mod.rs | 2 | ||||
-rw-r--r-- | src-tauri/src/platform_specific/windows.rs | 40 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src-tauri/src/platform_specific/mod.rs b/src-tauri/src/platform_specific/mod.rs new file mode 100644 index 00000000..581af77f --- /dev/null +++ b/src-tauri/src/platform_specific/mod.rs @@ -0,0 +1,2 @@ +#[cfg(target_os = "windows")] +pub mod windows; diff --git a/src-tauri/src/platform_specific/windows.rs b/src-tauri/src/platform_specific/windows.rs new file mode 100644 index 00000000..7627fe4f --- /dev/null +++ b/src-tauri/src/platform_specific/windows.rs @@ -0,0 +1,40 @@ +/// Windows specific code + +use powershell_script::PsScriptBuilder; +use regex::Regex; + +use anyhow::{anyhow, Result}; + +use crate::check_is_valid_game_path; + +/// 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), + } + } + None => Err(anyhow!("No Origin install path found")), + } +} |