From 1df2353f0621d4b81e7e1e0e34689f47233297d7 Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Mon, 12 May 2025 17:31:47 +0100 Subject: [PATCH] fix: using realpath for fedora wine prefix --- src/locales/en/translation.json | 5 ++- src/locales/es/translation.json | 5 ++- src/locales/pt-BR/translation.json | 4 ++- .../get-default-wine-prefix-selection-path.ts | 32 +++++++++++-------- .../events/library/select-game-wine-prefix.ts | 22 ++++++++++--- src/main/services/cloud-sync.ts | 6 ++-- 6 files changed, 51 insertions(+), 23 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 5b5579ae..d226e8e1 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -199,7 +199,10 @@ "game_removed_from_favorites": "Game removed from favorites", "game_added_to_favorites": "Game added to favorites", "automatically_extract_downloaded_files": "Automatically extract downloaded files", - "create_start_menu_shortcut": "Create Start Menu shortcut" + "create_start_menu_shortcut": "Create Start Menu shortcut", + "invalid_wine_prefix_path": "Invalid Wine prefix path", + "invalid_wine_prefix_path_description": "The path to the Wine prefix is invalid. Please check the path and try again.", + "missing_wine_prefix": "Wine prefix is required to create a backup on Linux" }, "activation": { "title": "Activate Hydra", diff --git a/src/locales/es/translation.json b/src/locales/es/translation.json index f960b70e..82dad2ba 100644 --- a/src/locales/es/translation.json +++ b/src/locales/es/translation.json @@ -198,7 +198,10 @@ "download_error_not_cached_on_real_debrid": "Esta descarga no está disponible en Real-Debrid y el estado de descarga del sondeo de Real-Debrid aún no está disponible.", "download_error_not_cached_on_torbox": "Esta descarga no está disponible en TorBox y el estado de descarga del sondeo aún no está disponible.", "game_added_to_favorites": "Juego añadido a favoritos", - "game_removed_from_favorites": "Juego removido de favoritos" + "game_removed_from_favorites": "Juego removido de favoritos", + "invalid_wine_prefix_path": "Ruta de prefixo Wine inválida", + "invalid_wine_prefix_path_description": "La ruta al prefixo Wine es inválida. Por favor, verifica la ruta y vuelve a intentarlo.", + "missing_wine_prefix": "" }, "activation": { "title": "Activar Hydra", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index bf9c6e46..56dc8d44 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -188,7 +188,9 @@ "game_removed_from_favorites": "Jogo removido dos favoritos", "game_added_to_favorites": "Jogo adicionado aos favoritos", "automatically_extract_downloaded_files": "Extrair automaticamente os arquivos baixados", - "create_start_menu_shortcut": "Criar atalho no Menu Iniciar" + "create_start_menu_shortcut": "Criar atalho no Menu Iniciar", + "invalid_wine_prefix_path": "Caminho do prefixo Wine inválido", + "invalid_wine_prefix_path_description": "O caminho para o prefixo Wine é inválido. Por favor, verifique o caminho e tente novamente." }, "activation": { "title": "Ativação", diff --git a/src/main/events/library/get-default-wine-prefix-selection-path.ts b/src/main/events/library/get-default-wine-prefix-selection-path.ts index 27ea03bf..94f57d38 100644 --- a/src/main/events/library/get-default-wine-prefix-selection-path.ts +++ b/src/main/events/library/get-default-wine-prefix-selection-path.ts @@ -1,4 +1,4 @@ -import { SystemPath } from "@main/services"; +import { logger, SystemPath } from "@main/services"; import fs from "node:fs"; import path from "node:path"; import { registerEvent } from "../register-event"; @@ -6,20 +6,26 @@ import { registerEvent } from "../register-event"; const getDefaultWinePrefixSelectionPath = async ( _event: Electron.IpcMainInvokeEvent ) => { - const steamWinePrefixes = path.join( - SystemPath.getPath("home"), - ".local", - "share", - "Steam", - "steamapps", - "compatdata" - ); + try { + const steamWinePrefixes = path.join( + SystemPath.getPath("home"), + ".local", + "share", + "Steam", + "steamapps", + "compatdata" + ); - if (fs.existsSync(steamWinePrefixes)) { - return steamWinePrefixes; + if (fs.existsSync(steamWinePrefixes)) { + return fs.promises.realpath(steamWinePrefixes); + } + + return null; + } catch (err) { + logger.error("Failed to get default wine prefix selection path", err); + + return null; } - - return null; }; registerEvent( diff --git a/src/main/events/library/select-game-wine-prefix.ts b/src/main/events/library/select-game-wine-prefix.ts index ddb0f575..a0452302 100644 --- a/src/main/events/library/select-game-wine-prefix.ts +++ b/src/main/events/library/select-game-wine-prefix.ts @@ -1,4 +1,5 @@ import { registerEvent } from "../register-event"; +import fs from "node:fs"; import { levelKeys, gamesSublevel } from "@main/level"; import { Wine } from "@main/services"; import type { GameShop } from "@types"; @@ -9,19 +10,30 @@ const selectGameWinePrefix = async ( objectId: string, winePrefixPath: string | null ) => { - if (winePrefixPath && !Wine.validatePrefix(winePrefixPath)) { - throw new Error("Invalid wine prefix path"); - } - const gameKey = levelKeys.game(shop, objectId); const game = await gamesSublevel.get(gameKey); if (!game) return; + if (!winePrefixPath) { + await gamesSublevel.put(gameKey, { + ...game, + winePrefixPath: null, + }); + + return; + } + + const realWinePrefixPath = await fs.promises.realpath(winePrefixPath); + + if (!Wine.validatePrefix(realWinePrefixPath)) { + throw new Error("Invalid wine prefix path"); + } + await gamesSublevel.put(gameKey, { ...game, - winePrefixPath: winePrefixPath, + winePrefixPath: realWinePrefixPath, }); }; diff --git a/src/main/services/cloud-sync.ts b/src/main/services/cloud-sync.ts index 1717da6c..6da24ce1 100644 --- a/src/main/services/cloud-sync.ts +++ b/src/main/services/cloud-sync.ts @@ -135,10 +135,12 @@ export class CloudSync { shop, objectId, hostname: os.hostname(), - winePrefixPath: game?.winePrefixPath ?? null, + winePrefixPath: game?.winePrefixPath + ? fs.realpathSync(game.winePrefixPath) + : null, homeDir: this.getWindowsLikeUserProfilePath(game?.winePrefixPath ?? null), downloadOptionTitle, - platform: os.platform(), + platform: process.platform, label, });