mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
change and separe data config.json
This commit is contained in:
@@ -46,12 +46,12 @@ export class BSLocalVersionService{
|
||||
const versionFilePath = path.join(bsPath, 'Beat Saber_Data', 'globalgamemanagers');
|
||||
if(!this.utilsService.pathExist(versionFilePath)){ return null; }
|
||||
const versionsAvailable = await this.remoteVersionService.getAvailableVersions();
|
||||
return new Promise<string>(resolve => {
|
||||
return new Promise<string>(resolve => {
|
||||
const readLine = createInterface({ input: createReadStream(versionFilePath) });
|
||||
let findVersion: string = null;
|
||||
readLine.on('line', (line) => {
|
||||
for(const version of versionsAvailable){
|
||||
if(line.includes(version.BSVersion)){
|
||||
if(line.includes(version.BSVersion)){
|
||||
findVersion = version.BSVersion;
|
||||
readLine.close();
|
||||
break;
|
||||
@@ -66,7 +66,7 @@ export class BSLocalVersionService{
|
||||
}
|
||||
|
||||
private setCustomVersions(versions: BSVersion[]): void{
|
||||
this.configService.set(this.CUSTOM_VERSIONS_KEY, versions);
|
||||
this.configService.set(this.CUSTOM_VERSIONS_KEY, versions,this.CUSTOM_VERSIONS_KEY,this.installLocationService.installationDirectory);
|
||||
}
|
||||
|
||||
private addCustomVersion(version: BSVersion): void{
|
||||
@@ -74,7 +74,7 @@ export class BSLocalVersionService{
|
||||
}
|
||||
|
||||
private getCustomVersions(): BSVersion[]{
|
||||
return this.configService.get<BSVersion[]>(this.CUSTOM_VERSIONS_KEY) || [];
|
||||
return this.configService.get<BSVersion[]>(this.CUSTOM_VERSIONS_KEY,this.CUSTOM_VERSIONS_KEY) || [];
|
||||
}
|
||||
|
||||
private deleteCustomVersion(version: BSVersion): void{
|
||||
@@ -126,7 +126,7 @@ export class BSLocalVersionService{
|
||||
}
|
||||
|
||||
public async getInstalledVersions(): Promise<BSVersion[]>{
|
||||
|
||||
|
||||
const versions: BSVersion[] = [];
|
||||
const steamVersion = await this.getSteamVersion();
|
||||
if(steamVersion){ versions.push(steamVersion); }
|
||||
@@ -166,7 +166,7 @@ export class BSLocalVersionService{
|
||||
public async editVersion(version: BSVersion, name: string, color: string): Promise<BSVersion>{
|
||||
if(version.steam || version.oculus){ throw {title: "CantEditSteam", msg: "CantEditSteam"} as BsmException; }
|
||||
const oldPath = await this.getVersionPath(version);
|
||||
const editedVersion: BSVersion = version.BSVersion === name
|
||||
const editedVersion: BSVersion = version.BSVersion === name
|
||||
? {...version, name: undefined, color}
|
||||
: {...version, name: this.removeSpecialChar(name), color};
|
||||
const newPath = await this.getVersionPath(editedVersion);
|
||||
@@ -190,7 +190,7 @@ export class BSLocalVersionService{
|
||||
|
||||
public async cloneVersion(version: BSVersion, name: string, color: string): Promise<BSVersion>{
|
||||
const originPath = await this.getVersionPath(version);
|
||||
const cloneVersion: BSVersion = version.BSVersion === name
|
||||
const cloneVersion: BSVersion = version.BSVersion === name
|
||||
? {...version, name: undefined, color}
|
||||
: {...version, name: this.removeSpecialChar(name), color, steam: false, oculus: false};
|
||||
const newPath = await this.getVersionPath(cloneVersion);
|
||||
@@ -211,4 +211,4 @@ export class BSLocalVersionService{
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { Console } from "console";
|
||||
import ElectronStore from "electron-store";
|
||||
|
||||
|
||||
|
||||
export class ConfigurationService {
|
||||
|
||||
private static instance: ConfigurationService;
|
||||
|
||||
private readonly _stores: Map<string, ElectronStore>;
|
||||
private readonly _store: ElectronStore
|
||||
private readonly _storeFixe: ElectronStore
|
||||
|
||||
|
||||
|
||||
@@ -15,41 +18,43 @@ export class ConfigurationService {
|
||||
}
|
||||
|
||||
private constructor(){
|
||||
|
||||
this._stores = new Map();
|
||||
this._storeFixe = new ElectronStore();
|
||||
}
|
||||
|
||||
public get stores(): Map<string, ElectronStore> {return this._stores}
|
||||
public get store(): ElectronStore {return this._store}
|
||||
|
||||
|
||||
|
||||
public set(key: string, value: any, store?: string, options?: ElectronStore.Options<Record<string, any>>): void{
|
||||
|
||||
if(store && !this.stores.has(store)){
|
||||
this.stores.set(store, new ElectronStore(options));
|
||||
private getPropperStore(selectedStore?: string) : ElectronStore {
|
||||
if(selectedStore){
|
||||
return this._stores.get(selectedStore);
|
||||
}
|
||||
return this._storeFixe;
|
||||
|
||||
const eStore = !store ? this._store : this.stores.get(store)
|
||||
eStore.set(key, value);
|
||||
}
|
||||
|
||||
public get<T>(key: string,storeSelected : string): T{
|
||||
|
||||
if (storeSelected === "store"){
|
||||
return this.store.get(key) as T;
|
||||
}
|
||||
if (storeSelected === "versionBsStore"){
|
||||
return this.store.get(key) as T;
|
||||
public set(key: string, value: any, selectedStore?: string, path?: string): void{
|
||||
if(selectedStore && !this._stores.has(selectedStore)){
|
||||
this._stores.set(selectedStore, new ElectronStore({cwd:path,name:selectedStore}));
|
||||
}
|
||||
|
||||
const eStore = this.getPropperStore(selectedStore);
|
||||
eStore.set(key,value);
|
||||
|
||||
}
|
||||
|
||||
public delete(key: string,storeSelected : string): void{
|
||||
if (storeSelected === "store"){
|
||||
this.store.delete(key);
|
||||
}
|
||||
else if (storeSelected === "versionBsStore"){
|
||||
this.store.delete(key);
|
||||
}
|
||||
public get<T>(key: string,selectedStore?: string): T{
|
||||
|
||||
const eStore = this.getPropperStore(selectedStore);
|
||||
|
||||
if(!eStore){ return; }
|
||||
return eStore.get(key) as T;
|
||||
|
||||
}
|
||||
|
||||
public delete(key: string,selectedStore : string): void{
|
||||
|
||||
this.getPropperStore(selectedStore)?.delete(key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ export class InstallationLocationService {
|
||||
|
||||
public static getInstance(): InstallationLocationService{
|
||||
if(!InstallationLocationService.instance){ InstallationLocationService.instance = new InstallationLocationService(); }
|
||||
return InstallationLocationService.instance;
|
||||
return InstallationLocationService.instance;
|
||||
}
|
||||
|
||||
private constructor(){
|
||||
@@ -46,14 +46,14 @@ export class InstallationLocationService {
|
||||
if(!this.utilsService.pathExist(oldDir)){ this.utilsService.createFolderIfNotExist(oldDir); }
|
||||
fs.move(oldDir, newDest, { overwrite: true }).then(() => {
|
||||
this._installationDirectory = newDir;
|
||||
this.configService.store.set(this.STORE_INSTALLATION_PATH_KEY, newDir);
|
||||
this.configService.set(this.STORE_INSTALLATION_PATH_KEY, newDir);
|
||||
resolve(this.installationDirectory);
|
||||
}).catch((err: Error) => {
|
||||
reject({title: "CantMoveFolder", error: err} as BsmException);
|
||||
log.error(err);
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user