mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: better handle of different game installing formats
This commit is contained in:
parent
1bfb90f1a0
commit
fdd7f753b3
1 changed files with 36 additions and 17 deletions
|
@ -1,13 +1,28 @@
|
||||||
import { gameRepository } from "@main/repository";
|
import { shell } from "electron";
|
||||||
import { generateYML } from "../helpers/generate-lutris-yaml";
|
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import { writeFile } from "node:fs/promises";
|
import { writeFile } from "node:fs/promises";
|
||||||
import { spawnSync, exec } from "node:child_process";
|
import { spawnSync, exec } from "node:child_process";
|
||||||
|
|
||||||
import { registerEvent } from "../register-event";
|
import { gameRepository } from "@main/repository";
|
||||||
import { shell } from "electron";
|
|
||||||
|
import { generateYML } from "../helpers/generate-lutris-yaml";
|
||||||
import { getDownloadsPath } from "../helpers/get-downloads-path";
|
import { getDownloadsPath } from "../helpers/get-downloads-path";
|
||||||
|
import { registerEvent } from "../register-event";
|
||||||
|
|
||||||
|
const executeGameInsaller = (filePath: string) => {
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
shell.openPath(filePath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spawnSync("which", ["wine"]).status === 0) {
|
||||||
|
exec(`wine "${filePath}"`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
const openGameInstaller = async (
|
const openGameInstaller = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
|
@ -19,7 +34,7 @@ const openGameInstaller = async (
|
||||||
|
|
||||||
if (!game || !game.folderName) return true;
|
if (!game || !game.folderName) return true;
|
||||||
|
|
||||||
let gamePath = path.join(
|
const gamePath = path.join(
|
||||||
game.downloadPath ?? (await getDownloadsPath()),
|
game.downloadPath ?? (await getDownloadsPath()),
|
||||||
game.folderName!
|
game.folderName!
|
||||||
);
|
);
|
||||||
|
@ -29,14 +44,22 @@ const openGameInstaller = async (
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const setupPath = path.join(gamePath, "setup.exe");
|
if (fs.lstatSync(gamePath).isFile()) {
|
||||||
if (fs.existsSync(setupPath)) {
|
return executeGameInsaller(gamePath);
|
||||||
gamePath = setupPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform === "win32") {
|
const setupPath = path.join(gamePath, "setup.exe");
|
||||||
shell.openPath(gamePath);
|
if (fs.existsSync(setupPath)) {
|
||||||
return true;
|
return executeGameInsaller(setupPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
const gamePathFileNames = fs.readdirSync(gamePath);
|
||||||
|
const gameAlternativeSetupPath = gamePathFileNames.find(
|
||||||
|
(fileName: string) => path.extname(fileName).toLowerCase() === ".exe"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (gameAlternativeSetupPath) {
|
||||||
|
return executeGameInsaller(path.join(gamePath, gameAlternativeSetupPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawnSync("which", ["lutris"]).status === 0) {
|
if (spawnSync("which", ["lutris"]).status === 0) {
|
||||||
|
@ -46,12 +69,8 @@ const openGameInstaller = async (
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawnSync("which", ["wine"]).status === 0) {
|
shell.openPath(gamePath);
|
||||||
exec(`wine "${gamePath}"`);
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
registerEvent("openGameInstaller", openGameInstaller);
|
registerEvent("openGameInstaller", openGameInstaller);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue