mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
Merge pull request #746 from Zagrios/bugfix/clear-ipa-folder-when-installing-bsipa
[bugfix] clear the IPA folder when installing BSIPA
This commit is contained in:
@@ -10,7 +10,7 @@ import { deleteFolder, pathExist, Progression, unlinkPath } from "../../helpers/
|
||||
import { lastValueFrom, Observable } from "rxjs";
|
||||
import recursiveReadDir from "recursive-readdir";
|
||||
import { sToMs } from "../../../shared/helpers/time.helpers";
|
||||
import { copyFile, ensureDir, pathExistsSync } from "fs-extra";
|
||||
import { copyFile, ensureDir, pathExistsSync, readdirSync, rm, unlink } from "fs-extra";
|
||||
import { CustomError } from "shared/models/exceptions/custom-error.class";
|
||||
import { popElement } from "shared/helpers/array.helpers";
|
||||
import { LinuxService } from "../linux.service";
|
||||
@@ -203,6 +203,12 @@ export class BsModsManagerService {
|
||||
private async installMod(mod: BbmFullMod, version: BSVersion): Promise<boolean> {
|
||||
log.info("INSTALL MOD", mod.mod.name, "for version", `${version.BSVersion} - ${version.name}`);
|
||||
|
||||
const isBSIPA = mod.mod.name.toLowerCase() === "bsipa";
|
||||
|
||||
if(isBSIPA){
|
||||
await this.clearIpaFolder(version).catch(e => log.error("Error while clearing IPA folder", e));
|
||||
}
|
||||
|
||||
const downloadUrl = this.getModDownload(mod.version);
|
||||
|
||||
if (!downloadUrl) {
|
||||
@@ -231,7 +237,6 @@ export class BsModsManagerService {
|
||||
}
|
||||
|
||||
const versionPath = await this.bsLocalService.getVersionPath(version);
|
||||
const isBSIPA = mod.mod.name.toLowerCase() === "bsipa";
|
||||
const destDir = isBSIPA ? versionPath : path.join(versionPath, ModsInstallFolder.PENDING);
|
||||
|
||||
log.info("Start extracting mod zip", mod.mod.name, "to", destDir);
|
||||
@@ -258,6 +263,42 @@ export class BsModsManagerService {
|
||||
return res;
|
||||
}
|
||||
|
||||
private async clearIpaFolder(version: BSVersion): Promise<void> {
|
||||
log.info("Clearing IPA folder");
|
||||
|
||||
const versionPath = await this.bsLocalService.getVersionPath(version);
|
||||
const ipaPath = path.join(versionPath, ModsInstallFolder.IPA);
|
||||
|
||||
if(!pathExistsSync(ipaPath)){
|
||||
log.info("IPA folder does not exist, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
const contents = readdirSync(ipaPath, { withFileTypes: true });
|
||||
|
||||
for(const content of contents){
|
||||
|
||||
if (content.name === 'Backups' || content.name === 'Pending') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const contentPath = path.join(ipaPath, content.name);
|
||||
|
||||
const res = await tryit(() => content.isDirectory() ? (
|
||||
rm(contentPath, { force: true, recursive: true })
|
||||
) : (
|
||||
unlink(contentPath)
|
||||
));
|
||||
|
||||
if(res.error){
|
||||
log.error("Error while clearing IPA folder content", content.name, res.error);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("IPA folder cleared successfully");
|
||||
|
||||
}
|
||||
|
||||
private async uninstallBSIPA(mod: BbmFullMod, version: BSVersion): Promise<void> {
|
||||
const verionPath = await this.bsLocalService.getVersionPath(version);
|
||||
const hasIPAExe = await pathExist(path.join(verionPath, "IPA.exe"));
|
||||
|
||||
Reference in New Issue
Block a user