Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix calculation of appName from command parts #3522

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,13 +945,56 @@ interface RunnerProps {

const commandsRunning = {}

function appNameFromCommandParts(commandParts: string[], runner: Runner) {
let appNameIndex = -1
let idx = -1

switch (runner) {
case 'gog':
idx = commandParts.findIndex((value) => value === 'launch')
if (idx > -1) {
// for GOGdl, between `launch` and the app name there's another element
appNameIndex = idx + 2
} else {
// for the `download`, `repair` and `update` command it's right after
idx = commandParts.findIndex((value) =>
['download', 'repair', 'update'].includes(value)
)
if (idx > -1) {
appNameIndex = idx + 1
}
}
break
case 'legendary':
// for legendary, the appName comes right after the commands
idx = commandParts.findIndex((value) =>
['launch', 'install', 'repair', 'update'].includes(value)
)
if (idx > -1) {
appNameIndex = idx + 1
}
break
case 'nile':
// for nile, we pass the appName as the last command part
idx = commandParts.findIndex((value) =>
['launch', 'install', 'update', 'verify'].includes(value)
)
if (idx > -1) {
appNameIndex = commandParts.length - 1
}
break
}

return appNameIndex > -1 ? commandParts[appNameIndex] : ''
}

async function callRunner(
commandParts: string[],
runner: RunnerProps,
options?: CallRunnerOptions
): Promise<ExecResult> {
const fullRunnerPath = join(runner.dir, runner.bin)
const appName = commandParts[commandParts.findIndex(() => 'launch') + 1]
const appName = appNameFromCommandParts(commandParts, runner.name)

// Necessary to get rid of possible undefined or null entries, else
// TypeError is triggered
Expand Down
Loading