diff --git a/src/backend/launcher.ts b/src/backend/launcher.ts index 1ff89dfb03..032d15ee71 100644 --- a/src/backend/launcher.ts +++ b/src/backend/launcher.ts @@ -682,54 +682,69 @@ async function prepareWineLaunch( return { success: true, envVars: envVars } } -async function installFixes(appName: string, runner: Runner) { +function readKnownFixes(appName: string, runner: Runner) { const fixPath = join(fixesPath, `${appName}-${storeMap[runner]}.json`) - if (!existsSync(fixPath)) return + if (!existsSync(fixPath)) return null try { const fixesContent = JSON.parse( readFileSync(fixPath).toString() ) as KnowFixesInfo - if (fixesContent.winetricks) { - sendGameStatusUpdate({ - appName, - runner: runner, - status: 'winetricks' - }) + return fixesContent + } catch (error) { + // if we fail to download the json file, it can be malformed causing + // JSON.parse to throw an exception + logWarning(`Known fixes could not be applied, ignoring.\n${error}`) + return null + } +} - for (const winetricksPackage of fixesContent.winetricks) { - await Winetricks.install(runner, appName, winetricksPackage) - } +async function installFixes(appName: string, runner: Runner) { + const knownFixes = readKnownFixes(appName, runner) + + if (!knownFixes) return + + if (knownFixes.winetricks) { + sendGameStatusUpdate({ + appName, + runner: runner, + status: 'winetricks' + }) + + for (const winetricksPackage of knownFixes.winetricks) { + await Winetricks.install(runner, appName, winetricksPackage) } + } - if (fixesContent.runInPrefix) { - const gameInfo = gameManagerMap[runner].getGameInfo(appName) + if (knownFixes.runInPrefix) { + const gameInfo = gameManagerMap[runner].getGameInfo(appName) - sendGameStatusUpdate({ - appName, - runner: runner, - status: 'redist', - context: 'FIXES' - }) + sendGameStatusUpdate({ + appName, + runner: runner, + status: 'redist', + context: 'FIXES' + }) - for (const filePath of fixesContent.runInPrefix) { - const fullPath = join(gameInfo.install.install_path!, filePath) - await runWineCommandOnGame(appName, { - commandParts: [fullPath], - wait: true, - protonVerb: 'run' - }) - } + for (const filePath of knownFixes.runInPrefix) { + const fullPath = join(gameInfo.install.install_path!, filePath) + await runWineCommandOnGame(appName, { + commandParts: [fullPath], + wait: true, + protonVerb: 'run' + }) } - } catch (error) { - // if we fail to download the json file, it can be malformed causing - // JSON.parse to throw an exception - logWarning(`Known fixes could not be applied, ignoring.\n${error}`) } } +function getKnownFixesEnvVariables(appName: string, runner: Runner) { + const knownFixes = readKnownFixes(appName, runner) + + return knownFixes?.envVariables || {} +} + /** * Maps general settings to environment variables * @param gameSettings The GameSettings to get the environment variables for @@ -1135,7 +1150,7 @@ async function runWineCommand({ return { stdout: '', stderr: '' } } - const env_vars = { + const env_vars: Record = { ...process.env, GAMEID: 'umu-0', ...setupEnvVars(settings), @@ -1712,5 +1727,6 @@ export { callRunner, getRunnerCallWithoutCredentials, getWinePath, - launchEventCallback + launchEventCallback, + getKnownFixesEnvVariables } diff --git a/src/backend/storeManagers/gog/games.ts b/src/backend/storeManagers/gog/games.ts index 1b7cb698ab..f54906cc26 100644 --- a/src/backend/storeManagers/gog/games.ts +++ b/src/backend/storeManagers/gog/games.ts @@ -68,6 +68,7 @@ import { } from '../../logger/logger' import { GOGUser } from './user' import { + getKnownFixesEnvVariables, getRunnerCallWithoutCredentials, getWinePath, launchCleanup, @@ -536,7 +537,8 @@ export async function launch( ...setupWrapperEnvVars({ appName, appRunner: 'gog' }), ...(isWindows ? {} - : setupEnvVars(gameSettings, gameInfo.install.install_path)) + : setupEnvVars(gameSettings, gameInfo.install.install_path)), + ...getKnownFixesEnvVariables(appName, 'gog') } const wrappers = setupWrappers( diff --git a/src/backend/storeManagers/legendary/games.ts b/src/backend/storeManagers/legendary/games.ts index e879d197ba..956fe35fe3 100644 --- a/src/backend/storeManagers/legendary/games.ts +++ b/src/backend/storeManagers/legendary/games.ts @@ -59,7 +59,8 @@ import { setupWrappers, launchCleanup, getRunnerCallWithoutCredentials, - runWineCommand as runWineCommandUtil + runWineCommand as runWineCommandUtil, + getKnownFixesEnvVariables } from '../../launcher' import { addShortcuts as addShortcutsUtil, @@ -871,7 +872,8 @@ export async function launch( ...setupWrapperEnvVars({ appName, appRunner: 'legendary' }), ...(isWindows ? {} - : setupEnvVars(gameSettings, gameInfo.install.install_path)) + : setupEnvVars(gameSettings, gameInfo.install.install_path)), + ...getKnownFixesEnvVariables(appName, 'legendary') } const wrappers = setupWrappers( diff --git a/src/backend/storeManagers/nile/games.ts b/src/backend/storeManagers/nile/games.ts index d21fd28b5e..f40b1292e7 100644 --- a/src/backend/storeManagers/nile/games.ts +++ b/src/backend/storeManagers/nile/games.ts @@ -31,6 +31,7 @@ import { import { isLinux, isWindows } from 'backend/constants' import { GameConfig } from 'backend/game_config' import { + getKnownFixesEnvVariables, getRunnerCallWithoutCredentials, launchCleanup, prepareLaunch, @@ -344,7 +345,8 @@ export async function launch( ...setupWrapperEnvVars({ appName, appRunner: 'nile' }), ...(isWindows ? {} - : setupEnvVars(gameSettings, gameInfo.install.install_path)) + : setupEnvVars(gameSettings, gameInfo.install.install_path)), + ...getKnownFixesEnvVariables(appName, 'nile') } const wrappers = setupWrappers( diff --git a/src/backend/storeManagers/storeManagerCommon/games.ts b/src/backend/storeManagers/storeManagerCommon/games.ts index 43c84846e3..5a62cf0f93 100644 --- a/src/backend/storeManagers/storeManagerCommon/games.ts +++ b/src/backend/storeManagers/storeManagerCommon/games.ts @@ -15,6 +15,7 @@ import { constants as FS_CONSTANTS } from 'graceful-fs' import i18next from 'i18next' import { callRunner, + getKnownFixesEnvVariables, launchCleanup, prepareLaunch, prepareWineLaunch, @@ -219,7 +220,8 @@ export async function launchGame( const env = { ...process.env, ...setupWrapperEnvVars({ appName, appRunner: runner }), - ...setupEnvVars(gameSettings, gameInfo.install.install_path) + ...setupEnvVars(gameSettings, gameInfo.install.install_path), + ...getKnownFixesEnvVariables(appName, runner) } await callRunner( diff --git a/src/common/types.ts b/src/common/types.ts index 36bcb0f216..df6b97b192 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -766,6 +766,7 @@ export interface KnowFixesInfo { notes?: Record winetricks?: string[] runInPrefix?: string[] + envVariables?: Record } export interface UploadedLogData {