aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeckoEidechse <gecko.eidechse+git@pm.me>2022-09-01 19:26:39 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2022-09-01 19:26:39 +0200
commit312cddf2c2b6fd715e3133095c4562c78807b236 (patch)
treefb84f89970051ce13149e3aa9dc2ec08d5d49f3c
parent340b96e5878b892d81dbc7e5cdbc0215ce78b4d9 (diff)
downloadFlightCore-312cddf2c2b6fd715e3133095c4562c78807b236.tar.gz
FlightCore-312cddf2c2b6fd715e3133095c4562c78807b236.zip
Handle gamepath check if manually selected
as well as Northstar existence and up-to-date check
-rw-r--r--src-tauri/src/lib.rs13
-rw-r--r--src-tauri/src/main.rs17
-rw-r--r--src-ui/src/main.ts28
3 files changed, 50 insertions, 8 deletions
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 626f083b..58a04c5e 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -88,3 +88,16 @@ pub fn get_northstar_version_number() -> Result<String, anyhow::Error> {
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 is_correct_game_path =
+ std::path::Path::new(&format!("{}/Titanfall2.exe", game_install_path)).exists();
+ println!("Titanfall2.exe exists in path? {}", is_correct_game_path);
+
+ // Exit early if wrong game path
+ if !is_correct_game_path {
+ return Err(anyhow!("Incorrect game path \"{}\"", game_install_path)); // Return error cause wrong game path
+ }
+ Ok(())
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index e81be131..34dcc39c 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -8,7 +8,7 @@ use std::{
time::Duration,
};
-use app::{find_game_install_location, get_northstar_version_number};
+use app::{check_is_valid_game_path, find_game_install_location, get_northstar_version_number};
use tauri::{Manager, State};
use tokio::time::sleep;
@@ -47,7 +47,8 @@ fn main() {
find_game_install_location_caller,
get_version_number,
get_northstar_version_number_caller,
- check_is_northstar_outdated
+ check_is_northstar_outdated,
+ verify_install_location
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
@@ -107,3 +108,15 @@ fn check_is_northstar_outdated() -> bool {
// TODO implement check
false
}
+
+#[tauri::command]
+/// Checks if is valid Titanfall2 install based on certain conditions
+fn verify_install_location(game_path: String) -> bool {
+ match check_is_valid_game_path(&game_path) {
+ Ok(()) => true,
+ Err(err) => {
+ println!("{}", err);
+ false
+ }
+ }
+}
diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts
index aedcceb5..6eaee030 100644
--- a/src-ui/src/main.ts
+++ b/src-ui/src/main.ts
@@ -51,16 +51,32 @@ document.addEventListener("DOMContentLoaded", async function () {
} else {
// user selected a single directory
alert(selected);
-
- globalState.gamepath = selected;
+
// TODO Verify if valid Titanfall2 install location
+ let is_valid_titanfall2_install = await invoke("verify_install_location", { game_path: selected }) as boolean;
+ if (is_valid_titanfall2_install) {
+ globalState.gamepath = selected;
- // Update omni-button
- omniButtonEl.textContent = "Install";
+ // Update omni-button
+ omniButtonEl.textContent = "Install";
- // TODO Check for Northstar install
- // TODO Check for updated Northstar
+ // Check for Northstar install
+ 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 (${northstar_version_number})`;
+ // Check for updated Northstar
+ let northstar_is_outdated = await invoke("check_is_northstar_outdated") as boolean;
+ if (northstar_is_outdated) {
+ omniButtonEl.textContent = "Update";
+ }
+ }
+ }
+ else {
+ // Not valid Titanfall2 install
+ alert("Not a valid Titanfall2 install");
+ }
}
return;
}