Skip to content

Commit

Permalink
Merge branch 'Heroic-Games-Launcher:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
imLinguin authored Feb 6, 2022
2 parents a40d27d + 1723f1c commit 50a3bfb
Show file tree
Hide file tree
Showing 59 changed files with 960 additions and 429 deletions.
6 changes: 6 additions & 0 deletions electron/__mocks__/electron.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { tmpdir } from 'os'

export const dialog = {
showErrorBox: jest.fn(),
showMessageBox: jest.fn()
}

export const app = {
getPath: jest.fn().mockReturnValue(tmpdir())
}
1 change: 1 addition & 0 deletions electron/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ class GlobalConfigV0 extends GlobalConfig {
addDesktopShortcuts: false,
addStartMenuShortcuts: false,
autoInstallDxvk: false,
autoInstallVkd3d: false,
checkForUpdatesOnStartup: true,
customWinePaths: isWindows ? null : [],
defaultInstallPath: heroicInstallPath,
Expand Down
2 changes: 0 additions & 2 deletions electron/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const legendaryConfigPath = isFlatpak
const heroicFolder = isFlatpak
? `${home}/config/heroic/`
: `${home}/.config/heroic/`
const heroicLogFolder = `${heroicFolder}/Logs`
const { currentLogFile: currentLogFile, lastLogFile: lastLogFile } =
createNewLogFileAndClearOldOnces()
const heroicConfigPath = `${heroicFolder}config.json`
Expand Down Expand Up @@ -132,7 +131,6 @@ export {
heroicIconFolder,
heroicInstallPath,
heroicToolsPath,
heroicLogFolder,
home,
kofiPage,
icon,
Expand Down
46 changes: 38 additions & 8 deletions electron/dxvk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { existsSync, readFileSync } from 'graceful-fs'
import { execAsync, isOnline } from './utils'
import { execOptions, heroicToolsPath, home } from './constants'
import { logError, logInfo, LogPrefix, logWarning } from './logger/logger'
import { dialog } from 'electron'
import i18next from 'i18next'

export const DXVK = {
getLatest: async () => {
Expand All @@ -18,9 +20,14 @@ export const DXVK = {
}

const tools = [
{
name: 'vkd3d',
url: 'https://api.github.com/repos/HansKristian-Work/vkd3d-proton/releases/latest',
extractCommand: 'tar -I zstd -xvf'
},
{
name: 'dxvk',
url: 'https://api.github.com/repos/lutris/dxvk/releases/latest',
url: 'https://api.github.com/repos/doitsujin/dxvk/releases/latest',
extractCommand: 'tar -zxf'
}
]
Expand All @@ -31,7 +38,7 @@ export const DXVK = {
} = await axios.default.get(tool.url)

const { name, browser_download_url: downloadUrl } = assets[0]
const pkg = name.replace('.tar.gz', '')
const pkg = name.replace('.tar.gz', '').replace('.tar.zst', '')

const latestVersion = `${heroicToolsPath}/${tool.name}/${name}`
const pastVersionCheck = `${heroicToolsPath}/${tool.name}/latest_${tool.name}`
Expand All @@ -40,9 +47,13 @@ export const DXVK = {
pastVersion = readFileSync(pastVersionCheck).toString().split('\n')[0]
}

if (pastVersion === pkg) {
if (
pastVersion === pkg &&
existsSync(`${heroicToolsPath}/${tool.name}/${pkg}`)
) {
return
}

const downloadCommand = `curl -L ${downloadUrl} -o ${latestVersion} --create-dirs`
const extractCommand = `${tool.extractCommand} ${latestVersion} -C ${heroicToolsPath}/${tool.name}`
const echoCommand = `echo ${pkg} > ${heroicToolsPath}/${tool.name}/latest_${tool.name}`
Expand All @@ -56,15 +67,34 @@ export const DXVK = {
logInfo(`extracting ${tool.name}`, LogPrefix.DXVKInstaller)
exec(echoCommand)
await execAsync(extractCommand)
logInfo(`extracting ${tool.name} updated!`, LogPrefix.DXVKInstaller)
.then(() =>
logInfo(
`extracting ${tool.name} updated!`,
LogPrefix.DXVKInstaller
)
)
.catch((error) =>
logError(
`Extraction of ${tool.name} failed with: ${error}`,
LogPrefix.DXVKInstaller
)
)

exec(cleanCommand)
})
.catch((error) =>
.catch((error) => {
logError(
[`Error when downloading ${tool.name}`, error],
LogPrefix.DXVKInstaller
)
)
dialog.showErrorBox(
i18next.t('box.error.dxvk.title', 'DXVK/VKD3D error'),
i18next.t(
'box.error.dxvk.message',
'Error installing DXVK/VKD3D! Check your connection or if you have zstd/libzstd1 installed'
)
)
})
})
},

Expand Down Expand Up @@ -110,13 +140,13 @@ export const DXVK = {
.split('\n')[0]
}

const installCommand = `PATH=${wineBin}:$PATH WINEPREFIX='${winePrefix}' bash ${toolPath}/setup_dxvk.sh install --symlink`
const installCommand = `PATH=${wineBin}:$PATH WINEPREFIX='${winePrefix}' bash ${toolPath}/setup*.sh install --symlink`
const updatedVersionfile = `echo '${globalVersion}' > ${currentVersionCheck}`

if (action === 'restore') {
logInfo(`Removing ${tool} version information`, LogPrefix.DXVKInstaller)
const updatedVersionfile = `rm -rf ${currentVersionCheck}`
const removeCommand = `PATH=${wineBin}:$PATH WINEPREFIX='${winePrefix}' bash ${toolPath}/setup_dxvk.sh uninstall --symlink`
const removeCommand = `PATH=${wineBin}:$PATH WINEPREFIX='${winePrefix}' bash ${toolPath}/setup*.sh uninstall --symlink`
return execAsync(removeCommand, execOptions)
.then(() => {
logInfo(`${tool} removed from ${winePrefix}`, LogPrefix.DXVKInstaller)
Expand Down
12 changes: 9 additions & 3 deletions electron/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ Categories=Game;
showMangohud,
audioFix,
autoInstallDxvk,
autoInstallVkd3d,
offlineMode,
enableFSR,
maxSharpness,
Expand Down Expand Up @@ -603,8 +604,8 @@ Categories=Game;
return v
}

if (!wineVersion.bin) {
dialog.showErrorBox(
if (!existsSync(wineVersion.bin.replaceAll("'", ''))) {
return dialog.showErrorBox(
i18next.t('box.error.wine-not-found.title', 'Wine Not Found'),
i18next.t(
'box.error.wine-not-found.message',
Expand Down Expand Up @@ -670,6 +671,11 @@ Categories=Game;
await DXVK.installRemove(winePrefix, wineVersion.bin, 'dxvk', 'backup')
}

// Install VKD3D for non Proton/CrossOver Prefixes
if (!isProton && !isCrossover && autoInstallVkd3d) {
await DXVK.installRemove(winePrefix, winePath, 'vkd3d', 'backup')
}

if (wineVersion.name !== 'Wine Default') {
const { bin } = wineVersion
wineCommand = isProton
Expand Down Expand Up @@ -726,7 +732,7 @@ Categories=Game;

if (!existsSync(fixedWinePrefix)) {
mkdirSync(fixedWinePrefix, { recursive: true })
const initPrefixCommand = `WINEPREFIX='${fixedWinePrefix}' '${winePath}/wineboot' -i && '${winePath}/wineserver' --wait`
const initPrefixCommand = `WINEPREFIX='${fixedWinePrefix}' '${winePath}/wineboot' -i`
logInfo(['creating new prefix', fixedWinePrefix], LogPrefix.Backend)
return execAsync(initPrefixCommand)
.then(() => logInfo('Prefix created succesfuly!', LogPrefix.Backend))
Expand Down
37 changes: 15 additions & 22 deletions electron/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@
* Note that with console.log and console.warn everything will be saved too.
* error equals console.error
*/
import {
openSync,
existsSync,
readdirSync,
mkdirSync,
rmSync,
appendFileSync
} from 'graceful-fs'
import { openSync, readdirSync, unlinkSync, appendFileSync } from 'graceful-fs'
import Store from 'electron-store'
import {
currentLogFile,
heroicGamesConfigPath,
heroicLogFolder,
lastLogFile
} from '../constants'
import { app } from 'electron'

export enum LogPrefix {
General = '',
Expand Down Expand Up @@ -167,11 +160,9 @@ interface createLogFileReturn {
*/
export function createNewLogFileAndClearOldOnces(): createLogFileReturn {
const date = new Date()
const newLogFile = `${heroicLogFolder}/heroic-${date.toISOString()}.log`
const logDir = app.getPath('logs')
const newLogFile = `${logDir}/heroic-${date.toISOString()}.log`
try {
if (!existsSync(heroicLogFolder)) {
mkdirSync(heroicLogFolder)
}
openSync(newLogFile, 'w')
} catch (error) {
logError(
Expand All @@ -182,20 +173,22 @@ export function createNewLogFileAndClearOldOnces(): createLogFileReturn {
}

try {
const logs = readdirSync(heroicLogFolder)
const logs = readdirSync(logDir)
logs.forEach((log) => {
const dateString = log.replace('heroic-', '').replace('.log', '')
const logDate = new Date(dateString)
if (
logDate.getFullYear() < date.getFullYear() ||
logDate.getMonth() < date.getMonth()
) {
rmSync(`${heroicLogFolder}/${log}`)
if (log.includes('heroic-')) {
const dateString = log.replace('heroic-', '').replace('.log', '')
const logDate = new Date(dateString)
if (
logDate.getFullYear() < date.getFullYear() ||
logDate.getMonth() < date.getMonth()
) {
unlinkSync(`${logDir}/${log}`)
}
}
})
} catch (error) {
logError(
`Removing old logs in ${heroicLogFolder} failed with ${error}`,
`Removing old logs in ${logDir} failed with ${error}`,
LogPrefix.Backend,
true
)
Expand Down
8 changes: 6 additions & 2 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,13 @@ ipcMain.handle('requestSettings', async (event, appName) => {
return await GameConfig.get(appName).getSettings()
})

ipcMain.on('toggleDXVK', (event, [{ winePrefix, winePath }, action]) =>
ipcMain.on('toggleDXVK', (event, [{ winePrefix, winePath }, action]) => {
DXVK.installRemove(winePrefix, winePath, 'dxvk', action)
)
})

ipcMain.on('toggleVKD3D', (event, [{ winePrefix, winePath }, action]) => {
DXVK.installRemove(winePrefix, winePath, 'vkd3d', action)
})

ipcMain.handle('writeConfig', (event, [appName, config]) => {
if (appName === 'default') {
Expand Down
2 changes: 2 additions & 0 deletions electron/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface AppSettings {
altLegendaryBin: string
audioFix: boolean
autoInstallDxvk: boolean
autoInstallVkd3d: boolean
autoSyncSaves: boolean
checkForUpdatesOnStartup: boolean
customWinePaths: string[]
Expand Down Expand Up @@ -118,6 +119,7 @@ export interface InstallInfo {
export interface GameSettings {
audioFix: boolean
autoInstallDxvk: boolean
autoInstallVkd3d: boolean
autoSyncSaves: boolean
enableEsync: boolean
enableFSR: boolean
Expand Down
25 changes: 1 addition & 24 deletions electron/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import si from 'systeminformation'
import Store from 'electron-store'

import { GlobalConfig } from './config'
import { heroicGamesConfigPath, home, icon, legendaryBin } from './constants'
import { heroicGamesConfigPath, icon, legendaryBin } from './constants'
import { logError, logInfo, LogPrefix, logWarning } from './logger/logger'

const execAsync = promisify(exec)
Expand Down Expand Up @@ -260,29 +260,6 @@ function removeSpecialcharacters(text: string): string {
}

async function openUrlOrFile(url: string): Promise<string | void> {
if (process.platform === 'darwin') {
try {
await execAsync(`open ${url}`)
} catch (error) {
dialog.showErrorBox(
i18next.t('box.error.log.title', 'Log Not Found'),
i18next.t('box.error.log.message', 'No Log was found for this game')
)
return
}
}
if (process.platform === 'linux') {
try {
const fixedURL = url.replace('~', home)
await execAsync(`xdg-open '${fixedURL}'`)
} catch (error) {
dialog.showErrorBox(
i18next.t('box.error.log.title', 'Log Not Found'),
i18next.t('box.error.log.message', 'No Log was found for this game')
)
return
}
}
return shell.openPath(url)
}

Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "heroic",
"version": "2.1.0",
"version": "2.1.1",
"private": true,
"main": "public/main.js",
"homepage": "./",
Expand Down Expand Up @@ -77,35 +77,38 @@
"packageCategory": "games",
"depends": [
"gawk",
"curl"
"curl",
"zstd"
]
},
"pacman": {
"packageCategory": "games",
"depends": [
"gawk",
"curl"
"curl",
"zstd"
]
},
"rpm": {
"packageCategory": "games",
"depends": [
"gawk",
"curl"
"curl",
"zstd"
]
}
},
"dependencies": {
"@emotion/react": "^11.7.1",
"@emotion/styled": "^11.6.0",
"@fontsource/cabin": "^4.2.1",
"@fontsource/rubik": "^4.2.1",
"@fontsource/cabin": "^4.5.1",
"@fontsource/rubik": "^4.5.1",
"@fortawesome/fontawesome-svg-core": "^1.3.0-beta3",
"@fortawesome/free-brands-svg-icons": "^6.0.0-beta3",
"@fortawesome/free-solid-svg-icons": "^6.0.0-beta3",
"@fortawesome/react-fontawesome": "^0.1.16",
"@mui/icons-material": "^5.3.1",
"@mui/material": "^5.3.1",
"@mui/material": "^5.4.0",
"axios": "^0.21.1",
"classnames": "^2.2.6",
"discord-rich-presence-typescript": "^0.0.8",
Expand Down
Loading

0 comments on commit 50a3bfb

Please sign in to comment.