[feat-75] support multiple drag and drop zip files for maps

fixed issue in map downloads where download listener in MapsDownloaderService was not being removed
This commit is contained in:
silentrald
2024-09-10 00:03:02 +08:00
parent 0f3de55e9e
commit 7c88ea46e0
14 changed files with 144 additions and 31 deletions
+2 -2
View File
@@ -22,9 +22,9 @@ ipc.on("export-maps", async (args, reply) => {
reply(await maps.exportMaps(args.version, args.maps, args.outPath));
});
ipc.on("bs-maps.import-map", async (args, reply) => {
ipc.on("bs-maps.import-maps", async (args, reply) => {
const maps = LocalMapsManagerService.getInstance();
reply(from(maps.importMap(args.path, args.version)));
reply(maps.importMaps(args.paths, args.version));
})
ipc.on("bs-maps.download-map", async (args, reply) => {
@@ -328,7 +328,37 @@ export class LocalMapsManagerService {
return null;
}
public async importMap(zipPath: string, version?: BSVersion): Promise<BsmLocalMap> {
public importMaps(zipPaths: string[], version?: BSVersion): Observable<Progression> {
const progress: Progression<string> = {
total: zipPaths.length,
current: 0,
data: "",
};
return new Observable<Progression<string>>(observer => {
(async () => {
for (const zipPath of zipPaths) {
++progress.current;
progress.data = zipPath;
observer.next(progress);
try {
await this.importMap(zipPath, version);
} catch (error: any) {
log.error(`Could not import "${zipPath}"`, error);
this.ipc.send<{map: string, error: string}>(
"map-not-imported",
this.windows.getWindows("index.html").at(0),
{ map: zipPath, error: error.code }
);
}
}
observer.complete();
})();
});
}
private async importMap(zipPath: string, version?: BSVersion): Promise<BsmLocalMap> {
try {
if (!pathExistsSync(zipPath)) {
throw new CustomError(`Zip file "${zipPath}" does not exist`, "not-found-zip");
@@ -365,7 +395,7 @@ export class LocalMapsManagerService {
localMap.songDetails = this.songDetailsCache.getSongDetails(localMap.hash);
this.ipc.send<{map: BsmLocalMap, version?: BSVersion}>(
"map-downloaded",
"map-imported",
this.windows.getWindows("index.html").at(0),
{ map: localMap, version }
);