Skip to content

Commit 5629445

Browse files
authored
[Fix] Cache installed wine version on prefix (#4027)
* Cache installed wine version on prefix * Check for new prefix * Cache installed appNames on prefix * Prettier fix
1 parent df71f6a commit 5629445

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/backend/launcher.ts

+24-13
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import { showDialogBoxModalAuto } from './dialog/dialog'
6969
import { legendarySetup } from './storeManagers/legendary/setup'
7070
import { gameManagerMap } from 'backend/storeManagers'
7171
import * as VDF from '@node-steam/vdf'
72-
import { readFileSync } from 'fs'
72+
import { readFileSync, writeFileSync } from 'fs'
7373
import { LegendaryCommand } from './storeManagers/legendary/commands'
7474
import { commandToArgsArray } from './storeManagers/legendary/library'
7575
import { searchForExecutableOnPath } from './utils/os/path'
@@ -347,10 +347,27 @@ async function prepareWineLaunch(
347347
}
348348
}
349349

350-
const { updated: winePrefixUpdated } = await verifyWinePrefix(gameSettings)
350+
await verifyWinePrefix(gameSettings)
351351
const experimentalFeatures =
352352
GlobalConfig.get().getSettings().experimentalFeatures
353-
if (winePrefixUpdated) {
353+
354+
let hasUpdated = false
355+
const appsNamesPath = join(gameSettings.winePrefix, 'installed_games')
356+
if (!existsSync(appsNamesPath)) {
357+
writeFileSync(appsNamesPath, JSON.stringify([appName]), 'utf-8')
358+
hasUpdated = true
359+
} else {
360+
const installedGames: string[] = JSON.parse(
361+
readFileSync(appsNamesPath, 'utf-8')
362+
)
363+
if (!installedGames.includes(appName)) {
364+
installedGames.push(appName)
365+
writeFileSync(appsNamesPath, JSON.stringify(installedGames), 'utf-8')
366+
hasUpdated = true
367+
}
368+
}
369+
370+
if (hasUpdated) {
354371
logInfo(
355372
['Created/Updated Wineprefix at', gameSettings.winePrefix],
356373
LogPrefix.Backend
@@ -789,17 +806,17 @@ export async function validWine(
789806
*/
790807
export async function verifyWinePrefix(
791808
settings: GameSettings
792-
): Promise<{ res: ExecResult; updated: boolean }> {
809+
): Promise<{ res: ExecResult }> {
793810
const { winePrefix = defaultWinePrefix, wineVersion } = settings
794811

795812
const isValidWine = await validWine(wineVersion)
796813

797814
if (!isValidWine) {
798-
return { res: { stdout: '', stderr: '' }, updated: false }
815+
return { res: { stdout: '', stderr: '' } }
799816
}
800817

801818
if (wineVersion.type === 'crossover') {
802-
return { res: { stdout: '', stderr: '' }, updated: false }
819+
return { res: { stdout: '', stderr: '' } }
803820
}
804821

805822
if (!existsSync(winePrefix) && !(await isUmuSupported(wineVersion.type))) {
@@ -825,13 +842,7 @@ export async function verifyWinePrefix(
825842

826843
return command
827844
.then((result) => {
828-
// This is kinda hacky
829-
const wasUpdated = result.stderr.includes(
830-
wineVersion.type === 'proton'
831-
? 'Proton: Upgrading prefix from'
832-
: 'has been updated'
833-
)
834-
return { res: result, updated: wasUpdated }
845+
return { res: result }
835846
})
836847
.catch((error) => {
837848
logError(['Unable to create Wineprefix: ', error], LogPrefix.Backend)

0 commit comments

Comments
 (0)