Skip to content

Commit

Permalink
[TECH] Set Legendary's config path to a Heroic-specific location (#2803)
Browse files Browse the repository at this point in the history
* Set Legendary's config path to a Heroic-specific location

Legendary derives its configuration path using `XDG_CONFIG_HOME`. By
setting this environment variable to a Heroic-specific location, we can
rule out the user influencing Heroic's functionality by changing
Legendary's config file.

Legendary's configuration now lives in
`<heroic config>/legendaryConfig`, and Heroic will migrate an already
existent config directory to this new path if it's found.

* Remove "launch --json" call

The purpose of this was making sure the user didn't modify `config.ini`
in a problematic way. Now that we alone control the config file, we
don't have to worry about this anymore.

As a side effect, this also resolves issues for MacOS users without a
CrossOver installation (Legendary would try to auto-detect CX & crash if
nothing is found)
  • Loading branch information
CommandMC committed Jun 30, 2023
1 parent f7c35d3 commit c0bab68
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
4 changes: 1 addition & 3 deletions src/backend/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ const currentGlobalConfigVersion: GlobalConfigVersion = 'v0'
const flatPakHome = env.XDG_DATA_HOME?.replace('/data', '') || homedir()
const userHome = homedir()
const configFolder = app.getPath('appData')
const legendaryConfigPath = isLinux
? join(configFolder, 'legendary')
: join(userHome, '.config', 'legendary')
const appFolder = join(configFolder, 'heroic')
const legendaryConfigPath = join(appFolder, 'legendaryConfig', 'legendary')
const configPath = join(appFolder, 'config.json')
const gamesConfigPath = join(appFolder, 'GamesConfig')
const toolsPath = join(appFolder, 'tools')
Expand Down
25 changes: 0 additions & 25 deletions src/backend/storeManagers/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,31 +863,6 @@ export async function launch(
wineFlag = [...getWineFlags(wineBin, gameSettings, wineType)]
}

// Log any launch information configured in Legendary's config.ini
const { stdout } = await runLegendaryCommand(
['launch', appName, '--json', '--offline'],
createAbortController(appName)
)

appendFileSync(
logFileLocation(appName),
"Legendary's config from config.ini (before App's settings):\n"
)

try {
const json = JSON.parse(stdout)
// remove egl auth info
delete json['egl_parameters']

appendFileSync(
logFileLocation(appName),
JSON.stringify(json, null, 2) + '\n\n'
)
} catch (error) {
// in case legendary's command fails and the output is not json
appendFileSync(logFileLocation(appName), error + '\n' + stdout + '\n\n')
}

const commandParts = [
'launch',
appName,
Expand Down
27 changes: 26 additions & 1 deletion src/backend/storeManagers/legendary/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import {
fallBackImage,
legendaryConfigPath,
legendaryLogFile,
legendaryMetadata
legendaryMetadata,
isLinux,
userHome
} from '../../constants'
import {
logDebug,
Expand All @@ -50,12 +52,24 @@ import { dirname, join } from 'path'
import { isOnline } from 'backend/online_monitor'
import { update } from './games'
import axios from 'axios'
import { app } from 'electron'
import { copySync } from 'fs-extra'

const allGames: Set<string> = new Set()
let installedGames: Map<string, InstalledJsonMetadata> = new Map()
const library: Map<string, GameInfo> = new Map()

export async function initLegendaryLibraryManager() {
// Migrate user data from global Legendary config if necessary
const globalLegendaryConfig = isLinux
? join(app.getPath('appData'), 'legendary')
: join(userHome, '.config', 'legendary')
if (!existsSync(legendaryConfigPath) && existsSync(globalLegendaryConfig)) {
copySync(globalLegendaryConfig, legendaryConfigPath, {
recursive: true
})
}

loadGamesInAccount()
refreshInstalled()
}
Expand Down Expand Up @@ -632,6 +646,17 @@ export async function runRunnerCommand(
options?: CallRunnerOptions
): Promise<ExecResult> {
const { dir, bin } = getLegendaryBin()

// Set XDG_CONFIG_HOME to a custom, Heroic-specific location so user-made
// changes to Legendary's main config file don't affect us
if (!options) {
options = {}
}
if (!options.env) {
options.env = {}
}
options.env.XDG_CONFIG_HOME = dirname(legendaryConfigPath)

return callRunner(
commandParts,
{ name: 'legendary', logPrefix: LogPrefix.Legendary, bin, dir },
Expand Down

0 comments on commit c0bab68

Please sign in to comment.