Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unable to install games on linux #304

Merged
merged 18 commits into from
May 31, 2024
Merged
Changes from 16 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
52 changes: 35 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,22 @@ 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 gameAlternativeSetupPath = gamePathFileNames.find(
(fileName: string) => path.extname(fileName).toLowerCase() === ".exe"
);

if (gameAlternativeSetupPath) {
return executeGameInstaller(path.join(gamePath, gameAlternativeSetupPath));
}
scrlkx marked this conversation as resolved.
Show resolved Hide resolved

if (spawnSync("which", ["lutris"]).status === 0) {
Expand All @@ -47,12 +69,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);
Loading