From ced943059df2f5177159d9de8a115b8cf0ce575a Mon Sep 17 00:00:00 2001 From: Snaggly Date: Tue, 24 Sep 2024 18:37:09 +0200 Subject: [PATCH 1/4] Cache installed wine version on prefix --- src/backend/launcher.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/backend/launcher.ts b/src/backend/launcher.ts index 4818a7a085..ac67dc8d60 100644 --- a/src/backend/launcher.ts +++ b/src/backend/launcher.ts @@ -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' @@ -826,13 +826,16 @@ 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 } + const currentWinePath = join(winePrefix, 'current_wine') + if ( + !existsSync(currentWinePath) || + readFileSync(currentWinePath, 'utf-8') != wineVersion.bin + ) { + writeFileSync(currentWinePath, wineVersion.bin, 'utf-8') + return { res: result, updated: true } + } else { + return { res: result, updated: false } + } }) .catch((error) => { logError(['Unable to create Wineprefix: ', error], LogPrefix.Backend) From 10f2a15b63f2324e7188a78438dc18b22c74fb29 Mon Sep 17 00:00:00 2001 From: Snaggly Date: Tue, 5 Nov 2024 00:29:07 +0100 Subject: [PATCH 2/4] Check for new prefix --- src/backend/launcher.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/backend/launcher.ts b/src/backend/launcher.ts index ac67dc8d60..a0380e11ae 100644 --- a/src/backend/launcher.ts +++ b/src/backend/launcher.ts @@ -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, writeFileSync } from 'fs' +import { readFileSync } from 'fs' import { LegendaryCommand } from './storeManagers/legendary/commands' import { commandToArgsArray } from './storeManagers/legendary/library' import { searchForExecutableOnPath } from './utils/os/path' @@ -803,7 +803,8 @@ export async function verifyWinePrefix( return { res: { stdout: '', stderr: '' }, updated: false } } - if (!existsSync(winePrefix) && !(await isUmuSupported(wineVersion.type))) { + const newPrefix = !existsSync(winePrefix) + if (newPrefix && !(await isUmuSupported(wineVersion.type))) { mkdirSync(winePrefix, { recursive: true }) } @@ -826,16 +827,7 @@ export async function verifyWinePrefix( return command .then((result) => { - const currentWinePath = join(winePrefix, 'current_wine') - if ( - !existsSync(currentWinePath) || - readFileSync(currentWinePath, 'utf-8') != wineVersion.bin - ) { - writeFileSync(currentWinePath, wineVersion.bin, 'utf-8') - return { res: result, updated: true } - } else { - return { res: result, updated: false } - } + return { res: result, updated: newPrefix } }) .catch((error) => { logError(['Unable to create Wineprefix: ', error], LogPrefix.Backend) From d62af30ef89b76b236b0a9bd8303d6684bb26639 Mon Sep 17 00:00:00 2001 From: Snaggly Date: Tue, 5 Nov 2024 22:28:35 +0100 Subject: [PATCH 3/4] Cache installed appNames on prefix --- src/backend/launcher.ts | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/backend/launcher.ts b/src/backend/launcher.ts index a0380e11ae..8f78077574 100644 --- a/src/backend/launcher.ts +++ b/src/backend/launcher.ts @@ -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' @@ -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 @@ -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 }) } @@ -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) From 74a0c7f8493aa90184300275646ad04499fc420d Mon Sep 17 00:00:00 2001 From: Snaggly Date: Tue, 5 Nov 2024 22:34:53 +0100 Subject: [PATCH 4/4] Prettier fix --- src/backend/launcher.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/launcher.ts b/src/backend/launcher.ts index 8f78077574..a594f2a9ae 100644 --- a/src/backend/launcher.ts +++ b/src/backend/launcher.ts @@ -357,7 +357,9 @@ async function prepareWineLaunch( writeFileSync(appsNamesPath, JSON.stringify([appName]), 'utf-8') hasUpdated = true } else { - const installedGames : string[] = JSON.parse(readFileSync(appsNamesPath, 'utf-8')) + const installedGames: string[] = JSON.parse( + readFileSync(appsNamesPath, 'utf-8') + ) if (!installedGames.includes(appName)) { installedGames.push(appName) writeFileSync(appsNamesPath, JSON.stringify(installedGames), 'utf-8')