From 451a50b17f20b8051c6a499257b3bc57760024f2 Mon Sep 17 00:00:00 2001 From: developomp Date: Thu, 27 Jan 2022 15:19:16 +0900 Subject: [PATCH] separated install result and install error --- .../src/commands/install/install_bepinex.rs | 10 +- src-tauri/src/commands/install/install_mod.rs | 16 +-- src-tauri/src/commands/install/launch_game.rs | 6 +- .../src/commands/install/launch_options.rs | 12 +- src-tauri/src/commands/install/mod.rs | 39 +++--- src/pages/Install/Interrupts.svelte | 13 +- src/pages/Install/index.svelte | 119 ++++++++++-------- src/pages/Install/types.ts | 8 +- 8 files changed, 131 insertions(+), 92 deletions(-) diff --git a/src-tauri/src/commands/install/install_bepinex.rs b/src-tauri/src/commands/install/install_bepinex.rs index 150c446..45337b1 100644 --- a/src-tauri/src/commands/install/install_bepinex.rs +++ b/src-tauri/src/commands/install/install_bepinex.rs @@ -2,11 +2,11 @@ use std::env; use tauri::Window; -use super::InstallResult; +use super::InstallErr; use crate::commands::install::{emit, InstallSteps}; use crate::util; -pub async fn install_bepinex(window: &Window, game_path: &str) -> Result<(), InstallResult> { +pub async fn install_bepinex(window: &Window, game_path: &str) -> Result<(), InstallErr> { println!(); println!("Installing BepInEx"); @@ -26,7 +26,7 @@ pub async fn install_bepinex(window: &Window, game_path: &str) -> Result<(), Ins _ => { println!("Unsupported OS!"); - return Err(InstallResult::UnsupportedOS); + return Err(InstallErr::UnsupportedOS); } }; @@ -52,14 +52,14 @@ pub async fn install_bepinex(window: &Window, game_path: &str) -> Result<(), Ins Err(err) => { println!("Failed to unzip BepInEx.zip ({:#?})", err); - return Err(InstallResult::BepInExUnzipFailed); + return Err(InstallErr::BepInExUnzipFailed); } } } Err(_) => { println!("Failed to download BepInEx.zip"); - return Err(InstallResult::BepInExDownloadFailed); + return Err(InstallErr::BepInExDownloadFailed); } } diff --git a/src-tauri/src/commands/install/install_mod.rs b/src-tauri/src/commands/install/install_mod.rs index 9d5aa33..20ff151 100644 --- a/src-tauri/src/commands/install/install_mod.rs +++ b/src-tauri/src/commands/install/install_mod.rs @@ -1,9 +1,9 @@ use tauri::Window; -use super::InstallResult; +use super::InstallErr; use crate::commands::install::{emit, util, InstallSteps}; -pub async fn install_wbm_mod(window: &Window, game_path: &str) -> Result<(), InstallResult> { +pub async fn install_wbm_mod(window: &Window, game_path: &str) -> Result<(), InstallErr> { println!(); println!("Installing WBM mod"); @@ -15,13 +15,13 @@ pub async fn install_wbm_mod(window: &Window, game_path: &str) -> Result<(), Ins None => { println!("Failed to parse latest release"); - return Err(InstallResult::WBMDownloadFailed); + return Err(InstallErr::WBMDownloadFailed); } }, Err(_) => { println!("Failed to get latest release"); - return Err(InstallResult::WBMDownloadFailed); + return Err(InstallErr::WBMDownloadFailed); } }; @@ -35,7 +35,7 @@ pub async fn install_wbm_mod(window: &Window, game_path: &str) -> Result<(), Ins Ok(_) => {} Err(_) => { println!("Failed to remove existing WBM mod files"); - return Err(InstallResult::WBMRemoveFailed); + return Err(InstallErr::WBMRemoveFailed); } }; @@ -44,7 +44,7 @@ pub async fn install_wbm_mod(window: &Window, game_path: &str) -> Result<(), Ins Ok(_) => {} Err(_) => { println!("Failed to create WBM mod directory"); - return Err(InstallResult::WBMDirectoryCreationFailed); + return Err(InstallErr::WBMDirectoryCreationFailed); } } @@ -56,14 +56,14 @@ pub async fn install_wbm_mod(window: &Window, game_path: &str) -> Result<(), Ins Err(err) => { println!("Failed to unzip WBM.zip: ({:#?})", err); - return Err(InstallResult::WBMUnzipFailed); + return Err(InstallErr::WBMUnzipFailed); } }; } Err(_) => { println!("Failed to download WBM.zip"); - return Err(InstallResult::WBMDownloadFailed); + return Err(InstallErr::WBMDownloadFailed); } } diff --git a/src-tauri/src/commands/install/launch_game.rs b/src-tauri/src/commands/install/launch_game.rs index 3dd8d19..bd45b25 100644 --- a/src-tauri/src/commands/install/launch_game.rs +++ b/src-tauri/src/commands/install/launch_game.rs @@ -1,12 +1,12 @@ use tauri::Window; -use super::InstallResult; +use super::{InstallErr, InstallResult}; use crate::commands::install::{emit, InstallSteps}; -pub async fn launch_game_once(window: &Window) -> Result<(), InstallResult> { +pub async fn launch_game_once(window: &Window) -> Result { println!(); println!("Launch Game once"); emit(&window, InstallSteps::LaunchGame); - return Err(InstallResult::LaunchGame); // stop install + return Ok(InstallResult::LaunchGame); // stop install } diff --git a/src-tauri/src/commands/install/launch_options.rs b/src-tauri/src/commands/install/launch_options.rs index 6e0a65c..ed848bb 100644 --- a/src-tauri/src/commands/install/launch_options.rs +++ b/src-tauri/src/commands/install/launch_options.rs @@ -1,12 +1,12 @@ use tauri::Window; -use super::InstallResult; +use super::{InstallErr, InstallResult}; use crate::commands::install::{emit, InstallSteps}; use crate::util; use std::fs; -pub async fn unix_launch_option_setup(window: &Window) -> Result<(), InstallResult> { +pub async fn unix_launch_option_setup(window: &Window) -> Result { // skip if the OS is not linux or macOS match std::env::consts::OS { "linux" | "macos" => { @@ -18,18 +18,18 @@ pub async fn unix_launch_option_setup(window: &Window) -> Result<(), InstallResu println!(); println!("Skipping unix launch option setup"); - return Ok(()); + return Ok(InstallResult::Skip); } }; if is_already_set() { println!("Steam launch option is already set. Skipping."); - return Ok(()); + return Ok(InstallResult::Skip); } - println!("Prompt user to launch option"); + println!("Prompt user to set launch option"); emit(&window, InstallSteps::LaunchOption); - return Err(InstallResult::SetLaunchOption); // stop install function + return Ok(InstallResult::SetLaunchOption); } fn is_already_set() -> bool { diff --git a/src-tauri/src/commands/install/mod.rs b/src-tauri/src/commands/install/mod.rs index f073adb..3d85edd 100644 --- a/src-tauri/src/commands/install/mod.rs +++ b/src-tauri/src/commands/install/mod.rs @@ -10,7 +10,7 @@ mod launch_game; mod launch_options; // [Sync] -#[derive(Clone)] +#[derive(Clone, serde::Serialize)] pub enum InstallSteps { DownloadBepInEx, InstallBepInEx, @@ -22,14 +22,21 @@ pub enum InstallSteps { } // [Sync] +#[derive(serde::Serialize, PartialEq)] pub enum InstallResult { NoErr, + SetLaunchOption, + LaunchGame, + Skip, // only used for subcommands +} + +// [Sync] +#[derive(serde::Serialize)] +pub enum InstallErr { FailedToGetGamePath, UnsupportedOS, BepInExDownloadFailed, BepInExUnzipFailed, - SetLaunchOption, - LaunchGame, WBMDownloadFailed, WBMRemoveFailed, WBMDirectoryCreationFailed, @@ -71,7 +78,7 @@ pub async fn install( game_path: String, is_launch_option_set: bool, was_game_launched: bool, -) -> i64 { +) -> Result { println!("install command called"); // @@ -83,7 +90,7 @@ pub async fn install( _ => { println!("Unsupported OS!"); - return InstallResult::UnsupportedOS as i64; + return Err(InstallErr::UnsupportedOS); } } @@ -97,7 +104,7 @@ pub async fn install( // failed to find game install location. // Prompt user to manually choose the game location. - None => return InstallResult::FailedToGetGamePath as i64, + None => return Err(InstallErr::FailedToGetGamePath), }; default_game_path @@ -114,7 +121,7 @@ pub async fn install( if !is_launch_option_set { match install_bepinex::install_bepinex(&window, game_path).await { Ok(()) => {} - Err(err) => return err as i64, + Err(err) => return Err(err), } } @@ -124,8 +131,8 @@ pub async fn install( if !was_game_launched { match launch_options::unix_launch_option_setup(&window).await { - Ok(()) => {} - Err(err) => return err as i64, + Ok(_) => {} + Err(err) => return Err(err), } } @@ -134,8 +141,12 @@ pub async fn install( // match launch_game::launch_game_once(&window).await { - Ok(()) => {} - Err(err) => return err as i64, + Ok(res) => { + if res != InstallResult::Skip { + return Ok(res); + } + } + Err(err) => return Err(err), } // @@ -144,7 +155,7 @@ pub async fn install( match install_mod::install_wbm_mod(&window, game_path).await { Ok(()) => {} - Err(err) => return err as i64, + Err(err) => return Err(err), } // @@ -154,9 +165,9 @@ pub async fn install( emit(&window, InstallSteps::Done); println!("Install complete!"); - return InstallResult::NoErr as i64; + return Ok(InstallResult::NoErr); } pub fn emit(window: &Window, payload: InstallSteps) { - util::emit(&window, constants::EVENT_INSTALL, payload as i64); + util::emit(&window, constants::EVENT_INSTALL, payload); } diff --git a/src/pages/Install/Interrupts.svelte b/src/pages/Install/Interrupts.svelte index f374da3..3390dd6 100644 --- a/src/pages/Install/Interrupts.svelte +++ b/src/pages/Install/Interrupts.svelte @@ -3,11 +3,15 @@ import { open as shellOpen } from "@tauri-apps/api/shell" import type { InstallStatus } from "./types" + import { InstallErr } from "./types" import { InstallResult } from "./types" export let lastReturnStatus: InstallResult + export let lastErrStaus: InstallErr export let installStatus: InstallStatus export let selectGamePathAndInstall: () => void + export let setSteamLaunchOptionAndInstall: () => void + export let launchGameAndInstall: () => void
@@ -19,10 +23,12 @@ > click to copy + + {/if} - {#if lastReturnStatus == InstallResult.FailedToGetGamePath} + {#if lastErrStaus == InstallErr.FailedToGetGamePath}

Default game install location was not found :(
@@ -46,6 +52,11 @@ Select folder and Install {/if} + + {#if lastReturnStatus == InstallResult.LaunchGame} + Launch game + + {/if}