Skip to content

Commit 34d861c

Browse files
authored
[Fix] Sideloaded games on Windows (#3562)
* Support empty commandParts in callRunner's Windows case In case the array is empty, we have to make sure to not pass the parameter at all (otherwise PS will error out) This is used by sideloaded games * Correctly pass the "runner" path for sideloaded games Sideloaded games pass their executable path as the runner. Before, this was done a little incorrectly. Assume the selected executable is `C:\Windows\System32\cmd.exe`. Before, the runner would then be: { bin: `C:\Windows\System32\cmd.exe` dir: `C:\Windows\System32\` } callRunner then just `join`s together these paths, resulting in `C:\Windows\System32\C:\Windows\System32\cmd.exe`. This is obviously wrong and will not work. Now, we correctly pass just the bin for `bin` (`cmd.exe` in our example). This is also in-line with how regular runners work * Add "./" in callRunner directly This was somewhat flawed before; callRunner relied on an implementation detail of `splitPathAndName` (it adding "./" to the "bin"). The relevant code was now moved to callRunner itself
1 parent 599fd51 commit 34d861c

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/backend/launcher.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,10 @@ async function callRunner(
993993
let bin = runner.bin
994994
let fullRunnerPath = join(runner.dir, bin)
995995

996+
// macOS/Linux: `spawn`ing an executable in the current working directory
997+
// requires a "./"
998+
if (!isWindows) bin = './' + bin
999+
9961000
// On Windows: Use PowerShell's `Start-Process` to wait for the process and
9971001
// its children to exit, provided PowerShell is available
9981002
if (shouldUsePowerShell === null)
@@ -1005,10 +1009,10 @@ async function callRunner(
10051009
'Start-Process',
10061010
`"\`"${fullRunnerPath}\`""`,
10071011
'-Wait',
1008-
'-ArgumentList',
1009-
argsAsString,
10101012
'-NoNewWindow'
10111013
]
1014+
if (argsAsString) commandParts.push('-ArgumentList', argsAsString)
1015+
10121016
bin = fullRunnerPath = 'powershell'
10131017
}
10141018

src/backend/storeManagers/storeManagerCommon/games.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
LogPrefix,
99
logWarning
1010
} from '../../logger/logger'
11-
import { dirname } from 'path'
11+
import { basename, dirname } from 'path'
1212
import { constants as FS_CONSTANTS } from 'graceful-fs'
1313
import i18next from 'i18next'
1414
import {
@@ -220,7 +220,7 @@ export async function launchGame(
220220
{
221221
name: runner,
222222
logPrefix: LogPrefix.Backend,
223-
bin: executable,
223+
bin: basename(executable),
224224
dir: dirname(executable)
225225
},
226226
{

src/backend/utils.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,7 @@ function showItemInFolder(item: string) {
428428

429429
function splitPathAndName(fullPath: string): { dir: string; bin: string } {
430430
const dir = dirname(fullPath)
431-
let bin = basename(fullPath)
432-
// On Windows, you can just launch executables that are in the current working directory
433-
// On Linux, you have to add a ./
434-
if (!isWindows) {
435-
bin = './' + bin
436-
}
431+
const bin = basename(fullPath)
437432
// Make sure to always return this as `dir, bin` to not break path
438433
// resolution when using `join(...Object.values(...))`
439434
return { dir, bin }

0 commit comments

Comments
 (0)