diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2022-11-22 19:02:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-22 19:02:03 +0100 |
commit | c49af0ce6d95d0529ddb06908c3f65867bae89ca (patch) | |
tree | f522e5e899c56c5794122392263ab556227a6a6d | |
parent | 71072b86032d58408bf2a53cfddd6c0da45b3fe6 (diff) | |
download | FlightCore-c49af0ce6d95d0529ddb06908c3f65867bae89ca.tar.gz FlightCore-c49af0ce6d95d0529ddb06908c3f65867bae89ca.zip |
refactor: Start moving NS related logic to own mod (#63)
-rw-r--r-- | src-tauri/src/lib.rs | 43 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 3 | ||||
-rw-r--r-- | src-tauri/src/northstar/mod.rs | 44 |
3 files changed, 51 insertions, 39 deletions
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index e73d2de8..ff923cb1 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -2,6 +2,8 @@ use std::env; use anyhow::{anyhow, Context, Result}; +mod northstar; + mod platform_specific; #[cfg(target_os = "windows")] use platform_specific::windows; @@ -12,6 +14,8 @@ use serde::{Deserialize, Serialize}; use sysinfo::SystemExt; use zip::ZipArchive; +use northstar::get_northstar_version_number; + #[derive(Serialize, Deserialize, Debug, Clone)] pub enum InstallType { STEAM, @@ -111,45 +115,6 @@ pub fn find_game_install_location() -> Result<GameInstall, String> { Err("Could not auto-detect game install location! Please enter it manually.".to_string()) } -/// Returns the current Northstar version number as a string -pub fn get_northstar_version_number(game_path: String) -> Result<String, anyhow::Error> { - println!("{}", game_path); - // println!("{:?}", install_type); - - // TODO: - // Check if NorthstarLauncher.exe exists and check its version number - let profile_folder = "R2Northstar"; - let core_mods = [ - "Northstar.Client", - "Northstar.Custom", - "Northstar.CustomServers", - ]; - let initial_version_number = match check_mod_version_number(format!( - "{}/{}/mods/{}", - game_path, profile_folder, core_mods[0] - )) { - Ok(version_number) => version_number, - Err(err) => return Err(err), - }; - - for core_mod in core_mods { - let current_version_number = match check_mod_version_number(format!( - "{}/{}/mods/{}", - game_path, profile_folder, core_mod - )) { - Ok(version_number) => version_number, - Err(err) => return Err(err), - }; - if current_version_number != initial_version_number { - // We have a version number mismatch - return Err(anyhow!("Found version number mismatch")); - } - } - println!("All mods same version"); - - Ok(initial_version_number) -} - /// Checks whether the provided path is a valid Titanfall2 gamepath by checking against a certain set of criteria pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), anyhow::Error> { let path_to_titanfall2_exe = format!("{}/Titanfall2.exe", game_install_path); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 1ddb4c69..b8b1ac3e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -22,6 +22,9 @@ use mod_management::{ fc_download_mod_and_install, get_installed_mods_and_properties, set_mod_enabled_status, }; +mod northstar; +use northstar::get_northstar_version_number; + use tauri::Manager; use tauri_plugin_store::PluginBuilder; use tokio::time::sleep; diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs new file mode 100644 index 00000000..a7ec044a --- /dev/null +++ b/src-tauri/src/northstar/mod.rs @@ -0,0 +1,44 @@ +//! This module deals with handling things around Northstar such as +//! - getting version number + +use crate::check_mod_version_number; +use anyhow::anyhow; + +/// Returns the current Northstar version number as a string +pub fn get_northstar_version_number(game_path: String) -> Result<String, anyhow::Error> { + println!("{}", game_path); + // println!("{:?}", install_type); + + // TODO: + // Check if NorthstarLauncher.exe exists and check its version number + let profile_folder = "R2Northstar"; + let core_mods = [ + "Northstar.Client", + "Northstar.Custom", + "Northstar.CustomServers", + ]; + let initial_version_number = match check_mod_version_number(format!( + "{}/{}/mods/{}", + game_path, profile_folder, core_mods[0] + )) { + Ok(version_number) => version_number, + Err(err) => return Err(err), + }; + + for core_mod in core_mods { + let current_version_number = match check_mod_version_number(format!( + "{}/{}/mods/{}", + game_path, profile_folder, core_mod + )) { + Ok(version_number) => version_number, + Err(err) => return Err(err), + }; + if current_version_number != initial_version_number { + // We have a version number mismatch + return Err(anyhow!("Found version number mismatch")); + } + } + println!("All mods same version"); + + Ok(initial_version_number) +} |