separated install result and install error
This commit is contained in:
parent
35117eefd5
commit
451a50b17f
8 changed files with 131 additions and 92 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<InstallResult, InstallErr> {
|
||||
println!();
|
||||
println!("Launch Game once");
|
||||
|
||||
emit(&window, InstallSteps::LaunchGame);
|
||||
return Err(InstallResult::LaunchGame); // stop install
|
||||
return Ok(InstallResult::LaunchGame); // stop install
|
||||
}
|
||||
|
|
|
@ -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<InstallResult, InstallErr> {
|
||||
// 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 {
|
||||
|
|
|
@ -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<InstallResult, InstallErr> {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
</script>
|
||||
|
||||
<div class="interrupts">
|
||||
|
@ -19,10 +23,12 @@
|
|||
>
|
||||
click to copy
|
||||
</span>
|
||||
|
||||
<button on:click={setSteamLaunchOptionAndInstall}>Resume</button>
|
||||
{/if}
|
||||
|
||||
<!-- if the game was not found in the default install location -->
|
||||
{#if lastReturnStatus == InstallResult.FailedToGetGamePath}
|
||||
{#if lastErrStaus == InstallErr.FailedToGetGamePath}
|
||||
<p>
|
||||
Default game install location was not found :(
|
||||
<br />
|
||||
|
@ -46,6 +52,11 @@
|
|||
Select folder and Install
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
{#if lastReturnStatus == InstallResult.LaunchGame}
|
||||
Launch game
|
||||
<button on:click={launchGameAndInstall}>Resume</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
|
|
|
@ -15,14 +15,22 @@
|
|||
|
||||
// types
|
||||
import { COMMANDS, EVENTS } from "../../constants"
|
||||
import { InstallResult, InstallSteps } from "./types"
|
||||
import { InstallErr, InstallResult, InstallSteps } from "./types"
|
||||
import type { InstallStatus } from "./types"
|
||||
|
||||
interface Args {
|
||||
gamePath?: string
|
||||
isLaunchOptionSet?: boolean
|
||||
wasGameLaunched?: boolean
|
||||
}
|
||||
|
||||
//
|
||||
// variables
|
||||
//
|
||||
|
||||
let lastReturnStatus: InstallResult = undefined
|
||||
let lastErrStaus: InstallErr = undefined
|
||||
let didLastRunFail = false
|
||||
let wasInstallButtonClicked = false
|
||||
let spinCog = false
|
||||
|
||||
|
@ -40,75 +48,73 @@
|
|||
// functions
|
||||
//
|
||||
|
||||
function _install(gamePath = "") {
|
||||
/**
|
||||
* only used inside other install functions.
|
||||
* Is never called directly.
|
||||
*
|
||||
* @param {Args} args
|
||||
*/
|
||||
function _install(args: Args) {
|
||||
wasInstallButtonClicked = true
|
||||
spinCog = true
|
||||
|
||||
invoke<InstallResult>(COMMANDS.INSTALL, { gamePath }).then((res) => {
|
||||
lastReturnStatus = res
|
||||
invoke<InstallResult>(COMMANDS.INSTALL, args as any)
|
||||
.then((res) => {
|
||||
lastReturnStatus = res
|
||||
|
||||
switch (res) {
|
||||
case InstallResult.NoErr: {
|
||||
break
|
||||
}
|
||||
switch (res) {
|
||||
case InstallResult.NoErr: {
|
||||
break
|
||||
}
|
||||
|
||||
case InstallResult.FailedToGetGamePath: {
|
||||
break
|
||||
}
|
||||
case InstallResult.SetLaunchOption: {
|
||||
break
|
||||
}
|
||||
|
||||
case InstallResult.UnsupportedOS: {
|
||||
break
|
||||
}
|
||||
case InstallResult.LaunchGame: {
|
||||
break
|
||||
}
|
||||
|
||||
case InstallResult.BepInExDownloadFailed: {
|
||||
break
|
||||
case InstallResult.Skip: {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
case InstallResult.BepInExUnzipFailed: {
|
||||
break
|
||||
}
|
||||
|
||||
case InstallResult.SetLaunchOption: {
|
||||
break
|
||||
}
|
||||
|
||||
case InstallResult.LaunchGame: {
|
||||
break
|
||||
}
|
||||
|
||||
case InstallResult.WBMDownloadFailed: {
|
||||
break
|
||||
}
|
||||
|
||||
case InstallResult.WBMRemoveFailed: {
|
||||
break
|
||||
}
|
||||
|
||||
case InstallResult.WBMDirectoryCreationFailed: {
|
||||
break
|
||||
}
|
||||
|
||||
case InstallResult.WBMUnzipFailed: {
|
||||
break
|
||||
}
|
||||
|
||||
case InstallResult.NoErr: {
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch((err: InstallErr) => {
|
||||
console.log(typeof err, err)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* entry point
|
||||
*/
|
||||
function install() {
|
||||
_install()
|
||||
_install({})
|
||||
}
|
||||
|
||||
/**
|
||||
* called when default game path was not found.
|
||||
*/
|
||||
function selectGamePathAndInstall() {
|
||||
dialogOpen({ directory: true, multiple: false }).then((gamePath) => {
|
||||
_install(gamePath as string)
|
||||
_install({ gamePath: gamePath as string })
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* called after setting the steam launch option.
|
||||
*/
|
||||
function setSteamLaunchOptionAndInstall() {
|
||||
_install({ isLaunchOptionSet: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* called after launching the game once.
|
||||
*/
|
||||
function launchGameAndInstall() {
|
||||
_install({ isLaunchOptionSet: true, wasGameLaunched: true })
|
||||
}
|
||||
|
||||
//
|
||||
// Event listener
|
||||
//
|
||||
|
@ -169,7 +175,14 @@
|
|||
<!-- show only when the install button is clicked -->
|
||||
{#if wasInstallButtonClicked}
|
||||
<Steps {installStatus} />
|
||||
<Interrupts {installStatus} {lastReturnStatus} {selectGamePathAndInstall} />
|
||||
<Interrupts
|
||||
{installStatus}
|
||||
{lastReturnStatus}
|
||||
{lastErrStaus}
|
||||
{selectGamePathAndInstall}
|
||||
{setSteamLaunchOptionAndInstall}
|
||||
{launchGameAndInstall}
|
||||
/>
|
||||
|
||||
{#if installStatus.Done}
|
||||
<Complete />
|
||||
|
|
|
@ -12,12 +12,16 @@ export enum InstallSteps {
|
|||
// types of install command return codes
|
||||
export enum InstallResult {
|
||||
NoErr,
|
||||
SetLaunchOption,
|
||||
LaunchGame,
|
||||
Skip, // only used for subcommands
|
||||
}
|
||||
|
||||
export enum InstallErr {
|
||||
FailedToGetGamePath,
|
||||
UnsupportedOS,
|
||||
BepInExDownloadFailed,
|
||||
BepInExUnzipFailed,
|
||||
SetLaunchOption,
|
||||
LaunchGame,
|
||||
WBMDownloadFailed,
|
||||
WBMRemoveFailed,
|
||||
WBMDirectoryCreationFailed,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue