From 80b8b2c318fbb04853a813c438c896a4b2f8b37d Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Sat, 10 Sep 2022 18:36:10 +0200 Subject: 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) --- src-tauri/src/lib.rs | 25 +++++++++++++++++++++---- src-tauri/src/main.rs | 6 +++--- 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 { // println!("{}", format!("{}/mod.json", path_to_mod_folder)); @@ -61,7 +68,7 @@ fn windows_origin_install_location_detection() -> Result } /// 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 { // 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 { +fn find_game_install_location_caller() -> Result { 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; -- cgit v1.2.3