mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-15 04:32:13 +00:00
fix: fixing windows path replacement
This commit is contained in:
parent
58502aeb1f
commit
0873c8e244
2 changed files with 25 additions and 12 deletions
|
@ -8,6 +8,8 @@ import path from "node:path";
|
|||
import { backupsPath } from "@main/constants";
|
||||
import type { GameShop } from "@types";
|
||||
|
||||
import os from "node:os";
|
||||
|
||||
import YAML from "yaml";
|
||||
|
||||
export interface LudusaviBackup {
|
||||
|
@ -20,14 +22,27 @@ export interface LudusaviBackup {
|
|||
}
|
||||
|
||||
const replaceLudusaviBackupWithCurrentUser = (
|
||||
mappingPath: string,
|
||||
gameBackupPath: string,
|
||||
backupHomeDir: string
|
||||
) => {
|
||||
const data = fs.readFileSync(mappingPath, "utf8");
|
||||
const manifest = YAML.parse(data);
|
||||
const mappingYamlPath = path.join(gameBackupPath, "mapping.yaml");
|
||||
|
||||
const data = fs.readFileSync(mappingYamlPath, "utf8");
|
||||
const manifest = YAML.parse(data) as {
|
||||
backups: LudusaviBackup[];
|
||||
drives: Record<string, string>;
|
||||
};
|
||||
|
||||
const currentHomeDir = app.getPath("home");
|
||||
|
||||
// TODO: Only works on Windows
|
||||
const usersDirPath = path.join(gameBackupPath, "drive-C", "Users");
|
||||
|
||||
fs.renameSync(
|
||||
path.join(usersDirPath, path.basename(backupHomeDir)),
|
||||
path.join(usersDirPath, os.userInfo().username)
|
||||
);
|
||||
|
||||
const backups = manifest.backups.map((backup: LudusaviBackup) => {
|
||||
const files = Object.entries(backup.files).reduce((prev, [key, value]) => {
|
||||
return {
|
||||
|
@ -42,7 +57,9 @@ const replaceLudusaviBackupWithCurrentUser = (
|
|||
};
|
||||
});
|
||||
|
||||
fs.writeFileSync(mappingPath, YAML.stringify({ ...manifest, backups }));
|
||||
console.log(backups);
|
||||
|
||||
fs.writeFileSync(mappingYamlPath, YAML.stringify({ ...manifest, backups }));
|
||||
};
|
||||
|
||||
const downloadGameArtifact = async (
|
||||
|
@ -89,15 +106,11 @@ const downloadGameArtifact = async (
|
|||
const [game] = await Ludusavi.findGames(shop, objectId);
|
||||
if (!game) throw new Error("Game not found in Ludusavi manifest");
|
||||
|
||||
const mappingPath = path.join(
|
||||
backupsPath,
|
||||
`${shop}-${objectId}`,
|
||||
game,
|
||||
"mapping.yaml"
|
||||
replaceLudusaviBackupWithCurrentUser(
|
||||
path.join(backupPath, game),
|
||||
path.normalize(homeDir).replace(/\\/g, "/")
|
||||
);
|
||||
|
||||
replaceLudusaviBackupWithCurrentUser(mappingPath, homeDir);
|
||||
|
||||
Ludusavi.restoreBackup(backupPath).then(() => {
|
||||
WindowManager.mainWindow?.webContents.send(
|
||||
`on-backup-download-complete-${objectId}-${shop}`,
|
||||
|
|
|
@ -50,7 +50,7 @@ const uploadSaveGame = async (
|
|||
shop,
|
||||
objectId,
|
||||
hostname: os.hostname(),
|
||||
homeDir: app.getPath("home"),
|
||||
homeDir: path.normalize(app.getPath("home")).replace(/\\/g, "/"),
|
||||
platform: os.platform(),
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue