mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
feat: dont set game as removed when deleting instalation folder
This commit is contained in:
parent
d6e57c20c7
commit
7ac7d92a28
@ -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";
|
||||||
@ -16,7 +14,6 @@ const deleteGameFolder = async (
|
|||||||
const game = await gameRepository.findOne({
|
const game = await gameRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: gameId,
|
id: gameId,
|
||||||
status: In(["removed", "complete"]),
|
|
||||||
isDeleted: false,
|
isDeleted: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -29,22 +26,34 @@ 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();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("folder exists");
|
||||||
|
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 () => {
|
||||||
|
console.log("resolved");
|
||||||
|
await gameRepository.update(
|
||||||
|
{ id: gameId },
|
||||||
|
{ downloadPath: null, folderName: null }
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -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));
|
||||||
|
@ -47,17 +47,21 @@ export function Downloads() {
|
|||||||
complete: [],
|
complete: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = library.reduce((prev, next) => {
|
const result = library
|
||||||
if (lastPacket?.game.id === next.id) {
|
.filter((game) => {
|
||||||
return { ...prev, downloading: [...prev.downloading, next] };
|
return game.downloadPath;
|
||||||
}
|
})
|
||||||
|
.reduce((prev, next) => {
|
||||||
|
if (lastPacket?.game.id === next.id) {
|
||||||
|
return { ...prev, downloading: [...prev.downloading, next] };
|
||||||
|
}
|
||||||
|
|
||||||
if (next.downloadQueue || next.status === "paused") {
|
if (next.downloadQueue || next.status === "paused") {
|
||||||
return { ...prev, queued: [...prev.queued, next] };
|
return { ...prev, queued: [...prev.queued, next] };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...prev, complete: [...prev.complete, next] };
|
return { ...prev, complete: [...prev.complete, next] };
|
||||||
}, initialValue);
|
}, initialValue);
|
||||||
|
|
||||||
const queued = orderBy(
|
const queued = orderBy(
|
||||||
result.queued,
|
result.queued,
|
||||||
@ -66,7 +70,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 {
|
||||||
|
@ -77,13 +77,11 @@ export function HeroPanelActions() {
|
|||||||
if (game) {
|
if (game) {
|
||||||
await removeGameFromLibrary(game.id);
|
await removeGameFromLibrary(game.id);
|
||||||
} else {
|
} else {
|
||||||
const gameExecutablePath = await selectGameExecutable();
|
|
||||||
|
|
||||||
await window.electron.addGameToLibrary(
|
await window.electron.addGameToLibrary(
|
||||||
objectID!,
|
objectID!,
|
||||||
gameTitle,
|
gameTitle,
|
||||||
"steam",
|
"steam",
|
||||||
gameExecutablePath
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,11 +108,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 +132,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 +192,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 +224,7 @@ export function HeroPanelActions() {
|
|||||||
if (game) {
|
if (game) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{game?.progress === 1 ? (
|
{game?.progress === 1 && game?.folderName && (
|
||||||
<>
|
<>
|
||||||
<BinaryNotFoundModal
|
<BinaryNotFoundModal
|
||||||
visible={showBinaryNotFoundModal}
|
visible={showBinaryNotFoundModal}
|
||||||
@ -243,10 +240,12 @@ export function HeroPanelActions() {
|
|||||||
{t("install")}
|
{t("install")}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
) : (
|
|
||||||
toggleGameOnLibraryButton
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{game?.progress === 1 && !game?.folderName && showDownloadOptionsButton}
|
||||||
|
|
||||||
|
{game?.progress !== 1 && toggleGameOnLibraryButton}
|
||||||
|
|
||||||
{isGameRunning ? (
|
{isGameRunning ? (
|
||||||
<Button
|
<Button
|
||||||
onClick={closeGame}
|
onClick={closeGame}
|
||||||
|
Loading…
Reference in New Issue
Block a user