wabbajack/Wabbajack.Common/StoreHandlers/EpicGameStoreHandler.cs

87 lines
2.8 KiB
C#
Raw Normal View History

2020-12-16 21:41:28 +00:00
using System;
using System.Linq;
using Microsoft.Win32;
namespace Wabbajack.Common.StoreHandlers
{
public class EpicGameStoreHandler : AStoreHandler
{
public override StoreType Type { get; internal set; }
public string BaseRegKey = @"SOFTWARE\Epic Games\EOS";
public override bool Init()
{
return true;
}
public override bool LoadAllGames()
{
2020-12-23 13:55:13 +00:00
try
2020-12-16 21:41:28 +00:00
{
2020-12-23 13:55:13 +00:00
using var eosKey = Registry.CurrentUser.OpenSubKey(BaseRegKey);
if (eosKey == null)
{
Utils.Log("Epic Game Store is not installed");
return false;
}
2020-12-16 21:41:28 +00:00
2020-12-23 13:55:13 +00:00
var name = eosKey.GetValue("ModSdkMetadataDir");
if (name == null)
{
Utils.Log("Registry key entry does not exist for Epic Game store");
return false;
}
2020-12-16 21:41:28 +00:00
2020-12-23 13:55:13 +00:00
var byID = GameRegistry.Games.SelectMany(g => g.Value.EpicGameStoreIDs
.Select(id => (id, g.Value.Game)))
.GroupBy(t => t.id)
.ToDictionary(t => t.Key, t => t.First().Game);
2020-12-16 21:41:28 +00:00
2020-12-23 13:55:13 +00:00
foreach (var itm in ((AbsolutePath)(string)(name!)).EnumerateFiles(false, "*.item"))
2020-12-16 21:41:28 +00:00
{
2020-12-23 13:55:13 +00:00
var item = itm.FromJson<EpicGameItem>();
Utils.Log($"Found Epic Game Store Game: {item.DisplayName} at {item.InstallLocation}");
2020-12-16 21:41:28 +00:00
2020-12-23 13:55:13 +00:00
if (byID.TryGetValue(item.CatalogItemId, out var game))
{
Games.Add(new EpicStoreGame(game, item));
}
2020-12-16 21:41:28 +00:00
2020-12-23 13:55:13 +00:00
}
}
catch (NullReferenceException ex)
{
Utils.Log("Epic Game Store is does not appear to be installed");
return false;
}
2020-12-16 21:41:28 +00:00
return true;
}
public class EpicStoreGame : AStoreGame
{
public EpicStoreGame(Game game, EpicGameItem item)
{
Type = StoreType.EpicGameStore;
Game = game;
Path = (AbsolutePath)item.InstallLocation;
Name = game.MetaData().HumanFriendlyGameName;
}
public override Game Game { get; internal set; }
public override StoreType Type { get; internal set; }
}
public class EpicGameItem
{
public string DisplayName { get; set; } = "";
public string InstallationGuid { get; set; } = "";
public string CatalogItemId { get; set; } = "";
public string CatalogNamespace { get; set; } = "";
public string InstallSessionId { get; set; } = "";
public string InstallLocation { get; set; } = "";
}
}
}