Skip to content

Commit

Permalink
Feature: support env variables in known fixes (#4195)
Browse files Browse the repository at this point in the history
  • Loading branch information
arielj authored Jan 6, 2025
1 parent 4b07b52 commit 74d64b6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 38 deletions.
82 changes: 49 additions & 33 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1135,7 +1150,7 @@ async function runWineCommand({
return { stdout: '', stderr: '' }
}

const env_vars = {
const env_vars: Record<string, string> = {
...process.env,
GAMEID: 'umu-0',
...setupEnvVars(settings),
Expand Down Expand Up @@ -1712,5 +1727,6 @@ export {
callRunner,
getRunnerCallWithoutCredentials,
getWinePath,
launchEventCallback
launchEventCallback,
getKnownFixesEnvVariables
}
4 changes: 3 additions & 1 deletion src/backend/storeManagers/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
} from '../../logger/logger'
import { GOGUser } from './user'
import {
getKnownFixesEnvVariables,
getRunnerCallWithoutCredentials,
getWinePath,
launchCleanup,
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions src/backend/storeManagers/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ import {
setupWrappers,
launchCleanup,
getRunnerCallWithoutCredentials,
runWineCommand as runWineCommandUtil
runWineCommand as runWineCommandUtil,
getKnownFixesEnvVariables
} from '../../launcher'
import {
addShortcuts as addShortcutsUtil,
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion src/backend/storeManagers/nile/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { isLinux, isWindows } from 'backend/constants'
import { GameConfig } from 'backend/game_config'
import {
getKnownFixesEnvVariables,
getRunnerCallWithoutCredentials,
launchCleanup,
prepareLaunch,
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion src/backend/storeManagers/storeManagerCommon/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { constants as FS_CONSTANTS } from 'graceful-fs'
import i18next from 'i18next'
import {
callRunner,
getKnownFixesEnvVariables,
launchCleanup,
prepareLaunch,
prepareWineLaunch,
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ export interface KnowFixesInfo {
notes?: Record<string, string>
winetricks?: string[]
runInPrefix?: string[]
envVariables?: Record<string, string>
}

export interface UploadedLogData {
Expand Down

0 comments on commit 74d64b6

Please sign in to comment.