aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeckoEidechse <gecko.eidechse+git@pm.me>2022-09-10 00:16:59 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2022-09-10 00:16:59 +0200
commit6cf9f19406dc4eb9463927bba85c71633f8f6fdb (patch)
tree034012e9fb1bf585363d6e6f61e1a5aaf31fa09b
parentc7edfc4b008ac88937ab04cae1f66813d55040cd (diff)
downloadFlightCore-6cf9f19406dc4eb9463927bba85c71633f8f6fdb.tar.gz
FlightCore-6cf9f19406dc4eb9463927bba85c71633f8f6fdb.zip
Implement manually selecting TF|2 install location
-rw-r--r--dist/index.html2
-rw-r--r--src-tauri/src/lib.rs18
-rw-r--r--src-tauri/src/main.rs8
-rw-r--r--src-ui/src/main.ts85
4 files changed, 55 insertions, 58 deletions
diff --git a/dist/index.html b/dist/index.html
index d964537a..bdc7fd5c 100644
--- a/dist/index.html
+++ b/dist/index.html
@@ -15,7 +15,7 @@
The functionality it serves and what it displays is based on the current state of the application
-->
<button id="omni-button", class="locked">Loading...</button>
- <install-location-holder>EMPTY</install-location-holder>
+ <install-location-holder>Couldn't find Titanfall2 install</install-location-holder>
<!-- <div class="hello">Click for Hello</div> -->
<!-- <counter-button>ADD</counter-button> -->
<!-- <counter-result>.</counter-result> -->
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index cf1213d1..d0c76d8e 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -1,4 +1,5 @@
use anyhow::{anyhow, Context, Result};
+use thermite::install;
use zip::ZipArchive;
#[derive(Debug)]
@@ -47,16 +48,9 @@ pub fn find_game_install_location() -> Result<(String, InstallType), anyhow::Err
}
/// Returns the current Northstar version number as a string
-pub fn get_northstar_version_number() -> Result<String, anyhow::Error> {
- // TODO: if `find_game_install_location` is unable to find game_path then function will fail to detect
- // Northstar install, even if game_path is known due to user entering it manually
- let (install_location, install_type) = match find_game_install_location() {
- Ok((path, install_type)) => (path, install_type),
- Err(err) => return Err(err),
- };
-
- println!("{}", install_location);
- println!("{:?}", install_type);
+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
@@ -68,7 +62,7 @@ pub fn get_northstar_version_number() -> Result<String, anyhow::Error> {
];
let initial_version_number = match check_mod_version_number(format!(
"{}/{}/mods/{}",
- install_location, profile_folder, core_mods[0]
+ game_path, profile_folder, core_mods[0]
)) {
Ok(version_number) => version_number,
Err(err) => return Err(err),
@@ -77,7 +71,7 @@ pub fn get_northstar_version_number() -> Result<String, anyhow::Error> {
for core_mod in core_mods {
let current_version_number = match check_mod_version_number(format!(
"{}/{}/mods/{}",
- install_location, profile_folder, core_mod
+ game_path, profile_folder, core_mod
)) {
Ok(version_number) => version_number,
Err(err) => return Err(err),
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 14d8d040..733da602 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -99,8 +99,8 @@ fn get_version_number() -> String {
}
#[tauri::command]
-fn get_northstar_version_number_caller() -> String {
- match get_northstar_version_number() {
+fn get_northstar_version_number_caller(game_path: String) -> String {
+ match get_northstar_version_number(game_path) {
Ok(version_number) => version_number,
Err(err) => {
println!("{}", err);
@@ -113,7 +113,7 @@ fn get_northstar_version_number_caller() -> String {
/// Checks if installed Northstar version is up-to-date
/// false -> Northstar install is up-to-date
/// true -> Northstar install is outdated
-async fn check_is_northstar_outdated() -> bool {
+async fn check_is_northstar_outdated(game_path: String) -> bool {
let index = thermite::api::get_package_index().await.unwrap().to_vec();
let nmod = index
.iter()
@@ -123,7 +123,7 @@ async fn check_is_northstar_outdated() -> bool {
dbg!(nmod);
- let version_number = match get_northstar_version_number() {
+ let version_number = match get_northstar_version_number(game_path) {
Ok(version_number) => version_number,
Err(err) => {
println!("{}", err);
diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts
index 73fad575..0bd22c58 100644
--- a/src-ui/src/main.ts
+++ b/src-ui/src/main.ts
@@ -7,7 +7,7 @@ const $ = document.querySelector.bind(document);
const button_install_string = "Install Northstar";
const button_update_string = "Update Northstar";
const button_play_string = "Launch Northstar";
-const button_manual_find_string = "Manually find Titanfall2 install location";
+const button_manual_find_string = "Manually select Titanfall2 install location";
// Stores the overall state of the application
var globalState = {
@@ -17,17 +17,53 @@ var globalState = {
}
async function get_northstar_version_number_and_set_button_accordingly(omniButtonEl: HTMLElement) {
- let northstar_version_number = await invoke("get_northstar_version_number_caller") as string;
+ let northstar_version_number = await invoke("get_northstar_version_number_caller", { gamePath: globalState.gamepath }) as string;
if (northstar_version_number && northstar_version_number.length > 0) {
globalState.installed_northstar_version = northstar_version_number;
omniButtonEl.textContent = `${button_play_string} (${northstar_version_number})`;
- let northstar_is_outdated = await invoke("check_is_northstar_outdated") as boolean;
+ let northstar_is_outdated = await invoke("check_is_northstar_outdated", { gamePath: globalState.gamepath }) as boolean;
if (northstar_is_outdated) {
omniButtonEl.textContent = button_update_string;
}
}
}
+async function manually_find_titanfall2_install(omniButtonEl: HTMLElement) {
+ // Open a selection dialog for directories
+ const selected = await open({
+ directory: true,
+ multiple: false,
+ defaultPath: await appDir(),
+ });
+ if (Array.isArray(selected)) {
+ // user selected multiple directories
+ alert("Please only select a single directory");
+ } else if (selected === null) {
+ // user cancelled the selection
+ } else {
+ // user selected a single directory
+
+ // Verify if valid Titanfall2 install location
+ let is_valid_titanfall2_install = await invoke("verify_install_location", { gamePath: selected }) as boolean;
+ if (is_valid_titanfall2_install) {
+ globalState.gamepath = selected;
+
+ let installLocationHolderEl = $("install-location-holder") as HTMLElement;
+ installLocationHolderEl.textContent = globalState.gamepath;
+
+ // Update omni-button
+ omniButtonEl.textContent = button_install_string;
+
+ // Check for Northstar install
+ await get_northstar_version_number_and_set_button_accordingly(omniButtonEl);
+ }
+ else {
+ // Not valid Titanfall2 install
+ alert("Not a valid Titanfall2 install");
+ }
+ }
+}
+
document.addEventListener("DOMContentLoaded", async function () {
// get the elements
// const helloEl = $("div.hello")! as HTMLElement;
@@ -50,46 +86,13 @@ document.addEventListener("DOMContentLoaded", async function () {
// omni button click
omniButtonEl.addEventListener("click", async function () {
- // // Check if Titanfall2 install path as found
- // let install_location = await invoke("find_game_install_location_caller") as string;
- // if (!(install_location && install_location.length > 0)) {
- // alert("Titanfall2 install not found");
- // // Open a selection dialog for directories
- // const selected = await open({
- // directory: true,
- // multiple: false,
- // defaultPath: await appDir(),
- // });
- // if (Array.isArray(selected)) {
- // // user selected multiple directories
- // alert("Please only select a single directory");
- // } else if (selected === null) {
- // // user cancelled the selection
- // } else {
- // // user selected a single directory
- // alert(selected);
-
-
- // // TODO Verify if valid Titanfall2 install location
- // let is_valid_titanfall2_install = await invoke("verify_install_location", { gamePath: selected }) as boolean;
- // if (is_valid_titanfall2_install) {
- // globalState.gamepath = selected;
-
- // // Update omni-button
- // omniButtonEl.textContent = button_install_string;
-
- // // Check for Northstar install
- // get_northstar_version_number_and_set_button_accordingly();
- // }
- // else {
- // // Not valid Titanfall2 install
- // alert("Not a valid Titanfall2 install");
- // }
- // }
- // return;
- // }
switch (omniButtonEl.textContent) {
+ // Find Titanfall2 install manually
+ case button_manual_find_string:
+ manually_find_titanfall2_install(omniButtonEl);
+ break;
+ // Install Northstar
case button_install_string:
omniButtonEl.textContent = "Installing";
await invoke("install_northstar_caller", { gamePath: globalState.gamepath }) as boolean;