mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-21 10:03:56 +00:00
refactor: change game delete to soft delete
This commit is contained in:
@@ -61,6 +61,9 @@ export class Game {
|
||||
@JoinColumn()
|
||||
repack: Repack;
|
||||
|
||||
@Column("boolean", { default: false })
|
||||
isDeleted: boolean;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ import "./catalogue/search-games";
|
||||
import "./hardware/get-disk-free-space";
|
||||
import "./library/add-game-to-library";
|
||||
import "./library/close-game";
|
||||
import "./library/delete-game-folder";
|
||||
import "./torrenting/delete-game-folder";
|
||||
import "./library/get-game-by-object-id";
|
||||
import "./library/get-library";
|
||||
import "./library/get-repackers-friendly-names";
|
||||
import "./library/open-game";
|
||||
import "./library/open-game-installer";
|
||||
import "./library/remove-game";
|
||||
import "./library/remove-game-from-library";
|
||||
import "./misc/get-or-cache-image";
|
||||
import "./misc/open-external";
|
||||
import "./misc/show-open-dialog";
|
||||
@@ -24,6 +24,7 @@ import "./torrenting/cancel-game-download";
|
||||
import "./torrenting/pause-game-download";
|
||||
import "./torrenting/resume-game-download";
|
||||
import "./torrenting/start-game-download";
|
||||
import "./torrenting/remove-game-from-download";
|
||||
import "./user-preferences/get-user-preferences";
|
||||
import "./user-preferences/update-user-preferences";
|
||||
|
||||
|
||||
@@ -13,15 +13,34 @@ const addGameToLibrary = async (
|
||||
gameShop: GameShop,
|
||||
executablePath: string
|
||||
) => {
|
||||
const iconUrl = await getImageBase64(await getSteamGameIconUrl(objectID));
|
||||
|
||||
return gameRepository.insert({
|
||||
title,
|
||||
iconUrl,
|
||||
objectID,
|
||||
shop: gameShop,
|
||||
executablePath,
|
||||
const game = await gameRepository.findOne({
|
||||
where: {
|
||||
objectID,
|
||||
},
|
||||
});
|
||||
|
||||
if (game) {
|
||||
return gameRepository.update(
|
||||
{
|
||||
id: game.id,
|
||||
},
|
||||
{
|
||||
shop: gameShop,
|
||||
executablePath,
|
||||
isDeleted: false,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
const iconUrl = await getImageBase64(await getSteamGameIconUrl(objectID));
|
||||
|
||||
return gameRepository.insert({
|
||||
title,
|
||||
iconUrl,
|
||||
objectID,
|
||||
shop: gameShop,
|
||||
executablePath,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
registerEvent(addGameToLibrary, {
|
||||
|
||||
@@ -9,6 +9,7 @@ const getGameByObjectID = async (
|
||||
gameRepository.findOne({
|
||||
where: {
|
||||
objectID,
|
||||
isDeleted: false,
|
||||
},
|
||||
relations: {
|
||||
repack: true,
|
||||
|
||||
@@ -8,6 +8,9 @@ import sortBy from "lodash/sortBy";
|
||||
const getLibrary = async (_event: Electron.IpcMainInvokeEvent) =>
|
||||
gameRepository
|
||||
.find({
|
||||
where: {
|
||||
isDeleted: false,
|
||||
},
|
||||
order: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
|
||||
13
src/main/events/library/remove-game-from-library.ts
Normal file
13
src/main/events/library/remove-game-from-library.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { registerEvent } from "../register-event";
|
||||
import { gameRepository } from "../../repository";
|
||||
|
||||
const removeGameFromLibrary = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
gameId: number
|
||||
) => {
|
||||
gameRepository.update({ id: gameId }, { isDeleted: true });
|
||||
};
|
||||
|
||||
registerEvent(removeGameFromLibrary, {
|
||||
name: "removeGameFromLibrary",
|
||||
});
|
||||
@@ -1,11 +0,0 @@
|
||||
import { registerEvent } from "../register-event";
|
||||
import { gameRepository } from "../../repository";
|
||||
|
||||
const removeGame = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
gameId: number
|
||||
) => gameRepository.delete({ id: gameId });
|
||||
|
||||
registerEvent(removeGame, {
|
||||
name: "removeGame",
|
||||
});
|
||||
@@ -25,14 +25,13 @@ const cancelGameDownload = async (
|
||||
|
||||
if (!game) return;
|
||||
|
||||
gameRepository
|
||||
await gameRepository
|
||||
.update(
|
||||
{
|
||||
id: game.id,
|
||||
},
|
||||
{
|
||||
status: GameStatus.Cancelled,
|
||||
downloadPath: null,
|
||||
bytesDownloaded: 0,
|
||||
progress: 0,
|
||||
}
|
||||
|
||||
@@ -22,7 +22,10 @@ const deleteGameFolder = async (
|
||||
if (!game) return;
|
||||
|
||||
if (game.folderName) {
|
||||
const folderPath = path.join(await getDownloadsPath(), game.folderName);
|
||||
const folderPath = path.join(
|
||||
game.downloadPath ?? (await getDownloadsPath()),
|
||||
game.folderName
|
||||
);
|
||||
|
||||
if (fs.existsSync(folderPath)) {
|
||||
return new Promise((resolve, reject) => {
|
||||
34
src/main/events/torrenting/remove-game-from-download.ts
Normal file
34
src/main/events/torrenting/remove-game-from-download.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { GameStatus } from "@main/constants";
|
||||
import { gameRepository } from "@main/repository";
|
||||
|
||||
import { registerEvent } from "../register-event";
|
||||
|
||||
const removeGameFromDownload = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
gameId: number
|
||||
) => {
|
||||
const game = await gameRepository.findOne({
|
||||
where: {
|
||||
id: gameId,
|
||||
status: GameStatus.Cancelled,
|
||||
},
|
||||
});
|
||||
|
||||
if (!game) return;
|
||||
|
||||
gameRepository.update(
|
||||
{
|
||||
id: game.id,
|
||||
},
|
||||
{
|
||||
status: null,
|
||||
downloadPath: null,
|
||||
bytesDownloaded: 0,
|
||||
progress: 0,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
registerEvent(removeGameFromDownload, {
|
||||
name: "removeGameFromDownload",
|
||||
});
|
||||
@@ -59,6 +59,7 @@ const startGameDownload = async (
|
||||
status: GameStatus.DownloadingMetadata,
|
||||
downloadPath: downloadsPath,
|
||||
repack: { id: repackId },
|
||||
isDeleted: false,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -71,13 +72,6 @@ const startGameDownload = async (
|
||||
|
||||
game.status = GameStatus.DownloadingMetadata;
|
||||
|
||||
writePipe.write({
|
||||
action: "start",
|
||||
game_id: game.id,
|
||||
magnet: repack.magnet,
|
||||
save_path: downloadsPath,
|
||||
});
|
||||
|
||||
return game;
|
||||
} else {
|
||||
const iconUrl = await getImageBase64(await getSteamGameIconUrl(objectID));
|
||||
|
||||
Reference in New Issue
Block a user