Skip to content

Commit

Permalink
[Fix] Sideloaded games on Windows (#3562)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
CommandMC authored Mar 9, 2024
1 parent 599fd51 commit 34d861c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,10 @@ async function callRunner(
let bin = runner.bin
let fullRunnerPath = join(runner.dir, bin)

// macOS/Linux: `spawn`ing an executable in the current working directory
// requires a "./"
if (!isWindows) bin = './' + bin

// On Windows: Use PowerShell's `Start-Process` to wait for the process and
// its children to exit, provided PowerShell is available
if (shouldUsePowerShell === null)
Expand All @@ -1005,10 +1009,10 @@ async function callRunner(
'Start-Process',
`"\`"${fullRunnerPath}\`""`,
'-Wait',
'-ArgumentList',
argsAsString,
'-NoNewWindow'
]
if (argsAsString) commandParts.push('-ArgumentList', argsAsString)

bin = fullRunnerPath = 'powershell'
}

Expand Down
4 changes: 2 additions & 2 deletions src/backend/storeManagers/storeManagerCommon/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
LogPrefix,
logWarning
} from '../../logger/logger'
import { dirname } from 'path'
import { basename, dirname } from 'path'
import { constants as FS_CONSTANTS } from 'graceful-fs'
import i18next from 'i18next'
import {
Expand Down Expand Up @@ -220,7 +220,7 @@ export async function launchGame(
{
name: runner,
logPrefix: LogPrefix.Backend,
bin: executable,
bin: basename(executable),
dir: dirname(executable)
},
{
Expand Down
7 changes: 1 addition & 6 deletions src/backend/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,7 @@ function showItemInFolder(item: string) {

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

0 comments on commit 34d861c

Please sign in to comment.