diff --git a/electron-builder.yml b/electron-builder.yml index 751686cc..dd10e81a 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -23,7 +23,6 @@ win: extraResources: - from: binaries/7z.exe - from: binaries/7z.dll - - from: resources/commonredist/** target: - nsis - portable diff --git a/resources/commonredist/dotNetFx40_Full_setup.exe b/resources/commonredist/dotNetFx40_Full_setup.exe deleted file mode 100644 index 384fb834..00000000 Binary files a/resources/commonredist/dotNetFx40_Full_setup.exe and /dev/null differ diff --git a/resources/commonredist/dxwebsetup.exe b/resources/commonredist/dxwebsetup.exe deleted file mode 100644 index 07ef6b81..00000000 Binary files a/resources/commonredist/dxwebsetup.exe and /dev/null differ diff --git a/resources/commonredist/install.bat b/resources/commonredist/install.bat deleted file mode 100644 index 05602898..00000000 --- a/resources/commonredist/install.bat +++ /dev/null @@ -1,36 +0,0 @@ -@echo off -:: Request admin privileges if not already elevated -net session >nul 2>&1 -if %errorLevel% neq 0 ( - echo Requesting administrative privileges... - powershell -Command "Start-Process '%~f0' -Verb RunAs" - exit -) - -:: Change to the script’s directory -cd /d "%~dp0" - -echo Installing prerequisites silently... - -:: Install .NET Framework 4.0 -if exist dotNetFx40_Full_setup.exe dotNetFx40_Full_setup.exe /q /norestart /log dotnet_install.log - -:: Install DirectX -if exist dxwebsetup.exe dxwebsetup.exe /Q - -:: Install OpenAL -if exist oalinst.exe oalinst.exe /silent - -:: Install Visual C++ Redistributables (2015-2019) -if exist vcredist_2015-2019_x64.exe vcredist_2015-2019_x64.exe /quiet /norestart -if exist vcredist_2015-2019_x86.exe vcredist_2015-2019_x86.exe /quiet /norestart - -:: Install older Visual C++ Redistributables -if exist vcredist_x64.exe vcredist_x64.exe /quiet /norestart -if exist vcredist_x86.exe vcredist_x86.exe /quiet /norestart - -:: Install XNA Framework 4.0 -if exist xnafx40_redist.msi msiexec /i xnafx40_redist.msi /quiet /norestart - -echo Installation complete! -pause \ No newline at end of file diff --git a/resources/commonredist/oalinst.exe b/resources/commonredist/oalinst.exe deleted file mode 100644 index 0b61822d..00000000 Binary files a/resources/commonredist/oalinst.exe and /dev/null differ diff --git a/resources/commonredist/vcredist_2015-2019_x64.exe b/resources/commonredist/vcredist_2015-2019_x64.exe deleted file mode 100644 index 7476d75a..00000000 Binary files a/resources/commonredist/vcredist_2015-2019_x64.exe and /dev/null differ diff --git a/resources/commonredist/vcredist_2015-2019_x86.exe b/resources/commonredist/vcredist_2015-2019_x86.exe deleted file mode 100644 index e1fe7cf7..00000000 Binary files a/resources/commonredist/vcredist_2015-2019_x86.exe and /dev/null differ diff --git a/resources/commonredist/vcredist_x64.exe b/resources/commonredist/vcredist_x64.exe deleted file mode 100644 index 6ae64fb4..00000000 Binary files a/resources/commonredist/vcredist_x64.exe and /dev/null differ diff --git a/resources/commonredist/vcredist_x86.exe b/resources/commonredist/vcredist_x86.exe deleted file mode 100644 index 57e15c0b..00000000 Binary files a/resources/commonredist/vcredist_x86.exe and /dev/null differ diff --git a/resources/commonredist/xnafx40_redist.msi b/resources/commonredist/xnafx40_redist.msi deleted file mode 100644 index 42bbb26c..00000000 Binary files a/resources/commonredist/xnafx40_redist.msi and /dev/null differ diff --git a/src/main/constants.ts b/src/main/constants.ts index 5e0b0409..48390250 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -12,10 +12,9 @@ export const levelDatabasePath = path.join( `hydra-db${isStaging ? "-staging" : ""}` ); -export const databaseDirectory = path.join(app.getPath("appData"), "hydra"); -export const databasePath = path.join( - databaseDirectory, - isStaging ? "hydra_test.db" : "hydra.db" +export const commonRedistPath = path.join( + app.getPath("userData"), + "CommonRedist" ); export const logsPath = path.join(app.getPath("userData"), "logs"); diff --git a/src/main/events/index.ts b/src/main/events/index.ts index 25d4b941..d2ced3de 100644 --- a/src/main/events/index.ts +++ b/src/main/events/index.ts @@ -39,7 +39,7 @@ import "./misc/show-open-dialog"; import "./misc/get-features"; import "./misc/show-item-in-folder"; import "./misc/get-badges"; -import "./misc/install-commonredist"; +import "./misc/install-common-redist"; import "./torrenting/cancel-game-download"; import "./torrenting/pause-game-download"; import "./torrenting/resume-game-download"; diff --git a/src/main/events/misc/install-common-redist.ts b/src/main/events/misc/install-common-redist.ts new file mode 100644 index 00000000..34e609ec --- /dev/null +++ b/src/main/events/misc/install-common-redist.ts @@ -0,0 +1,10 @@ +import { registerEvent } from "../register-event"; +import { CommonRedistManager } from "@main/services/common-redist-manager"; + +const installCommonRedist = async (_event: Electron.IpcMainInvokeEvent) => { + if (await CommonRedistManager.canInstallCommonRedist()) { + CommonRedistManager.installCommonRedist(); + } +}; + +registerEvent("installCommonRedist", installCommonRedist); diff --git a/src/main/events/misc/install-commonredist.ts b/src/main/events/misc/install-commonredist.ts deleted file mode 100644 index bce9c4cf..00000000 --- a/src/main/events/misc/install-commonredist.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { app } from "electron"; -import path from "node:path"; -import cp from "node:child_process"; -import { registerEvent } from "../register-event"; -import { logger } from "@main/services"; - -const installScriptPath = app.isPackaged - ? path.join(process.resourcesPath, "commonredist", "install.bat") - : path.join( - __dirname, - "..", - "..", - "resources", - "commonredist", - "install.bat" - ); - -const installCommonRedist = async (_event: Electron.IpcMainInvokeEvent) => { - cp.execFile(installScriptPath, (error) => { - if (error) { - logger.error(error); - } - }); -}; - -registerEvent("installCommonRedist", installCommonRedist); diff --git a/src/main/main.ts b/src/main/main.ts index c9a8e3a8..ad5e778f 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -9,7 +9,7 @@ import { Downloader } from "@shared"; import { levelKeys, db } from "./level"; import type { UserPreferences } from "@types"; import { TorBoxClient } from "./services/download/torbox"; - +import { CommonRedistManager } from "./services/common-redist-manager"; export const loadState = async () => { const userPreferences = await db.get( levelKeys.userPreferences, @@ -65,4 +65,6 @@ export const loadState = async () => { await DownloadManager.startRPC(nextItemOnQueue, downloadsToSeed); startMainLoop(); + + CommonRedistManager.downloadCommonRedist(); }; diff --git a/src/main/services/common-redist-manager.ts b/src/main/services/common-redist-manager.ts new file mode 100644 index 00000000..9c8c7b67 --- /dev/null +++ b/src/main/services/common-redist-manager.ts @@ -0,0 +1,59 @@ +import { commonRedistPath } from "@main/constants"; +import axios from "axios"; +import fs from "node:fs"; +import cp from "node:child_process"; +import path from "node:path"; +import { logger } from "./logger"; + +export class CommonRedistManager { + private static readonly redistributables = [ + "dotNetFx40_Full_setup.exe", + "dxwebsetup.exe", + "oalinst.exe", + "install.bat", + "vcredist_2015-2019_x64.exe", + "vcredist_2015-2019_x86.exe", + "vcredist_x64.exe", + "vcredist_x86.exe", + "xnafx40_redist.msi", + ]; + + public static async installCommonRedist() { + cp.execFile(path.join(commonRedistPath, "install.bat"), (error) => { + if (error) { + logger.error("Failed to run install.bat", error); + } + }); + } + + public static async canInstallCommonRedist() { + return this.redistributables.every((redist) => { + const filePath = path.join(commonRedistPath, redist); + + return fs.existsSync(filePath); + }); + } + + public static async downloadCommonRedist() { + if (!fs.existsSync(commonRedistPath)) { + await fs.promises.mkdir(commonRedistPath, { recursive: true }); + } + + for (const redist of this.redistributables) { + const filePath = path.join(commonRedistPath, redist); + + if (fs.existsSync(filePath)) { + continue; + } + + const response = await axios.get( + `https://github.com/hydralauncher/hydra-common-redist/raw/refs/heads/main/${redist}`, + { + responseType: "arraybuffer", + } + ); + + await fs.promises.writeFile(filePath, response.data); + } + } +} diff --git a/src/main/services/index.ts b/src/main/services/index.ts index b942aa79..30b502f5 100644 --- a/src/main/services/index.ts +++ b/src/main/services/index.ts @@ -10,3 +10,4 @@ export * from "./ludusavi"; export * from "./cloud-sync"; export * from "./7zip"; export * from "./game-files-manager"; +export * from "./common-redist-manager";