Skip to content

Commit

Permalink
Bug/issue 2: Adding support for multiple Oculus libraries, in differe…
Browse files Browse the repository at this point in the history
…nt locations (#5)

* support for multiple oculus library locations

* Fixing paths from alternative libraries
  • Loading branch information
Shawson authored Dec 5, 2019
1 parent ba58f97 commit a4713af
Showing 1 changed file with 105 additions and 49 deletions.
154 changes: 105 additions & 49 deletions OculusLibrary/OculusLibraryPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,67 +34,78 @@ public override IEnumerable<GameInfo> GetGames()

var gameInfos = new List<GameInfo>();

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}");
}
}
}
}
Expand All @@ -108,7 +119,7 @@ private IEnumerable<OculusManifest> GetOculusAppManifests(string oculusBasePath)
{
logger.Debug($"Listing Oculus manifests");

string[] fileEntries = Directory.GetFiles($@"{oculusBasePath}Software\Manifests\");
string[] fileEntries = Directory.GetFiles($@"{oculusBasePath}\Manifests\");

if (!fileEntries.Any())
{
Expand All @@ -126,6 +137,51 @@ private IEnumerable<OculusManifest> GetOculusAppManifests(string oculusBasePath)
}
}

private List<string> GetOculusLibraryLocations(RegistryView platformView)
{
var libraryPaths = new List<string>();

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})");
Expand Down Expand Up @@ -156,19 +212,19 @@ private string GetOculusBaseFromRegistry(RegistryView platformView)
}
}

private string GetOculusBasePath()
private List<string> 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;
}
}
}

0 comments on commit a4713af

Please sign in to comment.