[chore-245] clean "setInstallationDirectory" process

This commit is contained in:
MathieuG-P
2023-07-16 15:10:00 +02:00
parent cab6a90c78
commit 2d7b1bd8f3
4 changed files with 37 additions and 47 deletions
+6 -10
View File
@@ -3,8 +3,9 @@ import { BSInstallerService, DownloadEventType, DownloadInfo } from "../services
import { IpcRequest } from "shared/models/ipc";
import { InstallationLocationService } from "../services/installation-location.service";
import { UtilsService } from "../services/utils.service";
import { BsmException } from "shared/models/bsm-exception.model";
import { LocalMapsManagerService } from "../services/additional-content/local-maps-manager.service";
import { IpcService } from "../services/ipc.service";
import { from } from "rxjs";
export interface InitDownloadInfoInterface {
cwd: string;
@@ -16,6 +17,8 @@ export interface InitDownloadInfoInterface {
stay: boolean;
}
const ipc = IpcService.getInstance();
ipcMain.on("is-dotnet-6-installed", async (event, request: IpcRequest<void>) => {
const installer = BSInstallerService.getInstance();
const utils = UtilsService.getInstance();
@@ -54,16 +57,9 @@ ipcMain.on("bs-download.installation-folder", async (event, request: IpcRequest<
UtilsService.getInstance().ipcSend(request.responceChannel, { success: true, data: installationFolder });
});
ipcMain.on("bs-download.set-installation-folder", (event, request: IpcRequest<string>) => {
ipc.on<string>("bs-download.set-installation-folder", (req, reply) => {
const installerService = InstallationLocationService.getInstance();
installerService
.setInstallationDirectory(request.args)
.then(res => {
UtilsService.getInstance().ipcSend(request.responceChannel, { success: true, data: res });
})
.catch((err: BsmException) => {
UtilsService.getInstance().ipcSend(request.responceChannel, { success: false, error: err });
});
reply(from(installerService.setInstallationDirectory(req.args)));
});
ipcMain.on("bs-download.import-version", (event, request: IpcRequest<string>) => {
@@ -43,26 +43,20 @@ export class InstallationLocationService {
this.updateListeners.forEach(listener => listener());
}
public setInstallationDirectory(newDir: string): Promise<string> {
public async setInstallationDirectory(newDir: string): Promise<string> {
const oldDir = this.installationDirectory;
const newDest = path.join(newDir, this.INSTALLATION_FOLDER);
return new Promise<string>(async (resolve, reject) => {
await ensureFolderExist(oldDir);
try {
await copyDirectoryWithJunctions(oldDir, newDest, { overwrite: true });
await ensureFolderExist(oldDir);
this._installationDirectory = newDir;
this.installPathConfig.set(this.STORE_INSTALLATION_PATH_KEY, newDir);
await copyDirectoryWithJunctions(oldDir, newDest, { overwrite: true });
deleteFolder(oldDir);
this._installationDirectory = newDir;
this.installPathConfig.set(this.STORE_INSTALLATION_PATH_KEY, newDir);
return resolve(this.installationDirectory);
} catch (err) {
log.error(err);
reject(err);
}
});
deleteFolder(oldDir);
return this.installationDirectory;
}
public onInstallLocationUpdate(fn: Listener) {