Skip to content

Commit

Permalink
Merge pull request #304 from scrlkx/linux-install
Browse files Browse the repository at this point in the history
fix: unable to install games on linux
  • Loading branch information
zamitto authored May 31, 2024
2 parents 2de142d + 4ba82d3 commit a295626
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions src/main/events/library/open-game-installer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import { gameRepository } from "@main/repository";
import { generateYML } from "../helpers/generate-lutris-yaml";
import { shell } from "electron";
import path from "node:path";
import fs from "node:fs";
import { writeFile } from "node:fs/promises";
import { spawnSync, exec } from "node:child_process";

import { registerEvent } from "../register-event";
import { shell } from "electron";
import { gameRepository } from "@main/repository";

import { generateYML } from "../helpers/generate-lutris-yaml";
import { getDownloadsPath } from "../helpers/get-downloads-path";
import { registerEvent } from "../register-event";

const executeGameInstaller = (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 (
_event: Electron.IpcMainInvokeEvent,
Expand All @@ -17,7 +32,7 @@ const openGameInstaller = async (
where: { id: gameId, isDeleted: false },
});

if (!game) return true;
if (!game || !game.folderName) return true;

const gamePath = path.join(
game.downloadPath ?? (await getDownloadsPath()),
Expand All @@ -29,15 +44,24 @@ const openGameInstaller = async (
return true;
}

if (fs.lstatSync(gamePath).isFile()) {
return executeGameInstaller(gamePath);
}

const setupPath = path.join(gamePath, "setup.exe");
if (!fs.existsSync(setupPath)) {
shell.openPath(gamePath);
return true;
if (fs.existsSync(setupPath)) {
return executeGameInstaller(setupPath);
}

if (process.platform === "win32") {
shell.openPath(setupPath);
return true;
const gamePathFileNames = fs.readdirSync(gamePath);
const gamePathExecutableFiles = gamePathFileNames.filter(
(fileName: string) => path.extname(fileName).toLowerCase() === ".exe"
);

if (gamePathExecutableFiles.length === 1) {
return executeGameInstaller(
path.join(gamePath, gamePathExecutableFiles[0])
);
}

if (spawnSync("which", ["lutris"]).status === 0) {
Expand All @@ -47,12 +71,8 @@ const openGameInstaller = async (
return true;
}

if (spawnSync("which", ["wine"]).status === 0) {
exec(`wine "${setupPath}"`);
return true;
}

return false;
shell.openPath(gamePath);
return true;
};

registerEvent("openGameInstaller", openGameInstaller);

0 comments on commit a295626

Please sign in to comment.