Skip to content

Commit

Permalink
fix cannot read installed version when steam is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
Zagrios committed Oct 23, 2022
1 parent 4abf0e9 commit 6e07adb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/services/bs-local-version.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
14 changes: 9 additions & 5 deletions src/main/services/steam.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6e07adb

Please sign in to comment.