aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/main.rs
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2022-11-19 10:04:43 +0100
committerGitHub <noreply@github.com>2022-11-19 10:04:43 +0100
commit38e12489a517662157d85ec6efec00f225cccc9c (patch)
tree16d8218fffaba26f8e44d6dff56ef4e3e1f29233 /src-tauri/src/main.rs
parentd3c190bd4d3461fc4c310f64eb74a8e2425baaad (diff)
downloadFlightCore-38e12489a517662157d85ec6efec00f225cccc9c.tar.gz
FlightCore-38e12489a517662157d85ec6efec00f225cccc9c.zip
feat: Initial support for installing mods from TS (#32)
* feat: Initial support for installing mods from TS This is the basic code needed to install a mod from Thunderstore * refactor: Remove console log, show msg in notif Instead of console logging result message, show it in notification instead. * refactor: Rename function to indicate behaviour Function not only installs but also downloads mod first. Although it does remove downloaded zip post installation. * refactor: Move install logic to dedicated module `mod_management` module didn't exist when this PR was created * chore: Trim single leftover newline * fix: Update code for newer `libthermite` version * feat: Allow installing older versions of mods Installs the given version number instead of only allowing latest. * fix: Explicit error msg for installing NS as mod While it would fail during install anyway, having explicit error message is nicer * feat: Write TS mod string to mod.json Write Thunderstore mod string of installed mod to its `mod.json` This way we can later check whether a mod is outdated based on the Thunderstore mod string * fix: Early return on empty string Prevent trying to install the first mod that matches an early string. We should never pass an empty string in the first place but better safe then sorry. * build: Add dependency for recursive async Needed for recursive mod dependency install * feat: Recursively install mod dependencies * fix: Early catch installing R2modman as mod Just in case to prevent someone trying to install R2modman as a mod. * refactor: Remove debug prints * fix: Allow installing mods having NS as dependency They would previously error out as Northstar cannot be installed as dependency. We now catch that specific error and return Ok(()) * fix: Delete download folder after mod install Deletes download folder after mod install if non-empty. * fix: Do not early leave when dependency is NS Logic error, instead of skipping installing Northstar as dependency it would previously just return early with success. * chore: Remove leftover commented out code
Diffstat (limited to 'src-tauri/src/main.rs')
-rw-r--r--src-tauri/src/main.rs42
1 files changed, 39 insertions, 3 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 7db9e089..1ddb4c69 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -15,10 +15,12 @@ mod github;
use github::release_notes::{get_northstar_release_notes, check_is_flightcore_outdated};
mod repair_and_verify;
-use repair_and_verify::{verify_game_files, disable_all_but_core};
+use repair_and_verify::{clean_up_download_folder, disable_all_but_core, verify_game_files};
mod mod_management;
-use mod_management::{set_mod_enabled_status, get_installed_mods_and_properties};
+use mod_management::{
+ fc_download_mod_and_install, get_installed_mods_and_properties, set_mod_enabled_status,
+};
use tauri::Manager;
use tauri_plugin_store::PluginBuilder;
@@ -92,6 +94,8 @@ fn main() {
get_northstar_release_notes,
linux_checks,
get_installed_mods_caller,
+ install_mod_caller,
+ clean_up_download_folder_caller,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
@@ -275,7 +279,9 @@ async fn verify_game_files_caller(game_install: GameInstall) -> Result<String, S
}
#[tauri::command]
-async fn get_enabled_mods_caller(game_install: GameInstall) -> Result<serde_json::value::Value, String> {
+async fn get_enabled_mods_caller(
+ game_install: GameInstall,
+) -> Result<serde_json::value::Value, String> {
get_enabled_mods(game_install)
}
@@ -297,3 +303,33 @@ async fn disable_all_but_core_caller(game_install: GameInstall) -> Result<(), St
async fn get_installed_mods_caller(game_install: GameInstall) -> Result<Vec<NorthstarMod>, String> {
get_installed_mods_and_properties(game_install)
}
+
+#[tauri::command]
+/// Installs the specified mod
+async fn install_mod_caller(
+ game_install: GameInstall,
+ thunderstore_mod_string: String,
+) -> Result<(), String> {
+ fc_download_mod_and_install(game_install.clone(), thunderstore_mod_string).await?;
+ match clean_up_download_folder(game_install, false) {
+ Ok(()) => Ok(()),
+ Err(err) => {
+ println!("Failed to delete download folder due to {}", err);
+ // Failure to delete download folder is not an error in mod install
+ // As such ignore. User can still force delete if need be
+ Ok(())
+ }
+ }
+}
+
+#[tauri::command]
+/// Installs the specified mod
+async fn clean_up_download_folder_caller(
+ game_install: GameInstall,
+ force: bool,
+) -> Result<(), String> {
+ match clean_up_download_folder(game_install, force) {
+ Ok(()) => Ok(()),
+ Err(err) => Err(err.to_string()),
+ }
+}