mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[chore-245] clean "setInstallationDirectory" process
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -32,6 +32,8 @@ import { ModelsManagerService } from "renderer/services/models-management/models
|
||||
import { useTranslation } from "renderer/hooks/use-translation.hook";
|
||||
import { VersionFolderLinkerService } from "renderer/services/version-folder-linker.service";
|
||||
import { useService } from "renderer/hooks/use-service.hook";
|
||||
import { lastValueFrom } from "rxjs";
|
||||
import { BsmException } from "shared/models/bsm-exception.model";
|
||||
|
||||
export function SettingsPage() {
|
||||
|
||||
@@ -125,31 +127,29 @@ export function SettingsPage() {
|
||||
|
||||
notificationService.notifySuccess({ title: "notifications.settings.move-folder.success.titles.transfer-started", desc: "notifications.settings.move-folder.success.descs.transfer-started" });
|
||||
|
||||
downloaderService.setInstallationFolder(fileChooserRes.filePaths[0]).then(async res => {
|
||||
setTimeout(() => {
|
||||
progressBarService.complete();
|
||||
setTimeout(() => progressBarService.hide(true), 1000);
|
||||
}, 1000);
|
||||
lastValueFrom(downloaderService.setInstallationFolder(fileChooserRes.filePaths[0])).then(res => {
|
||||
|
||||
if (res.success) {
|
||||
setInstallationFolder(res.data);
|
||||
progressBarService.complete();
|
||||
progressBarService.hide(true);
|
||||
|
||||
notificationService.notifySuccess({ title: "notifications.settings.move-folder.success.titles.transfer-finished", duration: 3000 });
|
||||
setInstallationFolder(res);
|
||||
|
||||
versionLinker
|
||||
.relinkAllVersionsFolders()
|
||||
.toPromise()
|
||||
.catch(() => {
|
||||
notificationService.notifyError({ title: "notifications.types.error", desc: "notifications.settings.move-folder.errors.descs.restore-linked-folders", duration: 15_000 });
|
||||
});
|
||||
} else {
|
||||
if (res?.error?.code === "COPY_TO_SUBPATH") {
|
||||
notificationService.notifyError({ title: "notifications.settings.move-folder.errors.titles.transfer-failed", desc: "notifications.settings.move-folder.errors.descs.COPY_TO_SUBPATH", duration: 10_000 });
|
||||
return;
|
||||
}
|
||||
notificationService.notifySuccess({ title: "notifications.settings.move-folder.success.titles.transfer-finished", duration: 3000 });
|
||||
|
||||
notificationService.notifyError({ title: "notifications.settings.move-folder.errors.titles.transfer-failed" });
|
||||
// Restore links of external BS versions (steam, oculus, etc.)
|
||||
lastValueFrom(versionLinker.relinkAllVersionsFolders()).catch(() => {
|
||||
notificationService.notifyError({ title: "notifications.types.error", desc: "notifications.settings.move-folder.errors.descs.restore-linked-folders", duration: 15_000 });
|
||||
});
|
||||
|
||||
}).catch((err: BsmException) => {
|
||||
progressBarService.hide(true);
|
||||
|
||||
if (err?.code === "COPY_TO_SUBPATH") {
|
||||
notificationService.notifyError({ title: "notifications.settings.move-folder.errors.titles.transfer-failed", desc: "notifications.settings.move-folder.errors.descs.COPY_TO_SUBPATH", duration: 10_000 });
|
||||
return;
|
||||
}
|
||||
|
||||
notificationService.notifyError({ title: "notifications.settings.move-folder.errors.titles.transfer-failed" });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DownloadEvent, DownloadInfo } from "main/services/bs-installer.service";
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
import { BehaviorSubject, Observable } from "rxjs";
|
||||
import { distinctUntilChanged, filter, throttleTime } from "rxjs/operators";
|
||||
import { IpcResponse } from "shared/models/ipc";
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
@@ -197,8 +197,8 @@ export class BsDownloaderService {
|
||||
return this._isVerification;
|
||||
}
|
||||
|
||||
public setInstallationFolder(path: string): Promise<IpcResponse<string>> {
|
||||
return this.ipcService.send<string>("bs-download.set-installation-folder", { args: path });
|
||||
public setInstallationFolder(path: string): Observable<string> {
|
||||
return this.ipcService.sendV2<string>("bs-download.set-installation-folder", { args: path });
|
||||
}
|
||||
|
||||
public async importVersion(pathToImport: string): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user