feat: implement archive deletion prompt and translations for confirmation messages

This commit is contained in:
Moyasee
2025-12-12 12:44:02 +02:00
parent 0470958629
commit 63f8289d0a
12 changed files with 127 additions and 23 deletions

View File

@@ -0,0 +1,23 @@
import fs from "node:fs";
import { registerEvent } from "../register-event";
import { logger } from "@main/services";
const deleteArchive = async (
_event: Electron.IpcMainInvokeEvent,
filePath: string
) => {
try {
if (fs.existsSync(filePath)) {
await fs.promises.unlink(filePath);
logger.info(`Deleted archive: ${filePath}`);
return true;
}
return true;
} catch (err) {
logger.error(`Failed to delete archive: ${filePath}`, err);
return false;
}
};
registerEvent("deleteArchive", deleteArchive);

View File

@@ -8,6 +8,7 @@ import "./close-game";
import "./copy-custom-game-asset";
import "./create-game-shortcut";
import "./create-steam-shortcut";
import "./delete-archive";
import "./delete-game-folder";
import "./extract-game-download";
import "./get-default-wine-prefix-selection-path";

View File

@@ -116,17 +116,15 @@ export class GameFilesManager {
}
}
for (const file of compressedFiles) {
const extractionPath = path.join(directoryPath, file);
const archivePaths = compressedFiles
.map((file) => path.join(directoryPath, file))
.filter((archivePath) => fs.existsSync(archivePath));
try {
if (fs.existsSync(extractionPath)) {
await fs.promises.unlink(extractionPath);
logger.info(`Deleted archive: ${file}`);
}
} catch (err) {
logger.error(`Failed to delete file: ${file}`, err);
}
if (archivePaths.length > 0) {
WindowManager.mainWindow?.webContents.send(
"on-archive-deletion-prompt",
archivePaths
);
}
}
@@ -186,12 +184,10 @@ export class GameFilesManager {
await this.extractFilesInDirectory(extractionPath);
if (fs.existsSync(extractionPath) && fs.existsSync(filePath)) {
try {
await fs.promises.unlink(filePath);
logger.info(`Deleted archive: ${download.folderName}`);
} catch (err) {
logger.error(`Failed to delete file: ${download.folderName}`, err);
}
WindowManager.mainWindow?.webContents.send(
"on-archive-deletion-prompt",
[filePath]
);
}
await downloadsSublevel.put(this.gameKey, {