Skip to content

Commit

Permalink
Adding installation path as part of parsing process (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawson authored Apr 19, 2020
1 parent 5ce52a8 commit be649f9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
15 changes: 15 additions & 0 deletions OculusLibrary/ManifestParseException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace OculusLibrary
{
[Serializable]
public class ManifestParseException : Exception
{
public ManifestParseException() { }
public ManifestParseException(string message) : base(message) { }
public ManifestParseException(string message, Exception inner) : base(message, inner) { }
protected ManifestParseException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
}
1 change: 1 addition & 0 deletions OculusLibrary/OculusLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DataExtraction\IOculusPathSniffer.cs" />
<Compile Include="ManifestParseException.cs" />
<Compile Include="OS\IPathNormaliser.cs" />
<Compile Include="OS\IRegistryValueProvider.cs" />
<Compile Include="OS\IWindowsManagementObjectQueryProvider.cs" />
Expand Down
31 changes: 10 additions & 21 deletions OculusLibrary/OculusLibraryPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,31 @@ public override IEnumerable<GameInfo> GetGames()

using (var view = PlayniteApi.WebViews.CreateOffscreenView())
{
foreach (var oculusBasePath in oculusLibraryLocations)
foreach (var currentLibraryBasePath in oculusLibraryLocations)
{
logger.Info($"Processing Oculus library location {oculusBasePath}");
logger.Info($"Processing Oculus library location {currentLibraryBasePath}");

foreach (var manifest in GetOculusAppManifests(oculusBasePath))
foreach (var manifest in GetOculusAppManifests(currentLibraryBasePath))
{
logger.Info($"Processing manifest {manifest.CanonicalName} {manifest.AppId}");

try
{
var executableFullPath = $@"{oculusBasePath}\Software\{manifest.CanonicalName}\{manifest.LaunchFile}";
var installationPath = $@"{currentLibraryBasePath}\Software\{manifest.CanonicalName}";
var executableFullPath = $@"{installationPath}\{manifest.LaunchFile}";

// set a default name
var executableName = Path.GetFileNameWithoutExtension(executableFullPath);

var icon = $@"{oculusBasePath}\..\CoreData\Software\StoreAssets\{manifest.CanonicalName}_assets\icon_image.jpg";
var icon = $@"{currentLibraryBasePath}\..\CoreData\Software\StoreAssets\{manifest.CanonicalName}_assets\icon_image.jpg";

if (!File.Exists(icon))
{
logger.Debug($"Oculus store icon missing from file system- reverting to executable icon");
icon = executableFullPath;
}

var backgroundImage = $@"{oculusBasePath}\..\CoreData\Software\StoreAssets\{manifest.CanonicalName}_assets\cover_landscape_image_large.png";
var backgroundImage = $@"{currentLibraryBasePath}\..\CoreData\Software\StoreAssets\{manifest.CanonicalName}_assets\cover_landscape_image_large.png";

if (!File.Exists(backgroundImage))
{
Expand All @@ -92,6 +93,7 @@ public override IEnumerable<GameInfo> GetGames()
Name = scrapedData?.Name ?? executableName,
Description = scrapedData?.Description ?? string.Empty,
GameId = manifest.AppId,
InstallDirectory = installationPath,
PlayAction = new GameAction
{
Type = GameActionType.File,
Expand Down Expand Up @@ -142,21 +144,8 @@ private List<OculusManifest> GetOculusAppManifests(string oculusBasePath)
}

var json = File.ReadAllText(fileName);

if (string.IsNullOrWhiteSpace(json))
{
logger.Error($"JSON file is empty ({fileName})");
continue;
}

var manifest = JsonConvert.DeserializeObject<OculusManifest>(json);

if (manifest == null)
{
logger.Error($"Could not deserialise json ({fileName})");
}

manifest.LaunchFile = manifest?.LaunchFile?.Replace("/", @"\");

var manifest = OculusManifest.Parse(json);

manifests.Add(manifest);
}
Expand Down
24 changes: 23 additions & 1 deletion OculusLibrary/OculusManifest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
namespace OculusLibrary
using Newtonsoft.Json;
using System;

namespace OculusLibrary
{
internal class OculusManifest
{
public string AppId { get; set; }
public string LaunchFile { get; set; }
public string LaunchParameters { get; set; }
public string CanonicalName { get; set; }

public static OculusManifest Parse(string json)
{
if (string.IsNullOrWhiteSpace(json))
{
throw new ArgumentException("JSON string cannot be null and empty");
}

var manifest = JsonConvert.DeserializeObject<OculusManifest>(json);

if (manifest == null)
{
throw new ManifestParseException("Could not deserialise json");
}

manifest.LaunchFile = manifest?.LaunchFile?.Replace("/", @"\");

return manifest;
}
}
}

0 comments on commit be649f9

Please sign in to comment.