chore: resolving merge conflict on downloads

This commit is contained in:
Chubby Granny Chaser 2024-06-05 14:30:12 +01:00
commit d123f63095
No known key found for this signature in database
5 changed files with 56 additions and 41 deletions

View file

@ -1,8 +1,6 @@
import path from "node:path"; import path from "node:path";
import fs from "node:fs"; import fs from "node:fs";
import { In } from "typeorm";
import { gameRepository } from "@main/repository"; import { gameRepository } from "@main/repository";
import { getDownloadsPath } from "../helpers/get-downloads-path"; import { getDownloadsPath } from "../helpers/get-downloads-path";
@ -14,11 +12,18 @@ const deleteGameFolder = async (
gameId: number gameId: number
): Promise<void> => { ): Promise<void> => {
const game = await gameRepository.findOne({ const game = await gameRepository.findOne({
where: { where: [
id: gameId, {
status: In(["removed", "complete"]), id: gameId,
isDeleted: false, isDeleted: false,
}, status: "removed",
},
{
id: gameId,
progress: 1,
isDeleted: false,
},
],
}); });
if (!game) return; if (!game) return;
@ -29,22 +34,32 @@ const deleteGameFolder = async (
game.folderName game.folderName
); );
if (fs.existsSync(folderPath)) { if (!fs.existsSync(folderPath)) {
return new Promise((resolve, reject) => { await gameRepository.update(
fs.rm( { id: gameId },
folderPath, { downloadPath: null, folderName: null }
{ recursive: true, force: true, maxRetries: 5, retryDelay: 200 }, );
(error) => {
if (error) {
logger.error(error);
reject();
}
resolve();
}
);
});
} }
return new Promise<void>((resolve, reject) => {
fs.rm(
folderPath,
{ recursive: true, force: true, maxRetries: 5, retryDelay: 200 },
(error) => {
if (error) {
logger.error(error);
reject();
}
resolve();
}
);
}).then(async () => {
await gameRepository.update(
{ id: gameId },
{ downloadPath: null, folderName: null }
);
});
} }
}; };

View file

@ -30,6 +30,6 @@ export const getSteamAppDetails = async (
}) })
.catch((err) => { .catch((err) => {
logger.error(err, { method: "getSteamAppDetails" }); logger.error(err, { method: "getSteamAppDetails" });
throw new Error(err); return null;
}); });
}; };

View file

@ -52,7 +52,6 @@ export function useDownload() {
try { try {
await window.electron.deleteGameFolder(gameId); await window.electron.deleteGameFolder(gameId);
await window.electron.removeGame(gameId);
updateLibrary(); updateLibrary();
} finally { } finally {
dispatch(removeGameFromDeleting(gameId)); dispatch(removeGameFromDeleting(gameId));

View file

@ -69,7 +69,7 @@ export function Downloads() {
); );
const complete = orderBy(result.complete, (game) => const complete = orderBy(result.complete, (game) =>
game.status === "complete" ? 0 : 1 game.progress === 1 ? 0 : 1
); );
return { return {

View file

@ -110,11 +110,6 @@ export function HeroPanelActions() {
return; return;
} }
if (game?.executablePath) {
window.electron.openGame(game.id, game.executablePath);
return;
}
const gameExecutablePath = await selectGameExecutable(); const gameExecutablePath = await selectGameExecutable();
if (gameExecutablePath) if (gameExecutablePath)
window.electron.openGame(game.id, gameExecutablePath); window.electron.openGame(game.id, gameExecutablePath);
@ -139,6 +134,17 @@ export function HeroPanelActions() {
</Button> </Button>
); );
const showDownloadOptionsButton = (
<Button
onClick={openRepacksModal}
theme="outline"
disabled={deleting}
className={styles.heroPanelAction}
>
{t("open_download_options")}
</Button>
);
if (game?.status === "active" && game?.progress !== 1) { if (game?.status === "active" && game?.progress !== 1) {
return ( return (
<> <>
@ -188,14 +194,7 @@ export function HeroPanelActions() {
if (game?.status === "removed") { if (game?.status === "removed") {
return ( return (
<> <>
<Button {showDownloadOptionsButton}
onClick={openRepacksModal}
theme="outline"
disabled={deleting}
className={styles.heroPanelAction}
>
{t("open_download_options")}
</Button>
<Button <Button
onClick={() => removeGameFromLibrary(game.id).then(updateGame)} onClick={() => removeGameFromLibrary(game.id).then(updateGame)}
@ -227,7 +226,7 @@ export function HeroPanelActions() {
if (game) { if (game) {
return ( return (
<> <>
{game?.progress === 1 ? ( {game.progress === 1 && game.downloadPath && (
<> <>
<BinaryNotFoundModal <BinaryNotFoundModal
visible={showBinaryNotFoundModal} visible={showBinaryNotFoundModal}
@ -243,10 +242,12 @@ export function HeroPanelActions() {
{t("install")} {t("install")}
</Button> </Button>
</> </>
) : (
toggleGameOnLibraryButton
)} )}
{game.progress === 1 && !game.downloadPath && showDownloadOptionsButton}
{game.progress !== 1 && toggleGameOnLibraryButton}
{isGameRunning ? ( {isGameRunning ? (
<Button <Button
onClick={closeGame} onClick={closeGame}