Skip to content

No longer log commands twice #1405

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
47 changes: 20 additions & 27 deletions electron/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -96,12 +96,9 @@ class GOGGame extends Game {
}

public async import(path: string): Promise<ExecResult> {
const commandParts = ['import', path]
const command = getGogdlCommand(commandParts)

logInfo([`Importing ${this.appName} with:`, command], LogPrefix.Gog)

const res = await runGogdlCommand(commandParts)
const res = await runGogdlCommand(['import', path], {
purpose: `Importing ${this.appName}`
})

if (res.error) {
logError(
Expand Down Expand Up @@ -185,17 +182,14 @@ class GOGGame extends Game {
`--lang=${installLanguage}`,
...workers
]
const command = getGogdlCommand(commandParts)

logInfo([`Installing ${this.appName} with:`, command], LogPrefix.Gog)

const onOutput = (data: string) => {
this.onInstallOrUpdateOutput('installing', data)
}

const res = await runGogdlCommand(commandParts, {
logFile: logPath,
onOutput
onOutput,
purpose: `Installing ${this.appName}`
})

if (res.error) {
Expand Down Expand Up @@ -395,13 +389,16 @@ class GOGGame extends Game {
launcherArgs
]
}
const command = getGogdlCommand(commandParts, commandEnv, wrappers)

logInfo([`Launching ${gameInfo.title}:`, command], LogPrefix.Gog)

const { error, stderr, stdout } = await runGogdlCommand(commandParts, {
const {
error,
stderr,
stdout,
fullCommand: command
} = await runGogdlCommand(commandParts, {
env: commandEnv,
wrappers
wrappers,
purpose: `Launching ${gameInfo.title}`
})

if (error) {
Expand Down Expand Up @@ -467,11 +464,10 @@ class GOGGame extends Game {
'-b=' + gameData.install.buildId,
...workers
]
const command = getGogdlCommand(commandParts)

logInfo([`Repairing ${this.appName} with:`, command], LogPrefix.Gog)

const res = await runGogdlCommand(commandParts, { logFile: logPath })
const res = await runGogdlCommand(commandParts, {
logFile: logPath,
purpose: `Repairing ${this.appName}`
})

if (res.error) {
logError(
Expand Down Expand Up @@ -578,17 +574,14 @@ class GOGGame extends Game {
`--lang=${gameData.install.language || 'en-US'}`,
...workers
]
const command = getGogdlCommand(commandParts)

logInfo([`Updating ${this.appName} with:`, command], LogPrefix.Gog)

const onOutput = (data: string) => {
this.onInstallOrUpdateOutput('updating', data)
}

const res = await runGogdlCommand(commandParts, {
logFile: logPath,
onOutput
onOutput,
purpose: `Updating ${this.appName}`
})

// This always has to be done, so we do it before checking for res.error
Expand Down
29 changes: 5 additions & 24 deletions electron/gog/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,11 +166,10 @@ export class GOGLibrary {
'--os',
installPlatform
]
const command = getGogdlCommand(commandParts)

logInfo(['Getting game metadata:', command], LogPrefix.Gog)

const res = await runGogdlCommand(commandParts)
const res = await runGogdlCommand(commandParts, {
purpose: 'Getting game metadata'
})
if (res.error) {
logError(
['Failed to get game metadata for', `${appName}:`, res.error],
Expand Down Expand Up @@ -630,6 +626,7 @@ export async function runGogdlCommand(
env?: Record<string, string>
wrappers?: string[]
onOutput?: (output: string) => void
purpose?: string
}
): Promise<ExecResult> {
const { dir, bin } = getGOGdlBin()
Expand All @@ -639,19 +636,3 @@ export async function runGogdlCommand(
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<string, string> = {},
wrappers: string[] = []
): string {
const gogdlPath = join(...Object.values(getGOGdlBin()))
return getLegendaryOrGogdlCommand(commandParts, env, wrappers, gogdlPath)
}
15 changes: 12 additions & 3 deletions electron/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,17 +481,20 @@ async function runLegendaryOrGogdlCommand(
env?: Record<string, string>
wrappers?: string[]
onOutput?: (output: string) => void
purpose?: string
}
): Promise<ExecResult> {
const fullRunnerPath = join(runner.dir, runner.bin)
const appName = commandParts[commandParts.findIndex(() => 'launch') + 1]

const safeCommand = getLegendaryOrGogdlCommand(
commandParts,
options?.env,
options?.wrappers,
fullRunnerPath
)
logDebug(['Running', runner.name, 'command:', safeCommand], runner.logPrefix)
const commandPurpose = options?.purpose ?? `Running ${runner.name} command`
logDebug([`${commandPurpose}:`, safeCommand], runner.logPrefix)
if (options?.logFile) {
logDebug([`Logging to file "${options.logFile}"`], runner.logPrefix)
}
Expand Down Expand Up @@ -590,6 +593,13 @@ async function runLegendaryOrGogdlCommand(
})
}

/**
* Generates a "safe" Legendary/GOGDL command **for formatting**.
* Command generated by this function are not meant to be ran directly, use runLegendaryOrGogdlCommand for that.
* A "safe" command does not include the user's SID/token
* @param commandParts The command to run, e. g. 'update', 'install'...
* @returns The full command as a string
*/
function getLegendaryOrGogdlCommand(
commandParts: string[],
env: Record<string, string> = {},
Expand Down Expand Up @@ -635,6 +645,5 @@ export {
setupWineEnvVars,
setupWrappers,
runWineCommand,
runLegendaryOrGogdlCommand,
getLegendaryOrGogdlCommand
runLegendaryOrGogdlCommand
}
63 changes: 27 additions & 36 deletions electron/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -298,9 +298,6 @@ 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)

const onOutput = (data: string) => {
this.onInstallOrUpdateOutput(
Expand All @@ -312,7 +309,8 @@ class LegendaryGame extends Game {

const res = await runLegendaryCommand(commandParts, {
logFile: logPath,
onOutput
onOutput,
purpose: `Updating ${this.appName}`
})

this.window.webContents.send('setGameStatus', {
Expand Down Expand Up @@ -393,8 +391,6 @@ class LegendaryGame extends Game {
...workers,
'-y'
]
const command = getLegendaryCommand(commandParts)
logInfo([`Installing ${this.appName} with:`, command], LogPrefix.Legendary)

const onOutput = (data: string) => {
this.onInstallOrUpdateOutput(
Expand All @@ -406,7 +402,8 @@ class LegendaryGame extends Game {

let res = await runLegendaryCommand(commandParts, {
logFile: logPath,
onOutput
onOutput,
purpose: `Installing ${this.appName}`
})

// try to run the install again with higher memory limit
Expand Down Expand Up @@ -434,19 +431,18 @@ class LegendaryGame extends Game {

public async uninstall(): Promise<ExecResult> {
const commandParts = ['uninstall', this.appName, '-y']
const command = getLegendaryCommand(commandParts)

logInfo([`Uninstalling ${this.appName}:`, command], LogPrefix.Legendary)

LegendaryLibrary.get().installState(this.appName, false)
const res = await runLegendaryCommand(commandParts)
const res = await runLegendaryCommand(commandParts, {
purpose: `Uninstalling ${this.appName}`
})

if (res.error) {
logError(
['Failed to uninstall', `${this.appName}:`, res.error],
LogPrefix.Legendary
)
} else {
LegendaryLibrary.get().installState(this.appName, false)
removeShortcuts(this.appName, 'legendary')
}
return res
Expand All @@ -463,11 +459,10 @@ 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)

const res = await runLegendaryCommand(commandParts, { logFile: logPath })
const res = await runLegendaryCommand(commandParts, {
logFile: logPath,
purpose: `Repairing ${this.appName}`
})

if (res.error) {
logError(
Expand All @@ -480,11 +475,9 @@ class LegendaryGame extends Game {

public async import(path: string): Promise<ExecResult> {
const commandParts = ['import', this.appName, path]
const command = getLegendaryCommand(commandParts)

logInfo([`Importing ${this.appName}:`, command], LogPrefix.Legendary)

const res = await runLegendaryCommand(commandParts)
const res = await runLegendaryCommand(commandParts, {
purpose: `Importing ${this.appName}`
})

if (res.error) {
logError(
Expand Down Expand Up @@ -517,14 +510,9 @@ class LegendaryGame extends Game {
this.appName,
'-y'
]
const command = getLegendaryCommand(commandParts)

logInfo(
[`Syncing saves for ${this.appName}:`, command],
LogPrefix.Legendary
)

const res = await runLegendaryCommand(commandParts)
const res = await runLegendaryCommand(commandParts, {
purpose: `Syncing saves for ${this.appName}`
})

if (res.error) {
logError(
Expand Down Expand Up @@ -659,12 +647,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, {
const {
error,
stderr,
stdout,
fullCommand: command
} = await runLegendaryCommand(commandParts, {
env: commandEnv,
wrappers: wrappers
wrappers: wrappers,
purpose: `Launching ${gameInfo.title}`
})

if (error) {
Expand Down
29 changes: 5 additions & 24 deletions electron/legendary/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -262,10 +258,9 @@ export class LegendaryLibrary {
}

const commandParts = ['list-installed', '--check-updates', '--tsv']
const command = getLegendaryCommand(commandParts)

logInfo(['Checking for game updates:', command], LogPrefix.Legendary)
const res = await runLegendaryCommand(commandParts)
const res = await runLegendaryCommand(commandParts, {
purpose: 'Checking for game updates'
})

if (res.error) {
logError(
Expand Down Expand Up @@ -586,6 +581,7 @@ export async function runLegendaryCommand(
env?: Record<string, string>
wrappers?: string[]
onOutput?: (output: string) => void
purpose?: string
}
): Promise<ExecResult> {
const { dir, bin } = getLegendaryBin()
Expand All @@ -595,18 +591,3 @@ export async function runLegendaryCommand(
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<string, string> = {},
wrappers: string[] = []
): string {
const legendaryPath = join(...Object.values(getLegendaryBin()))
return getLegendaryOrGogdlCommand(commandParts, env, wrappers, legendaryPath)
}
Loading