diff options
author | GeckoEidechse <gecko.eidechse+git@pm.me> | 2022-09-10 18:36:10 +0200 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2022-09-10 18:36:10 +0200 |
commit | 80b8b2c318fbb04853a813c438c896a4b2f8b37d (patch) | |
tree | deebbe224307a6d78948a6c2c2e5c8dfcf3540a9 | |
parent | 578516b2bcbfa2c80e02d51951d99e3083360749 (diff) | |
download | FlightCore-80b8b2c318fbb04853a813c438c896a4b2f8b37d.tar.gz FlightCore-80b8b2c318fbb04853a813c438c896a4b2f8b37d.zip |
Return GameInstall object instead of tuple
The object contains the path Titanfall2 is installed in, as well as how
it was installed (Steam, Origin, EA-App)
-rw-r--r-- | src-tauri/src/lib.rs | 25 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 6 | ||||
-rw-r--r-- | src-ui/src/main.ts | 13 |
3 files changed, 34 insertions, 10 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()) diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts index 61fec575..24c9f04a 100644 --- a/src-ui/src/main.ts +++ b/src-ui/src/main.ts @@ -11,6 +11,11 @@ const button_in_update_string = "Updating..."; const button_play_string = "Launch Northstar"; const button_manual_find_string = "Manually select Titanfall2 install location"; +interface GameInstall { + game_path: string; + install_type: number; + } + // Stores the overall state of the application var globalState = { gamepath: "", @@ -181,13 +186,15 @@ document.addEventListener("DOMContentLoaded", async function () { // Get install location await invoke("find_game_install_location_caller", { gamePath: globalState.gamepath }) - .then((game_path) => { + .then((game_install) => { // Found some gamepath - console.log(game_path); + console.log(game_install); + + let game_install_obj = game_install as GameInstall; // Change omni-button content based on whether game install was found - let game_path_str = game_path as string + let game_path_str = game_install_obj.game_path as string omniButtonEl.textContent = button_install_string; installLocationHolderEl.value = game_path_str; globalState.gamepath = game_path_str; |