Skip to content

Commit

Permalink
[Fix] Fix calculation of appName from command parts (#3522)
Browse files Browse the repository at this point in the history
* Fix calculation of appName from command parts

* Include update/repair/verify command in calculation
  • Loading branch information
arielj authored Feb 5, 2024
1 parent 67a351d commit 0fb4813
Showing 1 changed file with 44 additions and 1 deletion.
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

0 comments on commit 0fb4813

Please sign in to comment.