From 274c00fdfecfdf8753d2914ed454380b161e21f7 Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Sat, 6 Jan 2024 12:47:07 -0300 Subject: [PATCH] Remove fixes file when the game uninstalled --- src/backend/downloadmanager/utils.ts | 11 +++-------- src/backend/launcher.ts | 9 ++------- src/backend/main.ts | 12 +++++++++++- src/backend/wiki_game_info/gamesdb/utils.ts | 7 +------ src/common/utils.ts | 8 ++++++++ 5 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 src/common/utils.ts diff --git a/src/backend/downloadmanager/utils.ts b/src/backend/downloadmanager/utils.ts index a70b54797c..5b2351fb70 100644 --- a/src/backend/downloadmanager/utils.ts +++ b/src/backend/downloadmanager/utils.ts @@ -13,6 +13,7 @@ import { fixesPath } from 'backend/constants' import path from 'path' import { existsSync, mkdirSync } from 'graceful-fs' import { platform } from 'os' +import { storeMap } from 'common/utils' async function installQueueElement(params: InstallParams): Promise<{ status: DMStatus @@ -169,15 +170,9 @@ async function updateQueueElement(params: InstallParams): Promise<{ } } -const runnerToStore = { - legendary: 'epic', - gog: 'gog', - nile: 'amazon' -} - async function downloadFixesFor(appName: string, runner: Runner) { - const url = `https://raw.githubusercontent.com/Heroic-Games-Launcher/known-fixes/main/${appName}-${runnerToStore[runner]}.json` - const dest = path.join(fixesPath, `${appName}-${runnerToStore[runner]}.json`) + const url = `https://raw.githubusercontent.com/Heroic-Games-Launcher/known-fixes/main/${appName}-${storeMap[runner]}.json` + const dest = path.join(fixesPath, `${appName}-${storeMap[runner]}.json`) if (!existsSync(fixesPath)) { mkdirSync(fixesPath, { recursive: true }) } diff --git a/src/backend/launcher.ts b/src/backend/launcher.ts index 863f844655..a907509664 100644 --- a/src/backend/launcher.ts +++ b/src/backend/launcher.ts @@ -73,6 +73,7 @@ import { deleteAbortController } from './utils/aborthandler/aborthandler' import { download, isInstalled } from './wine/runtimes/runtimes' +import { storeMap } from 'common/utils' async function prepareLaunch( gameSettings: GameSettings, @@ -389,14 +390,8 @@ async function prepareWineLaunch( return { success: true, envVars: envVars } } -const runnerToStore = { - legendary: 'epic', - gog: 'gog', - nile: 'amazon' -} - async function installFixes(appName: string, runner: Runner) { - const fixPath = join(fixesPath, `${appName}-${runnerToStore[runner]}.json`) + const fixPath = join(fixesPath, `${appName}-${storeMap[runner]}.json`) if (!existsSync(fixPath)) return diff --git a/src/backend/main.ts b/src/backend/main.ts index ffc3105bfe..0bb43624cd 100644 --- a/src/backend/main.ts +++ b/src/backend/main.ts @@ -93,7 +93,8 @@ import { customThemesWikiLink, createNecessaryFolders, fixAsarPath, - isSnap + isSnap, + fixesPath } from './constants' import { handleProtocol } from './protocol' import { @@ -151,6 +152,7 @@ import { getGameSdl } from 'backend/storeManagers/legendary/library' import { formatSystemInfo, getSystemInfo } from './utils/systeminfo' +import { storeMap } from 'common/utils' app.commandLine?.appendSwitch('ozone-platform-hint', 'auto') @@ -1239,6 +1241,14 @@ ipcMain.handle( removeIfExists(appName.concat('-lastPlay.log')) } + const fixFilePath = path.join( + fixesPath, + `${appName}-${storeMap[runner]}.json` + ) + if (existsSync(fixFilePath)) { + rmSync(fixFilePath) + } + notify({ title, body: i18next.t('notify.uninstalled') }) logInfo('Finished uninstalling', LogPrefix.Backend) } diff --git a/src/backend/wiki_game_info/gamesdb/utils.ts b/src/backend/wiki_game_info/gamesdb/utils.ts index 896021eb89..74f6ca5c70 100644 --- a/src/backend/wiki_game_info/gamesdb/utils.ts +++ b/src/backend/wiki_game_info/gamesdb/utils.ts @@ -2,6 +2,7 @@ import { GamesDBInfo, Runner } from 'common/types' import { logInfo, LogPrefix } from 'backend/logger/logger' import { GamesDBData } from 'common/types/gog' import { getGamesdbData } from 'backend/storeManagers/gog/library' +import { storeMap } from 'common/utils' export async function getInfoFromGamesDB( title: string, @@ -10,12 +11,6 @@ export async function getInfoFromGamesDB( ): Promise { logInfo(`Getting GamesDB data for ${title}`, LogPrefix.ExtraGameInfo) - const storeMap: { [key in Runner]: string | undefined } = { - legendary: 'epic', - gog: 'gog', - nile: 'amazon', - sideload: undefined - } const storeName = storeMap[runner] if (!storeName) { return { steamID: '' } diff --git a/src/common/utils.ts b/src/common/utils.ts new file mode 100644 index 0000000000..b3fef0112c --- /dev/null +++ b/src/common/utils.ts @@ -0,0 +1,8 @@ +import { Runner } from './types' + +export const storeMap: { [key in Runner]: string | undefined } = { + legendary: 'epic', + gog: 'gog', + nile: 'amazon', + sideload: undefined +}