Skip to content

Commit

Permalink
Pull latest upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
imLinguin committed Feb 6, 2022
2 parents 0f0bd05 + 50a3bfb commit 5d72a38
Show file tree
Hide file tree
Showing 58 changed files with 951 additions and 426 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 @@ -59,7 +59,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 @@ -148,7 +147,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
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 @@ -631,9 +631,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 @@ -13,6 +13,7 @@ export interface AppSettings {
altLegendaryBin: string
audioFix: boolean
autoInstallDxvk: boolean
autoInstallVkd3d: boolean
autoSyncSaves: boolean
checkForUpdatesOnStartup: boolean
customWinePaths: string[]
Expand Down Expand Up @@ -124,6 +125,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 @@ -78,35 +78,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
21 changes: 16 additions & 5 deletions public/locales/bg/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
"message": "Няма достатъчно свободно място на диска",
"title": "Недостатъчно място"
},
"dxvk": {
"message": "Error installing DXVK/VKD3D! Check your connection or if you have zstd/libzstd1 installed",
"title": "DXVK/VKD3D error"
},
"generic": {
"message": "Възникна неизвестна грешка",
"title": "Неизвестна грешка"
},
"launch": "Грешка при пускането на играта. Проверете журнала!",
"log": {
"message": "Не е намерен журнал за тази игра",
"title": "Журналът не е намерен"
},
"title": "Грешка",
"wine-not-found": {
"message": "No Wine Version Selected. Check Game Settings!",
Expand Down Expand Up @@ -156,6 +156,7 @@
},
"install": {
"canceled": "Инсталирането е преустановено",
"error": "",
"finished": "Инсталирането е завършено",
"imported": "Играта е внесена",
"startInstall": "Инсталацията е започната"
Expand Down Expand Up @@ -197,8 +198,9 @@
"addgamestostartmenu": "Автоматично добавяне на игрите в менюто с приложения",
"alt-legendary-bin": "Избиране на алтернативен изпълним файл на Legendary (изисква рестартиране)",
"audiofix": "Поправка за звука (забавяне на Pulse Audio)",
"autodxvk": "Автоматично инсталиране/обновяване на DXVK/VKD3D в префикса",
"autodxvk": "Автоматично инсталиране/обновяване на DXVK в префикса",
"autosync": "Автоматично синхронизиране на запазените файлове",
"autovkd3d": "Auto Install/Update VKD3D on Prefix",
"change-target-exe": "Изберете алтернативен файл EXE за изпълнение",
"checkForUpdatesOnStartup": "Проверка за обновления при стартиране",
"customWineProton": "Персонализирани пътища за Wine/Proton",
Expand Down Expand Up @@ -255,6 +257,9 @@
"clear-cache": "Изчистване на кеша на Heroic",
"copiedToClipboard": "Copied to Clipboard!",
"copyToClipboard": "Копиране на всички настройки в буфера за обмен",
"log": {
"long-log-hint": "Log truncated, last 1000 lines are shown!"
},
"navbar": {
"general": "Общи",
"log": "Log",
Expand All @@ -280,6 +285,12 @@
"unrealProjects": "Unreal – Проекти",
"updates": "Изчакващи обновления"
},
"toolbox": {
"settings": {
"default-wineprefix": "Select the default prefix folder for new configs",
"wineprefix": "Select a Folder for new Wine Prefixes"
}
},
"tooltip": {
"addpath": "Добавяне на нов път",
"removepath": "Премахване на пътя"
Expand Down
Loading

0 comments on commit 5d72a38

Please sign in to comment.