diff --git a/src/main/services/additional-content/maps/local-maps-manager.service.ts b/src/main/services/additional-content/maps/local-maps-manager.service.ts index 904af572..03812321 100644 --- a/src/main/services/additional-content/maps/local-maps-manager.service.ts +++ b/src/main/services/additional-content/maps/local-maps-manager.service.ts @@ -334,25 +334,30 @@ export class LocalMapsManagerService { (async () => { const mapsPath = await this.getMapsFolderPath(version); - root: for(const zipPath of zipPaths) { - if(unsubscribed) { break; } + for(const zipPath of zipPaths) { + + if(unsubscribed) { + log.info("Maps importation from zip has been cancelled"); + return; + } progress = { total: 0, current: 0 }; obs.next(progress); // reset progress for each zip if(!pathExistsSync(zipPath)) { continue; } + const zip = new StreamZip.async({ file: zipPath }); const { result: zipEntries, error } = await tryit(() => zip.entries()); const zipEntriesValues = Object.values(zipEntries); if(error) { log.error("Could not read zip entries", zipPath, error); - zip.close(); + await zip.close(); continue; } const mapsFolders = zipEntriesValues.reduce((acc, entry) => { - if(!/(^|\/)(I|i)nfo.dat$/.test(entry.name)){ return acc; } + if(!/(^|\/)[I-i]nfo\.dat$/.test(entry.name)){ return acc; } acc.push(path.dirname(entry.name)); return acc; }, []); @@ -365,9 +370,11 @@ export class LocalMapsManagerService { obs.next(progress); for(const folder of mapsFolders) { + if(unsubscribed) { - zip.close(); - break root; + log.info("Maps importation from zip has been cancelled"); + await zip.close(); + return; } const isRoot = folder === "."; @@ -406,7 +413,7 @@ export class LocalMapsManagerService { obs.next(progress); } - zip.close(); + await zip.close(); } })() .then(() => { diff --git a/src/renderer/components/maps-playlists-panel/maps-playlists-panel.component.tsx b/src/renderer/components/maps-playlists-panel/maps-playlists-panel.component.tsx index 5d274785..9aa29c5a 100644 --- a/src/renderer/components/maps-playlists-panel/maps-playlists-panel.component.tsx +++ b/src/renderer/components/maps-playlists-panel/maps-playlists-panel.component.tsx @@ -107,13 +107,12 @@ export function MapsPlaylistsPanel({ version, isActive }: Props) { const handleFileDrop = async (files: FileList) => { const zipMimeTypes = ["application/zip", "application/zip-compressed", "application/x-zip-compressed"]; - const paths: string[] = []; - for (let i = 0; i < files.length; ++i) { - const file = files[i]; + const paths: string[] = Array.from(files).reduce((acc, file) => { if (zipMimeTypes.includes(file.type)) { - paths.push(window.electron.webUtils.getPathForFile(file)); + acc.push(window.electron.webUtils.getPathForFile(file)); } - } + return acc; + }, []); if (paths.length === 0) { notifications.notifyError({