diff options
Diffstat (limited to 'src-tauri')
-rw-r--r-- | src-tauri/src/lib.rs | 25 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 6 |
2 files changed, 24 insertions, 7 deletions
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 5971f421..916a78ed 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,9 +1,10 @@ use anyhow::{anyhow, Context, Result}; use powershell_script::PsScriptBuilder; use regex::Regex; +use serde::{Deserialize, Serialize}; use zip::ZipArchive; -#[derive(Debug)] +#[derive(Serialize, Deserialize, Debug)] pub enum InstallType { STEAM, ORIGIN, @@ -11,6 +12,12 @@ pub enum InstallType { UNKNOWN, } +#[derive(Serialize, Deserialize, Debug)] +pub struct GameInstall { + game_path: String, + install_type: InstallType, +} + /// Check version number of a mod pub fn check_mod_version_number(path_to_mod_folder: String) -> Result<String, anyhow::Error> { // println!("{}", format!("{}/mod.json", path_to_mod_folder)); @@ -61,7 +68,7 @@ fn windows_origin_install_location_detection() -> Result<String, anyhow::Error> } /// Attempts to find the game install location -pub fn find_game_install_location() -> Result<(String, InstallType), anyhow::Error> { +pub fn find_game_install_location() -> Result<GameInstall, anyhow::Error> { // Attempt parsing Steam library directly match steamlocate::SteamDir::locate() { Some(mut steamdir) => { @@ -69,7 +76,11 @@ pub fn find_game_install_location() -> Result<(String, InstallType), anyhow::Err match steamdir.app(&titanfall2_steamid) { Some(app) => { // println!("{:#?}", app); - return Ok((app.path.to_str().unwrap().to_string(), InstallType::STEAM)); + let game_install = GameInstall { + game_path: app.path.to_str().unwrap().to_string(), + install_type: InstallType::STEAM, + }; + return Ok(game_install); } None => println!("Couldn't locate Titanfall2"), } @@ -80,7 +91,13 @@ pub fn find_game_install_location() -> Result<(String, InstallType), anyhow::Err // (On Windows only) try parsing Windows registry for Origin install path #[cfg(target_os = "windows")] match windows_origin_install_location_detection() { - Ok(game_path) => return Ok((game_path, InstallType::ORIGIN)), + Ok(game_path) => { + let game_install = GameInstall { + game_path: game_path, + install_type: InstallType::ORIGIN, + }; + return Ok(game_install); + } Err(err) => { println!("{}", err); } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 34caddc7..2ba190bb 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -11,7 +11,7 @@ use std::{ use app::{ check_is_valid_game_path, find_game_install_location, get_northstar_version_number, - install_northstar, + install_northstar, GameInstall, }; use tauri::{Manager, State}; use tokio::time::sleep; @@ -63,9 +63,9 @@ fn main() { #[tauri::command] /// Wrapper for `find_game_install_location` as tauri doesn't allow passing `Result<>` types to front-end -fn find_game_install_location_caller() -> Result<String, String> { +fn find_game_install_location_caller() -> Result<GameInstall, String> { match find_game_install_location() { - Ok((path, install_type)) => Ok(path), + Ok(game_install) => Ok(game_install), Err(err) => { println!("{}", err); Err(err.to_string()) |