-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUbisoftCatalog.cs
56 lines (44 loc) · 1.66 KB
/
UbisoftCatalog.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using GameLib.Plugin.Ubisoft.Model;
using YamlDotNet.Serialization;
namespace GameLib.Plugin.Ubisoft;
internal class UbisoftCatalog
{
private readonly string _catalogPath;
private List<UbisoftCatalogItem> _catalog = new();
public IEnumerable<UbisoftCatalogItem> Catalog => _catalog;
public UbisoftCatalog(string launcherPath)
{
_catalogPath = Path.Combine(launcherPath, "cache", "configuration", "configurations");
Refresh();
}
public void Refresh()
{
List<UbisoftCatalogItem> deserializedUbisoftCatalogList = new();
if (!File.Exists(_catalogPath))
{
throw new FileNotFoundException("Configuration file not found, probably UPC client hasn't been started at least once.", _catalogPath);
}
using var file = File.OpenRead(_catalogPath);
var catalogCollection = ProtoBuf.Serializer.Deserialize<UbisoftCatalogCollection>(file);
if (catalogCollection is null || catalogCollection.Games is null)
{
throw new InvalidDataException("Error while parsing catalog file.");
}
var deserializer = new DeserializerBuilder()
.IgnoreUnmatchedProperties()
.Build();
foreach (var item in catalogCollection.Games.Where(p => !string.IsNullOrEmpty(p.GameInfoYaml)))
{
try
{
item.GameInfo = deserializer.Deserialize<UbisoftProductInformation>(item.GameInfoYaml!);
}
catch
{
continue;
}
deserializedUbisoftCatalogList.Add(item);
}
_catalog = deserializedUbisoftCatalogList;
}
}