diff --git a/src/main/helpers/fs.helpers.ts b/src/main/helpers/fs.helpers.ts index d2ab14f3..4b2d0578 100644 --- a/src/main/helpers/fs.helpers.ts +++ b/src/main/helpers/fs.helpers.ts @@ -1,4 +1,4 @@ -import { move } from "fs-extra"; +import { copyFile, ensureDir, move, symlink } from "fs-extra"; import { access, mkdir, rm, readdir, unlink, lstat, readlink } from "fs/promises"; import path from "path"; import { Observable } from "rxjs"; @@ -81,6 +81,27 @@ export function moveFolderContent(src: string, dest: string): Observable { + + await ensureDir(destination); + const items = await readdir(source); + + for (const item of items) { + const sourcePath = path.join(source, item); + const destinationPath = path.join(destination, item); + const stats = await lstat(sourcePath); + + if (stats.isDirectory()) { + await copyDirectoryWithJunctions(sourcePath, destinationPath); + } else if (stats.isFile()) { + await copyFile(sourcePath, destinationPath); + } else if (stats.isSymbolicLink()) { + const symlinkTarget = await readlink(sourcePath); + await symlink(symlinkTarget, destinationPath, "junction"); + } + } +} + export interface Progression{ total: number; current: number; diff --git a/src/main/services/bs-local-version.service.ts b/src/main/services/bs-local-version.service.ts index 95906cf3..b4822b4c 100644 --- a/src/main/services/bs-local-version.service.ts +++ b/src/main/services/bs-local-version.service.ts @@ -5,7 +5,6 @@ import { SteamService } from "./steam.service"; import { BS_APP_ID, OCULUS_BS_DIR } from "../constants"; import path from "path"; import { createReadStream } from "fs"; -import fs from "fs-extra"; import { ConfigurationService } from "./configuration.service"; import { rename } from "fs/promises"; import { BsmException } from "shared/models/bsm-exception.model"; @@ -13,7 +12,7 @@ import log from "electron-log"; import { OculusService } from "./oculus.service"; import { DownloadLinkType } from "shared/models/mods"; import sanitize from "sanitize-filename"; -import { deleteFolder, getFoldersInFolder, pathExist } from "../helpers/fs.helpers"; +import { copyDirectoryWithJunctions, deleteFolder, getFoldersInFolder, pathExist } from "../helpers/fs.helpers"; import { FolderLinkerService } from "./folder-linker.service"; export class BSLocalVersionService{ @@ -223,7 +222,7 @@ export class BSLocalVersionService{ if(await pathExist(newPath)){ throw {title: "VersionAlreadExist"} as BsmException; } - return fs.copy(originPath, newPath, {dereference: true}).then(() => { + return copyDirectoryWithJunctions(originPath, newPath).then(() => { this.addCustomVersion(cloneVersion); return cloneVersion; }).catch((err: Error) => {