diff options
author | Rémy Raes <contact@remyraes.com> | 2022-09-24 19:01:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-24 19:01:33 +0200 |
commit | 5bf2254204692066fbd5774097b1e3fbc33d0157 (patch) | |
tree | 73652a5b6b0245aa81a9ce30451165207ac868f5 | |
parent | bdba63fa033a9f98d63951ec0cf9109f7949f444 (diff) | |
parent | 94979acb5d62fc5a0498b8d0170308511972fbb7 (diff) | |
download | FlightCore-5bf2254204692066fbd5774097b1e3fbc33d0157.tar.gz FlightCore-5bf2254204692066fbd5774097b1e3fbc33d0157.zip |
Merge branch 'GeckoEidechse:main' into feat/new-ui
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | dist/index.html | 4 | ||||
-rw-r--r-- | src-tauri/src/lib.rs | 40 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 20 | ||||
-rw-r--r-- | src-tauri/src/platform_specific/mod.rs | 2 | ||||
-rw-r--r-- | src-tauri/src/platform_specific/windows.rs | 40 | ||||
-rw-r--r-- | src-tauri/src/repair_and_verify/mod.rs | 9 | ||||
-rw-r--r-- | src-ui/src/main.ts | 37 |
8 files changed, 114 insertions, 40 deletions
@@ -33,7 +33,7 @@ npx tauri dev > On Windows instead of `npm run ui-dev`, you may need to run > `./node_modules/.bin/rollup --config --watch` > and -> `npm run localhost` +> `./node_modules/.bin/servor dist index.html 8080 --reload` > in two separate console windows ### Tips diff --git a/dist/index.html b/dist/index.html index 2d4d1acb..ae87ebe7 100644 --- a/dist/index.html +++ b/dist/index.html @@ -30,6 +30,10 @@ <!-- Should be switched to dropdown menu later --> Use release candidate? <input type="checkbox" id="use-release-candidate-checkbox" /> + <!-- Stuff directly below would go to a repair/verify Titanfall2/Northstar page in the app --> + <button id="force-reinstall-northstar-button">Force reinstall Northstar</button> + <button id="verify-game-files-button">Verify Titanfall2 game files</button> + <!-- This showcases ping activity between frontend and backend. Should be hidden in non-dev/debug mode --> <backend-ping class="server"></backend-ping> </body> diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f19a178c..d0bc9be2 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<String, an Ok(mod_version_number.to_string()) } -#[cfg(target_os = "windows")] -/// Runs a powershell command and parses output to get Titanfall2 install location on Origin -fn windows_origin_install_location_detection() -> Result<String, anyhow::Error> { - 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<GameInstall, anyhow::Error> { // Attempt parsing Steam library directly @@ -97,7 +63,7 @@ pub fn find_game_install_location() -> Result<GameInstall, anyhow::Error> { // (On Windows only) try parsing Windows registry for Origin install path #[cfg(target_os = "windows")] - match 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/main.rs b/src-tauri/src/main.rs index 536acbe5..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"); @@ -106,7 +111,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] @@ -240,3 +251,8 @@ fn launch_northstar_caller(game_install: GameInstall) -> Result<String, String> fn get_log_list_caller(game_install: GameInstall) -> Result<Vec<std::path::PathBuf>, String> { get_log_list(game_install) } + +#[tauri::command] +fn verify_game_files_caller(game_install: GameInstall) -> Result<String, String> { + verify_game_files(game_install) +} diff --git a/src-tauri/src/platform_specific/mod.rs b/src-tauri/src/platform_specific/mod.rs new file mode 100644 index 00000000..581af77f --- /dev/null +++ b/src-tauri/src/platform_specific/mod.rs @@ -0,0 +1,2 @@ +#[cfg(target_os = "windows")] +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..7627fe4f --- /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 origin_install_location_detection() -> Result<String, anyhow::Error> { + 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")), + } +} 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<String, String> { + 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..d68a0154 100644 --- a/src-ui/src/main.ts +++ b/src-ui/src/main.ts @@ -99,6 +99,8 @@ 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; + let forceReinstallNorthstarButtonEl = document.getElementById("force-reinstall-northstar-button") as HTMLElement; useReleaseCandidateCheckboxEl.addEventListener('change', async function () { // Switch between main release and release candidates @@ -227,6 +229,41 @@ 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); + }); + }); + + // Handles force reinstall click + forceReinstallNorthstarButtonEl.addEventListener("click", async function () { + let install_northstar_result = invoke("install_northstar_caller", { gamePath: globalState.gamepath, northstarPackageName: globalState.northstar_package_name }); + + // Update button while installl process is run + omniButtonEl.textContent = button_in_install_string; + + await install_northstar_result.then((message) => { + console.log(message); + }) + .catch((error) => { + console.error(error); + alert(error); + }); + + get_northstar_version_number_and_set_button_accordingly(omniButtonEl); + }); + // panic button click panicButtonEl.addEventListener("pointerup", async function () { await invoke("force_panic"); |