Skip to content

Commit

Permalink
[Tech] Refactor Extraction methods (#3181)
Browse files Browse the repository at this point in the history
* [Tech] Use Decompress lib for downloaded tools

* fix: dxvk-nvapi folder

* tech: use decompress for wine, proton and runtimes

* feat: refactor to one single method

* chore: use exact dependencies

* mock xhmikosr decompress and decompress-targz (#3185)

* fix: types and tests

* fix: utils runtime mocks

* Revert "chore: use exact dependencies"

This reverts commit f257b14.

* fix: lint and codecheck

* fix: prettier (?)

* Revert "Revert "chore: use exact dependencies""

This reverts commit 49c3b09.

* fix: use exact dependencies version and update react types

---------

Co-authored-by: Flavio F Lima <[email protected]>
Co-authored-by: Brett <[email protected]>
  • Loading branch information
3 people authored Nov 3, 2023
1 parent e9ae7b0 commit ad2fac9
Show file tree
Hide file tree
Showing 14 changed files with 2,792 additions and 2,661 deletions.
186 changes: 94 additions & 92 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,53 +137,56 @@
}
},
"dependencies": {
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@fontsource/cabin": "^4.5.10",
"@fontsource/rubik": "^4.5.14",
"@fortawesome/fontawesome-svg-core": "^6.3.0",
"@fortawesome/free-brands-svg-icons": "^6.3.0",
"@fortawesome/free-regular-svg-icons": "^6.3.0",
"@fortawesome/free-solid-svg-icons": "^6.3.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@mui/icons-material": "^5.11.11",
"@mui/material": "^5.11.12",
"@node-steam/vdf": "^2.2.0",
"@shockpkg/icon-encoder": "^2.1.3",
"axios": "^0.26.1",
"check-disk-space": "^3.3.1",
"classnames": "^2.3.1",
"compare-versions": "^6.0.0-rc.1",
"crc": "^4.3.2",
"discord-rich-presence-typescript": "^0.0.8",
"easydl": "^1.1.0",
"electron-store": "^8.0.1",
"electron-updater": "^5.0.1",
"filesize": "^10.0.6",
"font-list": "^1.4.5",
"fs-extra": "^11.1.0",
"fuse.js": "^6.6.2",
"graceful-fs": "^4.2.10",
"i18next": "^22.4.11",
"i18next-fs-backend": "^2.1.1",
"i18next-http-backend": "^2.1.1",
"ini": "^3.0.0",
"json5": "^2.2.3",
"plist": "^3.0.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^12.2.0",
"react-markdown": "^8.0.5",
"react-router-dom": "^6.9.0",
"recharts": "^2.4.3",
"sanitize-filename": "^1.6.3",
"semver": "^7.5.2",
"shlex": "^2.1.2",
"short-uuid": "^4.2.2",
"simple-keyboard": "^3.5.33",
"steam-shortcut-editor": "^3.1.1",
"tslib": "^2.5.0",
"zod": "^3.21.4"
"@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",
"@fortawesome/free-brands-svg-icons": "6.3.0",
"@fortawesome/free-regular-svg-icons": "6.3.0",
"@fortawesome/free-solid-svg-icons": "6.3.0",
"@fortawesome/react-fontawesome": "0.2.0",
"@mui/icons-material": "5.11.11",
"@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",
"axios": "0.26.1",
"check-disk-space": "3.3.1",
"classnames": "2.3.1",
"compare-versions": "6.1.0",
"crc": "4.3.2",
"discord-rich-presence-typescript": "0.0.8",
"easydl": "1.1.0",
"electron-store": "8.0.1",
"electron-updater": "5.0.1",
"filesize": "10.0.6",
"font-list": "1.4.5",
"fs-extra": "11.1.0",
"fuse.js": "6.6.2",
"graceful-fs": "4.2.10",
"i18next": "22.4.11",
"i18next-fs-backend": "2.1.1",
"i18next-http-backend": "2.1.1",
"ini": "3.0.0",
"json5": "2.2.3",
"plist": "3.0.5",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-i18next": "12.2.0",
"react-markdown": "8.0.5",
"react-router-dom": "6.9.0",
"recharts": "2.4.3",
"sanitize-filename": "1.6.3",
"semver": "7.5.2",
"shlex": "2.1.2",
"short-uuid": "4.2.2",
"simple-keyboard": "3.5.33",
"steam-shortcut-editor": "3.1.1",
"tslib": "2.5.0",
"zod": "3.21.4"
},
"scripts": {
"start": "vite",
Expand Down Expand Up @@ -222,53 +225,52 @@
]
},
"devDependencies": {
"@electron/notarize": "^1.2.3",
"@playwright/test": "^1.32.1",
"@testing-library/dom": "^9.0.1",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.1.1",
"@types/classnames": "^2.3.1",
"@types/i18next-fs-backend": "^1.1.2",
"@types/ini": "^1.3.31",
"@types/jest": "^29.4.0",
"@types/node": "^18.15.0",
"@types/plist": "^3.0.2",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/react-router-dom": "^5.3.3",
"@types/tmp": "^0.2.3",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"@vitejs/plugin-react-swc": "^3.2.0",
"cross-env": "^7.0.3",
"@electron/notarize": "1.2.3",
"@playwright/test": "1.32.1",
"@testing-library/dom": "9.0.1",
"@testing-library/jest-dom": "5.16.4",
"@testing-library/react": "14.0.0",
"@testing-library/user-event": "14.1.1",
"@types/i18next-fs-backend": "1.1.4",
"@types/ini": "1.3.31",
"@types/jest": "29.4.0",
"@types/node": "18.15.0",
"@types/plist": "3.0.2",
"@types/react": "18.2.34",
"@types/react-dom": "18.2.14",
"@types/react-router-dom": "5.3.3",
"@types/tmp": "0.2.3",
"@typescript-eslint/eslint-plugin": "5.47.1",
"@typescript-eslint/parser": "5.47.1",
"@vitejs/plugin-react-swc": "3.2.0",
"cross-env": "7.0.3",
"electron": "castlabs/electron-releases#27.0.0+wvcus",
"electron-builder": "^24.6.4",
"electron-devtools-installer": "^3.2.0",
"electron-playwright-helpers": "^1.5.5",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-react": "^7.31.11",
"husky": "^8.0.3",
"i18next-parser": "^7.7.0",
"jest": "^29.5.0",
"playwright": "^1.32.1",
"prettier": "^2.8.1",
"pretty-quick": "^3.1.3",
"sass": "^1.59.2",
"tmp": "^0.2.1",
"ts-jest": "^29.0.5",
"ts-prune": "^0.10.3",
"type-fest": "^3.6.1",
"typescript": "^4.9.4",
"unimported": "^1.26.0",
"vite": "^3.2.7",
"vite-plugin-electron": "^0.10.2",
"vite-plugin-svgr": "^2.4.0",
"xml-js": "^1.6.11"
"electron-builder": "24.6.4",
"electron-devtools-installer": "3.2.0",
"electron-playwright-helpers": "1.5.5",
"eslint": "8.36.0",
"eslint-config-prettier": "8.7.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-react": "7.31.11",
"husky": "8.0.3",
"i18next-parser": "7.7.0",
"jest": "29.5.0",
"playwright": "1.32.1",
"prettier": "2.8.1",
"pretty-quick": "3.1.3",
"sass": "1.59.2",
"tmp": "0.2.1",
"ts-jest": "29.0.5",
"ts-prune": "0.10.3",
"type-fest": "3.6.1",
"typescript": "4.9.4",
"unimported": "1.26.0",
"vite": "3.2.7",
"vite-plugin-electron": "0.10.2",
"vite-plugin-svgr": "2.4.0",
"xml-js": "1.6.11"
},
"resolutions": {
"ts-morph": "^17.0.1"
"ts-morph": "17.0.1"
}
}
1 change: 1 addition & 0 deletions src/backend/__mocks__/@xhmikosr/decompress-targz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
1 change: 1 addition & 0 deletions src/backend/__mocks__/@xhmikosr/decompress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
2 changes: 1 addition & 1 deletion src/backend/logger/logfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const createLogFile = (filePath: string) => {
openSync(filePath, 'w')
} catch (error) {
logError([`Open ${filePath} failed with`, error], {
prefix: LogPrefix.Backend,
prefix: LogPrefix?.Backend,
skipLogToFile: true
})
}
Expand Down
29 changes: 21 additions & 8 deletions src/backend/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ExecResult, GameSettings, Runner, WineCommandArgs } from 'common/types'
import axios from 'axios'

import {
existsSync,
readFileSync,
Expand All @@ -9,8 +10,14 @@ import {
copyFile,
rm
} from 'graceful-fs'

import { exec, spawn } from 'child_process'
import { downloadFile, execAsync, getWineFromProton } from '../utils'
import {
downloadFile,
execAsync,
extractFiles,
getWineFromProton
} from '../utils'
import {
execOptions,
toolsPath,
Expand Down Expand Up @@ -60,25 +67,21 @@ export const DXVK = {
{
name: 'vkd3d',
url: getVkd3dUrl(),
extractCommand: 'tar -xf',
os: 'linux'
},
{
name: 'dxvk',
url: getDxvkUrl(),
extractCommand: 'tar -xf',
os: 'linux'
},
{
name: 'dxvk-nvapi',
url: 'https://api.github.com/repos/jp7677/dxvk-nvapi/releases/latest',
extractCommand: 'tar --one-top-level -xf',
os: 'linux'
},
{
name: 'dxvk-macOS',
url: 'https://api.github.com/repos/Gcenx/DXVK-macOS/releases/latest',
extractCommand: 'tar -xf',
os: 'darwin'
}
]
Expand Down Expand Up @@ -120,9 +123,13 @@ export const DXVK = {
})
}

const extractCommand = `${tool.extractCommand} ${latestVersion} -C ${toolsPath}/${tool.name}`
const echoCommand = `echo ${pkg} > '${toolsPath}/${tool.name}/latest_${tool.name}'`
const cleanCommand = `rm ${toolsPath}/${tool.name}/${name}`
const destination = join(
toolsPath,
tool.name,
tool.name === 'dxvk-nvapi' ? pkg : ''
)

logInfo([`Updating ${tool.name} to:`, pkg], LogPrefix.DXVKInstaller)

Expand All @@ -135,9 +142,12 @@ export const DXVK = {
logInfo(`downloaded ${tool.name}`, LogPrefix.DXVKInstaller)
logInfo(`extracting ${tool.name}`, LogPrefix.DXVKInstaller)
exec(echoCommand)
await execAsync(extractCommand)
await extractFiles({
path: latestVersion,
destination,
strip: 0
})
.then(() => {
exec(cleanCommand)
logInfo(`${tool.name} updated!`, LogPrefix.DXVKInstaller)
})
.catch((error) => {
Expand All @@ -146,6 +156,9 @@ export const DXVK = {
LogPrefix.DXVKInstaller
)
})
.finally(() => {
exec(cleanCommand)
})
})
.catch((error: string) => {
logWarning(
Expand Down
20 changes: 19 additions & 1 deletion src/backend/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ import { getHeroicVersion } from './utils/systeminfo/heroicVersion'
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'

const execAsync = promisify(exec)

const { showMessageBox } = dialog
Expand Down Expand Up @@ -1337,6 +1341,19 @@ function calculateEta(
return eta
}

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

async function extractFiles({ path, destination, strip = 0 }: ExtractOptions) {
return decompress(path, destination, {
plugins: [decompressTargz(), decompressTarxz()],
strip
})
}

export {
errorHandler,
execAsync,
Expand Down Expand Up @@ -1368,7 +1385,8 @@ export {
getFileSize,
memoryLog,
removeFolder,
calculateEta
calculateEta,
extractFiles
}

// Exported only for testing purpose
Expand Down
1 change: 1 addition & 0 deletions src/backend/utils/__tests__/compatibility_layers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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
Loading

0 comments on commit ad2fac9

Please sign in to comment.