Merge pull request #331 from Zagrios/bugfix/one-click-map-download-may-not-work-with-shared-maps

[bugfix] Fix OneClick map download may not work with multiple maps sharing
This commit is contained in:
MathieuG-P
2023-10-04 00:21:22 +02:00
committed by GitHub
2 changed files with 9 additions and 1 deletions
+2
View File
@@ -6,6 +6,7 @@ import { BsmLocalMap } from "shared/models/maps/bsm-local-map.interface";
import { BsvMapDetail } from "shared/models/maps";
import { IpcService } from "../services/ipc.service";
import { from } from "rxjs";
import log from "electron-log"
const ipc = IpcService.getInstance();
@@ -71,6 +72,7 @@ ipc.on("one-click-install-map", async (request: IpcRequest<BsvMapDetail>) => {
utils.ipcSend(request.responceChannel, { success: true });
})
.catch(err => {
log.error(err);
utils.ipcSend(request.responceChannel, { success: false, error: err });
});
});
@@ -7,7 +7,7 @@ import { InstallationLocationService } from "../installation-location.service";
import { UtilsService } from "../utils.service";
import crypto from "crypto";
import { lstatSync } from "fs";
import { copy, createReadStream, ensureDir, unlink } from "fs-extra";
import { copy, createReadStream, ensureDir, realpath, unlink } from "fs-extra";
import StreamZip from "node-stream-zip";
import { RequestService } from "../request.service";
import sanitize from "sanitize-filename";
@@ -290,10 +290,16 @@ export class LocalMapsManagerService {
const versions = await this.localVersion.getInstalledVersions();
const downloadedMap = await this.downloadMap(map, versions.pop());
const downloadedMapRealFolder = await realpath(path.dirname(downloadedMap.path));
for (const version of versions) {
const versionMapsPath = await this.getMapsFolderPath(version);
await ensureDir(versionMapsPath);
if((await realpath(versionMapsPath)) === downloadedMapRealFolder){
continue;
}
await copy(downloadedMap.path, path.join(versionMapsPath, path.basename(downloadedMap.path)), { overwrite: true });
}
}