Skip to content

Commit be649f9

Browse files
authored
Adding installation path as part of parsing process (#15)
1 parent 5ce52a8 commit be649f9

4 files changed

Lines changed: 49 additions & 22 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace OculusLibrary
4+
{
5+
[Serializable]
6+
public class ManifestParseException : Exception
7+
{
8+
public ManifestParseException() { }
9+
public ManifestParseException(string message) : base(message) { }
10+
public ManifestParseException(string message, Exception inner) : base(message, inner) { }
11+
protected ManifestParseException(
12+
System.Runtime.Serialization.SerializationInfo info,
13+
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
14+
}
15+
}

OculusLibrary/OculusLibrary.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
</ItemGroup>
5252
<ItemGroup>
5353
<Compile Include="DataExtraction\IOculusPathSniffer.cs" />
54+
<Compile Include="ManifestParseException.cs" />
5455
<Compile Include="OS\IPathNormaliser.cs" />
5556
<Compile Include="OS\IRegistryValueProvider.cs" />
5657
<Compile Include="OS\IWindowsManagementObjectQueryProvider.cs" />

OculusLibrary/OculusLibraryPlugin.cs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,31 @@ public override IEnumerable<GameInfo> GetGames()
4747

4848
using (var view = PlayniteApi.WebViews.CreateOffscreenView())
4949
{
50-
foreach (var oculusBasePath in oculusLibraryLocations)
50+
foreach (var currentLibraryBasePath in oculusLibraryLocations)
5151
{
52-
logger.Info($"Processing Oculus library location {oculusBasePath}");
52+
logger.Info($"Processing Oculus library location {currentLibraryBasePath}");
5353

54-
foreach (var manifest in GetOculusAppManifests(oculusBasePath))
54+
foreach (var manifest in GetOculusAppManifests(currentLibraryBasePath))
5555
{
5656
logger.Info($"Processing manifest {manifest.CanonicalName} {manifest.AppId}");
5757

5858
try
5959
{
60-
var executableFullPath = $@"{oculusBasePath}\Software\{manifest.CanonicalName}\{manifest.LaunchFile}";
60+
var installationPath = $@"{currentLibraryBasePath}\Software\{manifest.CanonicalName}";
61+
var executableFullPath = $@"{installationPath}\{manifest.LaunchFile}";
6162

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

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

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

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

7576
if (!File.Exists(backgroundImage))
7677
{
@@ -92,6 +93,7 @@ public override IEnumerable<GameInfo> GetGames()
9293
Name = scrapedData?.Name ?? executableName,
9394
Description = scrapedData?.Description ?? string.Empty,
9495
GameId = manifest.AppId,
96+
InstallDirectory = installationPath,
9597
PlayAction = new GameAction
9698
{
9799
Type = GameActionType.File,
@@ -142,21 +144,8 @@ private List<OculusManifest> GetOculusAppManifests(string oculusBasePath)
142144
}
143145

144146
var json = File.ReadAllText(fileName);
145-
146-
if (string.IsNullOrWhiteSpace(json))
147-
{
148-
logger.Error($"JSON file is empty ({fileName})");
149-
continue;
150-
}
151-
152-
var manifest = JsonConvert.DeserializeObject<OculusManifest>(json);
153-
154-
if (manifest == null)
155-
{
156-
logger.Error($"Could not deserialise json ({fileName})");
157-
}
158-
159-
manifest.LaunchFile = manifest?.LaunchFile?.Replace("/", @"\");
147+
148+
var manifest = OculusManifest.Parse(json);
160149

161150
manifests.Add(manifest);
162151
}

OculusLibrary/OculusManifest.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1-
namespace OculusLibrary
1+
using Newtonsoft.Json;
2+
using System;
3+
4+
namespace OculusLibrary
25
{
36
internal class OculusManifest
47
{
58
public string AppId { get; set; }
69
public string LaunchFile { get; set; }
710
public string LaunchParameters { get; set; }
811
public string CanonicalName { get; set; }
12+
13+
public static OculusManifest Parse(string json)
14+
{
15+
if (string.IsNullOrWhiteSpace(json))
16+
{
17+
throw new ArgumentException("JSON string cannot be null and empty");
18+
}
19+
20+
var manifest = JsonConvert.DeserializeObject<OculusManifest>(json);
21+
22+
if (manifest == null)
23+
{
24+
throw new ManifestParseException("Could not deserialise json");
25+
}
26+
27+
manifest.LaunchFile = manifest?.LaunchFile?.Replace("/", @"\");
28+
29+
return manifest;
30+
}
931
}
1032
}

0 commit comments

Comments
 (0)