aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src-tauri/src/main.rs73
-rw-r--r--src-ui/src/main.ts9
2 files changed, 81 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)
+}
diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts
index eccd1919..127aa119 100644
--- a/src-ui/src/main.ts
+++ b/src-ui/src/main.ts
@@ -62,6 +62,15 @@ document.addEventListener("DOMContentLoaded", async function () {
omniButtonEl.textContent = "Install";
installLocationHolderEl.textContent = install_location;
globalState.gamepath = install_location;
+
+ // Check installed Northstar version if found
+ let northstar_version_number = await invoke("get_northstar_version_number_caller") as string;
+ if (northstar_version_number && northstar_version_number.length > 0) {
+ globalState.installed_northstar_version = northstar_version_number;
+ omniButtonEl.textContent = "Play"
+ // TODO check if version is newest
+ }
+ console.log(globalState);
}
else {
omniButtonEl.textContent = "Find Titanfall2 install location";