diff --git a/src/main/services/bs-local-version.service.ts b/src/main/services/bs-local-version.service.ts index d908505b..d2c09148 100644 --- a/src/main/services/bs-local-version.service.ts +++ b/src/main/services/bs-local-version.service.ts @@ -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(resolve => { + return new Promise(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(this.CUSTOM_VERSIONS_KEY) || []; + return this.configService.get(this.CUSTOM_VERSIONS_KEY,this.CUSTOM_VERSIONS_KEY) || []; } private deleteCustomVersion(version: BSVersion): void{ @@ -126,7 +126,7 @@ export class BSLocalVersionService{ } public async getInstalledVersions(): Promise{ - + 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{ 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{ 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{ }) } -} \ No newline at end of file +} diff --git a/src/main/services/configuration.service.ts b/src/main/services/configuration.service.ts index 1b3a4d72..ce158e1b 100644 --- a/src/main/services/configuration.service.ts +++ b/src/main/services/configuration.service.ts @@ -1,11 +1,14 @@ +import { Console } from "console"; import ElectronStore from "electron-store"; + + export class ConfigurationService { private static instance: ConfigurationService; private readonly _stores: Map; - 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 {return this._stores} - public get store(): ElectronStore {return this._store} - - - - public set(key: string, value: any, store?: string, options?: ElectronStore.Options>): 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(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(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); + } } diff --git a/src/main/services/installation-location.service.ts b/src/main/services/installation-location.service.ts index 4503d552..48a58c66 100644 --- a/src/main/services/installation-location.service.ts +++ b/src/main/services/installation-location.service.ts @@ -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); }) }) - + } -} \ No newline at end of file +}