From 175ff756f706828fc4eb2e9d7782230ef467c062 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Fri, 23 Sep 2022 02:12:40 +0200 Subject: Move platform specific code into separate file --- src-tauri/src/lib.rs | 40 +++--------------------------- src-tauri/src/platform_specific/mod.rs | 1 + src-tauri/src/platform_specific/windows.rs | 40 ++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 src-tauri/src/platform_specific/mod.rs create mode 100644 src-tauri/src/platform_specific/windows.rs (limited to 'src-tauri/src') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f19a178c..ed438ab9 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -2,10 +2,9 @@ use std::env; use anyhow::{anyhow, Context, Result}; +mod platform_specific; #[cfg(target_os = "windows")] -use powershell_script::PsScriptBuilder; -#[cfg(target_os = "windows")] -use regex::Regex; +use platform_specific::windows; use serde::{Deserialize, Serialize}; use sysinfo::SystemExt; @@ -41,39 +40,6 @@ pub fn check_mod_version_number(path_to_mod_folder: String) -> Result Result { - 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")), - } -} - /// Attempts to find the game install location pub fn find_game_install_location() -> Result { // Attempt parsing Steam library directly @@ -97,7 +63,7 @@ pub fn find_game_install_location() -> Result { // (On Windows only) try parsing Windows registry for Origin install path #[cfg(target_os = "windows")] - match windows_origin_install_location_detection() { + match windows::windows_origin_install_location_detection() { Ok(game_path) => { let game_install = GameInstall { game_path: game_path, diff --git a/src-tauri/src/platform_specific/mod.rs b/src-tauri/src/platform_specific/mod.rs new file mode 100644 index 00000000..0d034fd3 --- /dev/null +++ b/src-tauri/src/platform_specific/mod.rs @@ -0,0 +1 @@ +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..b7641888 --- /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 windows_origin_install_location_detection() -> Result { + 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")), + } +} -- cgit v1.2.3 From 4557140aaea7ca3b9fbd670d8eb534e488799d98 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Fri, 23 Sep 2022 02:17:33 +0200 Subject: Show if debug in version number --- src-tauri/src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 536acbe5..264a8395 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -106,7 +106,13 @@ fn force_panic() { /// Returns the current version number as a string fn get_version_number() -> String { let version = env!("CARGO_PKG_VERSION"); - format!("v{}", version) + if cfg!(debug_assertions) { + // Debugging enabled + format!("v{} (debug mode)", version) + } else { + // Debugging disabled + format!("v{}", version) + } } #[tauri::command] -- cgit v1.2.3 From 74d958c068f193f0716fb8b4ee456b72a475b2a8 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Fri, 23 Sep 2022 11:39:30 +0200 Subject: Only include OS specific code on said OS when building --- src-tauri/src/platform_specific/mod.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src-tauri/src') diff --git a/src-tauri/src/platform_specific/mod.rs b/src-tauri/src/platform_specific/mod.rs index 0d034fd3..581af77f 100644 --- a/src-tauri/src/platform_specific/mod.rs +++ b/src-tauri/src/platform_specific/mod.rs @@ -1 +1,2 @@ +#[cfg(target_os = "windows")] pub mod windows; -- cgit v1.2.3 From 468d843b2eaf0f9f3de00177a79420313c9fc3ed Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Fri, 23 Sep 2022 22:45:06 +0200 Subject: Rename function --- src-tauri/src/lib.rs | 2 +- src-tauri/src/platform_specific/windows.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index ed438ab9..d0bc9be2 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -63,7 +63,7 @@ pub fn find_game_install_location() -> Result { // (On Windows only) try parsing Windows registry for Origin install path #[cfg(target_os = "windows")] - match windows::windows_origin_install_location_detection() { + match windows::origin_install_location_detection() { Ok(game_path) => { let game_install = GameInstall { game_path: game_path, diff --git a/src-tauri/src/platform_specific/windows.rs b/src-tauri/src/platform_specific/windows.rs index b7641888..7627fe4f 100644 --- a/src-tauri/src/platform_specific/windows.rs +++ b/src-tauri/src/platform_specific/windows.rs @@ -8,7 +8,7 @@ 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 windows_origin_install_location_detection() -> Result { +pub fn origin_install_location_detection() -> Result { dbg!(); // Run PowerShell command to get Titanfall2 Origin install path -- cgit v1.2.3 From c0b597f1bfaa63153a337eb7280fbbb4fa7b824a Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Sat, 24 Sep 2022 17:30:04 +0200 Subject: Add code skeleton to verify game files Once done, should help with some tickets. --- dist/index.html | 3 +++ src-tauri/src/main.rs | 12 +++++++++++- src-tauri/src/repair_and_verify/mod.rs | 9 +++++++++ src-ui/src/main.ts | 18 ++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src-tauri/src/repair_and_verify/mod.rs (limited to 'src-tauri/src') diff --git a/dist/index.html b/dist/index.html index 2d4d1acb..95403ebd 100644 --- a/dist/index.html +++ b/dist/index.html @@ -30,6 +30,9 @@ Use release candidate? + + + diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 264a8395..025b6863 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -15,6 +15,10 @@ use app::{ get_host_os, get_log_list, get_northstar_version_number, install_northstar, launch_northstar, GameInstall, }; + +mod repair_and_verify; +use repair_and_verify::verify_game_files; + use tauri::Manager; use tokio::time::sleep; use tauri_plugin_store::PluginBuilder; @@ -78,7 +82,8 @@ fn main() { update_northstar_caller, launch_northstar_caller, check_is_flightcore_outdated_caller, - get_log_list_caller + get_log_list_caller, + verify_game_files_caller ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); @@ -246,3 +251,8 @@ fn launch_northstar_caller(game_install: GameInstall) -> Result fn get_log_list_caller(game_install: GameInstall) -> Result, String> { get_log_list(game_install) } + +#[tauri::command] +fn verify_game_files_caller(game_install: GameInstall) -> Result { + verify_game_files(game_install) +} diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs new file mode 100644 index 00000000..e99dcbfc --- /dev/null +++ b/src-tauri/src/repair_and_verify/mod.rs @@ -0,0 +1,9 @@ +/// Contains various functions to repair common issues and verifying installation + +use app::GameInstall; + +/// Verifies Titanfall2 game files +pub fn verify_game_files(game_install: GameInstall) -> Result { + dbg!(game_install); + Err("TODO, not yet implemented".to_string()) +} diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts index 3b47e6f4..5648605c 100644 --- a/src-ui/src/main.ts +++ b/src-ui/src/main.ts @@ -99,6 +99,7 @@ document.addEventListener("DOMContentLoaded", async function () { let originRunningHolderEl = $("origin-running-holder") as HTMLElement; let northstarVersionHolderEl = $("northstar-version-holder") as HTMLElement; let useReleaseCandidateCheckboxEl = document.getElementById("use-release-candidate-checkbox") as HTMLInputElement; + let verifyGameFilesButtonEl = document.getElementById("verify-game-files-button") as HTMLElement; useReleaseCandidateCheckboxEl.addEventListener('change', async function () { // Switch between main release and release candidates @@ -227,6 +228,23 @@ document.addEventListener("DOMContentLoaded", async function () { } }); + // Handles verify button click + verifyGameFilesButtonEl.addEventListener("click", async function () { + let game_install = { + game_path: globalState.gamepath, + install_type: installTypeHolderEl.textContent + } as GameInstall; + await invoke("verify_game_files_caller", { gameInstall: game_install }) + .then((message) => { + // Found some gamepath + console.log(message); + }) + .catch((error) => { + console.error(error); + alert(error); + }); + }); + // panic button click panicButtonEl.addEventListener("pointerup", async function () { await invoke("force_panic"); -- cgit v1.2.3