feat: adding cross cloud save

This commit is contained in:
Chubby Granny Chaser
2025-05-11 19:07:30 +01:00
parent 6c55d667bd
commit 592ac45740
20 changed files with 303 additions and 298 deletions

View File

@@ -7,7 +7,7 @@ import os from "node:os";
import type { GameShop, User } from "@types";
import { backupsPath } from "@main/constants";
import { HydraApi } from "./hydra-api";
import { normalizePath } from "@main/helpers";
import { normalizePath, parseRegFile } from "@main/helpers";
import { logger } from "./logger";
import { WindowManager } from "./window-manager";
import axios from "axios";
@@ -17,6 +17,53 @@ 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"));
if (process.platform === "linux") {
if (!winePrefixPath) {
throw new Error("Wine prefix path is required");
}
const userReg = fs.readFileSync(
path.join(winePrefixPath, "user.reg"),
"utf8"
);
const entries = parseRegFile(userReg);
const volatileEnvironment = entries.find(
(entry) => entry.path === "Volatile Environment"
);
if (!volatileEnvironment) {
throw new Error("Volatile environment not found in user.reg");
}
const { values } = volatileEnvironment;
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 {
userProfilePath: currentHomeDir,
publicProfilePath: path.join("C:", "Users", "Public"),
};
}
public static getBackupLabel(automatic: boolean) {
const language = i18next.language;
@@ -102,7 +149,9 @@ export class CloudSync {
shop,
objectId,
hostname: os.hostname(),
homeDir: normalizePath(SystemPath.getPath("home")),
winePrefixPath: game?.winePrefixPath ?? null,
homeDir: this.getProfilePaths(game?.winePrefixPath ?? null)
.userProfilePath,
downloadOptionTitle,
platform: os.platform(),
label,