mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-23 10:51:02 +00:00
feat: implement archive deletion prompt and translations for confirmation messages
This commit is contained in:
23
src/main/events/library/delete-archive.ts
Normal file
23
src/main/events/library/delete-archive.ts
Normal 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);
|
||||
@@ -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";
|
||||
|
||||
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user