A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.
TypeScript amazon-primeelectronepic-games-launcherepic-games-storeepic-storegaminggoggog-galaxyheroic-games-launcherlinuxplay-gamesprotonsteamwine
[Fix] Update gogdl to 1.4.1 to fix Linux install and Witcher 3 update (#6186)
Flávio Fearn6aefa7b60000
diff --git a/meta/downloadHelperBinaries.ts b/meta/downloadHelperBinaries.tsindex 1cdb94278..d0758e2a3 100644--- a/meta/downloadHelperBinaries.ts+++ b/meta/downloadHelperBinaries.ts@@ -29,7 +29,7 @@ type DownloadedBinary =const RELEASE_TAGS = {legendary: '0.21.1',- gogdl: 'v1.4.0',+ gogdl: 'v1.4.1',nile: 'v1.2.0',comet: 'v0.4.1',aurelia: 'v0.4.0',diff --git a/src/backend/__tests__/launcher.test.ts b/src/backend/__tests__/launcher.test.tsnew file mode 100644index 000000000..d3fb093cf--- /dev/null+++ b/src/backend/__tests__/launcher.test.ts@@ -0,0 +1,79 @@+import {+ buildPowerShellCommand,+ callRunner,+ getRunnerCallWithoutCredentials+} from '../launcher'+import { LogPrefix } from '../logger'++jest.mock('../logger', () => ({+ ...jest.requireActual<typeof import('../logger')>('../logger'),+ logInfo: jest.fn(),+ logError: jest.fn(),+ getRunnerLogWriter: () => ({ logInfo: jest.fn(), writeString: jest.fn() })+}))++const unixIt = process.platform === 'win32' ? it.skip : it++describe('callRunner', () => {+ unixIt('passes the exit code of the runner through', async () => {+ const runner = { name: 'gog' as const, logPrefix: LogPrefix.Gog, bin: 'sh' }++ expect((await callRunner(['-c', 'exit 3'], runner, {})).exitCode).toBe(3)+ expect((await callRunner(['-c', 'exit 0'], runner, {})).exitCode).toBe(0)+ })+})++describe('buildPowerShellCommand', () => {+ const backtick = '`'+ const quote = (value: string) => `"${backtick}"${value}${backtick}""`++ it('builds the exact Start-Process invocation with quoting and ExitCode handling', () => {+ const runnerPath = 'C:\\Program Files & Games\\gogdl.exe'+ const args = [+ quote('download'),+ quote('1207664643'),+ quote('C:\\\\Games & Stuff')+ ].join(',')+ const expectedScript =+ `$process = Start-Process ${quote(runnerPath)} -Wait -NoNewWindow -PassThru ` ++ `-ArgumentList ${args}; if ($null -eq $process) { exit 1 }; exit $process.ExitCode`++ expect(+ buildPowerShellCommand(+ ['download', '1207664643', 'C:\\Games & Stuff'],+ runnerPath+ )+ ).toEqual(['-NoProfile', '-Command', expectedScript])+ })++ it('keeps credentials in the command that is executed', () => {+ const command = buildPowerShellCommand(+ ['auth', '--code', 'secret-code', '--password', 'secret-branch-password'],+ 'gogdl.exe'+ )++ expect(command[2]).toContain('--code')+ expect(command[2]).toContain('secret-code')+ expect(command[2]).toContain('--password')+ expect(command[2]).toContain('secret-branch-password')+ })+})++describe('getRunnerCallWithoutCredentials', () => {+ it('redacts GOG and Legendary auth credentials', () => {+ const commands = [+ ['--auth-config-path', 'auth.json', 'auth', '--code', 'secret-code'],+ ['auth', '--token', 'secret-token'],+ ['update', '1207664643', '--password', 'secret-branch-password'],+ ['-p', 'secret-password'],+ ['--guard', 'secret-guard']+ ]++ for (const command of commands) {+ const safeCommand = getRunnerCallWithoutCredentials(command, {}, 'gogdl')++ expect(safeCommand).not.toContain(command.at(-1))+ expect(safeCommand).toContain('<redacted>')+ }+ })+})diff --git a/src/backend/launcher.ts b/src/backend/launcher.tsindex 7a904753d..ca4123d0a 100644--- a/src/backend/launcher.ts+++ b/src/backend/launcher.ts@@ -1746,6 +1746,27 @@ function appNameFromCommandParts(commandParts: string[], runner: Runner) {return appNameIndex > -1 ? commandParts[appNameIndex] : ''}+function buildPowerShellCommand(+ commandParts: string[],+ fullRunnerPath: string+): string[] {+ const argsAsString = commandParts+ .map((part) => part.replaceAll('\\', '\\\\'))+ .map((part) => `"\`"${part}\`""`)+ .join(',')+ const startProcessParts = [+ 'Start-Process',+ `"\`"${fullRunnerPath}\`""`,+ '-Wait',+ '-NoNewWindow',+ '-PassThru'+ ]+ let script = `$process = ${startProcessParts.join(' ')}`+ if (argsAsString) script += ` -ArgumentList ${argsAsString}`+ script += '; if ($null -eq $process) { exit 1 }; exit $process.ExitCode'+ return ['-NoProfile', '-Command', script]+}+async function callRunner(commandParts: string[],runner: RunnerProps,@@ -1768,6 +1789,14 @@ async function callRunner(// requires a "./"if (!isWindows && !isAbsolute(bin) && runner.dir) bin = './' + bin+ // Build the redacted command before any PowerShell rewriting: the+ // sensitive flags are part of the original arguments, not the wrapper.+ const safeCommand = getRunnerCallWithoutCredentials(+ [...commandParts],+ options?.env,+ fullRunnerPath+ )+// On Windows: Use PowerShell's `Start-Process` to wait for the process and// its children to exit, provided PowerShell is availableif (shouldUsePowerShell === null)@@ -1775,28 +1804,10 @@ async function callRunner(isWindows && !!(await searchForExecutableOnPath('powershell'))if (shouldUsePowerShell && options?.waitForChildProcesses !== false) {- const argsAsString = commandParts- .map((part) => part.replaceAll('\\', '\\\\'))- .map((part) => `"\`"${part}\`""`)- .join(',')- commandParts = [- '-NoProfile',- 'Start-Process',- `"\`"${fullRunnerPath}\`""`,- '-Wait',- '-NoNewWindow'- ]- if (argsAsString) commandParts.push('-ArgumentList', argsAsString)-+ commandParts = buildPowerShellCommand(commandParts, fullRunnerPath)bin = fullRunnerPath = 'powershell'}- const safeCommand = getRunnerCallWithoutCredentials(- [...commandParts],- options?.env,- fullRunnerPath- )-const prefix = `${options.logMessagePrefix ?? 'Running command'}:`logInfo([prefix, safeCommand], runner.logPrefix)@@ -1878,7 +1889,8 @@ async function callRunner(res({stdout: stdout.join(),- stderr: stderr.join('\n')+ stderr: stderr.join('\n'),+ exitCode: code ?? undefined})})@@ -1888,8 +1900,8 @@ async function callRunner(})promise = promise- .then(({ stdout, stderr }) => {- return { stdout, stderr, fullCommand: safeCommand }+ .then(({ stdout, stderr, exitCode }) => {+ return { stdout, stderr, fullCommand: safeCommand, exitCode }}).catch((error) => {if (abortController.signal.aborted) {@@ -1944,7 +1956,13 @@ function getRunnerCallWithoutCredentials(const modifiedCommand = [...command]// Redact sensitive arguments (Authorization Code for Legendary, token for// GOGDL, password (`-p`)/Steam Guard code for Aurelia)- for (const sensitiveArg of ['--code', '--token', '-p', '--guard']) {+ for (const sensitiveArg of [+ '--code',+ '--token',+ '--password',+ '-p',+ '--guard'+ ]) {// PowerShell's argument formatting is quite different, instead of having// arguments as members of `command`, they're all in one specific member// (the one after "-ArgumentList")@@ -2143,6 +2161,8 @@ export {setupWrappers,runWineCommand,callRunner,+ buildPowerShellCommand,+ getRunnerCallWithoutCredentials,getWinePath,launchEventCallback,getKnownFixesEnvVariablesdiff --git a/src/backend/storeManagers/gog/__tests__/library.test.ts b/src/backend/storeManagers/gog/__tests__/library.test.tsnew file mode 100644index 000000000..9eeab048b--- /dev/null+++ b/src/backend/storeManagers/gog/__tests__/library.test.ts@@ -0,0 +1,41 @@+import { callRunner } from 'backend/launcher'+import GOGLibraryManager from '../library'++jest.mock('backend/logger')+jest.mock('backend/launcher', () => ({ callRunner: jest.fn() }))+jest.mock('backend/utils', () => ({+ ...jest.requireActual<typeof import('backend/utils')>('backend/utils'),+ getGOGdlBin: () => ({ dir: '', bin: 'gogdl' })+}))+// storeManagers/index constructs GOGLibraryManager while library.ts is still loading+jest.mock('../../index', () => ({ libraryManagerMap: {} }))++describe('GOGLibraryManager.runRunnerCommand', () => {+ const run = async (+ command: string,+ exitCode: number | undefined,+ abort?: boolean+ ) => {+ jest+ .mocked(callRunner)+ .mockResolvedValueOnce({ stdout: '', stderr: '', exitCode, abort })+ return new GOGLibraryManager().runRunnerCommand([command, '1207664643'])+ }++ it('turns a non-zero exit of a download command into an error', async () => {+ for (const command of ['download', 'update', 'repair', 'redist']) {+ expect((await run(command, 1)).error).toBe('gogdl exited with code 1')+ }+ })++ it('leaves successful and aborted downloads alone', async () => {+ expect((await run('update', 0)).error).toBeUndefined()+ expect((await run('update', undefined, true)).error).toBeUndefined()+ })++ it('ignores non-download commands', async () => {+ for (const command of ['launch', 'auth', 'import']) {+ expect((await run(command, 1)).error).toBeUndefined()+ }+ })+})diff --git a/src/backend/storeManagers/gog/library.ts b/src/backend/storeManagers/gog/library.tsindex 02597c300..ea264a7e2 100644--- a/src/backend/storeManagers/gog/library.ts+++ b/src/backend/storeManagers/gog/library.ts@@ -1518,11 +1518,26 @@ export default class GOGLibraryManager implements LibraryManager {}options.env.GOGDL_CONFIG_PATH = dirname(gogdlConfigPath)- return callRunner(+ const res = await callRunner(['--auth-config-path', authConfig, ...commandParts],{ name: 'gog', logPrefix: LogPrefix.Gog, bin, dir },options)+ // gogdl reports a failed download (e.g. a patch that can't be applied) only through its exit code.+ // Not checked for other commands: `launch` exits with the game's own status.+ const isDownload = ['download', 'update', 'repair', 'redist'].includes(+ commandParts[0]+ )+ if (+ isDownload &&+ typeof res.exitCode === 'number' &&+ res.exitCode !== 0 &&+ !res.error &&+ !res.abort+ ) {+ res.error = `gogdl exited with code ${res.exitCode}`+ }+ return res}/* eslint-disable @typescript-eslint/no-unused-vars */diff --git a/src/common/types.ts b/src/common/types.tsindex 00e54811b..7800a213e 100644--- a/src/common/types.ts+++ b/src/common/types.ts@@ -199,6 +199,7 @@ export type ExecResult = {fullCommand?: stringerror?: stringabort?: boolean+ exitCode?: number}export interface ExtraInfo {diff --git a/src/frontend/state/GlobalState.tsx b/src/frontend/state/GlobalState.tsxindex 8cf5d2c9f..71281861c 100644--- a/src/frontend/state/GlobalState.tsx+++ b/src/frontend/state/GlobalState.tsx@@ -1078,8 +1078,8 @@ class GlobalState extends PureComponent<Props> {// when error or done we remove it from the status infoif (['error', 'done'].includes(status)) {- // also remove from updates if it was updating- if (currentApp.status === 'updating') {+ // also remove from updates if it was updating; GOG updates end with a redist setup step+ if (['updating', 'redist'].includes(currentApp.status)) {const updatedGamesUpdates = gameUpdates.filter((game) => game !== appName)