diff --git a/src/main/services/configuration.service.ts b/src/main/services/configuration.service.ts index a299d281..c1270769 100644 --- a/src/main/services/configuration.service.ts +++ b/src/main/services/configuration.service.ts @@ -1,6 +1,7 @@ import ElectronStore from "electron-store"; import fs from "fs-extra"; import { InstallationLocationService } from "./installation-location.service"; +import { CustomError } from "shared/models/exceptions/custom-error.class"; export class ConfigurationService { private static instance: ConfigurationService; @@ -14,6 +15,7 @@ export class ConfigurationService { private readonly locations: InstallationLocationService; + private contentPath: string; private store: ElectronStore; private constructor() { @@ -29,6 +31,7 @@ export class ConfigurationService { return; } + this.contentPath = contentPath; this.store = new ElectronStore({ cwd: contentPath, name: "config", @@ -37,15 +40,25 @@ export class ConfigurationService { }); } + private checkStore(): void { + // Can be null if config.cfg does not exist or corrupted + if (!this.store) { + throw CustomError.fromError(new Error(`Can't read config.cfg on ${this.contentPath}`)); + } + } + public set(key: string, value: unknown): void { + this.checkStore(); this.store.set(key, value); } public get(key: string): T { + this.checkStore(); return this.store.get(key) as T; } public delete(key: string): void { + this.checkStore(); this.store.delete(key); } } diff --git a/src/renderer/components/modal/modal-types/ask-install-path.component.tsx b/src/renderer/components/modal/modal-types/ask-install-path.component.tsx index eb94fcde..c712b118 100644 --- a/src/renderer/components/modal/modal-types/ask-install-path.component.tsx +++ b/src/renderer/components/modal/modal-types/ask-install-path.component.tsx @@ -77,7 +77,7 @@ export const AskInstallPathModal: ModalComponent<{ installPath: string }, {}> = @@ -88,14 +88,14 @@ export const AskInstallPathModal: ModalComponent<{ installPath: string }, {}> = className="col-start-3 rounded-md text-center transition-all" onClick={onDefaultButtonPressed} withBar={false} - text={"modals.ask-install-path.default"} + text="modals.ask-install-path.default" /> diff --git a/src/renderer/services/setup.service.ts b/src/renderer/services/setup.service.ts index 92448a8c..316e1710 100644 --- a/src/renderer/services/setup.service.ts +++ b/src/renderer/services/setup.service.ts @@ -33,6 +33,7 @@ export class SetupService { public async check(): Promise { try { + // NOTE: for modal sequencing await this.checkInstallationPath(); } catch (error) { logRenderError(error); @@ -57,7 +58,7 @@ export class SetupService { await lastValueFrom(this.steamDownloaderService.setInstallationFolder(modalResponse.data.installPath)); // Refresh the versions tab - await this.versionManagerService.askInstalledVersions() + await this.versionManagerService.askInstalledVersions(); } catch (error) { logRenderError(error); }