diff --git a/src/main/services/bs-local-version.service.ts b/src/main/services/bs-local-version.service.ts index 8ffb588d..59ca0c6f 100644 --- a/src/main/services/bs-local-version.service.ts +++ b/src/main/services/bs-local-version.service.ts @@ -102,7 +102,7 @@ export class BSLocalVersionService{ public async getInstalledVersions(): Promise{ const versions: BSVersion[] = []; - const steamBsFolder = await this.steamService.getGameFolder(BS_APP_ID, "Beat Saber") + const steamBsFolder = await this.steamService.getGameFolder(BS_APP_ID, "Beat Saber"); if(steamBsFolder && this.utilsService.pathExist(steamBsFolder)){ const steamBsVersion = await this.getVersionOfBSFolder(steamBsFolder); if(steamBsVersion){ diff --git a/src/main/services/steam.service.ts b/src/main/services/steam.service.ts index f678cd74..c880f97b 100644 --- a/src/main/services/steam.service.ts +++ b/src/main/services/steam.service.ts @@ -27,27 +27,31 @@ export class SteamService{ } public async getSteamPath(): Promise{ - if(this.steamPath !== ''){ return this.steamPath; } + + if(!!this.steamPath){ return this.steamPath; } + const [win32Res, win64Res] = await Promise.all([ regedit.promisified.list(['HKLM\\SOFTWARE\\Valve\\Steam']), regedit.promisified.list(['HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam']) ]); + const [win32, win64] = [win32Res["HKLM\\SOFTWARE\\Valve\\Steam"], win64Res["HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam"]]; - let res = '' - if(win64.values.InstallPath.value){ res = win64.values.InstallPath.value as string; } - else if(win32.values.InstallPath.value){ res = win32.values.InstallPath.value as string; } + + let res = ''; + if(win64.exists && win64?.values?.InstallPath?.value){ res = win64.values.InstallPath.value as string; } + else if(win32.exists && win32?.values?.InstallPath?.value){ res = win32.values.InstallPath.value as string; } this.steamPath = res; return this.steamPath; } public async getGameFolder(gameId: string, gameFolder?: string): Promise{ const steamPath = await this.getSteamPath(); + let libraryFolders: any = path.join(steamPath, 'steamapps', 'libraryfolders.vdf'); if(!this.utils.pathExist(libraryFolders)){ return null; } libraryFolders = parse(await readFile(libraryFolders, {encoding: 'utf-8'})); - if(!libraryFolders.libraryfolders){ return null; } libraryFolders = libraryFolders.libraryfolders