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 1 commit
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
4 changes: 4 additions & 0 deletions electron/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ function getLegendaryBin() {
isWindows ? 'legendary.exe' : 'legendary'
)
)}`

// dont fix windows issues
if (bin.includes(' ')) {
return `"${bin}"`
}
Expand All @@ -77,6 +79,8 @@ function getGOGdlBin() {
isWindows ? 'gogdl.exe' : 'gogdl'
)
)

// dont fix windows issues
if (bin.includes(' ')) {
return `"${bin}"`
}
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
34 changes: 27 additions & 7 deletions electron/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import { spawn } from 'child_process'
import Store from 'electron-store'
import { launch } from '../launcher'
import { addShortcuts, removeShortcuts } from '../shortcuts'
import { join } from 'path'
import { dirname, join } from 'path'

const legendaryPath = dirname(legendaryBin).replaceAll('"', '')
process.chdir(legendaryPath)

const store = new Store({
cwd: 'lib-cache',
Expand Down Expand Up @@ -233,7 +236,12 @@ 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 legendaryPath = dirname(legendaryBin).replaceAll('"', '')
process.chdir(legendaryPath)
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 +311,11 @@ 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 legendaryPath = dirname(legendaryBin).replaceAll('"', '')
process.chdir(legendaryPath)
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 +333,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 +364,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 +381,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 +410,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
11 changes: 9 additions & 2 deletions electron/legendary/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import Store from 'electron-store'
import { GlobalConfig } from '../config'
import path from 'path'

const legendaryPath = path.dirname(legendaryBin).replaceAll('"', '')
process.chdir(legendaryPath)

const libraryStore = new Store({
cwd: 'lib-cache',
name: 'library'
Expand Down Expand Up @@ -232,7 +235,7 @@ class LegendaryLibrary {
}
try {
const { stdout } = await execAsync(
`${legendaryBin} -J info ${appName} ${
`${isWindows ? 'legendary.exe' : 'legendary'} -J info ${appName} ${
epicOffline ? '--offline' : ''
} --json`
)
Expand Down Expand Up @@ -266,7 +269,11 @@ class LegendaryLibrary {
return []
}

const command = `${legendaryBin} list-installed --check-updates --tsv`
const legendaryPath = path.dirname(legendaryBin).replaceAll('"', '')
process.chdir(legendaryPath)
const command = `${
isWindows ? 'legendary.exe' : 'legendary'
} list-installed --check-updates --tsv`
try {
const { stdout } = await execAsync(command)
logInfo('Checking for game updates', LogPrefix.Legendary)
Expand Down
7 changes: 6 additions & 1 deletion electron/legendary/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { dirname } from 'path'
const configStore = new Store({
cwd: 'store'
})

const legendaryPath = dirname(legendaryBin).replaceAll('"', '')
process.chdir(legendaryPath)
export class LegendaryUser {
public static async login(sid: string) {
logInfo('Logging with Legendary...', LogPrefix.Legendary)
Expand Down Expand Up @@ -50,7 +53,9 @@ export class LegendaryUser {
}

public static async logout() {
await execAsync(`${legendaryBin} auth --delete`)
await execAsync(
`${isWindows ? 'legendary.exe' : 'legendary'} auth --delete`
)
const ses = session.fromPartition('persist:epicstore')
await ses.clearStorageData()
await ses.clearCache()
Expand Down
7 changes: 5 additions & 2 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from 'graceful-fs'
import Backend from 'i18next-fs-backend'
import i18next from 'i18next'
import { join } from 'path'
import { dirname, join } from 'path'

import { DXVK } from './dxvk'
import { Game } from './games'
Expand Down Expand Up @@ -1167,6 +1167,9 @@ ipcMain.handle('egsSync', async (event, args) => {
}
}

const legendaryPath = dirname(legendaryBin).replaceAll('"', '')
process.chdir(legendaryPath)

const linkArgs = isWindows
? `--enable-sync`
: `--enable-sync --egl-wine-prefix ${args}`
Expand All @@ -1176,7 +1179,7 @@ ipcMain.handle('egsSync', async (event, args) => {

try {
const { stderr, stdout } = await execAsync(
`${legendaryBin} egl-sync ${command} -y`
`${isWindows ? 'legendary.exe' : 'legendary'} egl-sync ${command} -y`
)
logInfo(`${stdout}`, LogPrefix.Legendary)
if (stderr.includes('ERROR')) {
Expand Down
9 changes: 7 additions & 2 deletions electron/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ import {
legendaryBin
} from './constants'
import { logError, logInfo, LogPrefix, logWarning } from './logger/logger'
import { join } from 'path'
import { dirname, join } from 'path'

const execAsync = promisify(exec)
const statAsync = promisify(stat)

const { showErrorBox, showMessageBox } = dialog

const legendaryPath = dirname(legendaryBin).replaceAll('"', '')
process.chdir(legendaryPath)

/**
* Compares 2 SemVer strings following "major.minor.patch".
* Checks if target is newer than base.
Expand Down Expand Up @@ -93,7 +96,9 @@ export const getLegendaryVersion = async () => {
if (altLegendaryBin && !altLegendaryBin.includes('legendary')) {
return 'invalid'
}
const { stdout } = await execAsync(`${legendaryBin} --version`)
const { stdout } = await execAsync(
`${isWindows ? 'legendary.exe' : 'legendary'} --version`
)
return stdout
.split('legendary version')[1]
.replaceAll('"', '')
Expand Down