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

[Tech] Refactor Game Managers #2578

Merged
merged 26 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b9246ec
[Tech] Refactor game managers (#183)
BrettCleary Mar 17, 2023
42bc2a4
fix merge errors
BrettCleary Mar 28, 2023
4077228
fix build errors
BrettCleary Mar 28, 2023
3761817
rm unused vars
BrettCleary Mar 28, 2023
7cc5d04
prettier
BrettCleary Mar 28, 2023
d1ac2e7
Merge branch 'main' into tech/refactor_game_managers
BrettCleary Mar 28, 2023
6e97bfc
fix merge errors
BrettCleary Mar 28, 2023
6535396
change back to import folder
BrettCleary Mar 28, 2023
c004dd4
prettier fix
BrettCleary Mar 28, 2023
cb07624
revert importPath translation
BrettCleary Mar 28, 2023
f1d21d0
fix isNative check in main
BrettCleary Mar 28, 2023
12866ff
gog fixes
BrettCleary Mar 28, 2023
4fa0bfe
fix download manager successive installs
BrettCleary Mar 28, 2023
6261b35
fix gog import
BrettCleary Mar 28, 2023
4e616e7
fix deadcode
BrettCleary Mar 28, 2023
c97ed19
check anticheat on mac
BrettCleary Mar 28, 2023
242f960
rm main import
BrettCleary Mar 30, 2023
b151af0
add skip test on windows
BrettCleary Mar 30, 2023
063087b
Merge branch 'main' into tech/refactor_game_managers
BrettCleary Mar 30, 2023
40e050c
update games launch with merge changes
BrettCleary Mar 30, 2023
eaee68f
fix dead code
BrettCleary Mar 30, 2023
7cdc00b
move removeFolder to utils
BrettCleary Mar 30, 2023
7bcfb2d
import removeFolder fxn
BrettCleary Mar 30, 2023
4e0ae86
Merge branch 'main' of github.com:Heroic-Games-Launcher/HeroicGamesLa…
flavioislima Apr 6, 2023
6704007
chore: make variables names more generic
flavioislima Apr 6, 2023
3c436eb
tests: updated tests
flavioislima Apr 6, 2023
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
2 changes: 1 addition & 1 deletion .ts-prunerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ignore": "src/common/typedefs"
}
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"editor.bracketPairColorization.enabled": true,
"prettier.configPath": "${fileDirname}/../.prettierrc.json",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "esbenp.prettier-vscode",
"files.insertFinalNewline": true
}
2 changes: 2 additions & 0 deletions public/locales/en/gamepage.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@
},
"status": {
"clickToUpdate": "Click to Update",
"downloading": "Downloading",
"extracting": "Extracting",
"gameNotAvailable": "Game not available",
"hasUpdates": "New Version Available!",
"installed": "Installed",
Expand Down
2 changes: 2 additions & 0 deletions src/backend/__tests__/skip.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const describeSkipOnWindows =
process.platform === 'win32' ? describe.skip : describe

export const testSkipOnWindows = process.platform === 'win32' ? test.skip : test
11 changes: 7 additions & 4 deletions src/backend/anticheat/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { heroicAnticheatDataPath, isWindows } from '../constants'
import { anticheatDataPath, isWindows } from '../constants'
import * as axios from 'axios'
import { logInfo, LogPrefix, logWarning } from '../logger/logger'
import { readFileSync, writeFileSync } from 'graceful-fs'
Expand All @@ -13,7 +13,7 @@ async function downloadAntiCheatData() {
const { data } = await axios.default.get(
'https://raw.githubusercontent.com/Starz0r/AreWeAntiCheatYet/HEAD/games.json'
)
writeFileSync(heroicAnticheatDataPath, JSON.stringify(data, null, 2))
writeFileSync(anticheatDataPath, JSON.stringify(data, null, 2))
logInfo(`AreWeAntiCheatYet data downloaded`, LogPrefix.Backend)
} catch (error) {
logWarning(
Expand All @@ -24,10 +24,13 @@ async function downloadAntiCheatData() {
})
}

function gameAnticheatInfo(appNamespace: string): AntiCheatInfo | null {
function gameAnticheatInfo(
appNamespace: string | undefined
): AntiCheatInfo | null {
if (appNamespace === undefined) return null
if (isWindows) return null

const data = readFileSync(heroicAnticheatDataPath)
const data = readFileSync(anticheatDataPath)
const jsonData = JSON.parse(data.toString())
return jsonData.find((info: AntiCheatInfo) => {
const namespace = info.storeIds.epic?.namespace
Expand Down
16 changes: 8 additions & 8 deletions src/backend/api/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
Runner,
InstallParams,
LaunchParams,
SideloadGame,
ImportGameArgs,
GameStatus
GameStatus,
GameInfo
} from 'common/types'

export const removeFolder = (args: [path: string, folderName: string]) =>
Expand All @@ -21,7 +21,11 @@ export const uninstall = async (
shouldRemoveSetting: boolean
) => {
if (runner === 'sideload') {
return ipcRenderer.invoke('removeApp', { appName, shouldRemovePrefix })
return ipcRenderer.invoke('removeApp', {
appName,
shouldRemovePrefix,
runner
})
} else {
return ipcRenderer.invoke(
'uninstall',
Expand Down Expand Up @@ -87,8 +91,4 @@ export const handleRecentGamesChanged = (callback: any) => {
}
}

export const addNewApp = (args: SideloadGame) =>
ipcRenderer.send('addNewApp', args)

export const launchApp = async (appName: string): Promise<boolean> =>
ipcRenderer.invoke('launchApp', appName)
export const addNewApp = (args: GameInfo) => ipcRenderer.send('addNewApp', args)
6 changes: 2 additions & 4 deletions src/backend/api/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ export const authGOG = async (token: string) =>
export const logoutGOG = () => ipcRenderer.send('logoutGOG')
export const checkGameUpdates = async () =>
ipcRenderer.invoke('checkGameUpdates')
export const refreshLibrary = async (
fullRefresh?: boolean,
library?: Runner | 'all'
) => ipcRenderer.invoke('refreshLibrary', fullRefresh, library)
export const refreshLibrary = async (library?: Runner | 'all') =>
ipcRenderer.invoke('refreshLibrary', library)

export const gamepadAction = async (args: GamepadActionArgs) =>
ipcRenderer.invoke('gamepadAction', args)
Expand Down
4 changes: 4 additions & 0 deletions src/backend/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ export default class CacheStore<ValueType, KeyType extends string = string> {
}

public clear = () => this.store.clear()

public has(key: string) {
return this.store.has(key)
}
}
53 changes: 26 additions & 27 deletions src/backend/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ import {
GlobalConfigVersion,
WineInstallation
} from 'common/types'
import { LegendaryUser } from './legendary/user'
import { LegendaryUser } from 'backend/storeManagers/legendary/user'
import {
currentGlobalConfigVersion,
heroicConfigPath,
heroicDefaultWinePrefixDir,
heroicGamesConfigPath,
configPath,
defaultWinePrefix,
gamesConfigPath,
heroicInstallPath,
heroicToolsPath,
toolsPath,
userHome,
isFlatpak,
isMac,
isWindows,
getSteamLibraries,
getSteamCompatFolder,
configStore,
heroicDefaultWinePrefix
configStore
} from './constants'
import { execAsync } from './utils'
import { execSync } from 'child_process'
Expand Down Expand Up @@ -63,17 +62,17 @@ abstract class GlobalConfig {
let version: GlobalConfigVersion

// Config file doesn't already exist, make one with the current version.
if (!existsSync(heroicConfigPath)) {
if (!existsSync(configPath)) {
version = currentGlobalConfigVersion
}
// Config file exists, detect its version.
else {
// Check version field in the config.
try {
version = JSON.parse(readFileSync(heroicConfigPath, 'utf-8'))['version']
version = JSON.parse(readFileSync(configPath, 'utf-8'))['version']
} catch (error) {
logError(
`Config file is corrupted, please check ${heroicConfigPath}`,
`Config file is corrupted, please check ${configPath}`,
LogPrefix.Backend
)
version = 'v0'
Expand Down Expand Up @@ -171,7 +170,7 @@ abstract class GlobalConfig {
const winePaths = new Set<string>()

// search for wine installed on $HOME/Library/Application Support/heroic/tools/wine
const wineToolsPath = `${heroicToolsPath}/wine/`
const wineToolsPath = `${toolsPath}/wine/`
if (existsSync(wineToolsPath)) {
readdirSync(wineToolsPath).forEach((path) => {
winePaths.add(join(wineToolsPath, path))
Expand Down Expand Up @@ -311,18 +310,18 @@ abstract class GlobalConfig {
return [...macOsWineSet]
}

if (!existsSync(`${heroicToolsPath}/wine`)) {
mkdirSync(`${heroicToolsPath}/wine`, { recursive: true })
if (!existsSync(`${toolsPath}/wine`)) {
mkdirSync(`${toolsPath}/wine`, { recursive: true })
}

if (!existsSync(`${heroicToolsPath}/proton`)) {
mkdirSync(`${heroicToolsPath}/proton`, { recursive: true })
if (!existsSync(`${toolsPath}/proton`)) {
mkdirSync(`${toolsPath}/proton`, { recursive: true })
}

const altWine = new Set<WineInstallation>()

readdirSync(`${heroicToolsPath}/wine/`).forEach((version) => {
const wineBin = join(heroicToolsPath, 'wine', version, 'bin', 'wine')
readdirSync(`${toolsPath}/wine/`).forEach((version) => {
const wineBin = join(toolsPath, 'wine', version, 'bin', 'wine')
altWine.add({
bin: wineBin,
name: `Wine - ${version}`,
Expand All @@ -348,7 +347,7 @@ abstract class GlobalConfig {
})
}

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

await getSteamLibraries().then((libs) => {
libs.forEach((path) => {
Expand Down Expand Up @@ -478,7 +477,7 @@ abstract class GlobalConfig {
public abstract resetToDefaults(): void

protected writeToFile(config: Record<string, unknown>) {
return writeFileSync(heroicConfigPath, JSON.stringify(config, null, 2))
return writeFileSync(configPath, JSON.stringify(config, null, 2))
}

/**
Expand All @@ -495,7 +494,7 @@ abstract class GlobalConfig {
*/
protected load() {
// Config file doesn't exist, make one.
if (!existsSync(heroicConfigPath)) {
if (!existsSync(configPath)) {
this.resetToDefaults()
}
// Always upgrade before loading to avoid errors.
Expand Down Expand Up @@ -530,15 +529,15 @@ class GlobalConfigV0 extends GlobalConfig {
return this.config
}

if (!existsSync(heroicGamesConfigPath)) {
mkdirSync(heroicGamesConfigPath, { recursive: true })
if (!existsSync(gamesConfigPath)) {
mkdirSync(gamesConfigPath, { recursive: true })
}

if (!existsSync(heroicConfigPath)) {
if (!existsSync(configPath)) {
return this.getFactoryDefaults()
}

let settings = JSON.parse(readFileSync(heroicConfigPath, 'utf-8'))
let settings = JSON.parse(readFileSync(configPath, 'utf-8'))
const defaultSettings = settings.defaultSettings as AppSettings

// fix relative paths
Expand All @@ -565,7 +564,7 @@ class GlobalConfigV0 extends GlobalConfig {
public getCustomWinePaths(): Set<WineInstallation> {
const customPaths = new Set<WineInstallation>()
// skips this on new installations to avoid infinite loops
if (existsSync(heroicConfigPath)) {
if (existsSync(configPath)) {
const { customWinePaths = [] } = this.getSettings()
customWinePaths.forEach((path: string) => {
if (path.endsWith('proton')) {
Expand Down Expand Up @@ -607,7 +606,7 @@ class GlobalConfigV0 extends GlobalConfig {
defaultInstallPath: heroicInstallPath,
libraryTopSection: 'disabled',
defaultSteamPath: getSteamCompatFolder(),
defaultWinePrefix: heroicDefaultWinePrefixDir,
defaultWinePrefix: defaultWinePrefix,
hideChangelogsOnStartup: false,
language: 'en',
maxWorkers: 0,
Expand All @@ -622,7 +621,7 @@ class GlobalConfigV0 extends GlobalConfig {
name: userName
},
wineCrossoverBottle: 'Heroic',
winePrefix: isWindows ? '' : heroicDefaultWinePrefix,
winePrefix: isWindows ? '' : defaultWinePrefix,
wineVersion: defaultWine
} as AppSettings
}
Expand Down
49 changes: 20 additions & 29 deletions src/backend/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,20 @@ 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 appFolder = join(configFolder, 'heroic')
const configPath = join(appFolder, 'config.json')
const gamesConfigPath = join(appFolder, 'GamesConfig')
const toolsPath = join(appFolder, 'tools')
const heroicIconFolder = join(appFolder, 'icons')
const runtimePath = join(toolsPath, 'runtimes')
const userInfo = join(legendaryConfigPath, 'user.json')
const heroicInstallPath = join(homedir(), 'Games', 'Heroic')
const heroicDefaultWinePrefixDir = join(
homedir(),
'Games',
'Heroic',
'Prefixes'
)
const heroicDefaultWinePrefix = join(heroicDefaultWinePrefixDir, 'default')
const heroicAnticheatDataPath = join(heroicFolder, 'areweanticheatyet.json')
const imagesCachePath = join(heroicFolder, 'images-cache')
const defaultWinePrefixDir = join(homedir(), 'Games', 'Heroic', 'Prefixes')
const defaultWinePrefix = join(defaultWinePrefixDir, 'default')
const anticheatDataPath = join(appFolder, 'areweanticheatyet.json')
const imagesCachePath = join(appFolder, 'images-cache')
const cachedUbisoftInstallerPath = join(
heroicFolder,
appFolder,
'tools',
'UbisoftConnectInstaller.exe'
)
Expand Down Expand Up @@ -186,16 +181,12 @@ const execOptions = {
shell: getShell()
}

const defaultFolders = [
heroicGamesConfigPath,
heroicIconFolder,
imagesCachePath
]
const defaultFolders = [gamesConfigPath, heroicIconFolder, imagesCachePath]

const necessaryFoldersByPlatform = {
win32: [...defaultFolders],
linux: [...defaultFolders, heroicToolsPath],
darwin: [...defaultFolders, heroicToolsPath]
linux: [...defaultFolders, toolsPath],
darwin: [...defaultFolders, toolsPath]
}

export function createNecessaryFolders() {
Expand All @@ -217,15 +208,15 @@ export {
execOptions,
fixAsarPath,
configStore,
heroicConfigPath,
heroicGamesConfigPath,
configPath,
gamesConfigPath,
heroicGithubURL,
heroicIconFolder,
heroicInstallPath,
heroicToolsPath,
heroicDefaultWinePrefixDir,
heroicDefaultWinePrefix,
heroicAnticheatDataPath,
toolsPath,
defaultWinePrefixDir,
defaultWinePrefix,
anticheatDataPath,
imagesCachePath,
userHome,
flatPakHome,
Expand Down
Loading