Skip to content

Commit

Permalink
Cache installed appNames on prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaggly committed Nov 5, 2024
1 parent 10f2a15 commit d62af30
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 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,25 @@ 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,21 +805,20 @@ 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: '' } }
}

const newPrefix = !existsSync(winePrefix)
if (newPrefix && !(await isUmuSupported(wineVersion.type))) {
if (!existsSync(winePrefix) && !(await isUmuSupported(wineVersion.type))) {
mkdirSync(winePrefix, { recursive: true })
}

Expand All @@ -827,7 +841,7 @@ export async function verifyWinePrefix(

return command
.then((result) => {
return { res: result, updated: newPrefix }
return { res: result }
})
.catch((error) => {
logError(['Unable to create Wineprefix: ', error], LogPrefix.Backend)
Expand Down

0 comments on commit d62af30

Please sign in to comment.