diff --git a/src/main/events/cloud-save/download-game-artifact.ts b/src/main/events/cloud-save/download-game-artifact.ts index 52444f60..65e7bf45 100644 --- a/src/main/events/cloud-save/download-game-artifact.ts +++ b/src/main/events/cloud-save/download-game-artifact.ts @@ -8,7 +8,7 @@ import { backupsPath } from "@main/constants"; import type { GameShop, LudusaviBackupMapping } from "@types"; import YAML from "yaml"; -import { normalizePath } from "@main/helpers"; +import { addTrailingSlash, normalizePath } from "@main/helpers"; import { SystemPath } from "@main/services/system-path"; import { gamesSublevel, levelKeys } from "@main/level"; @@ -16,7 +16,9 @@ export const transformLudusaviBackupPathIntoWindowsPath = ( backupPath: string, winePrefixPath?: string | null ) => { - return backupPath.replace(winePrefixPath ?? "", "").replace("drive_c", "C:"); + return backupPath + .replace(winePrefixPath ? addTrailingSlash(winePrefixPath) : "", "") + .replace("drive_c", "C:"); }; const restoreLudusaviBackup = ( @@ -35,8 +37,8 @@ const restoreLudusaviBackup = ( drives: Record; }; - const { userProfilePath, publicProfilePath } = - CloudSync.getProfilePaths(winePrefixPath); + const userProfilePath = + CloudSync.getWindowsLikeUserProfilePath(winePrefixPath); manifest.backups.forEach((backup) => { Object.keys(backup.files).forEach((key) => { @@ -54,9 +56,7 @@ const restoreLudusaviBackup = ( const destinationPath = transformLudusaviBackupPathIntoWindowsPath( key, artifactWinePrefixPath - ) - .replace(homeDir, userProfilePath) - .replace("C:/Users/Public", publicProfilePath); + ).replace(homeDir, userProfilePath); logger.info(`Moving ${sourcePath} to ${destinationPath}`); diff --git a/src/main/helpers/index.ts b/src/main/helpers/index.ts index 695bc95f..2da49a1c 100644 --- a/src/main/helpers/index.ts +++ b/src/main/helpers/index.ts @@ -33,4 +33,7 @@ export const isPortableVersion = () => { export const normalizePath = (str: string) => path.posix.normalize(str).replace(/\\/g, "/"); +export const addTrailingSlash = (str: string) => + str.endsWith("/") ? str : `${str}/`; + export * from "./reg-parser"; diff --git a/src/main/services/cloud-sync.ts b/src/main/services/cloud-sync.ts index 1195abe8..79ec2756 100644 --- a/src/main/services/cloud-sync.ts +++ b/src/main/services/cloud-sync.ts @@ -17,9 +17,7 @@ import i18next, { t } from "i18next"; import { SystemPath } from "./system-path"; export class CloudSync { - public static getProfilePaths(winePrefixPath?: string | null) { - const currentHomeDir = normalizePath(SystemPath.getPath("home")); - + public static getWindowsLikeUserProfilePath(winePrefixPath?: string | null) { if (process.platform === "linux") { if (!winePrefixPath) { throw new Error("Wine prefix path is required"); @@ -43,25 +41,13 @@ export class CloudSync { const userProfile = String(values["USERPROFILE"]); if (userProfile) { - return { - userProfilePath: path.join( - winePrefixPath, - normalizePath(userProfile.replace("C:", "drive_c")) - ), - publicProfilePath: path.join( - winePrefixPath, - "drive_c", - "users", - "Public" - ), - }; + return normalizePath(userProfile.replace("C:", "drive_c")); + } else { + throw new Error("User profile not found in user.reg"); } } - return { - userProfilePath: currentHomeDir, - publicProfilePath: path.join("C:", "Users", "Public"), - }; + return normalizePath(SystemPath.getPath("home")); } public static getBackupLabel(automatic: boolean) { @@ -150,8 +136,7 @@ export class CloudSync { objectId, hostname: os.hostname(), winePrefixPath: game?.winePrefixPath ?? null, - homeDir: this.getProfilePaths(game?.winePrefixPath ?? null) - .userProfilePath, + homeDir: this.getWindowsLikeUserProfilePath(game?.winePrefixPath ?? null), downloadOptionTitle, platform: os.platform(), label,