Skip to content

[Linux/MacOS] Split Enviroment Variable and Wrapper Option #1533

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

Merged
merged 27 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dd049d9
First poc
Nocccer Jun 23, 2022
4c9f933
Fixes and small design update
Nocccer Jun 23, 2022
fe17937
Made Table component more generic
Nocccer Jun 24, 2022
4a84136
lint fix
Nocccer Jun 24, 2022
cd0163c
Wrong key fixes
Nocccer Jun 24, 2022
75b1143
Refactor TableInput two 2 Column table
Nocccer Jun 30, 2022
feb5f28
translation update
Nocccer Jun 30, 2022
30a636b
Table component style, some text changes
arielj Jul 3, 2022
2f6c56f
Added mapper for depcrecated otherOptions
Nocccer Jul 6, 2022
57de213
Merge branch 'improve-extra-env' of https://github.com/Heroic-Games-L…
Nocccer Jul 6, 2022
507a47b
Merge branch 'beta' into improve-extra-env
Nocccer Jul 7, 2022
97142e9
Merge branch 'beta' into improve-extra-env
Nocccer Jul 9, 2022
c353f87
Trim input to get rit of unessecary spaces
Nocccer Jul 9, 2022
918e6a1
remove quotes because spawn cares about
Nocccer Jul 10, 2022
d36759b
Remove console.log
Nocccer Jul 10, 2022
fb30a49
Merge branch 'beta' into improve-extra-env
Nocccer Jul 10, 2022
d03d6a6
Merge branch 'beta' into improve-extra-env
Nocccer Jul 10, 2022
93f793d
Implement suggestion
Nocccer Jul 10, 2022
19ef0c0
Merge branch 'beta' into improve-extra-env
Nocccer Jul 10, 2022
7fc5a57
Make Envs editable
Nocccer Jul 11, 2022
e012c01
yarn lint
Nocccer Jul 11, 2022
10e92e2
Merge branch 'beta' into improve-extra-env
Nocccer Jul 11, 2022
dc992bc
Added new util function removeQuoteIfNessecary
Nocccer Jul 11, 2022
00ab791
Small update on old school theme for contrast and
arielj Jul 12, 2022
e19e72a
Merge branch 'beta' into improve-extra-env
Nocccer Jul 12, 2022
02d8377
Small fixes
Nocccer Jul 12, 2022
a11702e
Merge branch 'beta' into improve-extra-env
Nocccer Jul 13, 2022
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
27 changes: 27 additions & 0 deletions electron/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { quoteIfNecessary, removeQuoteIfNecessary } from '../utils'

describe('electron/utils.ts', () => {
test('quoteIfNeccessary', () => {
const testCases = new Map<string, string>([
['path/without/spaces', 'path/without/spaces'],
['path/with /spaces', '"path/with /spaces"'],
['"path/quoted/without/spaces"', '"path/quoted/without/spaces"'],
['"path/quoted/with /spaces"', '"path/quoted/with /spaces"']
])

testCases.forEach((expectString, inputString) => {
expect(quoteIfNecessary(inputString)).toStrictEqual(expectString)
})
})

test('removeQuotesIfNeccessary', () => {
const testCases = new Map<string, string>([
['path/without/quotes', 'path/without/quotes'],
['"path/with/quotes"', 'path/with/quotes']
])

testCases.forEach((expectString, inputString) => {
expect(removeQuoteIfNecessary(inputString)).toStrictEqual(expectString)
})
})
})
3 changes: 2 additions & 1 deletion electron/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ class GlobalConfigV0 extends GlobalConfig {
maxWorkers: 0,
minimizeOnLaunch: false,
nvidiaPrime: false,
otherOptions: '',
enviromentOptions: [],
wrapperOptions: [],
showUnrealMarket: false,
showFps: false,
useGameMode: false,
Expand Down
6 changes: 4 additions & 2 deletions electron/game_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ class GameConfigV0 extends GameConfig {
launcherArgs,
nvidiaPrime,
offlineMode,
otherOptions,
enviromentOptions,
wrapperOptions,
savesPath,
showFps,
showMangohud,
Expand All @@ -248,7 +249,8 @@ class GameConfigV0 extends GameConfig {
launcherArgs,
nvidiaPrime,
offlineMode,
otherOptions,
enviromentOptions: enviromentOptions,
wrapperOptions,
savesPath,
showFps,
showMangohud,
Expand Down
10 changes: 6 additions & 4 deletions electron/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
import { addShortcuts, removeShortcuts } from '../shortcuts'
import setup from './setup'
import { runGogdlCommand } from './library'
import shlex from 'shlex'

class GOGGame extends Game {
public appName: string
Expand Down Expand Up @@ -319,15 +320,16 @@ class GOGGame extends Game {
steamRuntime
)
}

commandParts = [
'launch',
gameInfo.install.install_path,
...exeOverrideFlag,
gameInfo.app_name,
'--platform',
`${gameInfo.install.platform}`,
launchArguments,
gameSettings.launcherArgs
...shlex.split(launchArguments ?? ''),
...shlex.split(gameSettings.launcherArgs ?? '')
]
} else {
const {
Expand Down Expand Up @@ -384,8 +386,8 @@ class GOGGame extends Game {
...winePrefixFlag,
'--os',
gameInfo.install.platform.toLowerCase(),
launchArguments,
launcherArgs
...shlex.split(launchArguments ?? ''),
...shlex.split(launcherArgs ?? '')
]
}

Expand Down
41 changes: 20 additions & 21 deletions electron/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
showErrorBoxModalAuto,
searchForExecutableOnPath,
quoteIfNecessary,
errorHandler
errorHandler,
removeQuoteIfNecessary
} from './utils'
import {
logDebug,
Expand All @@ -34,15 +35,20 @@ import { DXVK } from './tools'
import setup from './gog/setup'
import { GOGGame } from 'gog/games'
import { LegendaryGame } from 'legendary/games'
import { CallRunnerOptions, GameInfo, Runner } from './types'
import {
CallRunnerOptions,
GameInfo,
Runner,
EnviromentVariable,
WrapperVariable,
ExecResult,
GameSettings,
LaunchPreperationResult,
RpcClient,
WineInstallation
} from './types'
import { spawn } from 'child_process'
import shlex from 'shlex'

async function prepareLaunch(
game: LegendaryGame | GOGGame,
Expand Down Expand Up @@ -240,16 +246,10 @@ function setupEnvVars(gameSettings: GameSettings) {
if (gameSettings.audioFix) {
ret.PULSE_LATENCY_MSEC = '60'
}
if (gameSettings.otherOptions) {
gameSettings.otherOptions
.split(' ')
.filter((val) => val.indexOf('=') !== -1)
.forEach((envKeyAndVar) => {
const keyAndValueSplit = envKeyAndVar.split('=')
const key = keyAndValueSplit.shift()
const value = keyAndValueSplit.join('=')
ret[key] = value
})
if (gameSettings.enviromentOptions) {
gameSettings.enviromentOptions.forEach((envEntry: EnviromentVariable) => {
ret[envEntry.key] = removeQuoteIfNecessary(envEntry.value)
})
}

// setup LD_PRELOAD if not defined
Expand Down Expand Up @@ -305,7 +305,9 @@ function setupWineEnvVars(gameSettings: GameSettings, gameId = '0') {
ret.PROTON_LOG_DIR = flatPakHome

// Only set WINEDEBUG if PROTON_LOG is set since Proton will also log if just WINEDEBUG is set
if (gameSettings.otherOptions.includes('PROTON_LOG=')) {
if (
gameSettings.enviromentOptions.find((env) => env.key === 'PROTON_LOG')
) {
// Stop Proton from overriding WINEDEBUG; this prevents logs growing to a few GB for some games
ret.WINEDEBUG = 'timestamp'
}
Expand Down Expand Up @@ -338,14 +340,11 @@ function setupWrappers(
steamRuntime: string
): Array<string> {
const wrappers = Array<string>()
// Wrappers could be specified in the environment variable section as well
if (gameSettings.otherOptions) {
gameSettings.otherOptions
.split(' ')
.filter((val) => val.indexOf('=') === -1)
.forEach((val) => {
wrappers.push(val)
})
if (gameSettings.wrapperOptions) {
gameSettings.wrapperOptions.forEach((wrapperEntry: WrapperVariable) => {
wrappers.push(wrapperEntry.exe)
wrappers.push(...shlex.split(wrapperEntry.args ?? ''))
})
}
if (gameSettings.showMangohud) {
// Mangohud needs some arguments in addition to the command, so we have to split here
Expand Down
11 changes: 7 additions & 4 deletions electron/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { addShortcuts, removeShortcuts } from '../shortcuts'
import { basename, join } from 'path'
import { runLegendaryCommand } from './library'
import { gameInfoStore } from './electronStores'
import shlex from 'shlex'

class LegendaryGame extends Game {
public appName: string
Expand Down Expand Up @@ -584,6 +585,7 @@ class LegendaryGame extends Game {
...commandEnv,
...setupEnvVars(gameSettings)
}

wrappers = setupWrappers(
gameSettings,
mangoHudCommand,
Expand All @@ -599,8 +601,8 @@ class LegendaryGame extends Game {
...languageFlag,
...exeOverrideFlag,
offlineFlag,
launchArguments,
gameSettings.launcherArgs
...shlex.split(launchArguments ?? ''),
...shlex.split(gameSettings.launcherArgs ?? '')
]
} else {
// -> We're using Wine/Proton/CX on either Linux or Mac
Expand All @@ -622,6 +624,7 @@ class LegendaryGame extends Game {
...setupEnvVars(gameSettings),
...wineEnvVars
}

wrappers = setupWrappers(
gameSettings,
mangoHudCommand,
Expand Down Expand Up @@ -666,8 +669,8 @@ class LegendaryGame extends Game {
offlineFlag,
...wineFlag,
...winePrefixFlag,
launchArguments,
launcherArgs
...shlex.split(launchArguments ?? ''),
...shlex.split(launcherArgs ?? '')
]
}

Expand Down
51 changes: 48 additions & 3 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
GamepadInputEventKey,
GamepadInputEventWheel,
GamepadInputEventMouse,
Runner
Runner,
AppSettings,
GameSettings
} from './types'
import * as path from 'path'
import {
Expand Down Expand Up @@ -93,6 +95,7 @@ import { logError, logInfo, LogPrefix, logWarning } from './logger/logger'
import { gameInfoStore } from './legendary/electronStores'
import { getFonts } from 'font-list'
import { verifyWinePrefix } from './launcher'
import shlex from 'shlex'

const { showMessageBox, showOpenDialog } = dialog
const isWindows = platform() === 'win32'
Expand Down Expand Up @@ -721,11 +724,53 @@ ipcMain.handle('readConfig', async (event, config_class) => {
})

ipcMain.handle('requestSettings', async (event, appName) => {
// To the changes how we handle env and wrappers
// otherOptions is deprectaed and needs to be mapped
// to new approach.
// Can be removed if otherOptions is removed aswell
const mapOtherSettings = (config: AppSettings | GameSettings) => {
if (config.otherOptions) {
if (config.enviromentOptions.length <= 0) {
config.otherOptions
.split(' ')
.filter((val) => val.indexOf('=') !== -1)
.forEach((envKeyAndVar) => {
const keyAndValueSplit = envKeyAndVar.split('=')
const key = keyAndValueSplit.shift()
const value = keyAndValueSplit.join('=')
config.enviromentOptions.push({ key, value })
})
}

if (config.wrapperOptions.length <= 0) {
const args = [] as string[]
config.otherOptions
.split(' ')
.filter((val) => val.indexOf('=') === -1)
.forEach((val, index) => {
if (index === 0) {
config.wrapperOptions.push({ exe: val, args: '' })
} else {
args.push(val)
}
})

if (config.wrapperOptions.at(0)) {
config.wrapperOptions.at(0).args = shlex.join(args)
}
}

delete config.otherOptions
}
return config
}

if (appName === 'default') {
return GlobalConfig.get().config
return mapOtherSettings(GlobalConfig.get().config)
}
// We can't use .config since apparently its not loaded fast enough.
return GameConfig.get(appName).getSettings()
const config = await GameConfig.get(appName).getSettings()
return mapOtherSettings(config)
})

ipcMain.on('toggleDXVK', (event, [{ winePrefix, winePath }, action]) => {
Expand Down
18 changes: 16 additions & 2 deletions electron/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export interface AppSettings {
minimizeOnLaunch: boolean
nvidiaPrime: boolean
offlineMode: boolean
otherOptions: string
otherOptions: string //depricated
enviromentOptions: EnviromentVariable[]
wrapperOptions: WrapperVariable[]
savesPath: string
showFps: boolean
showMangohud: boolean
Expand Down Expand Up @@ -145,7 +147,9 @@ export interface GameSettings {
launcherArgs: string
nvidiaPrime: boolean
offlineMode: boolean
otherOptions: string
otherOptions: string //deprecated
enviromentOptions: EnviromentVariable[]
wrapperOptions: WrapperVariable[]
savesPath: string
showFps: boolean
showMangohud: boolean
Expand Down Expand Up @@ -373,6 +377,16 @@ export interface CallRunnerOptions {
onOutput?: (output: string, child: ChildProcess) => void
}

export interface EnviromentVariable {
key: string
value: string
}

export interface WrapperVariable {
exe: string
args: string
}

export type AntiCheatStatus =
| 'Planned'
| 'Denied'
Expand Down
5 changes: 5 additions & 0 deletions electron/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ function quoteIfNecessary(stringToQuote: string) {
return stringToQuote
}

function removeQuoteIfNecessary(stringToUnquote: string) {
return stringToUnquote.replace(/^"+/, '').replace(/"+$/, '')
}

function killPattern(pattern: string) {
logInfo(['Trying to kill', pattern], LogPrefix.Backend)
let ret
Expand Down Expand Up @@ -587,5 +591,6 @@ export {
getSteamRuntime,
constructAndUpdateRPC,
quoteIfNecessary,
removeQuoteIfNecessary,
killPattern
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
"react-i18next": "^11.16.7",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"shlex": "^2.1.2",
"simple-keyboard": "^3.4.24",
"source-map-support": "^0.5.21",
"systeminformation": "^5.11.14",
Expand Down
Loading