Skip to content

Commit

Permalink
Merge pull request #331 from Zagrios/bugfix/one-click-map-download-ma…
Browse files Browse the repository at this point in the history
…y-not-work-with-shared-maps

[bugfix] Fix OneClick map download may not work with multiple maps sharing
  • Loading branch information
Zagrios authored Oct 3, 2023
2 parents d61f59c + 92fd59b commit 139f17d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/ipcs/bs-maps-ipcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 });
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 });
}
}
Expand Down

0 comments on commit 139f17d

Please sign in to comment.