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] Check for game updates before launch #1335

Merged
merged 3 commits into from
May 18, 2022
Merged
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
8 changes: 4 additions & 4 deletions electron/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async function verifyWinePrefix(
): Promise<{ res: ExecResult; updated: boolean }> {
const { winePrefix, wineVersion } = await game.getSettings()

if (wineVersion.type === 'crossover') {
if (!(wineVersion.type === 'wine')) {
return { res: { stdout: '', stderr: '' }, updated: false }
}

Expand Down Expand Up @@ -363,7 +363,7 @@ async function runWineCommand(
// Can't wait if we don't have a Wineserver
if (wait) {
if (wineVersion.wineserver) {
additional_command = `${wineVersion.wineserver} --wait`
additional_command = `"${wineVersion.wineserver}" --wait`
} else {
logWarning(
'Unable to wait on Wine command, no Wineserver!',
Expand All @@ -373,7 +373,7 @@ async function runWineCommand(
}
}

let finalCommand = `${wineBin} ${command}`
let finalCommand = `"${wineBin}" ${command}`
if (additional_command) {
finalCommand += ` && ${additional_command}`
}
Expand All @@ -385,7 +385,7 @@ async function runWineCommand(
return response
})
.catch((error) => {
logError(['Error running Wine command:', error], LogPrefix.Legendary)
logError(['Error running Wine command:', error], LogPrefix.Backend)
return { stderr: error, stdout: '' }
})
}
Expand Down
6 changes: 4 additions & 2 deletions electron/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class LegendaryGame extends Game {
return res
}

public async launch(launchArguments = ''): Promise<LaunchResult> {
public async launch(launchArguments: string): Promise<LaunchResult> {
const gameSettings =
GameConfig.get(this.appName).config ||
(await GameConfig.get(this.appName).getSettings())
Expand Down Expand Up @@ -572,6 +572,7 @@ class LegendaryGame extends Game {
steamRuntime
)
}

// These options are required on both Windows and Mac
commandParts = [
'launch',
Expand Down Expand Up @@ -623,7 +624,8 @@ class LegendaryGame extends Game {
offlineFlag,
...wineFlag,
...winePrefixFlag,
launcherArgs
launcherArgs,
launchArguments
]
}
const command = getLegendaryCommand(commandParts, commandEnv, wrappers)
Expand Down
52 changes: 27 additions & 25 deletions src/helpers/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,43 +249,45 @@ type LaunchOptions = {
t: TFunction<'gamepage'>
launchArguments?: string
runner: Runner
hasUpdate: boolean
}

const launch = async ({
appName,
t,
launchArguments,
runner
}: LaunchOptions): Promise<void> =>
ipcRenderer
runner,
hasUpdate
}: LaunchOptions): Promise<void> => {
if (hasUpdate) {
const args = {
buttons: [t('gamepage:box.yes'), t('box.no')],
message: t('gamepage:box.update.message'),
title: t('gamepage:box.update.title')
}

const { response } = await ipcRenderer.invoke('openMessageBox', args)

if (response === 0) {
return updateGame(appName, runner)
}

return ipcRenderer.invoke('launch', {
appName,
runner,
launchArguments: '--skip-version-check'
})
}

return ipcRenderer
.invoke('launch', { appName, launchArguments, runner })
.then(async (err: string | string[]) => {
if (!err) {
return
}

if (
typeof err === 'string' &&
err.includes('ERROR: Game is out of date')
) {
const args = {
buttons: [t('gamepage:box.yes'), t('box.no')],
message: t('gamepage:box.update.message'),
title: t('gamepage:box.update.title')
}

const { response } = await ipcRenderer.invoke('openMessageBox', args)

if (response === 0) {
return updateGame(appName, runner)
}
await ipcRenderer.invoke('launch', {
appName,
runner,
launchArguments: '--skip-version-check'
})
}
return ipcRenderer.invoke('showErrorBox', ['Error', `${err}`])
})
}

const updateGame = async (appName: string, runner: Runner): Promise<void> =>
ipcRenderer.invoke('updateGame', appName, runner)
Expand Down
8 changes: 7 additions & 1 deletion src/screens/Game/GamePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,13 @@ export default function GamePage(): JSX.Element | null {
await syncSaves(savesPath, appName)
setIsSyncing(false)
}
await launch({ appName, t, launchArguments, runner: gameInfo.runner })
await launch({
appName,
t,
launchArguments,
runner: gameInfo.runner,
hasUpdate
})

if (autoSyncSaves) {
setIsSyncing(true)
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Library/components/GameCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ const GameCard = ({
return sendKill(appName, runner)
}
if (isInstalled) {
return launch({ appName, t, runner })
return launch({ appName, t, runner, hasUpdate })
}
return
}
Expand Down
3 changes: 2 additions & 1 deletion src/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ export class GlobalState extends PureComponent<Props> {
)[0]
if (!currentApp) {
// Add finding a runner for games
return launch({ appName, t, runner })
const hasUpdate = this.state.gameUpdates?.includes(appName)
return launch({ appName, t, runner, hasUpdate })
}
})

Expand Down