From 63736e4e91c29de223f83e7423e462108bf7690a Mon Sep 17 00:00:00 2001 From: MathieuG-P Date: Thu, 21 Jul 2022 19:00:43 +0200 Subject: [PATCH] edit and clone version finished --- src/main/services/bs-local-version.service.ts | 5 +++-- .../pages/version-viewer.component.tsx | 4 ++-- .../services/bs-version-manager.service.ts | 18 +++++++++++++++--- src/shared/models/bsm-exception.model.ts | 1 + 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/services/bs-local-version.service.ts b/src/main/services/bs-local-version.service.ts index f7faa542..4de56cd5 100644 --- a/src/main/services/bs-local-version.service.ts +++ b/src/main/services/bs-local-version.service.ts @@ -131,7 +131,7 @@ export class BSLocalVersionService{ } public async editVersion(version: BSVersion, name: string, color: string): Promise{ - if(version.steam){ throw {title: "CantEditSteam"} as BsmException; } + if(version.steam){ throw {title: "CantEditSteam", msg: "CantEditSteam"} as BsmException; } const oldPath = await this.getVersionPath(version); const editedVersion: BSVersion = version.BSVersion === name ? {...version, name: undefined, color} @@ -168,8 +168,9 @@ export class BSLocalVersionService{ return cloneVersion; } + if(this.utilsService.pathExist(newPath)){ throw {title: "VersionAlreadExist"} as BsmException; } + return fs.copy(originPath, newPath).then(() => { - this.deleteCustomVersion(version); this.addCustomVersion(cloneVersion); return cloneVersion; }).catch((err: Error) => { diff --git a/src/renderer/pages/version-viewer.component.tsx b/src/renderer/pages/version-viewer.component.tsx index 797388eb..63e77194 100644 --- a/src/renderer/pages/version-viewer.component.tsx +++ b/src/renderer/pages/version-viewer.component.tsx @@ -135,8 +135,8 @@ export function VersionViewer() { diff --git a/src/renderer/services/bs-version-manager.service.ts b/src/renderer/services/bs-version-manager.service.ts index 7323c0ff..44f07e2e 100644 --- a/src/renderer/services/bs-version-manager.service.ts +++ b/src/renderer/services/bs-version-manager.service.ts @@ -3,6 +3,7 @@ import { BehaviorSubject } from "rxjs"; import { IpcService } from "./ipc.service"; import { ModalExitCode, ModalService, ModalType } from './modale.service'; import { NotificationService } from './notification.service'; +import { ProgressBarService } from './progress-bar.service'; export class BSVersionManagerService { @@ -11,6 +12,7 @@ export class BSVersionManagerService { private readonly ipcService: IpcService; private readonly modalService: ModalService; private readonly notificationService: NotificationService; + private readonly progressBarService: ProgressBarService; public readonly installedVersions$: BehaviorSubject = new BehaviorSubject([]); public readonly availableVersions$: BehaviorSubject = new BehaviorSubject([]); @@ -19,6 +21,7 @@ export class BSVersionManagerService { this.ipcService = IpcService.getInstance(); this.modalService = ModalService.getInsance(); this.notificationService = NotificationService.getInstance(); + this.progressBarService = ProgressBarService.getInstance(); this.askAvailableVersions(); this.askInstalledVersions(); } @@ -66,9 +69,12 @@ export class BSVersionManagerService { const modalRes = await this.modalService.openModal<{name: string, color: string}>(ModalType.EDIT_VERSION, version); if(modalRes.exitCode !== ModalExitCode.COMPLETED){ return null; } if(modalRes.data.name?.length < 2){ return null; } - return this.ipcService.send("bs-version.rename", {args: {version, name: modalRes.data.name, color: modalRes.data.color}}).then(res => { + return this.ipcService.send("bs-version.edit", {args: {version, name: modalRes.data.name, color: modalRes.data.color}}).then(res => { if(!res.success){ - this.notificationService.notifyError({title: res.error.title}); + this.notificationService.notifyError({ + title: `notifications.custom-version.errors.titles.${res.error.title}`, + ...(res.error.msg && {desc: `notifications.custom-version.errors.msg.${res.error.msg}`}) + }); return null; } this.askInstalledVersions(); @@ -80,11 +86,17 @@ export class BSVersionManagerService { const modalRes = await this.modalService.openModal<{name: string, color: string}>(ModalType.CLONE_VERSION, version); if(modalRes.exitCode !== ModalExitCode.COMPLETED){ return null; } if(modalRes.data.name?.length < 2){ return null; } + this.progressBarService.showFake(0.01); return this.ipcService.send("bs-version.clone", {args: {version, name: modalRes.data.name, color: modalRes.data.color}}).then(res => { + this.progressBarService.hide(true); if(!res.success){ - this.notificationService.notifyError({title: res.error.title}); + this.notificationService.notifyError({ + title: `notifications.custom-version.errors.titles.${res.error.title}`, + ...(res.error.msg && {desc: `notifications.custom-version.errors.msg.${res.error.msg}`}) + }); return null; } + this.notificationService.notifySuccess({title: "notifications.custom-version.success.titles.CloningFinished"}); this.askInstalledVersions(); return res.data; }) diff --git a/src/shared/models/bsm-exception.model.ts b/src/shared/models/bsm-exception.model.ts index 3b90aad0..2d251143 100644 --- a/src/shared/models/bsm-exception.model.ts +++ b/src/shared/models/bsm-exception.model.ts @@ -1,4 +1,5 @@ export interface BsmException { title: string, + msg?: string, error?: Error, } \ No newline at end of file