From a83743c8d515e6ff8b3dda33d06b86aadbf0c492 Mon Sep 17 00:00:00 2001 From: Flavio Lima Date: Thu, 28 Jan 2021 18:42:41 +0100 Subject: [PATCH] feat: added option to move games to another folder --- electron/main.ts | 38 ++++++++++++++++++++++++++-- electron/utils.ts | 20 +++++++-------- package-lock.json | 8 +++--- package.json | 2 +- src/components/GamePage/GamePage.tsx | 38 +++++++++++++++++++++++----- src/components/UI/GameCard.tsx | 7 +++-- src/state/GlobalState.tsx | 17 ++++++++++++- src/types.ts | 1 + 8 files changed, 103 insertions(+), 28 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index a5b306af08..ddbb97f2a2 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -56,7 +56,7 @@ import { } from 'electron' import { AppSettings, Game, InstalledInfo, KeyImage } from './types.js' -const { showMessageBox, showErrorBox } = dialog +const { showMessageBox, showErrorBox, showOpenDialog } = dialog let mainWindow: BrowserWindow = null function createWindow() { @@ -406,6 +406,40 @@ ipcMain.on('getLog', (event, appName) => spawn('xdg-open', [`${heroicGamesConfigPath}/${appName}-lastPlay.log`]) ) +const installed = `${legendaryConfigPath}/installed.json` + +ipcMain.handle('moveInstall', async (event, appName: string) => { + const { filePaths } = await showOpenDialog({ + title: 'Choose where you want to move', + buttonLabel: 'Choose', + properties: ['openDirectory'], + }) + + if (filePaths[0]) { + // @ts-ignore + const file = JSON.parse(readFileSync(installed)) + const installedGames: Game[] = Object.values(file) + const { install_path } = installedGames.filter( + (game) => game.app_name === appName + )[0] + + const splitPath = install_path.split('/') + const installFolder = splitPath[splitPath.length - 1] + const newPath = `${filePaths[0]}/${installFolder}` + const game: Game = { ...file[appName], install_path: newPath } + const modifiedInstall = { ...file, [appName]: game } + return await execAsync(`mv -f ${install_path} ${newPath}`) + .then(() => { + console.log('moved') + writeFile(installed, JSON.stringify(modifiedInstall, null, 2), () => + console.log('file updated') + ) + }) + .catch(console.log) + } + return +}) + ipcMain.handle('readFile', async (event, file) => { const loggedIn = isLoggedIn() @@ -413,7 +447,6 @@ ipcMain.handle('readFile', async (event, file) => { return { user: { displayName: null }, library: [] } } - const installed = `${legendaryConfigPath}/installed.json` const files: any = { // @ts-ignore user: loggedIn ? JSON.parse(readFileSync(userInfo)) : { displayName: null }, @@ -468,6 +501,7 @@ ipcMain.handle('readFile', async (event, file) => { const art_square = gameBoxTall ? gameBoxTall.url : fallBackImage const installedGames: Game[] = Object.values(files.installed) + const isInstalled = Boolean( installedGames.filter((game) => game.app_name === app_name).length ) diff --git a/electron/utils.ts b/electron/utils.ts index afcfe3b58e..57c7227b60 100644 --- a/electron/utils.ts +++ b/electron/utils.ts @@ -139,15 +139,14 @@ const launchGame = async (appName: any) => { prefix = isProton ? '' : `--wine-prefix ${winePrefix}` const options = { - fps: showFps ? ` DXVK_HUD=fps` : '', - audio: audioFix ? ` PULSE_LATENCY_MSEC=60` : '', - showMangohud: showMangohud ? ` MANGOHUD=1` : '', - proton: isProton ? ` STEAM_COMPAT_DATA_PATH=${winePrefix}` : '', + other: otherOptions ? otherOptions : '', + fps: showFps ? `DXVK_HUD=fps` : '', + audio: audioFix ? `PULSE_LATENCY_MSEC=60` : '', + showMangohud: showMangohud ? `MANGOHUD=1` : '', + proton: isProton ? `STEAM_COMPAT_DATA_PATH=${winePrefix}` : '', } - envVars = otherOptions - .concat(Object.values(options).join('')) - .replace(' ', '') + envVars = Object.values(options).join(' ') if (isProton) { console.log( `\n You are using Proton, this can lead to some bugs, @@ -305,10 +304,11 @@ async function getLatestDxvk() { 'https://api.github.com/repos/lutris/dxvk/releases/latest' ) const current = assets[0] - const name = current.name.replace('.tar.gz', '') + const pkg = current.name + const name = pkg.replace('.tar.gz', '') const downloadUrl = current.browser_download_url - const dxvkLatest = `${heroicToolsPath}/DXVK/${name}` + const dxvkLatest = `${heroicToolsPath}/DXVK/${pkg}` const pastVersionCheck = `${heroicToolsPath}/DXVK/latest_dxvk` let pastVersion = '' @@ -388,7 +388,7 @@ const handleExit = async () => { if (existsSync(`${heroicGamesConfigPath}/lock`)) { const { response } = await showMessageBox({ title: 'Exit', - message: 'Games are being download, are you sure?', + message: 'There are pending operations, are you sure?', buttons: ['NO', 'YES'], }) diff --git a/package-lock.json b/package-lock.json index 27745602eb..7306730158 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "heroic", - "version": "1.2.2", + "version": "1.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "1.2.2", + "version": "1.3.0", "license": "GPL-3.0-only", "dependencies": { "axios": "^0.21.1", @@ -20522,7 +20522,6 @@ "version": "4.1.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz", "integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==", - "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -38876,8 +38875,7 @@ "typescript": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz", - "integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==", - "dev": true + "integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==" }, "unicode-canonical-property-names-ecmascript": { "version": "1.0.4", diff --git a/package.json b/package.json index d4ce8db43f..e6784dd7ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "heroic", - "version": "1.2.2", + "version": "1.3.0", "private": true, "main": "public/main.js", "homepage": "./", diff --git a/src/components/GamePage/GamePage.tsx b/src/components/GamePage/GamePage.tsx index ef51611f7e..5f168c9edd 100644 --- a/src/components/GamePage/GamePage.tsx +++ b/src/components/GamePage/GamePage.tsx @@ -58,6 +58,7 @@ export default function GamePage() { const isPlaying = status === 'playing' const isUpdating = status === 'updating' const isReparing = status === 'repairing' + const isMoving = status === 'moving' useEffect(() => { const updateConfig = async () => { @@ -145,6 +146,12 @@ export default function GamePage() { > Verify and Repair {' '} + handleMoveInstall()} + className="hidden link" + > + Move Game + {' '} ipcRenderer.send('getLog', appName)} className="hidden link" @@ -229,7 +236,7 @@ export default function GamePage() { isInstalled || isInstalling ? '#0BD58C' : '#BD0A0A', }} > - {getInstallLabel(isInstalled, isUpdating)} + {getInstallLabel(isInstalled)}

{!isInstalled && !isInstalling && ( @@ -247,7 +254,7 @@ export default function GamePage() { {isInstalled && ( <>