feat: setting external common redist

This commit is contained in:
Chubby Granny Chaser
2025-04-02 19:06:21 +01:00
parent 01d440590b
commit 379e90568a
17 changed files with 77 additions and 69 deletions

View File

@@ -23,7 +23,6 @@ win:
extraResources: extraResources:
- from: binaries/7z.exe - from: binaries/7z.exe
- from: binaries/7z.dll - from: binaries/7z.dll
- from: resources/commonredist/**
target: target:
- nsis - nsis
- portable - portable

View File

@@ -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 scripts 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

Binary file not shown.

View File

@@ -12,10 +12,9 @@ export const levelDatabasePath = path.join(
`hydra-db${isStaging ? "-staging" : ""}` `hydra-db${isStaging ? "-staging" : ""}`
); );
export const databaseDirectory = path.join(app.getPath("appData"), "hydra"); export const commonRedistPath = path.join(
export const databasePath = path.join( app.getPath("userData"),
databaseDirectory, "CommonRedist"
isStaging ? "hydra_test.db" : "hydra.db"
); );
export const logsPath = path.join(app.getPath("userData"), "logs"); export const logsPath = path.join(app.getPath("userData"), "logs");

View File

@@ -39,7 +39,7 @@ import "./misc/show-open-dialog";
import "./misc/get-features"; import "./misc/get-features";
import "./misc/show-item-in-folder"; import "./misc/show-item-in-folder";
import "./misc/get-badges"; import "./misc/get-badges";
import "./misc/install-commonredist"; import "./misc/install-common-redist";
import "./torrenting/cancel-game-download"; import "./torrenting/cancel-game-download";
import "./torrenting/pause-game-download"; import "./torrenting/pause-game-download";
import "./torrenting/resume-game-download"; import "./torrenting/resume-game-download";

View File

@@ -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);

View File

@@ -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);

View File

@@ -9,7 +9,7 @@ import { Downloader } from "@shared";
import { levelKeys, db } from "./level"; import { levelKeys, db } from "./level";
import type { UserPreferences } from "@types"; import type { UserPreferences } from "@types";
import { TorBoxClient } from "./services/download/torbox"; import { TorBoxClient } from "./services/download/torbox";
import { CommonRedistManager } from "./services/common-redist-manager";
export const loadState = async () => { export const loadState = async () => {
const userPreferences = await db.get<string, UserPreferences | null>( const userPreferences = await db.get<string, UserPreferences | null>(
levelKeys.userPreferences, levelKeys.userPreferences,
@@ -65,4 +65,6 @@ export const loadState = async () => {
await DownloadManager.startRPC(nextItemOnQueue, downloadsToSeed); await DownloadManager.startRPC(nextItemOnQueue, downloadsToSeed);
startMainLoop(); startMainLoop();
CommonRedistManager.downloadCommonRedist();
}; };

View File

@@ -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);
}
}
}

View File

@@ -10,3 +10,4 @@ export * from "./ludusavi";
export * from "./cloud-sync"; export * from "./cloud-sync";
export * from "./7zip"; export * from "./7zip";
export * from "./game-files-manager"; export * from "./game-files-manager";
export * from "./common-redist-manager";