From a4713af6188e92c103fb2985db3436b53bd00816 Mon Sep 17 00:00:00 2001 From: Shaw Young Date: Thu, 5 Dec 2019 22:18:45 +0000 Subject: [PATCH] Bug/issue 2: Adding support for multiple Oculus libraries, in different locations (#5) * support for multiple oculus library locations * Fixing paths from alternative libraries --- OculusLibrary/OculusLibraryPlugin.cs | 154 ++++++++++++++++++--------- 1 file changed, 105 insertions(+), 49 deletions(-) diff --git a/OculusLibrary/OculusLibraryPlugin.cs b/OculusLibrary/OculusLibraryPlugin.cs index c516fd9..54e4daa 100644 --- a/OculusLibrary/OculusLibraryPlugin.cs +++ b/OculusLibrary/OculusLibraryPlugin.cs @@ -34,67 +34,78 @@ public override IEnumerable GetGames() var gameInfos = new List(); - var oculusBasePath = GetOculusBasePath(); + var oculusLibraryLocations = GetOculusLibraryLocations(); - if (string.IsNullOrWhiteSpace(oculusBasePath)) + if (oculusLibraryLocations == null || !oculusLibraryLocations.Any()) { - logger.Error($"Cannot ascertain Oculus base path"); + logger.Error($"Cannot ascertain Oculus library locations"); return gameInfos; } using (var view = PlayniteApi.WebViews.CreateOffscreenView()) { - foreach (var manifest in GetOculusAppManifests(oculusBasePath)) + foreach (var oculusBasePath in oculusLibraryLocations) { - try + logger.Info($"Processing Oculus library location {oculusBasePath}"); + + foreach (var manifest in GetOculusAppManifests(oculusBasePath)) { - var executableFullPath = $@"{oculusBasePath}Software\Software\{manifest.CanonicalName}\{manifest.LaunchFile}"; + logger.Info($"Processing manifest {manifest.CanonicalName} {manifest.AppId}"); - // set a default name - var executableName = Path.GetFileNameWithoutExtension(executableFullPath); + try + { + var executableFullPath = $@"{oculusBasePath}\Software\{manifest.CanonicalName}\{manifest.LaunchFile}"; - var icon = $@"{oculusBasePath}CoreData\Software\StoreAssets\{manifest.CanonicalName}_assets\icon_image.jpg"; + // set a default name + var executableName = Path.GetFileNameWithoutExtension(executableFullPath); - if (!File.Exists(icon)) - { - logger.Debug($"Oculus store icon missing from file system- reverting to executable icon"); - icon = executableFullPath; - } + var icon = $@"{oculusBasePath}zCoreData\Software\StoreAssets\{manifest.CanonicalName}_assets\icon_image.jpg"; - var backgroundImage = $@"{oculusBasePath}CoreData\Software\StoreAssets\{manifest.CanonicalName}_assets\cover_landscape_image_large.png"; + if (!File.Exists(icon)) + { + logger.Debug($"Oculus store icon missing from file system- reverting to executable icon"); + icon = executableFullPath; + } - if (!File.Exists(backgroundImage)) - { - logger.Debug($"Oculus store background missing from file system- selecting no background"); - backgroundImage = string.Empty; - } + var backgroundImage = $@"{oculusBasePath}zCoreData\Software\StoreAssets\{manifest.CanonicalName}_assets\cover_landscape_image_large.png"; - var scrapedData = oculusScraper.ScrapeDataForApplicationId(view, manifest.AppId); + if (!File.Exists(backgroundImage)) + { + logger.Debug($"Oculus store background missing from file system- selecting no background"); + backgroundImage = string.Empty; + } - if (scrapedData == null) - { - logger.Debug($"Failed to retrieve scraped data for game"); - } + var scrapedData = oculusScraper.ScrapeDataForApplicationId(view, manifest.AppId); - gameInfos.Add(new GameInfo - { - Name = scrapedData?.Name ?? executableName, - Description = scrapedData?.Description ?? string.Empty, - GameId = manifest.AppId, - PlayAction = new GameAction + if (scrapedData == null) { - Type = GameActionType.File, - Path = executableFullPath, - Arguments = manifest.LaunchParameters - }, - IsInstalled = true, - Icon = icon, - BackgroundImage = backgroundImage - }); - } - catch (Exception ex) - { - logger.Error($"Exception while adding game for manifest {manifest.AppId} : {ex}"); + logger.Debug($"Failed to retrieve scraped data for game"); + } + + logger.Info($"Executable {executableFullPath}"); + + gameInfos.Add(new GameInfo + { + Name = scrapedData?.Name ?? executableName, + Description = scrapedData?.Description ?? string.Empty, + GameId = manifest.AppId, + PlayAction = new GameAction + { + Type = GameActionType.File, + Path = executableFullPath, + Arguments = manifest.LaunchParameters + }, + IsInstalled = true, + Icon = icon, + BackgroundImage = backgroundImage + }); + + logger.Info($"Completed manifest {manifest.CanonicalName} {manifest.AppId}"); + } + catch (Exception ex) + { + logger.Error($"Exception while adding game for manifest {manifest.AppId} : {ex}"); + } } } } @@ -108,7 +119,7 @@ private IEnumerable GetOculusAppManifests(string oculusBasePath) { logger.Debug($"Listing Oculus manifests"); - string[] fileEntries = Directory.GetFiles($@"{oculusBasePath}Software\Manifests\"); + string[] fileEntries = Directory.GetFiles($@"{oculusBasePath}\Manifests\"); if (!fileEntries.Any()) { @@ -126,6 +137,51 @@ private IEnumerable GetOculusAppManifests(string oculusBasePath) } } + private List GetOculusLibraryLocations(RegistryView platformView) + { + var libraryPaths = new List(); + + logger.Debug($"Getting Oculus library locations from registry ({platformView})"); + + RegistryKey rootKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, platformView); + + try + { + var libraryKeyTitles = rootKey + .OpenSubKey(@"Software\Oculus VR, LLC\Oculus\Libraries\") + .GetSubKeyNames(); + + if (libraryKeyTitles == null || !libraryKeyTitles.Any()) + { + logger.Error("No libraries found"); + return null; + } + + foreach(var libraryKeyTitle in libraryKeyTitles) + { + var libraryPath = rootKey + .OpenSubKey($@"Software\Oculus VR, LLC\Oculus\Libraries\{libraryKeyTitle}") + .GetValue("OriginalPath") + .ToString(); + + if (!string.IsNullOrWhiteSpace(libraryPath)) + { + libraryPaths.Add(libraryPath); + logger.Debug($"Found library: {libraryPath}"); + } + } + + logger.Debug($"Libraries located: {libraryPaths.Count}"); + + return libraryPaths; + } + catch (Exception ex) + { + logger.Error($"Exception opening registry keys: {ex}"); + return null; + } + } + private string GetOculusBaseFromRegistry(RegistryView platformView) { logger.Debug($"Getting Oculus Base path from registry ({platformView})"); @@ -156,19 +212,19 @@ private string GetOculusBaseFromRegistry(RegistryView platformView) } } - private string GetOculusBasePath() + private List GetOculusLibraryLocations() { logger.Debug("Trying to get Oculus base path (REG64)"); - var resultPath = GetOculusBaseFromRegistry(RegistryView.Registry64); + var libraryLocations = GetOculusLibraryLocations(RegistryView.Registry64); - if (string.IsNullOrEmpty(resultPath)) + if (libraryLocations == null) { logger.Debug("Trying to get Oculus base path (REG32)"); - resultPath = GetOculusBaseFromRegistry(RegistryView.Registry32); + libraryLocations = GetOculusLibraryLocations(RegistryView.Registry32); } - return resultPath; + return libraryLocations; } } }