From 6ea179ae988f2dbd5627bc2be74fa6a243269065 Mon Sep 17 00:00:00 2001 From: tripp <86533397+trippjoe@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:03:10 -0400 Subject: [PATCH] automate successful install progression and handle file not found errors (#583) - automatically progress app after successful install. reduces friction leading to a better UX. - ignore file not found error when uninstalling. after deleted my `iso_data` directory I was unable to successfully uninstall the game because the `?` unwrap would propagate the file not found error. Since our intention is to delete these files, if they are not found we should ignore the error and continue deleting the rest. --- src-tauri/src/commands/game.rs | 35 +++++++++++++++++++-- src/components/games/job/GameJob.svelte | 20 +++--------- src/components/games/setup/GameSetup.svelte | 14 ++------- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src-tauri/src/commands/game.rs b/src-tauri/src/commands/game.rs index 5233d0c..ef7bebe 100644 --- a/src-tauri/src/commands/game.rs +++ b/src-tauri/src/commands/game.rs @@ -36,9 +36,38 @@ pub async fn uninstall_game( .join(&game_name) .join("data"); - std::fs::remove_dir_all(data_folder.join("decompiler_out"))?; - std::fs::remove_dir_all(data_folder.join("iso_data"))?; - std::fs::remove_dir_all(data_folder.join("out"))?; + match std::fs::remove_dir_all(data_folder.join("decompiler_out")) { + Ok(_) => Ok(()), + Err(e) => match e.kind() { + std::io::ErrorKind::NotFound => Ok(()), + _ => { + log::error!("Failed to delete directory: {:?}", e); + Err(e) + } + }, + }?; + + match std::fs::remove_dir_all(data_folder.join("iso_data")) { + Ok(_) => Ok(()), + Err(e) => match e.kind() { + std::io::ErrorKind::NotFound => Ok(()), + _ => { + log::error!("Failed to delete directory: {:?}", e); + Err(e) + } + }, + }?; + + match std::fs::remove_dir_all(data_folder.join("out")) { + Ok(_) => Ok(()), + Err(e) => match e.kind() { + std::io::ErrorKind::NotFound => Ok(()), + _ => { + log::error!("Failed to delete directory: {:?}", e); + Err(e) + } + }, + }?; config_lock .update_installed_game_version(&game_name, false) diff --git a/src/components/games/job/GameJob.svelte b/src/components/games/job/GameJob.svelte index d400973..2b67972 100644 --- a/src/components/games/job/GameJob.svelte +++ b/src/components/games/job/GameJob.svelte @@ -45,6 +45,10 @@ const dispatch = createEventDispatcher(); let installationError: string | undefined | null = undefined; + $: if ($progressTracker.overallStatus === "success") { + dispatch("jobFinished"); + } + async function setupDecompileJob() { installationError = undefined; progressTracker.init([ @@ -470,27 +474,13 @@ await setupCompileModJob(); } }); - - function dispatchCompleteJob() { - dispatch("jobFinished"); - }
-{#if $progressTracker.overallStatus === "success"} -
-
- -
-
-{:else if $progressTracker.overallStatus === "failed"} +{#if $progressTracker.overallStatus === "failed"}
diff --git a/src/components/games/setup/GameSetup.svelte b/src/components/games/setup/GameSetup.svelte index 81a9820..fca1a54 100644 --- a/src/components/games/setup/GameSetup.svelte +++ b/src/components/games/setup/GameSetup.svelte @@ -117,7 +117,7 @@ } } - async function dispatchSetupEvent() { + $: if ($progressTracker.overallStatus === "success") { dispatch("change"); } @@ -129,17 +129,7 @@
- {#if $progressTracker.overallStatus === "success"} -
-
- -
-
- {:else if $progressTracker.overallStatus === "failed"} + {#if $progressTracker.overallStatus === "failed"}