Implemented game uninstall functionality (#31)

Another one that's pretty self explanatory.

Added a function to delete the directories:
`data/decompiler_out/game`
`data/iso_data/game`
`data/out/game`

Where `game` is the specified game passed in.
This commit is contained in:
tripp 2022-09-13 22:23:33 -04:00 committed by GitHub
parent 5730ad2630
commit 08fe008133
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -3,7 +3,11 @@
import { getInternalName, SupportedGame } from "$lib/constants";
import { launchGame, launchGameInDebug } from "$lib/launch";
import { openDir } from "$lib/rpc/commands";
import { compileGame, decompileGameData } from "$lib/setup/setup";
import {
compileGame,
decompileGameData,
uninstallGame,
} from "$lib/setup/setup";
import { appDir, configDir, join } from "@tauri-apps/api/path";
import { createEventDispatcher, onMount } from "svelte";
import LogViewer from "./setup/LogViewer.svelte";
@ -42,6 +46,7 @@
const confirmed = await confirm("Are you sure you want to uninstall?");
if (confirmed) {
await launcherConfig.setInstallStatus(activeGame, false);
await uninstallGame(activeGame);
dispatch("change");
}
}

View file

@ -20,6 +20,7 @@ import { launcherConfig } from "$lib/config";
import { resolveErrorCode } from "./setup_errors";
import { installLog, log } from "$lib/utils/log";
import { ProcessLogs } from "$lib/stores/AppStore";
import { removeDir } from "@tauri-apps/api/fs";
let sidecarOptions = {};
@ -266,3 +267,18 @@ export async function recompileGame(game: SupportedGame): Promise<boolean> {
return false;
}
}
export async function uninstallGame(game: SupportedGame) {
const dataDir = await join(await appDir(), "data");
try {
const t0 = await join(dataDir, "decompiler_out", getInternalName(game));
const t1 = await join(dataDir, "iso_data", getInternalName(game));
const t2 = await join(dataDir, "out", getInternalName(game));
const targets = [t0, t1, t2];
for (const target of targets) {
await removeDir(target, { recursive: true });
}
} catch (error) {
console.error(error);
}
}