Merge pull request #398 from Zagrios/bugfix/handle-oculus-library-doesnt-have-originalpath

Bugfix/handle oculus library doesnt have originalpath
This commit is contained in:
MathieuG-P
2024-01-07 16:46:36 +01:00
committed by GitHub
3 changed files with 25 additions and 5 deletions
+12
View File
@@ -5,6 +5,8 @@ import { Observable, concatMap, from } from "rxjs";
import log from "electron-log";
import { BsmException } from "shared/models/bsm-exception.model";
import crypto from "crypto";
import { execSync } from "child_process";
import { tryit } from "../../shared/helpers/error.helpers";
export async function pathExist(path: string): Promise<boolean> {
try {
@@ -232,6 +234,16 @@ export async function isJunction(path: string): Promise<boolean>{
return lstats.isSymbolicLink() && stats.isDirectory();
}
export function resolveGUIDPath(guidPath: string): string {
const guidVolume = path.parse(guidPath).root;
const command = `powershell -command "(Get-WmiObject -Class Win32_Volume | Where-Object { $_.DeviceID -like '${guidVolume}' }).DriveLetter"`;
const {result: driveLetter, error} = tryit(() => execSync(command).toString().trim());
if (!driveLetter || error) {
throw new Error("Unable to resolve GUID path", error);
}
return path.join(driveLetter, path.relative(guidVolume, guidPath));
}
export interface Progression<T = unknown> {
total: number;
current: number;
@@ -34,7 +34,9 @@ export class OculusLauncherService extends AbstractLauncherService implements St
this.pathsService = InstallationLocationService.getInstance();
this.oculus.tryGetGameFolder([OCULUS_BS_DIR, OCULUS_BS_BACKUP_DIR]).then(async dirPath => {
if(dirPath){ return this.oculusLib$.next( path.join(dirPath, "..") ); }
if(dirPath){
return this.oculusLib$.next( path.join(dirPath, "..") );
}
const defaultLib = ((await this.oculus.getOculusLibs()) || []).find(lib => lib.isDefault);
if(defaultLib?.path){ return this.oculusLib$.next(path.join(defaultLib.path, "Software")); }
this.oculusLib$.next(null);
+10 -4
View File
@@ -1,8 +1,9 @@
import { list } from "regedit-rs";
import path from "path";
import { pathExist } from "../helpers/fs.helpers";
import { pathExist, resolveGUIDPath } from "../helpers/fs.helpers";
import log from "electron-log";
import { lstat } from "fs-extra";
import { tryit } from "../../shared/helpers/error.helpers";
export class OculusService {
private static instance: OculusService;
@@ -42,11 +43,16 @@ export class OculusService {
await Promise.all(libsRegData.keys.map(async key => {
const originalPath = await list([`${oculusLibsRegKey}\\${key}`]).then(res => res[`${oculusLibsRegKey}\\${key}`]);
if (!originalPath.values?.OriginalPath) {
return null;
if (originalPath.values?.OriginalPath) {
return { id: key, path: originalPath.values.OriginalPath.value, isDefault: defaultLibraryId === key } as OculusLibrary;
}
if(originalPath.values?.Path) {
const { result } = tryit(() => resolveGUIDPath(originalPath.values.Path.value as string));
return result ? { id: key, path: result, isDefault: defaultLibraryId === key } as OculusLibrary : null;
}
return { id: key, path: originalPath.values.OriginalPath.value, isDefault: defaultLibraryId === key } as OculusLibrary
return null;
}, []))
).filter(Boolean);