From ff67654a6674825b53a5091115024cb7f3d066f4 Mon Sep 17 00:00:00 2001 From: Nocccer Date: Mon, 30 May 2022 16:33:21 +0200 Subject: [PATCH 1/2] Restructured runLegendaryOrGogCommand - removed unessecary functions and logs - cleanup unessecary code --- electron/gog/games.ts | 33 ++++++++++----------- electron/gog/library.ts | 26 ++-------------- electron/launcher.ts | 56 +++++++++++++++++------------------ electron/legendary/games.ts | 42 +++++++++++--------------- electron/legendary/library.ts | 26 ++-------------- electron/legendary/user.ts | 10 +++---- electron/main.ts | 2 +- 7 files changed, 74 insertions(+), 121 deletions(-) diff --git a/electron/gog/games.ts b/electron/gog/games.ts index 006f296fe2..caf3de12eb 100644 --- a/electron/gog/games.ts +++ b/electron/gog/games.ts @@ -40,7 +40,7 @@ import { } from '../launcher' import { addShortcuts, removeShortcuts } from '../shortcuts' import setup from './setup' -import { getGogdlCommand, runGogdlCommand } from './library' +import { runGogdlCommand } from './library' function verifyProgress(stderr: string): boolean { const text = stderr.split('\n').at(-1) @@ -97,9 +97,8 @@ class GOGGame extends Game { public async import(path: string): Promise { const commandParts = ['import', path] - const command = getGogdlCommand(commandParts) - logInfo([`Importing ${this.appName} with:`, command], LogPrefix.Gog) + logInfo(`Importing ${this.appName}.`, LogPrefix.Gog) const res = await runGogdlCommand(commandParts) @@ -138,7 +137,7 @@ class GOGGame extends Game { `Progress for ${this.appName}:`, `${percent}%/${bytes}MiB/${eta}`.trim() ], - LogPrefix.Backend + LogPrefix.Gog ) this.window.webContents.send('setGameStatus', { @@ -185,9 +184,8 @@ class GOGGame extends Game { `--lang=${installLanguage}`, ...workers ] - const command = getGogdlCommand(commandParts) - logInfo([`Installing ${this.appName} with:`, command], LogPrefix.Gog) + logInfo(`Installing ${this.appName}.`, LogPrefix.Gog) const onOutput = (data: string) => { this.onInstallOrUpdateOutput('installing', data) @@ -270,6 +268,7 @@ class GOGGame extends Game { public async removeShortcuts() { return removeShortcuts(this.appName, 'gog') } + async launch(launchArguments?: string): Promise { const gameSettings = GameConfig.get(this.appName).config || @@ -395,14 +394,16 @@ class GOGGame extends Game { launcherArgs ] } - const command = getGogdlCommand(commandParts, commandEnv, wrappers) - logInfo([`Launching ${gameInfo.title}:`, command], LogPrefix.Gog) + logInfo(`Launching ${gameInfo.title}.`, LogPrefix.Gog) - const { error, stderr, stdout } = await runGogdlCommand(commandParts, { - env: commandEnv, - wrappers - }) + const { error, stderr, stdout, fullCommand } = await runGogdlCommand( + commandParts, + { + env: commandEnv, + wrappers + } + ) if (error) { logError(['Error launching game:', error], LogPrefix.Gog) @@ -415,7 +416,7 @@ class GOGGame extends Game { stdout, stderr, gameSettings, - command + command: fullCommand } } @@ -467,9 +468,8 @@ class GOGGame extends Game { '-b=' + gameData.install.buildId, ...workers ] - const command = getGogdlCommand(commandParts) - logInfo([`Repairing ${this.appName} with:`, command], LogPrefix.Gog) + logInfo(`Repairing ${this.appName}.`, LogPrefix.Gog) const res = await runGogdlCommand(commandParts, { logFile: logPath }) @@ -578,9 +578,8 @@ class GOGGame extends Game { `--lang=${gameData.install.language || 'en-US'}`, ...workers ] - const command = getGogdlCommand(commandParts) - logInfo([`Updating ${this.appName} with:`, command], LogPrefix.Gog) + logInfo(`Updating ${this.appName}.`, LogPrefix.Gog) const onOutput = (data: string) => { this.onInstallOrUpdateOutput('updating', data) diff --git a/electron/gog/library.ts b/electron/gog/library.ts index 7f510e62ab..87139dd832 100644 --- a/electron/gog/library.ts +++ b/electron/gog/library.ts @@ -19,10 +19,7 @@ import { libraryStore, installedGamesStore } from './electronStores' -import { - getLegendaryOrGogdlCommand, - runLegendaryOrGogdlCommand -} from '../launcher' +import { runLegendaryOrGogdlCommand } from '../launcher' export class GOGLibrary { private static globalInstance: GOGLibrary = null @@ -169,9 +166,8 @@ export class GOGLibrary { '--os', installPlatform ] - const command = getGogdlCommand(commandParts) - logInfo(['Getting game metadata:', command], LogPrefix.Gog) + logInfo('Getting game metadata.', LogPrefix.Gog) const res = await runGogdlCommand(commandParts) if (res.error) { @@ -635,23 +631,7 @@ export async function runGogdlCommand( const { dir, bin } = getGOGdlBin() return runLegendaryOrGogdlCommand( commandParts, - { name: 'GOGDL', logPrefix: LogPrefix.Gog, bin, dir }, + { name: 'gog', logPrefix: LogPrefix.Gog, bin, dir }, options ) } - -/** - * Generates a "safe" GOGDL command **for formatting**. - * Command generated by this function are not meant to be ran directly, use runGogdlCommand for that. - * A "safe" command does not include the user's token - * @param commandParts The command to run, e. g. 'update', 'install'... - * @returns The full command as a string - */ -export function getGogdlCommand( - commandParts: string[], - env: Record = {}, - wrappers: string[] = [] -): string { - const gogdlPath = join(...Object.values(getGOGdlBin())) - return getLegendaryOrGogdlCommand(commandParts, env, wrappers, gogdlPath) -} diff --git a/electron/launcher.ts b/electron/launcher.ts index aa651a9839..a935373e05 100644 --- a/electron/launcher.ts +++ b/electron/launcher.ts @@ -34,7 +34,7 @@ import { DXVK } from './tools' import setup from './gog/setup' import { GOGGame } from 'gog/games' import { LegendaryGame } from 'legendary/games' -import { GameInfo } from './types' +import { GameInfo, Runner } from './types' import { ExecResult, GameSettings, @@ -471,7 +471,7 @@ async function runWineCommand( async function runLegendaryOrGogdlCommand( commandParts: string[], runner: { - name: 'GOGDL' | 'Legendary' + name: Runner logPrefix: LogPrefix bin: string dir: string @@ -485,20 +485,22 @@ async function runLegendaryOrGogdlCommand( ): Promise { const fullRunnerPath = join(runner.dir, runner.bin) const appName = commandParts[commandParts.findIndex(() => 'launch') + 1] + + // Necessary to get rid of undefined or null entries, else + // TypeError is triggered + commandParts = commandParts.filter(Boolean) const safeCommand = getLegendaryOrGogdlCommand( commandParts, options?.env, options?.wrappers, fullRunnerPath ) - logDebug(['Running', runner.name, 'command:', safeCommand], runner.logPrefix) - if (options?.logFile) { - logDebug([`Logging to file "${options.logFile}"`], runner.logPrefix) - } - commandParts = commandParts.filter((n) => n) + logDebug(['Running', 'command:', safeCommand], runner.logPrefix) + logDebug(`Logging to file "${options?.logFile}"`, runner.logPrefix) + if (existsSync(options?.logFile)) { - writeFileSync(options.logFile, '') + writeFileSync(options?.logFile, '') } // If we have wrappers (things we want to run before the command), set bin to the first wrapper @@ -521,28 +523,27 @@ async function runLegendaryOrGogdlCommand( const stdout: string[] = [] const stderr: string[] = [] - if (options?.logFile) { - child.stdout.on('data', (data: Buffer) => { - appendFileSync(options.logFile, data.toString()) - }) - child.stderr.on('data', (data: Buffer) => { + child.stdout.on('data', (data: Buffer) => { + if (options?.logFile) { appendFileSync(options.logFile, data.toString()) - }) - } + } - if (options?.onOutput) { - child.stdout.on('data', (data: Buffer) => { - options.onOutput(data.toString()) - }) - child.stderr.on('data', (data: Buffer) => { + if (options?.onOutput) { options.onOutput(data.toString()) - }) - } + } - child.stdout.on('data', (data: Buffer) => { stdout.push(data.toString().trim()) }) + child.stderr.on('data', (data: Buffer) => { + if (options?.logFile) { + appendFileSync(options.logFile, data.toString()) + } + + if (options?.onOutput) { + options.onOutput(data.toString()) + } + stderr.push(data.toString().trim()) }) @@ -563,6 +564,7 @@ async function runLegendaryOrGogdlCommand( stderr: stderr.join('\n') }) }) + child.on('error', (error) => { rej(error) }) @@ -583,10 +585,11 @@ async function runLegendaryOrGogdlCommand( !`${error}`.includes('appears to be deleted') logError( - ['Error running', runner.name, 'command', `"${safeCommand}": ${error}`], + ['Error running', 'command', `"${safeCommand}": ${error}`], runner.logPrefix, showDialog ) + return { stdout: '', stderr: `${error}`, fullCommand: safeCommand, error } }) } @@ -597,8 +600,6 @@ function getLegendaryOrGogdlCommand( wrappers: string[] = [], runnerPath: string ): string { - commandParts = commandParts.filter((n) => n) - // Redact sensitive arguments (SID for Legendary, token for GOGDL) for (const sensitiveArg of ['--sid', '--token']) { const sensitiveArgIndex = commandParts.indexOf(sensitiveArg) @@ -636,6 +637,5 @@ export { setupWineEnvVars, setupWrappers, runWineCommand, - runLegendaryOrGogdlCommand, - getLegendaryOrGogdlCommand + runLegendaryOrGogdlCommand } diff --git a/electron/legendary/games.ts b/electron/legendary/games.ts index 56dcf85bd9..fac930c4af 100644 --- a/electron/legendary/games.ts +++ b/electron/legendary/games.ts @@ -6,7 +6,7 @@ import { ExecResult, ExtraInfo, InstallArgs, LaunchResult } from '../types' import { Game } from '../games' import { GameConfig } from '../game_config' import { GlobalConfig } from '../config' -import { getLegendaryCommand, LegendaryLibrary } from './library' +import { LegendaryLibrary } from './library' import { LegendaryUser } from './user' import { execAsync, getSteamRuntime, isOnline } from '../utils' import { @@ -266,7 +266,7 @@ class LegendaryGame extends Game { `Progress for ${this.appName}:`, `${percent}%/${bytes}MiB/${eta}`.trim() ], - LogPrefix.Backend + LogPrefix.Legendary ) this.window.webContents.send('setGameStatus', { @@ -298,9 +298,8 @@ class LegendaryGame extends Game { const logPath = join(heroicGamesConfigPath, this.appName + '.log') const commandParts = ['update', this.appName, ...workers, '-y'] - const command = getLegendaryCommand(commandParts) - logInfo([`Updating ${this.appName} with:`, command], LogPrefix.Legendary) + logInfo(`Updating ${this.appName}.`, LogPrefix.Legendary) const onOutput = (data: string) => { this.onInstallOrUpdateOutput( @@ -393,8 +392,8 @@ class LegendaryGame extends Game { ...workers, '-y' ] - const command = getLegendaryCommand(commandParts) - logInfo([`Installing ${this.appName} with:`, command], LogPrefix.Legendary) + + logInfo(`Installing ${this.appName}.`, LogPrefix.Legendary) const onOutput = (data: string) => { this.onInstallOrUpdateOutput( @@ -434,9 +433,8 @@ class LegendaryGame extends Game { public async uninstall(): Promise { const commandParts = ['uninstall', this.appName, '-y'] - const command = getLegendaryCommand(commandParts) - logInfo([`Uninstalling ${this.appName}:`, command], LogPrefix.Legendary) + logInfo(`Uninstalling ${this.appName}.`, LogPrefix.Legendary) LegendaryLibrary.get().installState(this.appName, false) const res = await runLegendaryCommand(commandParts) @@ -463,9 +461,8 @@ class LegendaryGame extends Game { const logPath = join(heroicGamesConfigPath, this.appName + '.log') const commandParts = ['repair', this.appName, ...workers, '-y'] - const command = getLegendaryCommand(commandParts) - logInfo([`Repairing ${this.appName}:`, command], LogPrefix.Legendary) + logInfo(`Repairing ${this.appName}.`, LogPrefix.Legendary) const res = await runLegendaryCommand(commandParts, { logFile: logPath }) @@ -480,9 +477,8 @@ class LegendaryGame extends Game { public async import(path: string): Promise { const commandParts = ['import', this.appName, path] - const command = getLegendaryCommand(commandParts) - logInfo([`Importing ${this.appName}:`, command], LogPrefix.Legendary) + logInfo(`Importing ${this.appName}.`, LogPrefix.Legendary) const res = await runLegendaryCommand(commandParts) @@ -517,12 +513,8 @@ class LegendaryGame extends Game { this.appName, '-y' ] - const command = getLegendaryCommand(commandParts) - logInfo( - [`Syncing saves for ${this.appName}:`, command], - LogPrefix.Legendary - ) + logInfo(`Syncing saves for ${this.appName}.`, LogPrefix.Legendary) const res = await runLegendaryCommand(commandParts) @@ -659,13 +651,15 @@ class LegendaryGame extends Game { launchArguments ] } - const command = getLegendaryCommand(commandParts, commandEnv, wrappers) - logInfo([`Launching ${gameInfo.title}:`, command], LogPrefix.Legendary) - const { error, stderr, stdout } = await runLegendaryCommand(commandParts, { - env: commandEnv, - wrappers: wrappers - }) + logInfo(`Launching ${gameInfo.title}.`, LogPrefix.Legendary) + const { error, stderr, stdout, fullCommand } = await runLegendaryCommand( + commandParts, + { + env: commandEnv, + wrappers: wrappers + } + ) if (error) { const showDialog = !`${error}`.includes('appears to be deleted') @@ -683,7 +677,7 @@ class LegendaryGame extends Game { stdout, stderr, gameSettings, - command + command: fullCommand } } diff --git a/electron/legendary/library.ts b/electron/legendary/library.ts index 660a32dca0..98a5984de9 100644 --- a/electron/legendary/library.ts +++ b/electron/legendary/library.ts @@ -37,12 +37,8 @@ import { logWarning } from '../logger/logger' import { GlobalConfig } from '../config' -import { join } from 'path' import { installStore, libraryStore } from './electronStores' -import { - getLegendaryOrGogdlCommand, - runLegendaryOrGogdlCommand -} from '../launcher' +import { runLegendaryOrGogdlCommand } from '../launcher' /** * Legendary LegendaryLibrary. @@ -262,9 +258,8 @@ export class LegendaryLibrary { } const commandParts = ['list-installed', '--check-updates', '--tsv'] - const command = getLegendaryCommand(commandParts) - logInfo(['Checking for game updates:', command], LogPrefix.Legendary) + logInfo('Checking for game updates.', LogPrefix.Legendary) const res = await runLegendaryCommand(commandParts) if (res.error) { @@ -591,22 +586,7 @@ export async function runLegendaryCommand( const { dir, bin } = getLegendaryBin() return runLegendaryOrGogdlCommand( commandParts, - { name: 'Legendary', logPrefix: LogPrefix.Legendary, bin, dir }, + { name: 'legendary', logPrefix: LogPrefix.Legendary, bin, dir }, options ) } - -/** - * Generates a legendary command **for formatting**. - * Commands generated by this function are not ment to be ran directly, use runLegendaryCommand for that. - * @param commandParts The command to run, e. g. 'list', 'egl-sync'... - * @returns The full command as a string - */ -export function getLegendaryCommand( - commandParts: string[], - env: Record = {}, - wrappers: string[] = [] -): string { - const legendaryPath = join(...Object.values(getLegendaryBin())) - return getLegendaryOrGogdlCommand(commandParts, env, wrappers, legendaryPath) -} diff --git a/electron/legendary/user.ts b/electron/legendary/user.ts index 86012c26c4..ae0d7ef45f 100644 --- a/electron/legendary/user.ts +++ b/electron/legendary/user.ts @@ -6,13 +6,13 @@ import { userInfo, configStore } from '../constants' import { logError, logInfo, LogPrefix } from '../logger/logger' import { userInfo as user } from 'os' import { session } from 'electron' -import { getLegendaryCommand, runLegendaryCommand } from './library' +import { runLegendaryCommand } from './library' export class LegendaryUser { public static async login(sid: string) { const commandParts = ['auth', '--sid', sid] - const command = getLegendaryCommand(commandParts) - logInfo(['Logging in with Legendary:', command], LogPrefix.Legendary) + + logInfo('Logging in with Legendary.', LogPrefix.Legendary) try { await runLegendaryCommand(commandParts) @@ -30,8 +30,8 @@ export class LegendaryUser { public static async logout() { const commandParts = ['auth', '--delete'] - const command = getLegendaryCommand(commandParts) - logInfo(['Logging out:', command], LogPrefix.Legendary) + + logInfo('Logging out.', LogPrefix.Legendary) const res = await runLegendaryCommand(commandParts) diff --git a/electron/main.ts b/electron/main.ts index b826f88bec..b8f1d3e710 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -1005,7 +1005,7 @@ ipcMain.handle('uninstall', async (event, args) => { .uninstall() .then(() => { if (shouldRemovePrefix) { - logInfo(`Removing prefix ${winePrefix}`) + logInfo(`Removing prefix ${winePrefix}`, LogPrefix.Backend) if (existsSync(winePrefix)) { // remove prefix if exists rmSync(winePrefix, { recursive: true }) From 3d51aba4a464e3573ab688df5e5a515fbcc8cf37 Mon Sep 17 00:00:00 2001 From: Nocccer Date: Tue, 31 May 2022 16:03:08 +0200 Subject: [PATCH 2/2] Review suggestions and cleanup --- electron/gog/games.ts | 30 ++++++++++------------- electron/gog/library.ts | 14 ++++------- electron/launcher.ts | 45 +++++++++++++++++++---------------- electron/legendary/games.ts | 33 +++++++++++++------------ electron/legendary/library.ts | 13 ++++------ electron/types.ts | 8 +++++++ 6 files changed, 70 insertions(+), 73 deletions(-) diff --git a/electron/gog/games.ts b/electron/gog/games.ts index caf3de12eb..0fb789bb84 100644 --- a/electron/gog/games.ts +++ b/electron/gog/games.ts @@ -96,11 +96,9 @@ class GOGGame extends Game { } public async import(path: string): Promise { - const commandParts = ['import', path] - - logInfo(`Importing ${this.appName}.`, LogPrefix.Gog) - - const res = await runGogdlCommand(commandParts) + const res = await runGogdlCommand(['import', path], { + logMessagePrefix: `Importing ${this.appName}` + }) if (res.error) { logError( @@ -185,15 +183,14 @@ class GOGGame extends Game { ...workers ] - logInfo(`Installing ${this.appName}.`, LogPrefix.Gog) - const onOutput = (data: string) => { this.onInstallOrUpdateOutput('installing', data) } const res = await runGogdlCommand(commandParts, { logFile: logPath, - onOutput + onOutput, + logMessagePrefix: `Installing ${this.appName}` }) if (res.error) { @@ -395,13 +392,12 @@ class GOGGame extends Game { ] } - logInfo(`Launching ${gameInfo.title}.`, LogPrefix.Gog) - const { error, stderr, stdout, fullCommand } = await runGogdlCommand( commandParts, { env: commandEnv, - wrappers + wrappers, + logMessagePrefix: `Launching ${gameInfo.title}` } ) @@ -469,9 +465,10 @@ class GOGGame extends Game { ...workers ] - logInfo(`Repairing ${this.appName}.`, LogPrefix.Gog) - - const res = await runGogdlCommand(commandParts, { logFile: logPath }) + const res = await runGogdlCommand(commandParts, { + logFile: logPath, + logMessagePrefix: `Repairing ${this.appName}` + }) if (res.error) { logError( @@ -579,15 +576,14 @@ class GOGGame extends Game { ...workers ] - logInfo(`Updating ${this.appName}.`, LogPrefix.Gog) - const onOutput = (data: string) => { this.onInstallOrUpdateOutput('updating', data) } const res = await runGogdlCommand(commandParts, { logFile: logPath, - onOutput + onOutput, + logMessagePrefix: `Updating ${this.appName}` }) // This always has to be done, so we do it before checking for res.error diff --git a/electron/gog/library.ts b/electron/gog/library.ts index 87139dd832..f004dfb03f 100644 --- a/electron/gog/library.ts +++ b/electron/gog/library.ts @@ -6,7 +6,8 @@ import { InstallInfo, InstalledInfo, GOGImportData, - ExecResult + ExecResult, + CallRunnerOptions } from '../types' import { join } from 'node:path' import { existsSync, readFileSync } from 'graceful-fs' @@ -19,7 +20,7 @@ import { libraryStore, installedGamesStore } from './electronStores' -import { runLegendaryOrGogdlCommand } from '../launcher' +import { callRunner } from '../launcher' export class GOGLibrary { private static globalInstance: GOGLibrary = null @@ -621,15 +622,10 @@ export class GOGLibrary { */ export async function runGogdlCommand( commandParts: string[], - options?: { - logFile?: string - env?: Record - wrappers?: string[] - onOutput?: (output: string) => void - } + options?: CallRunnerOptions ): Promise { const { dir, bin } = getGOGdlBin() - return runLegendaryOrGogdlCommand( + return callRunner( commandParts, { name: 'gog', logPrefix: LogPrefix.Gog, bin, dir }, options diff --git a/electron/launcher.ts b/electron/launcher.ts index a935373e05..2d86418493 100644 --- a/electron/launcher.ts +++ b/electron/launcher.ts @@ -34,7 +34,7 @@ import { DXVK } from './tools' import setup from './gog/setup' import { GOGGame } from 'gog/games' import { LegendaryGame } from 'legendary/games' -import { GameInfo, Runner } from './types' +import { CallRunnerOptions, GameInfo, Runner } from './types' import { ExecResult, GameSettings, @@ -468,39 +468,42 @@ async function runWineCommand( }) } -async function runLegendaryOrGogdlCommand( +interface RunnerProps { + name: Runner + logPrefix: LogPrefix + bin: string + dir: string +} + +async function callRunner( commandParts: string[], - runner: { - name: Runner - logPrefix: LogPrefix - bin: string - dir: string - }, - options?: { - logFile?: string - env?: Record - wrappers?: string[] - onOutput?: (output: string) => void - } + runner: RunnerProps, + options?: CallRunnerOptions ): Promise { const fullRunnerPath = join(runner.dir, runner.bin) const appName = commandParts[commandParts.findIndex(() => 'launch') + 1] - // Necessary to get rid of undefined or null entries, else + // Necessary to get rid of possible undefined or null entries, else // TypeError is triggered commandParts = commandParts.filter(Boolean) - const safeCommand = getLegendaryOrGogdlCommand( + const safeCommand = getRunnerCallWithoutCredentials( commandParts, options?.env, options?.wrappers, fullRunnerPath ) - logDebug(['Running', 'command:', safeCommand], runner.logPrefix) - logDebug(`Logging to file "${options?.logFile}"`, runner.logPrefix) + logInfo( + [options?.logMessagePrefix ?? `Running command`, ':', safeCommand], + runner.logPrefix + ) + + if (options?.logFile) { + logDebug(`Logging to file "${options?.logFile}"`, runner.logPrefix) + } if (existsSync(options?.logFile)) { - writeFileSync(options?.logFile, '') + writeFileSync(options.logFile, '') } // If we have wrappers (things we want to run before the command), set bin to the first wrapper @@ -594,7 +597,7 @@ async function runLegendaryOrGogdlCommand( }) } -function getLegendaryOrGogdlCommand( +function getRunnerCallWithoutCredentials( commandParts: string[], env: Record = {}, wrappers: string[] = [], @@ -637,5 +640,5 @@ export { setupWineEnvVars, setupWrappers, runWineCommand, - runLegendaryOrGogdlCommand + callRunner } diff --git a/electron/legendary/games.ts b/electron/legendary/games.ts index fac930c4af..4bc273328a 100644 --- a/electron/legendary/games.ts +++ b/electron/legendary/games.ts @@ -299,8 +299,6 @@ class LegendaryGame extends Game { const commandParts = ['update', this.appName, ...workers, '-y'] - logInfo(`Updating ${this.appName}.`, LogPrefix.Legendary) - const onOutput = (data: string) => { this.onInstallOrUpdateOutput( 'installing', @@ -311,7 +309,8 @@ class LegendaryGame extends Game { const res = await runLegendaryCommand(commandParts, { logFile: logPath, - onOutput + onOutput, + logMessagePrefix: `Updating ${this.appName}` }) this.window.webContents.send('setGameStatus', { @@ -393,8 +392,6 @@ class LegendaryGame extends Game { '-y' ] - logInfo(`Installing ${this.appName}.`, LogPrefix.Legendary) - const onOutput = (data: string) => { this.onInstallOrUpdateOutput( 'updating', @@ -405,7 +402,8 @@ class LegendaryGame extends Game { let res = await runLegendaryCommand(commandParts, { logFile: logPath, - onOutput + onOutput, + logMessagePrefix: `Installing ${this.appName}` }) // try to run the install again with higher memory limit @@ -434,10 +432,10 @@ class LegendaryGame extends Game { public async uninstall(): Promise { const commandParts = ['uninstall', this.appName, '-y'] - logInfo(`Uninstalling ${this.appName}.`, LogPrefix.Legendary) - LegendaryLibrary.get().installState(this.appName, false) - const res = await runLegendaryCommand(commandParts) + const res = await runLegendaryCommand(commandParts, { + logMessagePrefix: `Uninstalling ${this.appName}` + }) if (res.error) { logError( @@ -462,9 +460,10 @@ class LegendaryGame extends Game { const commandParts = ['repair', this.appName, ...workers, '-y'] - logInfo(`Repairing ${this.appName}.`, LogPrefix.Legendary) - - const res = await runLegendaryCommand(commandParts, { logFile: logPath }) + const res = await runLegendaryCommand(commandParts, { + logFile: logPath, + logMessagePrefix: `Repairing ${this.appName}` + }) if (res.error) { logError( @@ -514,9 +513,9 @@ class LegendaryGame extends Game { '-y' ] - logInfo(`Syncing saves for ${this.appName}.`, LogPrefix.Legendary) - - const res = await runLegendaryCommand(commandParts) + const res = await runLegendaryCommand(commandParts, { + logMessagePrefix: `Syncing saves for ${this.appName}` + }) if (res.error) { logError( @@ -652,12 +651,12 @@ class LegendaryGame extends Game { ] } - logInfo(`Launching ${gameInfo.title}.`, LogPrefix.Legendary) const { error, stderr, stdout, fullCommand } = await runLegendaryCommand( commandParts, { env: commandEnv, - wrappers: wrappers + wrappers: wrappers, + logMessagePrefix: `Launching ${gameInfo.title}` } ) diff --git a/electron/legendary/library.ts b/electron/legendary/library.ts index 98a5984de9..19eec469bd 100644 --- a/electron/legendary/library.ts +++ b/electron/legendary/library.ts @@ -1,4 +1,4 @@ -import { ExecResult } from './../types' +import { CallRunnerOptions, ExecResult } from './../types' import { existsSync, readFileSync, @@ -38,7 +38,7 @@ import { } from '../logger/logger' import { GlobalConfig } from '../config' import { installStore, libraryStore } from './electronStores' -import { runLegendaryOrGogdlCommand } from '../launcher' +import { callRunner } from '../launcher' /** * Legendary LegendaryLibrary. @@ -576,15 +576,10 @@ export class LegendaryLibrary { export async function runLegendaryCommand( commandParts: string[], - options?: { - logFile?: string - env?: Record - wrappers?: string[] - onOutput?: (output: string) => void - } + options?: CallRunnerOptions ): Promise { const { dir, bin } = getLegendaryBin() - return runLegendaryOrGogdlCommand( + return callRunner( commandParts, { name: 'legendary', logPrefix: LogPrefix.Legendary, bin, dir }, options diff --git a/electron/types.ts b/electron/types.ts index 21208b4f36..8494ff54ae 100644 --- a/electron/types.ts +++ b/electron/types.ts @@ -365,3 +365,11 @@ export interface RpcClient { reply(user: unknown, response: unknown): void disconnect(): void } + +export interface CallRunnerOptions { + logMessagePrefix?: string + logFile?: string + env?: Record + wrappers?: string[] + onOutput?: (output: string) => void +}