mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
edit and clone version finished
This commit is contained in:
@@ -131,7 +131,7 @@ export class BSLocalVersionService{
|
||||
}
|
||||
|
||||
public async editVersion(version: BSVersion, name: string, color: string): Promise<BSVersion>{
|
||||
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) => {
|
||||
|
||||
@@ -135,8 +135,8 @@ export function VersionViewer() {
|
||||
<BsmDropdownButton className='absolute top-5 right-5 h-9 w-9' items={[
|
||||
{text: "pages.version-viewer.dropdown.open-folder", icon: "folder", onClick: openFolder},
|
||||
{text: "pages.version-viewer.dropdown.verify-files", icon: "task", onClick: verifyFiles},
|
||||
(!state.steam && {text: "Editer (WIP)", icon: "task", onClick: edit}),
|
||||
{text: "pages.version-viewer.dropdown.clone (WIP)", icon: "copy", onClick: clone},
|
||||
(!state.steam && {text: "pages.version-viewer.dropdown.edit", icon: "task", onClick: edit}),
|
||||
{text: "pages.version-viewer.dropdown.clone", icon: "copy", onClick: clone},
|
||||
{text: "pages.version-viewer.dropdown.uninstall", icon:"trash", onClick: uninstall}
|
||||
]}/>
|
||||
</>
|
||||
|
||||
@@ -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<BSVersion[]> = new BehaviorSubject([]);
|
||||
public readonly availableVersions$: BehaviorSubject<BSVersion[]> = 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<BSVersion>("bs-version.rename", {args: {version, name: modalRes.data.name, color: modalRes.data.color}}).then(res => {
|
||||
return this.ipcService.send<BSVersion>("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<BSVersion>("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;
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export interface BsmException {
|
||||
title: string,
|
||||
msg?: string,
|
||||
error?: Error,
|
||||
}
|
||||
Reference in New Issue
Block a user