Skip to content

[Revert] Refactor Extraction methods #3181 #3663

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
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 0 additions & 4 deletions electron-builder.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
appId: com.heroicgameslauncher.hgl
productName: Heroic
afterSign: sign/afterSign.js
afterPack: sign/afterPack.js
files:
- build/**/*
- node_modules/**/*
Expand All @@ -18,9 +17,6 @@ asarUnpack:
- build/bin/**/*
- '!build/bin/legendary.LICENSE'

electronDownload:
mirror: https://github.com/castlabs/electron-releases/releases/download/v

protocols:
- name: heroic
schemes:
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"dependencies": {
"@emotion/react": "11.10.6",
"@emotion/styled": "11.10.6",
"@felipecrs/decompress-tarxz": "4.0.0",
"@fontsource/cabin": "4.5.10",
"@fontsource/rubik": "4.5.14",
"@fortawesome/fontawesome-svg-core": "6.3.0",
Expand All @@ -65,9 +64,6 @@
"@mui/material": "5.11.12",
"@node-steam/vdf": "2.2.0",
"@shockpkg/icon-encoder": "2.1.3",
"@xhmikosr/decompress": "9.0.1",
"@xhmikosr/decompress-targz": "7.0.0",
"@xhmikosr/decompress-unzip": "^7.0.0",
"axios": "0.26.1",
"classnames": "2.3.1",
"compare-versions": "6.1.0",
Expand Down Expand Up @@ -133,7 +129,7 @@
"@typescript-eslint/parser": "5.47.1",
"@vitejs/plugin-react-swc": "3.6.0",
"cross-env": "7.0.3",
"electron": "github:castlabs/electron-releases#v29.1.3+wvcus",
"electron": "29.1.3",
"electron-builder": "24.13.3",
"electron-vite": "^2.0.0",
"eslint": "8.36.0",
Expand Down
405 changes: 12 additions & 393 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions sign/afterPack.js

This file was deleted.

11 changes: 3 additions & 8 deletions sign/afterSign.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// const notarize = require("./notarize").default
const vmp = require("./vmp").default
const notarize = require("./notarize").default

exports.default = async function (context) {
// await notarize(context);
console.log("Finshed Signing, signing with VMP if on Windows. Platform:", context.packager.platform.name)
if (context.packager.platform.name === 'windows') {
console.log("Signing with VMP on Windows")
await vmp(context);
}
await notarize(context);
console.log("Finshed Signing, Notarizing with Apple")
}
45 changes: 0 additions & 45 deletions sign/vmp.js

This file was deleted.

1 change: 0 additions & 1 deletion src/backend/__mocks__/@xhmikosr/decompress-targz.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/backend/__mocks__/@xhmikosr/decompress.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
protocol,
screen,
clipboard,
components,
session
} from 'electron'
import 'backend/updater'
Expand Down Expand Up @@ -317,17 +316,6 @@ if (!gotTheLock) {
)
}

if (!process.env.CI) {
await components.whenReady().catch((e) => {
logError([
'Failed to download / update DRM components.',
'Make sure you do not block update.googleapis.com domain if you want to use WideVine in Browser sideloaded apps',
e
])
})
logInfo(['DRM module staus', components.status()])
}

// try to fix notification app name on windows
if (isWindows) {
app.setAppUserModelId('Heroic Games Launcher')
Expand Down
51 changes: 30 additions & 21 deletions src/backend/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
axiosClient,
downloadFile,
execAsync,
extractFiles,
getWineFromProton
} from '../utils'
import {
Expand Down Expand Up @@ -60,6 +59,7 @@ interface Tool {
name: string
url: string
os: string
extractCommand: string
strip?: number
}

Expand Down Expand Up @@ -117,24 +117,29 @@ async function installOrUpdateTool(tool: Tool) {

const extractDestination = join(toolsPath, tool.name, latestVersion)
mkdirSync(extractDestination, { recursive: true })
try {
await extractFiles({
path: latestVersionArchivePath,
destination: extractDestination,
strip: tool.strip ?? 1
const extractCommand = `${tool.extractCommand} ${latestVersion} -C ${toolsPath}/${tool.name}`
await execAsync(extractCommand)
.then(() => {
writeFileSync(installedVersionStorage, latestVersion)
logInfo(`${tool.name} updated!`, LogPrefix.DXVKInstaller)
})
.catch((error) => {
logWarning(
[`Error when extracting ${tool.name}`, error],
LogPrefix.DXVKInstaller
)
showDialogBoxModalAuto({
title: i18next.t('box.error.dxvk.title', 'DXVK/VKD3D error'),
message: i18next.t(
'box.error.dxvk.message',
'Error installing DXVK/VKD3D! Check your connection!'
),
type: 'ERROR'
})
})
.finally(() => {
rmSync(latestVersionArchivePath)
})
} catch (error) {
logError(
[`Extraction of ${tool.name} failed with:`, error],
LogPrefix.DXVKInstaller
)
return
} finally {
rmSync(latestVersionArchivePath)
}

writeFileSync(installedVersionStorage, latestVersion)
logInfo(`${tool.name} updated!`, LogPrefix.DXVKInstaller)
}

export const DXVK = {
Expand All @@ -154,23 +159,27 @@ export const DXVK = {
{
name: 'vkd3d',
url: getVkd3dUrl(),
os: 'linux'
os: 'linux',
extractCommand: 'tar -xf'
},
{
name: 'dxvk',
url: getDxvkUrl(),
os: 'linux'
os: 'linux',
extractCommand: 'tar -xf'
},
{
name: 'dxvk-nvapi',
url: 'https://api.github.com/repos/jp7677/dxvk-nvapi/releases/latest',
os: 'linux',
extractCommand: 'tar --one-top-level -xf',
strip: 0
},
{
name: 'dxvk-macOS',
url: 'https://api.github.com/repos/Gcenx/DXVK-macOS/releases/latest',
os: 'darwin'
os: 'darwin',
extractCommand: 'tar -xf'
}
]

Expand Down
68 changes: 1 addition & 67 deletions src/backend/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import {
GITHUB_API,
isMac,
configStore,
isLinux,
isSnap
isLinux
} from './constants'
import {
appendGamePlayLog,
Expand Down Expand Up @@ -81,10 +80,6 @@ import { backendEvents } from './backend_events'
import { wikiGameInfoStore } from './wiki_game_info/electronStore'
import EasyDl from 'easydl'

import decompress from '@xhmikosr/decompress'
import decompressTargz from '@xhmikosr/decompress-targz'
import decompressTarxz from '@felipecrs/decompress-tarxz'
import decompressUnzip from '@xhmikosr/decompress-unzip'
import {
deviceNameCache,
vendorNameCache
Expand Down Expand Up @@ -1483,66 +1478,6 @@ function calculateEta(
return eta
}

interface ExtractOptions {
path: string
destination: string
strip: number
}

async function extractFiles({ path, destination, strip = 0 }: ExtractOptions) {
if (!isSnap && (path.endsWith('.tar.xz') || path.endsWith('.tar.gz'))) {
try {
await extractNative(path, destination, strip)
} catch (error) {
logError(['Error:', error], LogPrefix.Backend)
}
} else {
try {
await extractDecompress(path, destination, strip)
} catch (error) {
logError(['Error:', error], LogPrefix.Backend)
}
}
}

async function extractNative(path: string, destination: string, strip: number) {
logInfo(
`Extracting ${path} to ${destination} using native tar`,
LogPrefix.Backend
)
const { code, stderr } = await spawnAsync('tar', [
'-xf',
path,
'-C',
destination,
`--strip-components=${strip}`
])
if (code !== 0) {
logError(`Extracting Error: ${stderr}`, LogPrefix.Backend)
return { status: 'error', error: stderr }
}
return { status: 'done', installPath: destination }
}

async function extractDecompress(
path: string,
destination: string,
strip: number
) {
logInfo(
`Extracting ${path} to ${destination} using decompress`,
LogPrefix.Backend
)
try {
await decompress(path, destination, {
plugins: [decompressTargz(), decompressTarxz(), decompressUnzip()],
strip
})
} catch (error) {
logError(['Error:', error], LogPrefix.Backend)
}
}

const axiosClient = axios.create({
timeout: 10 * 1000,
httpsAgent: new https.Agent({ keepAlive: true })
Expand Down Expand Up @@ -1583,7 +1518,6 @@ export {
sendGameStatusUpdate,
sendProgressUpdate,
calculateEta,
extractFiles,
axiosClient
}

Expand Down
1 change: 0 additions & 1 deletion src/backend/utils/__tests__/compatibility_layers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { mkdirSync } from 'graceful-fs'
import { dirname, join } from 'path'
import { tmpdir } from 'os'

jest.mock('@xhmikosr/decompress')
jest.mock('../../logger/logfile')

describe('getDefaultWine', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@ import { unzipFile } from '../../utilities'

jest.mock('backend/logger/logger')
jest.mock('backend/logger/logfile')
jest.mock('@xhmikosr/decompress', () => {
return jest.fn().mockImplementation(async () => Promise.resolve())
})

jest.mock('@xhmikosr/decompress-unzip', () => {
return jest.fn().mockImplementation(() => {})
})

jest.mock('@xhmikosr/decompress-targz', () => {
return jest.fn().mockImplementation(() => {})
})

jest.mock('@felipecrs/decompress-tarxz', () => {
return jest.fn().mockImplementation(() => {})
})

describe('Utilities - Unzip', () => {
test('unzip file fails because of invalid archive path', async () => {
Expand Down
Loading
Loading