Skip to content

[Fix] Cache installed wine version on prefix #4027

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

Merged
merged 4 commits into from
Nov 17, 2024
Merged
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
37 changes: 24 additions & 13 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import { showDialogBoxModalAuto } from './dialog/dialog'
import { legendarySetup } from './storeManagers/legendary/setup'
import { gameManagerMap } from 'backend/storeManagers'
import * as VDF from '@node-steam/vdf'
import { readFileSync } from 'fs'
import { readFileSync, writeFileSync } from 'fs'
import { LegendaryCommand } from './storeManagers/legendary/commands'
import { commandToArgsArray } from './storeManagers/legendary/library'
import { searchForExecutableOnPath } from './utils/os/path'
Expand Down Expand Up @@ -347,10 +347,27 @@ async function prepareWineLaunch(
}
}

const { updated: winePrefixUpdated } = await verifyWinePrefix(gameSettings)
await verifyWinePrefix(gameSettings)
const experimentalFeatures =
GlobalConfig.get().getSettings().experimentalFeatures
if (winePrefixUpdated) {

let hasUpdated = false
const appsNamesPath = join(gameSettings.winePrefix, 'installed_games')
if (!existsSync(appsNamesPath)) {
writeFileSync(appsNamesPath, JSON.stringify([appName]), 'utf-8')
hasUpdated = true
} else {
const installedGames: string[] = JSON.parse(
readFileSync(appsNamesPath, 'utf-8')
)
if (!installedGames.includes(appName)) {
installedGames.push(appName)
writeFileSync(appsNamesPath, JSON.stringify(installedGames), 'utf-8')
hasUpdated = true
}
}

if (hasUpdated) {
logInfo(
['Created/Updated Wineprefix at', gameSettings.winePrefix],
LogPrefix.Backend
Expand Down Expand Up @@ -790,17 +807,17 @@ export async function validWine(
*/
export async function verifyWinePrefix(
settings: GameSettings
): Promise<{ res: ExecResult; updated: boolean }> {
): Promise<{ res: ExecResult }> {
const { winePrefix = defaultWinePrefix, wineVersion } = settings

const isValidWine = await validWine(wineVersion)

if (!isValidWine) {
return { res: { stdout: '', stderr: '' }, updated: false }
return { res: { stdout: '', stderr: '' } }
}

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

if (!existsSync(winePrefix) && !(await isUmuSupported(wineVersion.type))) {
Expand All @@ -826,13 +843,7 @@ export async function verifyWinePrefix(

return command
.then((result) => {
// This is kinda hacky
const wasUpdated = result.stderr.includes(
wineVersion.type === 'proton'
? 'Proton: Upgrading prefix from'
: 'has been updated'
)
return { res: result, updated: wasUpdated }
return { res: result }
})
.catch((error) => {
logError(['Unable to create Wineprefix: ', error], LogPrefix.Backend)
Expand Down
Loading