2020-01-03 17:03:09 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-04-28 22:52:20 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2020-01-03 17:03:09 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Common.StoreHandlers
|
|
|
|
|
{
|
|
|
|
|
public enum StoreType
|
|
|
|
|
{
|
|
|
|
|
STEAM,
|
2020-04-22 12:02:58 +00:00
|
|
|
|
GOG,
|
|
|
|
|
BethNet
|
2020-01-03 17:03:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class StoreHandler
|
|
|
|
|
{
|
2020-04-28 22:52:20 +00:00
|
|
|
|
private static readonly Lazy<StoreHandler> _instance = new Lazy<StoreHandler>(() => new StoreHandler(), isThreadSafe: true);
|
2020-04-22 12:24:49 +00:00
|
|
|
|
public static StoreHandler Instance => _instance.Value;
|
2020-01-03 17:03:09 +00:00
|
|
|
|
|
|
|
|
|
private static readonly Lazy<SteamHandler> _steamHandler = new Lazy<SteamHandler>(() => new SteamHandler());
|
|
|
|
|
public SteamHandler SteamHandler = _steamHandler.Value;
|
|
|
|
|
|
|
|
|
|
private static readonly Lazy<GOGHandler> _gogHandler = new Lazy<GOGHandler>(() => new GOGHandler());
|
|
|
|
|
public GOGHandler GOGHandler = _gogHandler.Value;
|
|
|
|
|
|
2020-04-22 12:02:58 +00:00
|
|
|
|
private static readonly Lazy<BethNetHandler> _bethNetHandler = new Lazy<BethNetHandler>(() => new BethNetHandler());
|
|
|
|
|
public BethNetHandler BethNetHandler = _bethNetHandler.Value;
|
|
|
|
|
|
2020-01-03 17:03:09 +00:00
|
|
|
|
public List<AStoreGame> StoreGames;
|
|
|
|
|
|
|
|
|
|
public StoreHandler()
|
|
|
|
|
{
|
|
|
|
|
StoreGames = new List<AStoreGame>();
|
|
|
|
|
|
|
|
|
|
if (SteamHandler.Init())
|
|
|
|
|
{
|
|
|
|
|
if(SteamHandler.LoadAllGames())
|
|
|
|
|
StoreGames.AddRange(SteamHandler.Games);
|
|
|
|
|
else
|
|
|
|
|
Utils.Error(new StoreException("Could not load all Games from the SteamHandler, check previous error messages!"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Utils.Error(new StoreException("Could not Init the SteamHandler, check previous error messages!"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (GOGHandler.Init())
|
|
|
|
|
{
|
|
|
|
|
if(GOGHandler.LoadAllGames())
|
|
|
|
|
StoreGames.AddRange(GOGHandler.Games);
|
|
|
|
|
else
|
|
|
|
|
Utils.Error(new StoreException("Could not load all Games from the GOGHandler, check previous error messages!"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Utils.Error(new StoreException("Could not Init the GOGHandler, check previous error messages!"));
|
|
|
|
|
}
|
2020-04-22 12:02:58 +00:00
|
|
|
|
|
|
|
|
|
if (BethNetHandler.Init())
|
|
|
|
|
{
|
|
|
|
|
if (BethNetHandler.LoadAllGames())
|
|
|
|
|
StoreGames.AddRange(BethNetHandler.Games);
|
|
|
|
|
else
|
|
|
|
|
Utils.Error(new StoreException("Could not load all Games from the BethNetHandler, check previous error messages!"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Utils.Error(new StoreException("Could not Init the BethNetHandler, check previous error messages!"));
|
|
|
|
|
}
|
2020-01-03 17:03:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 18:57:02 +00:00
|
|
|
|
public AbsolutePath? TryGetGamePath(Game game)
|
2020-01-03 17:03:09 +00:00
|
|
|
|
{
|
|
|
|
|
return StoreGames.FirstOrDefault(g => g.Game == game)?.Path;
|
|
|
|
|
}
|
2020-04-28 22:52:20 +00:00
|
|
|
|
|
|
|
|
|
public static void Warmup()
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() => _instance.Value).FireAndForget();
|
|
|
|
|
}
|
2020-01-03 17:03:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class AStoreGame
|
|
|
|
|
{
|
|
|
|
|
public abstract Game Game { get; internal set; }
|
2020-04-03 23:23:13 +00:00
|
|
|
|
public virtual string Name { get; internal set; } = string.Empty;
|
|
|
|
|
public virtual AbsolutePath Path { get; internal set; }
|
|
|
|
|
public virtual int ID { get; internal set; }
|
2020-01-03 17:03:09 +00:00
|
|
|
|
public abstract StoreType Type { get; internal set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class AStoreHandler
|
|
|
|
|
{
|
2020-04-03 23:23:13 +00:00
|
|
|
|
public List<AStoreGame> Games { get; } = new List<AStoreGame>();
|
2020-01-03 17:03:09 +00:00
|
|
|
|
|
|
|
|
|
public abstract StoreType Type { get; internal set; }
|
|
|
|
|
|
|
|
|
|
public abstract bool Init();
|
|
|
|
|
|
|
|
|
|
public abstract bool LoadAllGames();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class StoreException : Exception
|
|
|
|
|
{
|
|
|
|
|
public StoreException(string msg) : base(msg)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|