aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/main.rs
diff options
context:
space:
mode:
authorGeckoEidechse <gecko.eidechse+git@pm.me>2022-08-29 22:21:45 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2022-08-29 22:21:45 +0200
commit975c9ffbbed337ce40f6922c86249225ab779075 (patch)
tree782268ddb69e58d1d6a4f00e6e524ea85d6602a9 /src-tauri/src/main.rs
parent17fb443a3dd8a71180a9081dbab64af95c53af26 (diff)
downloadFlightCore-975c9ffbbed337ce40f6922c86249225ab779075.tar.gz
FlightCore-975c9ffbbed337ce40f6922c86249225ab779075.zip
Check installed Northstar version
Diffstat (limited to 'src-tauri/src/main.rs')
-rw-r--r--src-tauri/src/main.rs73
1 files changed, 72 insertions, 1 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 747a51e0..c42a61dc 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -45,7 +45,8 @@ fn main() {
add_count,
force_panic,
find_game_install_location_caller,
- get_version_number
+ get_version_number,
+ get_northstar_version_number_caller
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
@@ -109,3 +110,73 @@ fn get_version_number() -> String {
let version = env!("CARGO_PKG_VERSION");
format!("v{}", version)
}
+
+#[tauri::command]
+fn get_northstar_version_number_caller() -> String {
+ match get_northstar_version_number() {
+ Ok(version_number) => version_number,
+ Err(err) => {
+ println!("{}", err);
+ "".to_string()
+ }
+ }
+}
+
+/// Check version number of a mod
+fn check_mod_version_number(path_to_mod_folder: String) -> Result<String, anyhow::Error> {
+ // println!("{}", format!("{}/mod.json", path_to_mod_folder));
+ let data = std::fs::read_to_string(format!("{}/mod.json", path_to_mod_folder))?;
+ let parsed_json: serde_json::Value = serde_json::from_str(&data)?;
+ // println!("{}", parsed_json);
+ let mod_version_number = match parsed_json.get("Version").and_then(|value| value.as_str()) {
+ Some(version_number) => version_number,
+ None => return Err(anyhow!("No version number found")),
+ };
+
+ println!("{}", mod_version_number);
+
+ Ok(mod_version_number.to_string())
+}
+
+/// Returns the current Northstar version number as a string
+fn get_northstar_version_number() -> Result<String, anyhow::Error> {
+ let install_location = match find_game_install_location() {
+ Ok(path) => path,
+ Err(err) => return Err(err),
+ };
+
+ println!("{}", install_location);
+
+ // 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/{}",
+ install_location, 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/{}",
+ install_location, 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)
+}