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 { backupsPath } from "@main/constants";
|
||||||
import type { GameShop } from "@types";
|
import type { GameShop } from "@types";
|
||||||
|
|
||||||
|
import os from "node:os";
|
||||||
|
|
||||||
import YAML from "yaml";
|
import YAML from "yaml";
|
||||||
|
|
||||||
export interface LudusaviBackup {
|
export interface LudusaviBackup {
|
||||||
|
@ -20,14 +22,27 @@ export interface LudusaviBackup {
|
||||||
}
|
}
|
||||||
|
|
||||||
const replaceLudusaviBackupWithCurrentUser = (
|
const replaceLudusaviBackupWithCurrentUser = (
|
||||||
mappingPath: string,
|
gameBackupPath: string,
|
||||||
backupHomeDir: string
|
backupHomeDir: string
|
||||||
) => {
|
) => {
|
||||||
const data = fs.readFileSync(mappingPath, "utf8");
|
const mappingYamlPath = path.join(gameBackupPath, "mapping.yaml");
|
||||||
const manifest = YAML.parse(data);
|
|
||||||
|
const data = fs.readFileSync(mappingYamlPath, "utf8");
|
||||||
|
const manifest = YAML.parse(data) as {
|
||||||
|
backups: LudusaviBackup[];
|
||||||
|
drives: Record<string, string>;
|
||||||
|
};
|
||||||
|
|
||||||
const currentHomeDir = app.getPath("home");
|
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 backups = manifest.backups.map((backup: LudusaviBackup) => {
|
||||||
const files = Object.entries(backup.files).reduce((prev, [key, value]) => {
|
const files = Object.entries(backup.files).reduce((prev, [key, value]) => {
|
||||||
return {
|
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 (
|
const downloadGameArtifact = async (
|
||||||
|
@ -89,15 +106,11 @@ const downloadGameArtifact = async (
|
||||||
const [game] = await Ludusavi.findGames(shop, objectId);
|
const [game] = await Ludusavi.findGames(shop, objectId);
|
||||||
if (!game) throw new Error("Game not found in Ludusavi manifest");
|
if (!game) throw new Error("Game not found in Ludusavi manifest");
|
||||||
|
|
||||||
const mappingPath = path.join(
|
replaceLudusaviBackupWithCurrentUser(
|
||||||
backupsPath,
|
path.join(backupPath, game),
|
||||||
`${shop}-${objectId}`,
|
path.normalize(homeDir).replace(/\\/g, "/")
|
||||||
game,
|
|
||||||
"mapping.yaml"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
replaceLudusaviBackupWithCurrentUser(mappingPath, homeDir);
|
|
||||||
|
|
||||||
Ludusavi.restoreBackup(backupPath).then(() => {
|
Ludusavi.restoreBackup(backupPath).then(() => {
|
||||||
WindowManager.mainWindow?.webContents.send(
|
WindowManager.mainWindow?.webContents.send(
|
||||||
`on-backup-download-complete-${objectId}-${shop}`,
|
`on-backup-download-complete-${objectId}-${shop}`,
|
||||||
|
|
|
@ -50,7 +50,7 @@ const uploadSaveGame = async (
|
||||||
shop,
|
shop,
|
||||||
objectId,
|
objectId,
|
||||||
hostname: os.hostname(),
|
hostname: os.hostname(),
|
||||||
homeDir: app.getPath("home"),
|
homeDir: path.normalize(app.getPath("home")).replace(/\\/g, "/"),
|
||||||
platform: os.platform(),
|
platform: os.platform(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue