added basic WBM remove feature
This commit is contained in:
parent
03fd685afc
commit
56e03bf6f4
4 changed files with 138 additions and 5 deletions
|
@ -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(());
|
||||
}
|
||||
|
|
|
@ -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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
|
|
|
@ -1,5 +1,81 @@
|
|||
<script lang="ts">
|
||||
/**
|
||||
* This component is shown during the removal of the War Brokers Mods.
|
||||
* It asks for user input when needed and shows error when something's gone wrong.
|
||||
*/
|
||||
|
||||
import store from "./store"
|
||||
import { RemoveErr } from "./types"
|
||||
import { selectGamePathAndRun } from "./logic"
|
||||
|
||||
let lastRemoveErr: RemoveErr = undefined
|
||||
let wasRemoveSuccessful: boolean = false
|
||||
|
||||
store.lastRemoveErr.subscribe((value) => {
|
||||
lastRemoveErr = value
|
||||
})
|
||||
|
||||
store.wasRemoveSuccessful.subscribe((value) => {
|
||||
wasRemoveSuccessful = value
|
||||
})
|
||||
|
||||
// todo: Reset steam launch option.
|
||||
</script>
|
||||
|
||||
<!-- Handle lastRemoveErr change -->
|
||||
<!-- On remove complete -->
|
||||
<div class="remove">
|
||||
{#if wasRemoveSuccessful}
|
||||
WBM Removed!
|
||||
<br />
|
||||
You may now close the installer.
|
||||
{:else if false}
|
||||
Reset steam launch options.
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<img alt="where to find property settings" src="/img/properties.png" />
|
||||
|
||||
<br />
|
||||
|
||||
<img alt="where to find launch option" src="/img/launch_option.png" />
|
||||
|
||||
<br />
|
||||
|
||||
<button
|
||||
on:click|once={() => {
|
||||
store.lastRemoveErr.set(undefined)
|
||||
store.wasRemoveSuccessful.set(true)
|
||||
}}
|
||||
>
|
||||
Continue!
|
||||
</button>
|
||||
{:else if lastRemoveErr == RemoveErr.FailedToGetGamePath}
|
||||
Where is the game folder?
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<button
|
||||
on:click|once={() => {
|
||||
selectGamePathAndRun("remove")
|
||||
lastRemoveErr = undefined
|
||||
}}
|
||||
>
|
||||
Select game path
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
@import "./styles/button.scss";
|
||||
|
||||
.remove {
|
||||
/* make install section scrollable */
|
||||
@apply w-full h-40 text-center overflow-y-auto overflow-x-hidden;
|
||||
|
||||
img {
|
||||
/* center image */
|
||||
@apply block ml-auto mr-auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue