aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-10-13 13:43:51 +0200
committerGitHub <noreply@github.com>2023-10-13 13:43:51 +0200
commitb58d8d138919ec911369b644d7a49c94215c77a9 (patch)
treed6442b34d339b6ebbf72d875ac6fddced47222d5 /src-tauri/src
parentb3b558dbab5ac41a64f36d36aac81f0b996101b0 (diff)
downloadFlightCore-b58d8d138919ec911369b644d7a49c94215c77a9.tar.gz
FlightCore-b58d8d138919ec911369b644d7a49c94215c77a9.zip
refactor: Move relevant functions to northstar module (#626)
* refactor: Move `get_available_northstar_versions` to northstar module * refactor: Move `check_is_northstar_outdated` to northstar module
Diffstat (limited to 'src-tauri/src')
-rw-r--r--src-tauri/src/main.rs97
-rw-r--r--src-tauri/src/northstar/mod.rs91
2 files changed, 94 insertions, 94 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 8d6ea769..207a148a 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -19,7 +19,6 @@ mod repair_and_verify;
mod thunderstore;
mod util;
-use semver::Version;
use serde::{Deserialize, Serialize};
#[cfg(target_os = "windows")]
use tauri::api::dialog::blocking::MessageDialogBuilder;
@@ -38,7 +37,7 @@ struct NorthstarThunderstoreRelease {
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
#[ts(export)]
-struct NorthstarThunderstoreReleaseWrapper {
+pub struct NorthstarThunderstoreReleaseWrapper {
label: String,
value: NorthstarThunderstoreRelease,
}
@@ -121,7 +120,7 @@ fn main() {
northstar::install::find_game_install_location,
util::get_flightcore_version_number,
northstar::get_northstar_version_number,
- check_is_northstar_outdated,
+ northstar::check_is_northstar_outdated,
repair_and_verify::verify_install_location,
platform_specific::get_host_os,
northstar::install::install_northstar_wrapper,
@@ -157,7 +156,7 @@ fn main() {
github::pull_requests::get_launcher_download_link,
util::close_application,
development::install_git_main,
- get_available_northstar_versions,
+ northstar::get_available_northstar_versions,
northstar::profile::fetch_profiles,
northstar::profile::validate_profile,
northstar::profile::delete_profile,
@@ -203,56 +202,6 @@ pub fn convert_release_candidate_number(version_number: String) -> String {
version_number.replace("-rc", "0").replace("00", "")
}
-/// Checks if installed Northstar version is up-to-date
-/// false -> Northstar install is up-to-date
-/// true -> Northstar install is outdated
-#[tauri::command]
-async fn check_is_northstar_outdated(
- game_install: GameInstall,
- northstar_package_name: Option<String>,
-) -> Result<bool, String> {
- let northstar_package_name = match northstar_package_name {
- Some(northstar_package_name) => {
- if northstar_package_name.len() <= 1 {
- "Northstar".to_string()
- } else {
- northstar_package_name
- }
- }
- None => "Northstar".to_string(),
- };
-
- let index = match thermite::api::get_package_index() {
- Ok(res) => res.to_vec(),
- Err(err) => return Err(format!("Couldn't check if Northstar up-to-date: {err}")),
- };
- let nmod = index
- .iter()
- .find(|f| f.name.to_lowercase() == northstar_package_name.to_lowercase())
- .expect("Couldn't find Northstar on thunderstore???");
- // .ok_or_else(|| anyhow!("Couldn't find Northstar on thunderstore???"))?;
-
- let version_number = match northstar::get_northstar_version_number(game_install) {
- Ok(version_number) => version_number,
- Err(err) => {
- log::warn!("{}", err);
- // If we fail to get new version just assume we are up-to-date
- return Err(err);
- }
- };
-
- // Release candidate version numbers are different between `mods.json` and Thunderstore
- let version_number = convert_release_candidate_number(version_number);
-
- if version_number != nmod.latest {
- log::info!("Installed Northstar version outdated");
- Ok(true)
- } else {
- log::info!("Installed Northstar version up-to-date");
- Ok(false)
- }
-}
-
/// Installs the specified mod
#[tauri::command]
async fn install_mod_wrapper(
@@ -290,46 +239,6 @@ async fn clean_up_download_folder_wrapper(
}
}
-/// Gets list of available Northstar versions from Thunderstore
-#[tauri::command]
-async fn get_available_northstar_versions() -> Result<Vec<NorthstarThunderstoreReleaseWrapper>, ()>
-{
- let northstar_package_name = "Northstar";
- let index = thermite::api::get_package_index().unwrap().to_vec();
- let nsmod = index
- .iter()
- .find(|f| f.name.to_lowercase() == northstar_package_name.to_lowercase())
- .ok_or_else(|| panic!("Couldn't find Northstar on thunderstore???"))
- .unwrap();
-
- let mut releases: Vec<NorthstarThunderstoreReleaseWrapper> = vec![];
- for (_version_string, nsmod_version_obj) in nsmod.versions.iter() {
- let current_elem = NorthstarThunderstoreRelease {
- package: nsmod_version_obj.name.clone(),
- version: nsmod_version_obj.version.clone(),
- };
- let current_elem_wrapped = NorthstarThunderstoreReleaseWrapper {
- label: format!(
- "{} v{}",
- nsmod_version_obj.name.clone(),
- nsmod_version_obj.version.clone()
- ),
- value: current_elem,
- };
-
- releases.push(current_elem_wrapped);
- }
-
- releases.sort_by(|a, b| {
- // Parse version number
- let a_ver = Version::parse(&a.value.version).unwrap();
- let b_ver = Version::parse(&b.value.version).unwrap();
- b_ver.partial_cmp(&a_ver).unwrap() // Sort newest first
- });
-
- Ok(releases)
-}
-
use anyhow::Result;
/// Defines how Titanfall2 was installed (Steam, Origin, ...)
diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs
index a6b895db..1c2023b6 100644
--- a/src-tauri/src/northstar/mod.rs
+++ b/src-tauri/src/northstar/mod.rs
@@ -9,8 +9,99 @@ use crate::{
platform_specific::get_host_os,
GameInstall, InstallType,
};
+use crate::{NorthstarThunderstoreRelease, NorthstarThunderstoreReleaseWrapper};
use anyhow::anyhow;
+/// Gets list of available Northstar versions from Thunderstore
+#[tauri::command]
+pub async fn get_available_northstar_versions(
+) -> Result<Vec<NorthstarThunderstoreReleaseWrapper>, ()> {
+ let northstar_package_name = "Northstar";
+ let index = thermite::api::get_package_index().unwrap().to_vec();
+ let nsmod = index
+ .iter()
+ .find(|f| f.name.to_lowercase() == northstar_package_name.to_lowercase())
+ .ok_or_else(|| panic!("Couldn't find Northstar on thunderstore???"))
+ .unwrap();
+
+ let mut releases: Vec<NorthstarThunderstoreReleaseWrapper> = vec![];
+ for (_version_string, nsmod_version_obj) in nsmod.versions.iter() {
+ let current_elem = NorthstarThunderstoreRelease {
+ package: nsmod_version_obj.name.clone(),
+ version: nsmod_version_obj.version.clone(),
+ };
+ let current_elem_wrapped = NorthstarThunderstoreReleaseWrapper {
+ label: format!(
+ "{} v{}",
+ nsmod_version_obj.name.clone(),
+ nsmod_version_obj.version.clone()
+ ),
+ value: current_elem,
+ };
+
+ releases.push(current_elem_wrapped);
+ }
+
+ releases.sort_by(|a, b| {
+ // Parse version number
+ let a_ver = semver::Version::parse(&a.value.version).unwrap();
+ let b_ver = semver::Version::parse(&b.value.version).unwrap();
+ b_ver.partial_cmp(&a_ver).unwrap() // Sort newest first
+ });
+
+ Ok(releases)
+}
+
+/// Checks if installed Northstar version is up-to-date
+/// false -> Northstar install is up-to-date
+/// true -> Northstar install is outdated
+#[tauri::command]
+pub async fn check_is_northstar_outdated(
+ game_install: GameInstall,
+ northstar_package_name: Option<String>,
+) -> Result<bool, String> {
+ let northstar_package_name = match northstar_package_name {
+ Some(northstar_package_name) => {
+ if northstar_package_name.len() <= 1 {
+ "Northstar".to_string()
+ } else {
+ northstar_package_name
+ }
+ }
+ None => "Northstar".to_string(),
+ };
+
+ let index = match thermite::api::get_package_index() {
+ Ok(res) => res.to_vec(),
+ Err(err) => return Err(format!("Couldn't check if Northstar up-to-date: {err}")),
+ };
+ let nmod = index
+ .iter()
+ .find(|f| f.name.to_lowercase() == northstar_package_name.to_lowercase())
+ .expect("Couldn't find Northstar on thunderstore???");
+ // .ok_or_else(|| anyhow!("Couldn't find Northstar on thunderstore???"))?;
+
+ let version_number = match get_northstar_version_number(game_install) {
+ Ok(version_number) => version_number,
+ Err(err) => {
+ log::warn!("{}", err);
+ // If we fail to get new version just assume we are up-to-date
+ return Err(err);
+ }
+ };
+
+ // Release candidate version numbers are different between `mods.json` and Thunderstore
+ let version_number = crate::convert_release_candidate_number(version_number);
+
+ if version_number != nmod.latest {
+ log::info!("Installed Northstar version outdated");
+ Ok(true)
+ } else {
+ log::info!("Installed Northstar version up-to-date");
+ Ok(false)
+ }
+}
+
/// Check version number of a mod
pub fn check_mod_version_number(path_to_mod_folder: &str) -> Result<String, anyhow::Error> {
let data = std::fs::read_to_string(format!("{path_to_mod_folder}/mod.json"))?;