mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[bugfix-487] Cloning a version was changing its color even if an error was occurring
This commit is contained in:
@@ -441,7 +441,8 @@
|
||||
"CantEditSteam": "Kann nicht bearbeitet werden",
|
||||
"CantRename": "Umbenennen unmöglich",
|
||||
"VersionAlreadExist": "Diese Version existiert bereits",
|
||||
"CantClone": "Klonen unmöglich"
|
||||
"CantClone": "Klonen unmöglich",
|
||||
"UnknownError": "Ein unbekannter Fehler ist aufgetreten"
|
||||
},
|
||||
"msg": {
|
||||
"CantEditSteam": "Die Steam-Version kann nicht bearbeitet werden. Du kannst es aber klonen."
|
||||
|
||||
@@ -448,7 +448,8 @@
|
||||
"CantEditSteam": "Unable to edit",
|
||||
"CantRename": "Renaming impossible",
|
||||
"VersionAlreadExist": "This version already exists",
|
||||
"CantClone": "Cloning impossible"
|
||||
"CantClone": "Cloning impossible",
|
||||
"UnknownError": "An unknown error occurred"
|
||||
},
|
||||
"msg": {
|
||||
"CantEditSteam": "You can't edit the Steam version. You can clone it though."
|
||||
|
||||
@@ -441,7 +441,8 @@
|
||||
"CantEditSteam": "Imposible editar",
|
||||
"CantRename": "Cambio de nombre imposible",
|
||||
"VersionAlreadExist": "Esta versión ya existe",
|
||||
"CantClone": "Clonación imposible"
|
||||
"CantClone": "Clonación imposible",
|
||||
"UnknownError": "Ocurrió un error desconocido"
|
||||
},
|
||||
"msg": {
|
||||
"CantEditSteam": "No puedes editar la versión de Steam. Sin embargo, puedes clonarla."
|
||||
|
||||
@@ -441,7 +441,8 @@
|
||||
"CantEditSteam": "Modification impossible",
|
||||
"CantRename": "Renommage impossible",
|
||||
"VersionAlreadExist": "Cette version existe déjà",
|
||||
"CantClone": "Clonage impossible"
|
||||
"CantClone": "Clonage impossible",
|
||||
"UnknownError": "Une erreur inconnue s'est produite"
|
||||
},
|
||||
"msg": {
|
||||
"CantEditSteam": "Tu ne peux pas modifier la version Steam, cependant tu peux la cloner."
|
||||
|
||||
@@ -441,7 +441,8 @@
|
||||
"CantEditSteam": "編集不可",
|
||||
"CantRename": "改名不可能",
|
||||
"VersionAlreadExist": "このバージョンは既に存在しています!",
|
||||
"CantClone": "クローン作成不可"
|
||||
"CantClone": "クローン作成不可",
|
||||
"UnknownError": "不明なエラーが発生しました"
|
||||
},
|
||||
"msg": {
|
||||
"CantEditSteam": "Steam版は編集できませんがクローンを作ることは可能です。"
|
||||
|
||||
@@ -441,7 +441,8 @@
|
||||
"CantEditSteam": "Не удалось изменить",
|
||||
"CantRename": "Переименование невозможно",
|
||||
"VersionAlreadExist": "Эта версия уже добавлена",
|
||||
"CantClone": "Клонирование невозможно"
|
||||
"CantClone": "Клонирование невозможно",
|
||||
"UnknownError": "Произошла неизвестная ошибка"
|
||||
},
|
||||
"msg": {
|
||||
"CantEditSteam": "Вы не можете изменить версию из Steam, но вы можете её клонировать."
|
||||
|
||||
@@ -441,7 +441,8 @@
|
||||
"CantEditSteam": "無法編輯",
|
||||
"CantRename": "無法重命名",
|
||||
"VersionAlreadExist": "該版本已存在",
|
||||
"CantClone": "無法複製"
|
||||
"CantClone": "無法複製",
|
||||
"UnknownError": "發生了未知錯誤"
|
||||
},
|
||||
"msg": {
|
||||
"CantEditSteam": "你不能編輯 Steam 版本。不過你可以複製它。"
|
||||
|
||||
@@ -441,7 +441,8 @@
|
||||
"CantEditSteam": "无法编辑",
|
||||
"CantRename": "无法重命名",
|
||||
"VersionAlreadExist": "该版本已存在",
|
||||
"CantClone": "无法克隆"
|
||||
"CantClone": "无法克隆",
|
||||
"UnknownError": "发生了未知错误"
|
||||
},
|
||||
"msg": {
|
||||
"CantEditSteam": "你不能编辑 Steam 版本。不过你可以克隆它。"
|
||||
|
||||
@@ -6,14 +6,13 @@ import { BS_APP_ID, OCULUS_BS_BACKUP_DIR, OCULUS_BS_DIR } from "../constants";
|
||||
import path from "path";
|
||||
import { ConfigurationService } from "./configuration.service";
|
||||
import { lstat, rename } from "fs/promises";
|
||||
import { BsmException } from "shared/models/bsm-exception.model";
|
||||
import log from "electron-log";
|
||||
import { OculusService } from "./oculus.service";
|
||||
import { DownloadLinkType } from "shared/models/mods";
|
||||
import sanitize from "sanitize-filename";
|
||||
import { Progression, copyDirectoryWithJunctions, deleteFolder, ensurePathNotAlreadyExist, getFoldersInFolder, rxCopy } from "../helpers/fs.helpers";
|
||||
import { FolderLinkerService } from "./folder-linker.service";
|
||||
import { ReadStream, createReadStream, pathExists, readFile, writeFile } from "fs-extra";
|
||||
import { ReadStream, createReadStream, pathExists, pathExistsSync, readFile, writeFile } from "fs-extra";
|
||||
import readline from "readline";
|
||||
import { Observable, Subject, catchError, finalize, from, map, switchMap, throwError } from "rxjs";
|
||||
import { BsStore } from "../../shared/models/bs-store.enum";
|
||||
@@ -306,54 +305,58 @@ export class BSLocalVersionService {
|
||||
.catch(() => { return false; })
|
||||
}
|
||||
|
||||
public async editVersion(version: BSVersion, name: string, color: string): Promise<BSVersion>{
|
||||
if(version.steam || version.oculus){ throw {title: "CantEditSteam", message: "CantEditSteam"} as BsmException; }
|
||||
const oldPath = await this.getVersionPath(version);
|
||||
const editedVersion: BSVersion = version.BSVersion === name
|
||||
? {...version, name: undefined, color}
|
||||
: {...version, name: sanitize(name), color};
|
||||
const newPath = await this.getVersionPath(editedVersion);
|
||||
public async editVersion(version: BSVersion, name: string, color: string): Promise<BSVersion>{
|
||||
if(version.steam || version.oculus){ throw new CustomError("Do not edit official Beat Saber versions", "CantEditSteam") }
|
||||
const oldPath = await this.getVersionPath(version);
|
||||
const editedVersion: BSVersion = version.BSVersion === name
|
||||
? {...version, name: undefined, color}
|
||||
: {...version, name: sanitize(name), color};
|
||||
const newPath = await this.getVersionPath(editedVersion);
|
||||
|
||||
if(oldPath === newPath){
|
||||
this.deleteCustomVersion(version);
|
||||
this.addCustomVersion(editedVersion);
|
||||
return editedVersion;
|
||||
}
|
||||
if(oldPath === newPath){
|
||||
this.deleteCustomVersion(version);
|
||||
this.addCustomVersion(editedVersion);
|
||||
return editedVersion;
|
||||
}
|
||||
|
||||
if((await pathExists(newPath)) && newPath === oldPath){ throw {title: "VersionAlreadExist"} as BsmException; }
|
||||
if(pathExistsSync(newPath)){
|
||||
throw new CustomError("Unable to edit the version, path already exist", "VersionAlreadExist");
|
||||
}
|
||||
|
||||
return rename(oldPath, newPath).then(() => {
|
||||
this.deleteCustomVersion(version);
|
||||
this.addCustomVersion(editedVersion);
|
||||
return editedVersion;
|
||||
}).catch((err: Error) => {
|
||||
log.error("edit version error", err, version, name, color);
|
||||
throw {title: "CantRename", ...err} as BsmException;
|
||||
});
|
||||
}
|
||||
return rename(oldPath, newPath).then(() => {
|
||||
this.deleteCustomVersion(version);
|
||||
this.addCustomVersion(editedVersion);
|
||||
return editedVersion;
|
||||
}).catch((err: Error) => {
|
||||
log.error("edit version error", err, version, name, color);
|
||||
throw CustomError.fromError(err, "CantRename");
|
||||
});
|
||||
}
|
||||
|
||||
public async cloneVersion(version: BSVersion, name: string, color: string): Promise<BSVersion>{
|
||||
const originPath = await this.getVersionPath(version);
|
||||
const cloneVersion: BSVersion = version.BSVersion === name
|
||||
? {...version, name: undefined, color, steam: false, oculus: false}
|
||||
: {...version, name: sanitize(name), color, steam: false, oculus: false};
|
||||
const newPath = await this.getVersionPath(cloneVersion);
|
||||
public async cloneVersion(version: BSVersion, name: string, color: string): Promise<BSVersion>{
|
||||
const originPath = await this.getVersionPath(version);
|
||||
const cloneVersion: BSVersion = version.BSVersion === name
|
||||
? {...version, name: undefined, color, steam: false, oculus: false}
|
||||
: {...version, name: sanitize(name), color, steam: false, oculus: false};
|
||||
const newPath = await this.getVersionPath(cloneVersion);
|
||||
|
||||
if(originPath === newPath){
|
||||
this.deleteCustomVersion(version);
|
||||
this.addCustomVersion(cloneVersion);
|
||||
}
|
||||
if(pathExistsSync(newPath)){
|
||||
throw new CustomError("Unable to clone the version, path already exist", "VersionAlreadExist");
|
||||
}
|
||||
|
||||
if(await pathExists(newPath)){ throw {title: "VersionAlreadExist"} as BsmException; }
|
||||
if(originPath === newPath){
|
||||
this.deleteCustomVersion(version);
|
||||
this.addCustomVersion(cloneVersion);
|
||||
}
|
||||
|
||||
return copyDirectoryWithJunctions(originPath, newPath).then(() => {
|
||||
this.addCustomVersion(cloneVersion);
|
||||
return cloneVersion;
|
||||
}).catch((err: Error) => {
|
||||
log.error("clone version error", err, version, name, color);
|
||||
throw {title: "CantClone", ...err} as BsmException
|
||||
})
|
||||
}
|
||||
return copyDirectoryWithJunctions(originPath, newPath).then(() => {
|
||||
this.addCustomVersion(cloneVersion);
|
||||
return cloneVersion;
|
||||
}).catch((err: Error) => {
|
||||
log.error("Error occured while cloning the version", err, version, name, color);
|
||||
throw CustomError.fromError(err, "CantClone");
|
||||
})
|
||||
}
|
||||
|
||||
public importVersion(opt: ImportVersionOptions): Observable<Progression<BSVersion>>{
|
||||
const { fromPath, store } = opt;
|
||||
|
||||
@@ -49,7 +49,7 @@ export class IpcService {
|
||||
const sub = observable.subscribe({
|
||||
next: data => this.send(channel, window, data),
|
||||
error: error => {
|
||||
log.error(error, error?.code);
|
||||
log.error(error, error?.code, error?.data);
|
||||
this.send(this.getErrorChannel(channel), window, serializeError(error));
|
||||
},
|
||||
complete: () => this.send(this.getCompleteChannel(channel), window)
|
||||
|
||||
@@ -8,6 +8,7 @@ import { EditVersionModal } from "renderer/components/modal/modal-types/edit-ver
|
||||
import { popElement } from "shared/helpers/array.helpers";
|
||||
import { ImportVersionModal } from "renderer/components/modal/modal-types/import-version-modal.component";
|
||||
import { Progression } from "main/helpers/fs.helpers";
|
||||
import { CustomError } from "shared/models/exceptions/custom-error.class";
|
||||
|
||||
export class BSVersionManagerService {
|
||||
private static instance: BSVersionManagerService;
|
||||
@@ -77,10 +78,19 @@ export class BSVersionManagerService {
|
||||
this.askInstalledVersions();
|
||||
return res;
|
||||
}).catch(e => {
|
||||
this.notification.notifyError({
|
||||
title: `notifications.custom-version.errors.titles.${e.error.title}`,
|
||||
...(e.error.message && { desc: `notifications.custom-version.errors.msg.${e.error.message}` }),
|
||||
});
|
||||
|
||||
const knownErrorTitlesCodes = ["CantEditSteam", "VersionAlreadExist", "CantRename"];
|
||||
const knownErrorMessagesCodes = ["CantEditSteam"];
|
||||
|
||||
if(knownErrorTitlesCodes.includes(e.code)){
|
||||
this.notification.notifyError({
|
||||
title: `notifications.custom-version.errors.titles.${e.code}`,
|
||||
desc: knownErrorMessagesCodes.includes(e.code) ? `notifications.custom-version.errors.msg.${e.code}` : null
|
||||
});
|
||||
} else {
|
||||
this.notification.notifyError({ title: `notifications.custom-version.errors.titles.UnknownError` });
|
||||
}
|
||||
|
||||
return null;
|
||||
})
|
||||
}
|
||||
@@ -103,11 +113,16 @@ export class BSVersionManagerService {
|
||||
this.notification.notifySuccess({ title: "notifications.custom-version.success.titles.CloningFinished" });
|
||||
this.askInstalledVersions();
|
||||
return res;
|
||||
}).catch(e => {
|
||||
this.notification.notifyError({
|
||||
title: `notifications.custom-version.errors.titles.${e.error.title}`,
|
||||
...(e.error.message && { desc: `notifications.custom-version.errors.msg.${e.error.message}` }),
|
||||
});
|
||||
}).catch((e: CustomError) => {
|
||||
|
||||
const knownErrorTitlesCodes = ["VersionAlreadExist", "CantClone"];
|
||||
|
||||
if(knownErrorTitlesCodes.includes(e.code)){
|
||||
this.notification.notifyError({ title: `notifications.custom-version.errors.titles.${e.code}` });
|
||||
} else {
|
||||
this.notification.notifyError({ title: `notifications.custom-version.errors.titles.UnknownError` });
|
||||
}
|
||||
|
||||
return null;
|
||||
}).finally(() => {
|
||||
this.progressBar.hide(true)
|
||||
|
||||
Reference in New Issue
Block a user