Skip to content

Commit 8723d4c

Browse files
authored
[Linux] Search for Proton on all steam libraries (#1369)
* feat: search for proton on all steamlibraries * chore: pr comments
1 parent 2930644 commit 8723d4c

File tree

4 files changed

+1317
-1033
lines changed

4 files changed

+1317
-1033
lines changed

electron/config.ts

+6-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
userHome,
2121
isFlatpak,
2222
isMac,
23-
isWindows
23+
isWindows,
24+
getSteamLibraries
2425
} from './constants'
2526
import { execAsync } from './utils'
2627
import { logError, logInfo, LogPrefix } from './logger/logger'
@@ -241,15 +242,7 @@ abstract class GlobalConfig {
241242

242243
const protonPaths = [`${heroicToolsPath}/proton/`]
243244

244-
// Known places where Steam might be found.
245-
// Just add a new string here in case another path is found on another distro.
246-
const steamPaths = [
247-
join(userHome, '.steam'),
248-
join(userHome, '.var/app/com.valvesoftware.Steam/.local/share/Steam'),
249-
'/usr/share/steam'
250-
].filter((path) => existsSync(path))
251-
252-
steamPaths.forEach((path) => {
245+
getSteamLibraries().forEach((path) => {
253246
protonPaths.push(`${path}/steam/steamapps/common`)
254247
protonPaths.push(`${path}/steamapps/common`)
255248
protonPaths.push(`${path}/root/compatibilitytools.d`)
@@ -262,11 +255,9 @@ abstract class GlobalConfig {
262255
protonPaths.forEach((path) => {
263256
if (existsSync(path)) {
264257
readdirSync(path).forEach((version) => {
265-
const name = version.toLowerCase()
266-
const hasProtonName =
267-
name.startsWith('proton') || name.startsWith('ge-proton')
268-
if (hasProtonName && !name.includes('runtime')) {
269-
const protonBin = join(path, version, 'proton')
258+
const protonBin = join(path, version, 'proton')
259+
// check if bin exists to avoid false positives
260+
if (existsSync(protonBin)) {
270261
proton.add({
271262
bin: protonBin,
272263
name: `Proton - ${version}`,

electron/constants.ts

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { homedir, platform } from 'os'
22
import { join } from 'path'
33
import Store from 'electron-store'
4+
import { parse } from '@node-steam/vdf'
45

56
import { GameConfigVersion, GlobalConfigVersion } from './types'
6-
import { createNewLogFileAndClearOldOnces } from './logger/logger'
7+
import {
8+
createNewLogFileAndClearOldOnces,
9+
logDebug,
10+
LogPrefix
11+
} from './logger/logger'
712
import { env } from 'process'
813
import { app } from 'electron'
9-
import { existsSync } from 'graceful-fs'
14+
import { existsSync, readFileSync } from 'graceful-fs'
1015

1116
const configStore = new Store({
1217
cwd: 'store'
@@ -109,6 +114,26 @@ function getSteamCompatFolder() {
109114
return `${userHome}/.steam/steam`
110115
}
111116

117+
export function getSteamLibraries(): string[] {
118+
const vdfFile = join(steamCompatFolder, 'steamapps', 'libraryfolders.vdf')
119+
const libraries = ['/usr/share/steam']
120+
121+
if (existsSync(vdfFile)) {
122+
const json = parse(readFileSync(vdfFile, 'utf-8'))
123+
const folders = Object.values(json.libraryfolders) as Array<{
124+
path: string
125+
}>
126+
return [...libraries, ...folders.map((folder) => folder.path)].filter(
127+
(path) => existsSync(path)
128+
)
129+
}
130+
logDebug(
131+
'Unable to load Steam Libraries, libraryfolders.vdf not found',
132+
LogPrefix.Backend
133+
)
134+
return libraries
135+
}
136+
112137
const MAX_BUFFER = 25 * 1024 * 1024 // 25MB should be safe enough for big installations even on really slow internet
113138

114139
const execOptions = {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"@fortawesome/react-fontawesome": "^0.1.18",
137137
"@mui/icons-material": "^5.6.2",
138138
"@mui/material": "^5.6.2",
139+
"@node-steam/vdf": "^2.2.0",
139140
"axios": "^0.26.1",
140141
"check-disk-space": "^3.3.0",
141142
"classnames": "^2.3.1",

0 commit comments

Comments
 (0)