aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-01-04 23:42:05 +0100
committerGitHub <noreply@github.com>2023-01-04 23:42:05 +0100
commit4951a7e9048b6538a72294184639f6590f78384e (patch)
tree4490516fabc1c6097fcd23d9e5fa7f35f0966d0f
parent4a63e92ea30fc65cf945b163d2757f17dd3c68cd (diff)
downloadFlightCore-4951a7e9048b6538a72294184639f6590f78384e.tar.gz
FlightCore-4951a7e9048b6538a72294184639f6590f78384e.zip
feat: Add button to delete Northstar mod (#110)
* feat: Expose installed NS mod directory This allows other functions to get a mod directory directly which is useful for e.g. deleting a mod. * feat: Add button to delete Northstar mod * refactor: Return vector of NorthstarMod instead of unnamed Tuples * refactor: Remove leftover print statement * chore: Remove leftover todo comment * feat: Show confirm warning before deleting mod * refactor: Call func directly instead of proxy Removes the `func_caller` pattern * fix: Call reloading mods after attempted delete
-rw-r--r--src-tauri/src/main.rs3
-rw-r--r--src-tauri/src/mod_management/mod.rs45
-rw-r--r--src-vue/src/views/ModsView.vue36
3 files changed, 82 insertions, 2 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 0d7e69af..a9483e95 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -23,7 +23,7 @@ use repair_and_verify::{
mod mod_management;
use mod_management::{
- fc_download_mod_and_install, get_installed_mods_and_properties, set_mod_enabled_status,
+ fc_download_mod_and_install, get_installed_mods_and_properties, set_mod_enabled_status, delete_northstar_mod,
};
mod northstar;
@@ -103,6 +103,7 @@ fn main() {
install_mod_caller,
clean_up_download_folder_caller,
get_newest_flightcore_version,
+ delete_northstar_mod,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs
index 4fe1b517..f6897b90 100644
--- a/src-tauri/src/mod_management/mod.rs
+++ b/src-tauri/src/mod_management/mod.rs
@@ -10,6 +10,8 @@ use app::GameInstall;
use json5;
+use crate::northstar::CORE_MODS;
+
pub const BLACKLISTED_MODS: [&str; 3] = [
"northstar-Northstar",
"northstar-NorthstarReleaseCandidate",
@@ -385,3 +387,46 @@ pub async fn fc_download_mod_and_install(
Ok(())
}
+
+/// Deletes a given Northstar mod folder
+fn delete_mod_folder(ns_mod_directory: String) -> Result<(), String> {
+ let ns_mod_dir_path = std::path::Path::new(&ns_mod_directory);
+
+ // Safety check: Check whether `mod.json` exists and exit early if not
+ // If it does not exist, we might not be dealing with a Northstar mod
+ let mod_json_path = ns_mod_dir_path.join("mod.json");
+ if !mod_json_path.exists() {
+ // If it doesn't exist, return an error
+ return Err(format!("mod.json does not exist in {}", ns_mod_directory));
+ }
+
+ match std::fs::remove_dir_all(&ns_mod_directory) {
+ Ok(()) => Ok(()),
+ Err(err) => Err(format!("Failed deleting mod: {err}")),
+ }
+}
+
+/// Deletes a Northstar mod based on its name
+#[tauri::command]
+pub fn delete_northstar_mod(game_install: GameInstall, nsmod_name: String) -> Result<(), String> {
+ // Prevent deleting core mod
+ for core_mod in CORE_MODS {
+ if nsmod_name == core_mod {
+ return Err(format!("Cannot remove core mod {nsmod_name}"));
+ }
+ }
+
+ // Get installed mods
+ let installed_ns_mods = get_installed_mods_and_properties(game_install)?;
+
+ // Get folder name based on northstarmods
+ for installed_ns_mod in installed_ns_mods {
+ // Installed mod matches specified mod
+ if installed_ns_mod.name == nsmod_name {
+ // Delete folder
+ return delete_mod_folder(installed_ns_mod.directory);
+ }
+ }
+
+ Err(format!("Mod {nsmod_name} not found to be installed"))
+}
diff --git a/src-vue/src/views/ModsView.vue b/src-vue/src/views/ModsView.vue
index af3b58a3..2f352ded 100644
--- a/src-vue/src/views/ModsView.vue
+++ b/src-vue/src/views/ModsView.vue
@@ -7,7 +7,15 @@
<el-card v-else shadow="hover" v-for="mod in installedMods" v-bind:key="mod.name">
<el-switch style="--el-switch-on-color: #13ce66; --el-switch-off-color: #8957e5" v-model="mod.enabled"
:before-change="() => updateWhichModsEnabled(mod)" :loading="global_load_indicator" />
- {{mod.name}}
+ <el-popconfirm
+ title="Are you sure to delete this mod?"
+ @confirm="deleteMod(mod)"
+ >
+ <template #reference>
+ <el-button type="danger">Delete</el-button>
+ </template>
+ </el-popconfirm>
+ {{ mod.name }}
</el-card>
</div>
</el-scrollbar>
@@ -69,6 +77,32 @@ export default defineComponent({
this.global_load_indicator = false;
return true;
+ },
+ async deleteMod(mod: NorthstarMod) {
+ let game_install = {
+ game_path: this.$store.state.game_path,
+ install_type: this.$store.state.install_type
+ } as GameInstall;
+ await invoke("delete_northstar_mod", { gameInstall: game_install, nsmodName: mod.name })
+ .then((message) => {
+ // Just a visual indicator that it worked
+ ElNotification({
+ title: `Success deleting ${mod.name}`,
+ type: 'success',
+ position: 'bottom-right'
+ });
+ })
+ .catch((error) => {
+ ElNotification({
+ title: 'Error',
+ message: error,
+ type: 'error',
+ position: 'bottom-right'
+ });
+ })
+ .finally(() => {
+ this.$store.commit('loadInstalledMods');
+ });
}
}
});