Skip to content

[FIX] Issues with Epic Login and refresh Library #1073

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

Merged
merged 9 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions .github/workflows/build-prs-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build Linux

on:
pull_request:
branches: [main]
workflow_dispatch:
inputs:
version:
description: 'Build Test Files'
required: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository.
uses: actions/checkout@v2
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install modules.
run: yarn
- name: Build artifacts.
run: yarn dist appimage --publish=never
- name: Upload AppImage.
uses: actions/upload-artifact@v2
with:
name: linux-appimage
path: dist/Heroic-*.AppImage
retention-days: 14
31 changes: 31 additions & 0 deletions .github/workflows/build-prs-mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build macOS

on:
pull_request:
branches: [main]
workflow_dispatch:
inputs:
version:
description: 'Build Test Files'
required: false

jobs:
build:
runs-on: macos-11
steps:
- name: Checkout repository.
uses: actions/checkout@v2
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install modules.
run: yarn
- name: Build artifacts.
run: yarn dist-mac --publish=never
- name: Upload DMG.
uses: actions/upload-artifact@v2
with:
name: mac-dmg
path: dist/Heroic*.dmg
retention-days: 14
31 changes: 31 additions & 0 deletions .github/workflows/build-prs-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build Windows

on:
pull_request:
branches: [main]
workflow_dispatch:
inputs:
version:
description: 'Build Test Files'
required: false

jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout repository.
uses: actions/checkout@v2
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install modules.
run: npm i --legacy-peer-deps
- name: Build artifacts.
run: npm run dist-win portable
- name: Upload EXE.
uses: actions/upload-artifact@v2
with:
name: win-portable
path: dist/Heroic*.exe
retention-days: 14
73 changes: 0 additions & 73 deletions .github/workflows/build-prs.yml

This file was deleted.

43 changes: 39 additions & 4 deletions electron/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { homedir, platform } from 'os'
import { join } from 'path'
import { dirname, join } from 'path'
import Store from 'electron-store'

import { GameConfigVersion, GlobalConfigVersion } from './types'
Expand All @@ -11,25 +11,58 @@ import {
import { env } from 'process'
import { app } from 'electron'
import { existsSync } from 'graceful-fs'
import os from 'os'

const configStore = new Store({
cwd: 'store'
})

// based on https://github.com/jy95/escape-path-with-spaces/blob/master/index.js
// unfortunatelly this cant go into utils since it needs to be loaded on app start
function fixPathWithSpaces(path: string) {
if (!isWindows) {
return path.replace(/(\s+)/g, '\\$1')
}

// For some windows version (Windows 10 v1803), it is not useful to escape spaces in path
// https://docs.microsoft.com/en-us/windows/release-information/
// to detect on with os user had used path.resolve(...)
const version = os.release()
const windows_version_regex = /(\d+\.\d+)\.(\d+)/
const should_not_escape = (major_release = '', os_build = '') =>
/1\d+\.\d+/.test(major_release) && Number(os_build) >= 17134.1184

// for windows, it depend of the build
const fixedPath = should_not_escape(
...windows_version_regex.exec(version).splice(1)
)
? // on major version, no need to escape anymore
// https://support.microsoft.com/en-us/help/4467268/url-encoded-unc-paths-not-url-decoded-in-windows-10-version-1803-later
path
: // on older version, replace space with symbol %20
path.replace(/(\s+)/g, '%20')
return fixedPath
}

function getLegendaryBin() {
const settings = configStore.get('settings') as { altLeg: string }
const bin =
settings?.altLeg ||
`"${fixAsarPath(
`${fixAsarPath(
join(
__dirname,
'bin',
process.platform,
isWindows ? 'legendary.exe' : 'legendary'
)
)}"`
)}`

logInfo(`Location: ${bin}`, LogPrefix.Legendary)
return bin
if (bin.includes(' ')) {
return `"${bin}"`
}

return fixPathWithSpaces(bin)
}

function getGOGdlBin() {
Expand Down Expand Up @@ -73,6 +106,7 @@ const { currentLogFile: currentLogFile, lastLogFile: lastLogFile } =
createNewLogFileAndClearOldOnces()

const legendaryBin = getLegendaryBin()
const legendaryPath = dirname(legendaryBin).replaceAll('"', '')
const gogdlBin = getGOGdlBin()

const icon = fixAsarPath(join(__dirname, 'icon.png'))
Expand Down Expand Up @@ -174,6 +208,7 @@ export {
legendaryBin,
gogdlBin,
legendaryConfigPath,
legendaryPath,
libraryPath,
epicLoginUrl,
gogLoginUrl,
Expand Down
8 changes: 6 additions & 2 deletions electron/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ async function launch(
) {
let command = ''
if (runner == 'legendary') {
command = `${legendaryBin} launch ${appName} ${exe} ${runOffline} ${
const legendaryPath = dirname(legendaryBin).replaceAll('"', '')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be defined once in constants.ts? Setting it in like 5 different places does not seem like a good idea

logInfo(['Launch Command:', command], LogPrefix.Legendary)
process.chdir(legendaryPath)
command = `${
isWindows ? './legendary.exe' : './legendary'
} launch ${appName} ${exe} ${runOffline} ${
launchArguments ?? ''
} ${launcherArgs}`
logInfo(['Launch Command:', command], LogPrefix.Legendary)
} else if (runner == 'gog') {
// MangoHud,Gamemode, nvidia prime, audio fix can be used in Linux native titles
if (isLinux) {
Expand Down
29 changes: 22 additions & 7 deletions electron/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
heroicGamesConfigPath,
home,
isWindows,
legendaryBin
legendaryPath
} from '../constants'
import { logError, logInfo, LogPrefix } from '../logger/logger'
import { spawn } from 'child_process'
Expand All @@ -23,6 +23,8 @@ import { launch } from '../launcher'
import { addShortcuts, removeShortcuts } from '../shortcuts'
import { join } from 'path'

process.chdir(legendaryPath)

const store = new Store({
cwd: 'lib-cache',
name: 'gameinfo'
Expand Down Expand Up @@ -233,7 +235,10 @@ class LegendaryGame extends Game {
const workers = maxWorkers === 0 ? '' : ` --max-workers ${maxWorkers}`
const logPath = `"${join(heroicGamesConfigPath, this.appName + '.log')}"`
const writeLog = isWindows ? `2>&1 > ${logPath}` : `|& tee ${logPath}`
const command = `${legendaryBin} update ${this.appName}${workers} -y ${writeLog}`

const command = `${isWindows ? './legendary.exe' : './legendary'} update ${
this.appName
}${workers} -y ${writeLog}`
return execAsync(command, execOptions)
.then(() => {
this.window.webContents.send('setGameStatus', {
Expand Down Expand Up @@ -303,7 +308,9 @@ class LegendaryGame extends Game {

const logPath = `"${join(heroicGamesConfigPath, this.appName + '.log')}"`
const writeLog = isWindows ? `2>&1 > ${logPath}` : `|& tee ${logPath}`
const command = `${legendaryBin} install ${this.appName} --platform ${platformToInstall} --base-path '${path}' ${withDlcs} ${installSdl} ${workers} -y ${writeLog}`
const command = `${isWindows ? './legendary.exe' : './legendary'} install ${
this.appName
} --platform ${platformToInstall} --base-path '${path}' ${withDlcs} ${installSdl} ${workers} -y ${writeLog}`
logInfo([`Installing ${this.appName} with:`, command], LogPrefix.Legendary)
return execAsync(command, execOptions)
.then(async ({ stdout, stderr }) => {
Expand All @@ -321,7 +328,9 @@ class LegendaryGame extends Game {
}

public async uninstall() {
const command = `${legendaryBin} uninstall ${this.appName} -y`
const command = `${
isWindows ? './legendary.exe' : './legendary'
} uninstall ${this.appName} -y`
logInfo(
[`Uninstalling ${this.appName} with:`, command],
LogPrefix.Legendary
Expand Down Expand Up @@ -350,7 +359,9 @@ class LegendaryGame extends Game {
const logPath = `"${join(heroicGamesConfigPath, this.appName + '.log')}"`
const writeLog = isWindows ? `2>&1 > ${logPath}` : `|& tee ${logPath}`

const command = `${legendaryBin} repair ${this.appName} ${workers} -y ${writeLog}`
const command = `${isWindows ? './legendary.exe' : './legendary'} repair ${
this.appName
} ${workers} -y ${writeLog}`

logInfo([`Repairing ${this.appName} with:`, command], LogPrefix.Legendary)
return await execAsync(command, execOptions)
Expand All @@ -365,7 +376,9 @@ class LegendaryGame extends Game {
}

public async import(path: string) {
const command = `${legendaryBin} import-game ${this.appName} '${path}'`
const command = `${
isWindows ? './legendary.exe' : './legendary'
} import-game ${this.appName} '${path}'`

logInfo(
[`Importing ${this.appName} from ${path} with:`, command],
Expand All @@ -392,7 +405,9 @@ class LegendaryGame extends Game {
? path.replaceAll("'", '').slice(0, -1)
: path.replaceAll("'", '')

const command = `${legendaryBin} sync-saves ${arg} --save-path "${fixedPath}" ${this.appName} -y`
const command = `${
isWindows ? './legendary.exe' : './legendary'
} sync-saves ${arg} --save-path "${fixedPath}" ${this.appName} -y`
const legendarySavesPath = join(home, 'legendary', '.saves')

//workaround error when no .saves folder exists
Expand Down
Loading