Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: support env variables in known fixes #4195

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 48 additions & 32 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,54 +463,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 @@ -916,7 +931,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 @@ -1493,6 +1508,7 @@ export {
callRunner,
getRunnerCallWithoutCredentials,
getWinePath,
getKnownFixesEnvVariables,
runAfterLaunchScript,
runBeforeLaunchScript
}
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
Loading