diff --git a/src/backend/tools/index.ts b/src/backend/tools/index.ts index 8d1d661933..c35c945f94 100644 --- a/src/backend/tools/index.ts +++ b/src/backend/tools/index.ts @@ -1,5 +1,6 @@ import { ExecResult, GameSettings, Runner, WineCommandArgs } from 'common/types' import axios from 'axios' + import { existsSync, readFileSync, @@ -10,12 +11,13 @@ import { rm } from 'graceful-fs' -import decompress from '@xhmikosr/decompress' -import decompressTargz from '@xhmikosr/decompress-targz' -import decompressTarxz from '@felipecrs/decompress-tarxz' - import { exec, spawn } from 'child_process' -import { downloadFile, execAsync, getWineFromProton } from '../utils' +import { + downloadFile, + execAsync, + extractFiles, + getWineFromProton +} from '../utils' import { execOptions, toolsPath, @@ -65,25 +67,21 @@ export const DXVK = { { name: 'vkd3d', url: getVkd3dUrl(), - extractPlugin: decompressTarxz(), os: 'linux' }, { name: 'dxvk', url: getDxvkUrl(), - extractPlugin: decompressTargz(), os: 'linux' }, { name: 'dxvk-nvapi', url: 'https://api.github.com/repos/jp7677/dxvk-nvapi/releases/latest', - extractPlugin: decompressTargz(), os: 'linux' }, { name: 'dxvk-macOS', url: 'https://api.github.com/repos/Gcenx/DXVK-macOS/releases/latest', - extractPlugin: decompressTargz(), os: 'darwin' } ] @@ -144,8 +142,10 @@ export const DXVK = { logInfo(`downloaded ${tool.name}`, LogPrefix.DXVKInstaller) logInfo(`extracting ${tool.name}`, LogPrefix.DXVKInstaller) exec(echoCommand) - await decompress(latestVersion, destination, { - plugins: [tool.extractPlugin] + await extractFiles({ + path: latestVersion, + destination, + strip: 0 }) .then(() => { logInfo(`${tool.name} updated!`, LogPrefix.DXVKInstaller) diff --git a/src/backend/utils.ts b/src/backend/utils.ts index 833e7cbb29..d78d0b29e8 100644 --- a/src/backend/utils.ts +++ b/src/backend/utils.ts @@ -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 @@ -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, @@ -1368,7 +1385,8 @@ export { getFileSize, memoryLog, removeFolder, - calculateEta + calculateEta, + extractFiles } // Exported only for testing purpose diff --git a/src/backend/wine/manager/downloader/utilities.ts b/src/backend/wine/manager/downloader/utilities.ts index d09eb8d0a7..07fa99d825 100644 --- a/src/backend/wine/manager/downloader/utilities.ts +++ b/src/backend/wine/manager/downloader/utilities.ts @@ -2,11 +2,9 @@ import { isMac } from '../../../constants' import * as axios from 'axios' import { existsSync, statSync, unlinkSync } from 'graceful-fs' import { spawnSync } from 'child_process' -import decompress from '@xhmikosr/decompress' -import decompressTargz from '@xhmikosr/decompress-targz' -import decompressTarxz from '@felipecrs/decompress-tarxz' import { ProgressInfo, State, VersionInfo, Type } from 'common/types' +import { extractFiles } from 'backend/utils' interface fetchProps { url: string @@ -152,19 +150,7 @@ async function unzipFile({ reject(error.message) } - let extractPlugin - if (filePath.endsWith('tar.gz')) { - extractPlugin = decompressTargz() - } else if (filePath.endsWith('tar.xz')) { - extractPlugin = decompressTarxz() - } else { - reject(`Archive type ${filePath.split('.').pop()} not supported!`) - } - - decompress(filePath, unzipDir, { - plugins: [extractPlugin], - strip: 1 - }) + extractFiles({ path: filePath, destination: unzipDir, strip: 1 }) .then(() => { onProgress('idle') resolve(`Succesfully unzip ${filePath} to ${unzipDir}.`) diff --git a/src/backend/wine/runtimes/util.ts b/src/backend/wine/runtimes/util.ts index fcdbfbb569..9e2df8f822 100644 --- a/src/backend/wine/runtimes/util.ts +++ b/src/backend/wine/runtimes/util.ts @@ -1,8 +1,6 @@ -import decompress from '@xhmikosr/decompress' import axios from 'axios' +import { extractFiles } from 'backend/utils' import { existsSync, mkdirSync, writeFile } from 'graceful-fs' -import decompressTargz from '@xhmikosr/decompress-targz' -import decompressTarxz from '@felipecrs/decompress-tarxz' interface GithubAssetMetadata { url: string @@ -93,13 +91,11 @@ async function extractTarFile( mkdirSync(extractedPath, { recursive: true }) const strip = options?.strip - return decompress(filePath, extractedPath, { - plugins: [ - contentType === 'application/x-gzip' - ? decompressTargz() - : decompressTarxz() - ], - strip: strip ? 1 : 0 + + return extractFiles({ + path: filePath, + destination: extractedPath, + strip: strip || 0 }) }