mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
single maps deletion finished
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<void>{
|
||||
public async deleteFolder(folderPath: string): Promise<void>{
|
||||
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<void>{
|
||||
|
||||
Reference in New Issue
Block a user