diff --git a/src/main/services/maps/local-maps-manager.service.ts b/src/main/services/maps/local-maps-manager.service.ts index 98eea524..2d83781c 100644 --- a/src/main/services/maps/local-maps-manager.service.ts +++ b/src/main/services/maps/local-maps-manager.service.ts @@ -6,7 +6,7 @@ import { BSLocalVersionService } from "../bs-local-version.service"; import { InstallationLocationService } from "../installation-location.service"; import { UtilsService } from "../utils.service"; import crypto from "crypto"; -import { lstat, lstatSync, symlinkSync, readdir, fstat, unlinkSync } from "fs"; +import { lstatSync, symlinkSync, unlinkSync, readdirSync } from "fs"; import { copySync } from "fs-extra"; export class LocalMapsManagerService { @@ -128,7 +128,22 @@ export class LocalMapsManagerService { } public async deleteMaps(maps: BsmLocalMap[], verion?: BSVersion){ - // TODO + + const mapsFolder = await this.getMapsFolderPath(verion); + + const mapsHashsToDelete = maps.map(m => m.hash); + + const mapsFolders = readdirSync(mapsFolder, {withFileTypes: true}); + + for(const content of mapsFolders){ + if(!content.isDirectory()){ continue; } + const mapFolderPath = path.join(mapsFolder, content.name); + const { hash } = await this.loadMapInfoFromPath(mapFolderPath); + if(mapsHashsToDelete.includes(hash)){ + await this.utils.deleteFolder(mapFolderPath); + } + } + } diff --git a/src/main/services/utils.service.ts b/src/main/services/utils.service.ts index d0f77d5b..9f643b9e 100644 --- a/src/main/services/utils.service.ts +++ b/src/main/services/utils.service.ts @@ -1,4 +1,4 @@ -import { existsSync, mkdirSync, readdirSync, readFile, unlinkSync } from "fs"; +import { existsSync, mkdirSync, readdirSync, readFile, rmSync } from "fs"; import { moveSync } from "fs-extra" import { spawnSync } from "child_process"; import { homedir } from "os"; @@ -75,10 +75,10 @@ export class UtilsService{ return files.map(f => fullPath ? path.join(dirPath, f.name) : f.name); } - public deleteFolder(folderPath: string): Promise{ + public async deleteFolder(folderPath: string): Promise{ const folderExist = this.pathExist(folderPath); if(!folderExist){ return; } - return rm(folderPath, {recursive: true}); + return rmSync(folderPath, {recursive: true}); } public async moveDirContent(src: string, dest: string, overwrite = false): Promise{