From 56e03bf6f4afbfec0dedfd6e88be9b094dd108a6 Mon Sep 17 00:00:00 2001 From: developomp Date: Thu, 3 Feb 2022 09:51:03 +0900 Subject: [PATCH] added basic WBM remove feature --- src-tauri/src/commands/remove/mod.rs | 54 ++++++++++++++++- src-tauri/src/commands/remove/types.rs | 6 +- src/pages/Operation/Remove.svelte | 80 +++++++++++++++++++++++++- src/pages/Operation/types.ts | 3 +- 4 files changed, 138 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/commands/remove/mod.rs b/src-tauri/src/commands/remove/mod.rs index 9814853..d959bef 100644 --- a/src-tauri/src/commands/remove/mod.rs +++ b/src-tauri/src/commands/remove/mod.rs @@ -2,7 +2,59 @@ mod types; use types::RemoveErr; +use crate::util; + #[tauri::command] -pub async fn remove(_game_path: String) -> Result<(), RemoveErr> { +pub async fn remove(game_path: String) -> Result<(), RemoveErr> { + println!("Remove command called"); + + // + // Test if OS is compatible + // + + match std::env::consts::OS { + "linux" | "macos" | "windows" => {} + + _ => { + println!("Unsupported OS!"); + return Err(RemoveErr::UnsupportedOS); + } + } + + // + // Resolve game path + // + + let game_path = if game_path.is_empty() { + let default_game_path = match util::get_default_game_path() { + Some(path) => path, + + // failed to find game install location. + // Prompt user to manually choose the game location. + None => return Err(RemoveErr::FailedToGetGamePath), + }; + + default_game_path + } else { + game_path + }; + let game_path = game_path.as_str(); + + // + // Remove files + // + + match util::uninstall(&game_path) { + Ok(_) => {} + + Err(_) => { + return Err(RemoveErr::FailedToRemoveFiles); + } + } + + // + // todo: Reset steam launch option + // + return Ok(()); } diff --git a/src-tauri/src/commands/remove/types.rs b/src-tauri/src/commands/remove/types.rs index ab7acb6..76f7849 100644 --- a/src-tauri/src/commands/remove/types.rs +++ b/src-tauri/src/commands/remove/types.rs @@ -1,7 +1,11 @@ /// must be synced with `src/pages/Remove/types.ts` #[derive(Clone, Copy)] -pub enum RemoveErr {} +pub enum RemoveErr { + UnsupportedOS, + FailedToGetGamePath, + FailedToRemoveFiles, +} impl serde::Serialize for RemoveErr { fn serialize(&self, serializer: S) -> Result diff --git a/src/pages/Operation/Remove.svelte b/src/pages/Operation/Remove.svelte index 9e373cb..067df58 100644 --- a/src/pages/Operation/Remove.svelte +++ b/src/pages/Operation/Remove.svelte @@ -1,5 +1,81 @@ - - +
+ {#if wasRemoveSuccessful} + WBM Removed! +
+ You may now close the installer. + {:else if false} + Reset steam launch options. + +
+
+ + where to find property settings + +
+ + where to find launch option + +
+ + + {:else if lastRemoveErr == RemoveErr.FailedToGetGamePath} + Where is the game folder? + +
+
+ + + {/if} +
+ + diff --git a/src/pages/Operation/types.ts b/src/pages/Operation/types.ts index 719ab5d..cc093eb 100644 --- a/src/pages/Operation/types.ts +++ b/src/pages/Operation/types.ts @@ -18,8 +18,9 @@ export enum InstallErr { * Must be synced with `src-tauri/src/commands/remove/types.rs` */ export enum RemoveErr { + UnsupportedOS, FailedToGetGamePath, - GamePathNotValid, + FailedToRemoveFiles, } export enum OperationType {