diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index adf06d09b..670060fe5 100755 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -757,6 +757,7 @@ "max_download_speed_unit_megabits": "Mbps", "max_download_speed_unlimited": "Unlimited", "extract_files_by_default": "Extract files by default after download", + "auto_delete_archive_after_extraction": "Delete downloaded archive files by default after extraction", "enable_steam_achievements": "Enable search for Steam achievements", "enable_new_download_options_badges": "Show new download options badges", "achievement_custom_notification_position": "Achievement custom notification position", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index fe92bc94d..6c87a4d24 100755 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -673,6 +673,7 @@ "max_download_speed_unit_megabits": "Mbps", "max_download_speed_unlimited": "Ilimitada", "extract_files_by_default": "Extrair arquivos automaticamente após o download", + "auto_delete_archive_after_extraction": "Excluir arquivos transferidos automaticamente após extração", "enable_steam_achievements": "Habilitar busca por conquistas da Steam", "enable_new_download_options_badges": "Mostrar badges de novas opções de download", "enable_achievement_custom_notifications": "Habilitar notificações customizadas de conquistas", diff --git a/src/locales/pt-PT/translation.json b/src/locales/pt-PT/translation.json index a5572a83c..5821ece74 100644 --- a/src/locales/pt-PT/translation.json +++ b/src/locales/pt-PT/translation.json @@ -638,6 +638,7 @@ "installing_common_redist": "A instalar…", "show_download_speed_in_megabytes": "Mostrar velocidade de transferência em megabytes por segundo", "extract_files_by_default": "Extrair ficheiros por defeito após a transferência", + "auto_delete_archive_after_extraction": "Eliminar ficheiros transferidos automaticamente após a extração", "enable_steam_achievements": "Ativar pesquisa de conquistas Steam", "enable_new_download_options_badges": "Mostrar badges de novas opções de transferência", "achievement_custom_notification_position": "Posição de notificação personalizada de conquista", diff --git a/src/main/events/library/delete-archive.ts b/src/main/events/library/delete-archive.ts index 108435055..145f33e6d 100644 --- a/src/main/events/library/delete-archive.ts +++ b/src/main/events/library/delete-archive.ts @@ -5,10 +5,7 @@ import { registerEvent } from "../register-event"; import { logger } from "@main/services"; import { downloadsSublevel, gamesSublevel, levelKeys } from "@main/level"; -const deleteArchive = async ( - _event: Electron.IpcMainInvokeEvent, - filePath: string -) => { +export const deleteArchiveFile = async (filePath: string) => { try { if (fs.existsSync(filePath)) { await fs.promises.unlink(filePath); @@ -47,4 +44,11 @@ const deleteArchive = async ( } }; +const deleteArchive = async ( + _event: Electron.IpcMainInvokeEvent, + filePath: string +) => { + return deleteArchiveFile(filePath); +}; + registerEvent("deleteArchive", deleteArchive); diff --git a/src/main/services/game-files-manager.ts b/src/main/services/game-files-manager.ts index d81f59753..5d96272e3 100644 --- a/src/main/services/game-files-manager.ts +++ b/src/main/services/game-files-manager.ts @@ -13,6 +13,7 @@ import { import { SevenZip, ExtractionProgress } from "./7zip"; import { WindowManager } from "./window-manager"; import { publishExtractionCompleteNotification } from "./notifications"; +import { deleteArchiveFile } from "@main/events/library/delete-archive"; import { logger } from "./logger"; import { getDirectorySize } from "@main/events/helpers/get-directory-size"; import { GameExecutables } from "./game-executables"; @@ -186,10 +187,21 @@ export class GameFilesManager { .filter((archivePath) => fs.existsSync(archivePath)); if (archivePaths.length > 0) { - WindowManager.mainWindow?.webContents.send( - "on-archive-deletion-prompt", - archivePaths + const userPreferences = await db.get( + levelKeys.userPreferences, + { valueEncoding: "json" } ); + + if (userPreferences?.autoDeleteArchiveAfterExtraction) { + for (const archivePath of archivePaths) { + await deleteArchiveFile(archivePath); + } + } else { + WindowManager.mainWindow?.webContents.send( + "on-archive-deletion-prompt", + archivePaths + ); + } } return true; @@ -656,10 +668,19 @@ export class GameFilesManager { } if (fs.existsSync(extractionPath) && fs.existsSync(filePath)) { - WindowManager.mainWindow?.webContents.send( - "on-archive-deletion-prompt", - [filePath] + const userPreferences = await db.get( + levelKeys.userPreferences, + { valueEncoding: "json" } ); + + if (userPreferences?.autoDeleteArchiveAfterExtraction) { + await deleteArchiveFile(filePath); + } else { + WindowManager.mainWindow?.webContents.send( + "on-archive-deletion-prompt", + [filePath] + ); + } } await downloadsSublevel.put(this.gameKey, { diff --git a/src/renderer/src/pages/settings/settings-behavior.tsx b/src/renderer/src/pages/settings/settings-behavior.tsx index 1235beab9..d0035de6b 100644 --- a/src/renderer/src/pages/settings/settings-behavior.tsx +++ b/src/renderer/src/pages/settings/settings-behavior.tsx @@ -32,6 +32,7 @@ export function SettingsBehavior() { showHiddenAchievementsDescription: false, showDownloadSpeedInMegabytes: false, extractFilesByDefault: true, + autoDeleteArchiveAfterExtraction: false, enableSteamAchievements: false, autoplayGameTrailers: true, hideToTrayOnGameStart: false, @@ -81,6 +82,8 @@ export function SettingsBehavior() { showDownloadSpeedInMegabytes: userPreferences.showDownloadSpeedInMegabytes ?? false, extractFilesByDefault: userPreferences.extractFilesByDefault ?? true, + autoDeleteArchiveAfterExtraction: + userPreferences.autoDeleteArchiveAfterExtraction ?? false, enableSteamAchievements: userPreferences.enableSteamAchievements ?? false, autoplayGameTrailers: userPreferences.autoplayGameTrailers ?? true, @@ -286,6 +289,17 @@ export function SettingsBehavior() { } /> + + handleChange({ + autoDeleteArchiveAfterExtraction: + !form.autoDeleteArchiveAfterExtraction, + }) + } + /> +
+ + handleChange({ + autoDeleteArchiveAfterExtraction: + !form.autoDeleteArchiveAfterExtraction, + }) + } + /> +