Skip to content

Commit

Permalink
[Tech] Skip empty arguments in sideload and frontend command launcher (
Browse files Browse the repository at this point in the history
…#3009)

backend/launcher: don't try to pass empty string as additional argument if falsy (empty, null, ...)

If the additional command line arguments are unset/set to an empty
string, the sideload command launcher likewise used to pass an empty
argument to the launched application.

While that is usually harmless, some applications try to parse this
argument and (rightfully) complain and usually exit with an error.

Make sure that we only pass additional arguments if they are actually
set, fixing that issue.

This has been encountered with Palia's launcher.

While at it, also fix a log line by including additional arguments and a
typo in a comment.
  • Loading branch information
rdbrschf authored Aug 4, 2024
1 parent 93a9930 commit 59a2127
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/backend/storeManagers/storeManagerCommon/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export async function launchGame(

const gameSettings = await getAppSettings(appName)
const { launcherArgs } = gameSettings
const extraArgs = shlex.split(launcherArgs ?? '')
const extraArgsJoined = extraArgs.join(' ')

if (executable) {
const isNative = gameManagerMap[runner].isNative(appName)
Expand Down Expand Up @@ -197,15 +199,15 @@ export async function launchGame(
// Native
if (isNative) {
logInfo(
`launching native sideloaded game: ${executable} ${launcherArgs ?? ''}`,
`launching native sideloaded game: ${executable} ${extraArgsJoined}`,
LogPrefix.Backend
)

try {
await access(executable, FS_CONSTANTS.X_OK)
} catch (error) {
logWarning(
'File not executable, changing permissions temporarilly',
'File not executable, changing permissions temporarily',
LogPrefix.Backend
)
// On Mac, it gives an error when changing the permissions of the file inside the app bundle. But we need it for other executables like scripts.
Expand All @@ -214,15 +216,14 @@ export async function launchGame(
}
}

const commandParts = shlex.split(launcherArgs ?? '')
const env = {
...process.env,
...setupWrapperEnvVars({ appName, appRunner: runner }),
...setupEnvVars(gameSettings, gameInfo.install.install_path)
}

await callRunner(
commandParts,
extraArgs,
{
name: runner,
logPrefix: LogPrefix.Backend,
Expand All @@ -246,12 +247,12 @@ export async function launchGame(
}

logInfo(
`launching non-native sideloaded: ${executable}}`,
`launching non-native sideloaded: ${executable} ${extraArgsJoined}`,
LogPrefix.Backend
)

await runWineCommand({
commandParts: [executable, launcherArgs ?? ''],
commandParts: [executable, ...extraArgs],
gameSettings,
wait: true,
protonVerb: 'waitforexitandrun',
Expand Down

0 comments on commit 59a2127

Please sign in to comment.