diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2023-05-13 12:56:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-13 12:56:44 +0200 |
commit | ec0f0a92f8387f4c6d8b314536bc3acdcae56c66 (patch) | |
tree | eeaabaa747370b75acf17682ef182cdd36835c87 /src-tauri/src | |
parent | d64f51f7cfb69407c8e5e572f7560e9c5e8dbbbe (diff) | |
download | FlightCore-ec0f0a92f8387f4c6d8b314536bc3acdcae56c66.tar.gz FlightCore-ec0f0a92f8387f4c6d8b314536bc3acdcae56c66.zip |
refactor: Move `find_game_install_location` to submodule (#350)
Diffstat (limited to 'src-tauri/src')
-rw-r--r-- | src-tauri/src/main.rs | 43 | ||||
-rw-r--r-- | src-tauri/src/northstar/install.rs | 45 |
2 files changed, 45 insertions, 43 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index d3aa3e04..7cff8f33 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -203,7 +203,7 @@ fn main() { /// Wrapper for `find_game_install_location` as tauri doesn't allow passing `Result<>` types to front-end #[tauri::command] async fn find_game_install_location_caller() -> Result<GameInstall, String> { - find_game_install_location() + northstar::install::find_game_install_location() } /// Returns true if linux compatible @@ -502,8 +502,6 @@ use anyhow::{Context, Result}; pub mod constants; mod platform_specific; -#[cfg(target_os = "windows")] -use platform_specific::windows; #[cfg(target_os = "linux")] use platform_specific::linux; @@ -559,45 +557,6 @@ pub fn linux_checks_librs() -> Result<(), String> { Ok(()) } -/// Attempts to find the game install location -pub fn find_game_install_location() -> Result<GameInstall, String> { - // Attempt parsing Steam library directly - match steamlocate::SteamDir::locate() { - Some(mut steamdir) => { - let titanfall2_steamid = TITANFALL2_STEAM_ID.parse().unwrap(); - match steamdir.app(&titanfall2_steamid) { - Some(app) => { - // println!("{:#?}", app); - let game_install = GameInstall { - game_path: app.path.to_str().unwrap().to_string(), - install_type: InstallType::STEAM, - }; - return Ok(game_install); - } - None => log::info!("Couldn't locate Titanfall2 Steam install"), - } - } - None => log::info!("Couldn't locate Steam on this computer!"), - } - - // (On Windows only) try parsing Windows registry for Origin install path - #[cfg(target_os = "windows")] - match windows::origin_install_location_detection() { - Ok(game_path) => { - let game_install = GameInstall { - game_path, - install_type: InstallType::ORIGIN, - }; - return Ok(game_install); - } - Err(err) => { - log::info!("{}", err); - } - }; - - Err("Could not auto-detect game install location! Please enter it manually.".to_string()) -} - /// Checks whether the provided path is a valid Titanfall2 gamepath by checking against a certain set of criteria pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> { let path_to_titanfall2_exe = format!("{game_install_path}/Titanfall2.exe"); diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs index 7de49eb5..94029350 100644 --- a/src-tauri/src/northstar/install.rs +++ b/src-tauri/src/northstar/install.rs @@ -4,7 +4,11 @@ use std::time::Duration; use std::{cell::RefCell, time::Instant}; use ts_rs::TS; -use crate::extract; +use crate::constants::TITANFALL2_STEAM_ID; +use crate::{extract, GameInstall, InstallType}; + +#[cfg(target_os = "windows")] +use crate::platform_specific::windows; #[derive(Serialize, Deserialize, Debug, Clone, TS)] #[ts(export)] @@ -142,3 +146,42 @@ pub async fn install_northstar( Ok(nmod.latest.clone()) } + +/// Attempts to find the game install location +pub fn find_game_install_location() -> Result<GameInstall, String> { + // Attempt parsing Steam library directly + match steamlocate::SteamDir::locate() { + Some(mut steamdir) => { + let titanfall2_steamid = TITANFALL2_STEAM_ID.parse().unwrap(); + match steamdir.app(&titanfall2_steamid) { + Some(app) => { + // println!("{:#?}", app); + let game_install = GameInstall { + game_path: app.path.to_str().unwrap().to_string(), + install_type: InstallType::STEAM, + }; + return Ok(game_install); + } + None => log::info!("Couldn't locate Titanfall2 Steam install"), + } + } + None => log::info!("Couldn't locate Steam on this computer!"), + } + + // (On Windows only) try parsing Windows registry for Origin install path + #[cfg(target_os = "windows")] + match windows::origin_install_location_detection() { + Ok(game_path) => { + let game_install = GameInstall { + game_path, + install_type: InstallType::ORIGIN, + }; + return Ok(game_install); + } + Err(err) => { + log::info!("{}", err); + } + }; + + Err("Could not auto-detect game install location! Please enter it manually.".to_string()) +} |