fix cannot read installed version when steam is not installed

This commit is contained in:
MathieuG-P
2022-10-23 21:03:32 +02:00
parent 4abf0e9ec4
commit 6e07adb990
2 changed files with 10 additions and 6 deletions
@@ -102,7 +102,7 @@ export class BSLocalVersionService{
public async getInstalledVersions(): Promise<BSVersion[]>{
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){
+9 -5
View File
@@ -27,27 +27,31 @@ export class SteamService{
}
public async getSteamPath(): Promise<string>{
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<string>{
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