Skip to content

Commit

Permalink
[Fix] Cache installed wine version on prefix (#4027)
Browse files Browse the repository at this point in the history
* Cache installed wine version on prefix

* Check for new prefix

* Cache installed appNames on prefix

* Prettier fix
  • Loading branch information
Snaggly authored Nov 17, 2024
1 parent df71f6a commit 5629445
Showing 1 changed file with 24 additions and 13 deletions.
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 @@ -789,17 +806,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 @@ -825,13 +842,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

0 comments on commit 5629445

Please sign in to comment.