Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/locales/pt-BR/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/locales/pt-PT/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions src/main/events/library/delete-archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -47,4 +44,11 @@ const deleteArchive = async (
}
};

const deleteArchive = async (
_event: Electron.IpcMainInvokeEvent,
filePath: string
) => {
return deleteArchiveFile(filePath);
};

registerEvent("deleteArchive", deleteArchive);
33 changes: 27 additions & 6 deletions src/main/services/game-files-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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";
Expand Down Expand Up @@ -102,7 +103,7 @@
this.updateExtractionProgress(progress.percent / 100);
};

async extractFilesInDirectory(directoryPath: string): Promise<boolean> {

Check failure on line 106 in src/main/services/game-files-manager.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=hydralauncher_hydra&issues=AZ2byNrBSEGiqujMPeN_&open=AZ2byNrBSEGiqujMPeN_&pullRequest=2156
let pathType: Awaited<ReturnType<typeof getPathType>>;
try {
pathType = await getPathType(directoryPath);
Expand Down Expand Up @@ -186,10 +187,21 @@
.filter((archivePath) => fs.existsSync(archivePath));

if (archivePaths.length > 0) {
WindowManager.mainWindow?.webContents.send(
"on-archive-deletion-prompt",
archivePaths
const userPreferences = await db.get<string, UserPreferences | null>(
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;
Expand Down Expand Up @@ -656,10 +668,19 @@
}

if (fs.existsSync(extractionPath) && fs.existsSync(filePath)) {
WindowManager.mainWindow?.webContents.send(
"on-archive-deletion-prompt",
[filePath]
const userPreferences = await db.get<string, UserPreferences | null>(
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, {
Expand Down
14 changes: 14 additions & 0 deletions src/renderer/src/pages/settings/settings-behavior.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function SettingsBehavior() {
showHiddenAchievementsDescription: false,
showDownloadSpeedInMegabytes: false,
extractFilesByDefault: true,
autoDeleteArchiveAfterExtraction: false,
enableSteamAchievements: false,
autoplayGameTrailers: true,
hideToTrayOnGameStart: false,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -286,6 +289,17 @@ export function SettingsBehavior() {
}
/>

<CheckboxField
label={t("auto_delete_archive_after_extraction")}
checked={form.autoDeleteArchiveAfterExtraction}
onChange={() =>
handleChange({
autoDeleteArchiveAfterExtraction:
!form.autoDeleteArchiveAfterExtraction,
})
}
/>

<div className={`settings-behavior__checkbox-container--with-tooltip`}>
<CheckboxField
label={t("enable_steam_achievements")}
Expand Down
14 changes: 14 additions & 0 deletions src/renderer/src/pages/settings/settings-context-downloads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function SettingsContextDownloads() {
seedAfterDownloadComplete: false,
showDownloadSpeedInMegabytes: false,
extractFilesByDefault: true,
autoDeleteArchiveAfterExtraction: false,
createStartMenuShortcut: true,
maxDownloadSpeedMegabytes: "",
});
Expand All @@ -60,6 +61,8 @@ export function SettingsContextDownloads() {
showDownloadSpeedInMegabytes:
userPreferences.showDownloadSpeedInMegabytes ?? false,
extractFilesByDefault: userPreferences.extractFilesByDefault ?? true,
autoDeleteArchiveAfterExtraction:
userPreferences.autoDeleteArchiveAfterExtraction ?? false,
createStartMenuShortcut: userPreferences.createStartMenuShortcut ?? true,
maxDownloadSpeedMegabytes:
typeof userPreferences.maxDownloadSpeedBytesPerSecond === "number" &&
Expand Down Expand Up @@ -176,6 +179,17 @@ export function SettingsContextDownloads() {
}
/>

<CheckboxField
label={t("auto_delete_archive_after_extraction")}
checked={form.autoDeleteArchiveAfterExtraction}
onChange={() =>
handleChange({
autoDeleteArchiveAfterExtraction:
!form.autoDeleteArchiveAfterExtraction,
})
}
/>

<CheckboxField
label={t("show_download_speed_in_megabytes")}
checked={form.showDownloadSpeedInMegabytes}
Expand Down
1 change: 1 addition & 0 deletions src/types/level.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface UserPreferences {
friendStartGameNotificationsEnabled?: boolean;
showDownloadSpeedInMegabytes?: boolean;
extractFilesByDefault?: boolean;
autoDeleteArchiveAfterExtraction?: boolean;
enableSteamAchievements?: boolean;
autoplayGameTrailers?: boolean;
hideToTrayOnGameStart?: boolean;
Expand Down
Loading