[bugfix] Fix error when downloading playlist with OneClick and having maps linked

This commit is contained in:
MathieuG-P
2023-10-08 22:38:34 +02:00
parent 226468aa00
commit fc2cb676d2
2 changed files with 18 additions and 3 deletions
+2
View File
@@ -2,6 +2,7 @@ import { ipcMain } from "electron";
import { IpcRequest } from "shared/models/ipc";
import { LocalPlaylistsManagerService } from "../services/additional-content/local-playlists-manager.service";
import { UtilsService } from "../services/utils.service";
import log from "electron-log";
ipcMain.on("one-click-install-playlist", async (event, request: IpcRequest<string>) => {
const utils = UtilsService.getInstance();
@@ -13,6 +14,7 @@ ipcMain.on("one-click-install-playlist", async (event, request: IpcRequest<strin
utils.ipcSend(request.responceChannel, { success: true });
})
.catch(e => {
log.error(e);
utils.ipcSend(request.responceChannel, { success: false, error: e });
});
});
@@ -14,7 +14,7 @@ import { IpcRequest } from "shared/models/ipc";
import { BPList, DownloadPlaylistProgression } from "shared/models/playlists/playlist.interface";
import { copyFileSync, readFileSync } from "fs";
import { BeatSaverService } from "../thrid-party/beat-saver/beat-saver.service";
import { copySync } from "fs-extra";
import { copy, realpath } from "fs-extra";
import { ensureFolderExist, pathExist } from "../../helpers/fs.helpers";
export class LocalPlaylistsManagerService {
@@ -180,14 +180,27 @@ export class LocalPlaylistsManagerService {
const { bpListPath, mapsPath } = await lastValueFrom(this.downloadPlaylist(bpListUrl, versions.pop()));
if(mapsPath?.length === 0 || !bpListPath) {
return;
}
const realSourceMapsFolder = await realpath(path.dirname(mapsPath[0]));
for (const version of versions) {
await this.installBPListFile(bpListPath, version);
const versionMapsFolder = await this.maps.getMapsFolderPath(version);
const realDestMapsFolder = await realpath(versionMapsFolder);
if(realSourceMapsFolder === realDestMapsFolder) {
continue;
}
for (const mapPath of mapsPath) {
const versionMapsFolder = await this.maps.getMapsFolderPath(version);
const mapDest = path.join(versionMapsFolder, path.basename(mapPath));
copySync(mapPath, mapDest, { overwrite: true });
await copy(mapPath, mapDest, { overwrite: true });
}
}
}