-
-
Notifications
You must be signed in to change notification settings - Fork 423
/
constants.ts
225 lines (209 loc) · 6.75 KB
/
constants.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import { homedir, platform } from 'os'
import { join, normalize } from 'path'
import Store from 'electron-store'
import { parse } from '@node-steam/vdf'
import { GameConfigVersion, GlobalConfigVersion } from './types'
import {
createNewLogFileAndClearOldOnces,
logDebug,
LogPrefix
} from './logger/logger'
import { env } from 'process'
import { app } from 'electron'
import { existsSync, readFileSync } from 'graceful-fs'
import { GlobalConfig } from './config'
const configStore = new Store({
cwd: 'store'
})
const tsStore = new Store({
cwd: 'store',
name: 'timestamp'
})
const fontsStore = new Store({
cwd: 'store',
name: 'fonts'
})
const isMac = platform() === 'darwin'
const isWindows = platform() === 'win32'
const isLinux = platform() === 'linux'
const isSteamDeckGameMode = process.env.XDG_CURRENT_DESKTOP === 'gamescope'
const isCLIFullscreen = process.argv.includes('--fullscreen')
const isCLINoGui = process.argv.includes('--no-gui')
const isFlatpak = Boolean(env.FLATPAK_ID)
const currentGameConfigVersion: GameConfigVersion = 'v0'
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 heroicFolder = join(configFolder, 'heroic')
const heroicConfigPath = join(heroicFolder, 'config.json')
const heroicGamesConfigPath = join(heroicFolder, 'GamesConfig')
const heroicToolsPath = join(heroicFolder, 'tools')
const heroicIconFolder = join(heroicFolder, 'icons')
const runtimePath = join(heroicToolsPath, 'runtimes')
const userInfo = join(legendaryConfigPath, 'user.json')
const heroicInstallPath = join(homedir(), 'Games', 'Heroic')
const heroicDefaultWinePrefix = join(homedir(), 'Games', 'Heroic', 'Prefixes')
const heroicAnticheatDataPath = join(heroicFolder, 'areweanticheatyet.json')
const { currentLogFile: currentLogFile, lastLogFile: lastLogFile } =
createNewLogFileAndClearOldOnces()
const icon = fixAsarPath(join(__dirname, 'icon.png'))
const iconDark = fixAsarPath(join(__dirname, 'icon-dark.png'))
const iconLight = fixAsarPath(join(__dirname, 'icon-light.png'))
const installed = join(legendaryConfigPath, 'installed.json')
const libraryPath = join(legendaryConfigPath, 'metadata')
const fallBackImage = 'fallback'
const epicLoginUrl =
'https://www.epicgames.com/id/login?redirectUrl=https%3A%2F%2Fwww.epicgames.com%2Fid%2Fapi%2Fredirect'
const gogLoginUrl =
'https://auth.gog.com/auth?client_id=46899977096215655&redirect_uri=https%3A%2F%2Fembed.gog.com%2Fon_login_success%3Forigin%3Dclient&response_type=code&layout=galaxy'
const sidInfoUrl =
'https://github.com/flavioislima/HeroicGamesLauncher/issues/42'
const heroicGithubURL =
'https://github.com/flavioislima/HeroicGamesLauncher/releases/latest'
const supportURL =
'https://github.com/flavioislima/HeroicGamesLauncher/blob/main/Support.md'
const discordLink = 'https://discord.gg/rHJ2uqdquK'
const wikiLink =
'https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/wiki'
const weblateUrl = 'https://hosted.weblate.org/projects/heroic-games-launcher'
const kofiPage = 'https://ko-fi.com/heroicgames'
const patreonPage = 'https://www.patreon.com/heroicgameslauncher'
/**
* Get shell for different os
* @returns Windows: powershell
* @returns unix: $SHELL or /usr/bin/bash
*/
function getShell() {
// Dont change this logic since Heroic will break when using SH or FISH
switch (process.platform) {
case 'win32':
return 'powershell.exe'
case 'linux':
return '/bin/bash'
case 'darwin':
return '/bin/zsh'
default:
return '/bin/bash'
}
}
/**
* Fix path for packed files with asar, else will do nothing.
* @param origin original path
* @returns fixed path
*/
function fixAsarPath(origin: string): string {
if (!origin.includes('app.asar.unpacked')) {
return origin.replace('app.asar', 'app.asar.unpacked')
}
return origin
}
export function getSteamCompatFolder() {
// Paths are from https://savelocation.net/steam-game-folder
if (isWindows) {
const defaultWinPath = join(process.env['PROGRAMFILES(X86)'], 'Steam')
return defaultWinPath
// Reading of steam registry key should work with registry-js
// in electron enviroment but there is a npm node-gyp problem so far:
// https://github.com/desktop/registry-js/issues/224
//
// try {
// const entry = enumerateValues(
// HKEY.HKEY_LOCAL_MACHINE,
// 'SOFTWARE\\WOW6432Node\\Valve\\Steam'
// ).filter((value) => value.name === 'InstallPath')[0]
// return (entry && String(entry.data)) || defaultWinPath
// } catch {
// return defaultWinPath
// }
} else if (isMac) {
return normalize(join(userHome, 'Library/Application Support/Steam'))
} else {
const flatpakSteamPath = normalize(
join(userHome, '.var/app/com.valvesoftware.Steam/.steam/steam')
)
if (existsSync(flatpakSteamPath)) {
return flatpakSteamPath
}
return normalize(join(userHome, '.steam/steam'))
}
}
export async function getSteamLibraries(): Promise<string[]> {
const { defaultSteamPath } = await GlobalConfig.get().getSettings()
const path = defaultSteamPath.replaceAll("'", '')
const vdfFile = join(path, 'steamapps', 'libraryfolders.vdf')
const libraries = ['/usr/share/steam']
if (existsSync(vdfFile)) {
const json = parse(readFileSync(vdfFile, 'utf-8'))
if (!json.libraryfolders) {
return libraries
}
const folders = Object.values(json.libraryfolders) as Array<{
path: string
}>
return [...libraries, ...folders.map((folder) => folder.path)].filter(
(path) => existsSync(path)
)
}
logDebug(
'Unable to load Steam Libraries, libraryfolders.vdf not found',
LogPrefix.Backend
)
return libraries
}
const MAX_BUFFER = 25 * 1024 * 1024 // 25MB should be safe enough for big installations even on really slow internet
const execOptions = {
maxBuffer: MAX_BUFFER,
shell: getShell()
}
export {
currentGameConfigVersion,
currentGlobalConfigVersion,
currentLogFile,
lastLogFile,
discordLink,
execOptions,
fixAsarPath,
getShell,
configStore,
heroicConfigPath,
heroicFolder,
heroicGamesConfigPath,
heroicGithubURL,
heroicIconFolder,
heroicInstallPath,
heroicToolsPath,
heroicDefaultWinePrefix,
heroicAnticheatDataPath,
userHome,
flatPakHome,
kofiPage,
icon,
iconDark,
iconLight,
installed,
isFlatpak,
isMac,
isWindows,
isLinux,
legendaryConfigPath,
libraryPath,
epicLoginUrl,
gogLoginUrl,
patreonPage,
sidInfoUrl,
supportURL,
fallBackImage,
userInfo,
weblateUrl,
wikiLink,
tsStore,
fontsStore,
isSteamDeckGameMode,
runtimePath,
isCLIFullscreen,
isCLINoGui
}