diff --git a/src/main/events/library/open-game.ts b/src/main/events/library/open-game.ts index 82c097bd..2c9b804d 100644 --- a/src/main/events/library/open-game.ts +++ b/src/main/events/library/open-game.ts @@ -1,6 +1,9 @@ import { gameRepository } from "@main/repository"; +import { generateYML } from "../misc/generate-lutris-yaml"; import path from "node:path"; import fs from "node:fs"; +import { writeFile } from "node:fs/promises"; +import { spawn, spawnSync } from "node:child_process"; import { registerEvent } from "../register-event"; import { shell } from "electron"; @@ -22,7 +25,23 @@ const openGame = async ( if (fs.existsSync(gamePath)) { const setupPath = path.join(gamePath, "setup.exe"); if (fs.existsSync(setupPath)) { - shell.openExternal(setupPath); + if (process.platform === "win32") { + shell.openExternal(setupPath); + } + if (process.platform === "linux") { + if (spawnSync('which', ['lutris']).status === 0) { + const ymlPath = path.join(gamePath, "setup.yml"); + await writeFile(ymlPath, generateYML(game)); + const subprocess = spawn(`lutris --install '${ymlPath}'`, { + shell: true, + detached: true, + stdio: 'ignore' + }); + subprocess.unref(); + } else { + spawn(`wine '${setupPath}'`, { shell: true }); + } + } } else { shell.openPath(gamePath); } diff --git a/src/main/events/misc/generate-lutris-yaml.ts b/src/main/events/misc/generate-lutris-yaml.ts new file mode 100644 index 00000000..cb14304d --- /dev/null +++ b/src/main/events/misc/generate-lutris-yaml.ts @@ -0,0 +1,31 @@ +import { Document as YMLDocument } from 'yaml'; +import { Game } from '@main/entity'; + +export function generateYML(game: Game) { + const slugfiedName = game.title.replace(/\s/g, '-').toLocaleLowerCase(); + + const doc = new YMLDocument({ + name: game.title, + game_slug: slugfiedName, + slug: `${slugfiedName}-installer`, + version: 'Installer', + runner: 'wine', + script: { + installer: [{ + task: { + name: "create_prefix", + arch: "win64", + prefix: "$GAMEDIR/prefix" + } + }, { + task: { + executable: `${game.downloadPath}/${game.folderName}/setup.exe`, + name: "wineexec", + prefix: "$GAMEDIR/prefix" + } + }] + } + }); + + return doc.toString(); +}