From de4307e2a542cd6d000c7306c9a5d084bdc0903c Mon Sep 17 00:00:00 2001 From: Daniel Freitas Date: Sat, 11 May 2024 22:19:12 -0300 Subject: [PATCH 1/6] fix: game installing do not reach linux steps --- src/main/events/library/open-game-installer.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/events/library/open-game-installer.ts b/src/main/events/library/open-game-installer.ts index 796e063b0..2edd88ebf 100644 --- a/src/main/events/library/open-game-installer.ts +++ b/src/main/events/library/open-game-installer.ts @@ -15,9 +15,9 @@ const openGameInstaller = async ( ) => { const game = await gameRepository.findOne({ where: { id: gameId } }); - if (!game) return true; + if (!game || !game.folderName) return true; - const gamePath = path.join( + let gamePath = path.join( game.downloadPath ?? (await getDownloadsPath()), game.folderName ); @@ -28,13 +28,12 @@ const openGameInstaller = async ( } const setupPath = path.join(gamePath, "setup.exe"); - if (!fs.existsSync(setupPath)) { - shell.openPath(gamePath); - return true; + if (fs.existsSync(setupPath)) { + gamePath = setupPath; } if (process.platform === "win32") { - shell.openPath(setupPath); + shell.openPath(gamePath); return true; } @@ -46,7 +45,7 @@ const openGameInstaller = async ( } if (spawnSync("which", ["wine"]).status === 0) { - exec(`wine "${setupPath}"`); + exec(`wine "${gamePath}"`); return true; } From fdd7f753b3acd9f5a85df833ba6122f3461fab09 Mon Sep 17 00:00:00 2001 From: Daniel Freitas Date: Thu, 30 May 2024 21:29:08 -0300 Subject: [PATCH 2/6] feat: better handle of different game installing formats --- .../events/library/open-game-installer.ts | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/src/main/events/library/open-game-installer.ts b/src/main/events/library/open-game-installer.ts index aa713ff38..851489932 100644 --- a/src/main/events/library/open-game-installer.ts +++ b/src/main/events/library/open-game-installer.ts @@ -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 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 ( _event: Electron.IpcMainInvokeEvent, @@ -19,7 +34,7 @@ const openGameInstaller = async ( if (!game || !game.folderName) return true; - let gamePath = path.join( + const gamePath = path.join( game.downloadPath ?? (await getDownloadsPath()), game.folderName! ); @@ -29,14 +44,22 @@ const openGameInstaller = async ( return true; } + if (fs.lstatSync(gamePath).isFile()) { + return executeGameInsaller(gamePath); + } + const setupPath = path.join(gamePath, "setup.exe"); if (fs.existsSync(setupPath)) { - gamePath = setupPath; + return executeGameInsaller(setupPath); } - if (process.platform === "win32") { - shell.openPath(gamePath); - return true; + 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) { @@ -46,12 +69,8 @@ const openGameInstaller = async ( return true; } - if (spawnSync("which", ["wine"]).status === 0) { - exec(`wine "${gamePath}"`); - return true; - } - - return false; + shell.openPath(gamePath); + return true; }; registerEvent("openGameInstaller", openGameInstaller); From 0cdb25e70553880b1c1c7dc41736f351a532df0b Mon Sep 17 00:00:00 2001 From: Daniel Freitas Date: Thu, 30 May 2024 21:38:30 -0300 Subject: [PATCH 3/6] chore: typo --- src/main/events/library/open-game-installer.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/events/library/open-game-installer.ts b/src/main/events/library/open-game-installer.ts index 851489932..0b7e98db1 100644 --- a/src/main/events/library/open-game-installer.ts +++ b/src/main/events/library/open-game-installer.ts @@ -10,7 +10,7 @@ import { generateYML } from "../helpers/generate-lutris-yaml"; import { getDownloadsPath } from "../helpers/get-downloads-path"; import { registerEvent } from "../register-event"; -const executeGameInsaller = (filePath: string) => { +const executeGameInstaller = (filePath: string) => { if (process.platform === "win32") { shell.openPath(filePath); return true; @@ -45,12 +45,12 @@ const openGameInstaller = async ( } if (fs.lstatSync(gamePath).isFile()) { - return executeGameInsaller(gamePath); + return executeGameInstaller(gamePath); } const setupPath = path.join(gamePath, "setup.exe"); if (fs.existsSync(setupPath)) { - return executeGameInsaller(setupPath); + return executeGameInstaller(setupPath); } const gamePathFileNames = fs.readdirSync(gamePath); @@ -59,7 +59,7 @@ const openGameInstaller = async ( ); if (gameAlternativeSetupPath) { - return executeGameInsaller(path.join(gamePath, gameAlternativeSetupPath)); + return executeGameInstaller(path.join(gamePath, gameAlternativeSetupPath)); } if (spawnSync("which", ["lutris"]).status === 0) { From f88cd61a239c14c5690d78226dc46834a123acd7 Mon Sep 17 00:00:00 2001 From: Daniel Freitas Date: Thu, 30 May 2024 21:39:11 -0300 Subject: [PATCH 4/6] chore: add logs folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7bd769300..c01a683ed 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ out *.log* .env .vite +logs/ From 81f453d60f0f35ea7110fb6da91c4300b36c022c Mon Sep 17 00:00:00 2001 From: Daniel Freitas Date: Thu, 30 May 2024 22:23:07 -0300 Subject: [PATCH 5/6] undo: add logs folder to .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index c01a683ed..7bd769300 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ out *.log* .env .vite -logs/ From 95a0d55426d47e6ed6c26ecf945f3893ef4d91e6 Mon Sep 17 00:00:00 2001 From: Daniel Freitas Date: Fri, 31 May 2024 14:45:26 -0300 Subject: [PATCH 6/6] feat: look for a single alternative setup when installing --- src/main/events/library/open-game-installer.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/events/library/open-game-installer.ts b/src/main/events/library/open-game-installer.ts index 0b7e98db1..5a3295ebf 100644 --- a/src/main/events/library/open-game-installer.ts +++ b/src/main/events/library/open-game-installer.ts @@ -54,12 +54,14 @@ const openGameInstaller = async ( } const gamePathFileNames = fs.readdirSync(gamePath); - const gameAlternativeSetupPath = gamePathFileNames.find( + const gamePathExecutableFiles = gamePathFileNames.filter( (fileName: string) => path.extname(fileName).toLowerCase() === ".exe" ); - if (gameAlternativeSetupPath) { - return executeGameInstaller(path.join(gamePath, gameAlternativeSetupPath)); + if (gamePathExecutableFiles.length === 1) { + return executeGameInstaller( + path.join(gamePath, gamePathExecutableFiles[0]) + ); } if (spawnSync("which", ["lutris"]).status === 0) {