This commit is contained in:
Jeddunk 2021-01-13 20:59:13 +01:00
parent 3dfc89dfed
commit 3033cb6a73

View File

@ -49,11 +49,11 @@ namespace GoldbergGUI.Core.Services
public class SteamService : ISteamService public class SteamService : ISteamService
{ {
// ReSharper disable StringLiteralTypo // ReSharper disable StringLiteralTypo
private readonly Dictionary<AppType, SteamCache> _caches = private readonly Dictionary<string, SteamCache> _caches =
new Dictionary<AppType, SteamCache> new Dictionary<string, SteamCache>
{ {
{ {
AppType.Game, AppType.Game.Value,
new SteamCache( new SteamCache(
"steamapps_games.json", "steamapps_games.json",
"https://api.steampowered.com/IStoreService/GetAppList/v1/" + "https://api.steampowered.com/IStoreService/GetAppList/v1/" +
@ -65,7 +65,7 @@ namespace GoldbergGUI.Core.Services
) )
}, },
{ {
AppType.DLC, AppType.DLC.Value,
new SteamCache( new SteamCache(
"steamapps_dlc.json", "steamapps_dlc.json",
"https://api.steampowered.com/IStoreService/GetAppList/v1/" + "https://api.steampowered.com/IStoreService/GetAppList/v1/" +
@ -99,10 +99,10 @@ namespace GoldbergGUI.Core.Services
return null; return null;
} }
foreach (var (_, c) in _caches) foreach (var (k, c) in _caches)
{ {
_log = log; _log = log;
_log.Info("Updating cache..."); _log.Info($"Updating cache ({k})...");
var updateNeeded = var updateNeeded =
DateTime.Now.Subtract(File.GetLastWriteTimeUtc(c.Filename)).TotalDays >= 1; DateTime.Now.Subtract(File.GetLastWriteTimeUtc(c.Filename)).TotalDays >= 1;
SteamApps steamApps; SteamApps steamApps;
@ -168,7 +168,7 @@ namespace GoldbergGUI.Core.Services
public IEnumerable<SteamApp> GetListOfAppsByName(string name) public IEnumerable<SteamApp> GetListOfAppsByName(string name)
{ {
var listOfAppsByName = _caches[AppType.Game].Cache.Search(x => x.Name) var listOfAppsByName = _caches[AppType.Game.Value].Cache.Search(x => x.Name)
.SetCulture(StringComparison.OrdinalIgnoreCase) .SetCulture(StringComparison.OrdinalIgnoreCase)
.ContainingAll(name.Split(' ')); .ContainingAll(name.Split(' '));
return listOfAppsByName; return listOfAppsByName;
@ -178,7 +178,7 @@ namespace GoldbergGUI.Core.Services
{ {
_log.Info($"Trying to get app {name}"); _log.Info($"Trying to get app {name}");
var comparableName = Regex.Replace(name, Misc.SpecialCharsRegex, "").ToLower(); var comparableName = Regex.Replace(name, Misc.SpecialCharsRegex, "").ToLower();
var app = _caches[AppType.Game].Cache.FirstOrDefault(x => x.CompareName(comparableName)); var app = _caches[AppType.Game.Value].Cache.FirstOrDefault(x => x.CompareName(comparableName));
if (app != null) _log.Info($"Successfully got app {app}"); if (app != null) _log.Info($"Successfully got app {app}");
return app; return app;
} }
@ -186,7 +186,7 @@ namespace GoldbergGUI.Core.Services
public SteamApp GetAppById(int appid) public SteamApp GetAppById(int appid)
{ {
_log.Info($"Trying to get app with ID {appid}"); _log.Info($"Trying to get app with ID {appid}");
var app = _caches[AppType.Game].Cache.FirstOrDefault(x => x.AppId.Equals(appid)); var app = _caches[AppType.Game.Value].Cache.FirstOrDefault(x => x.AppId.Equals(appid));
if (app != null) _log.Info($"Successfully got app {app}"); if (app != null) _log.Info($"Successfully got app {app}");
return app; return app;
} }
@ -203,7 +203,7 @@ namespace GoldbergGUI.Core.Services
{ {
steamAppDetails.DLC.ForEach(x => steamAppDetails.DLC.ForEach(x =>
{ {
var result = _caches[AppType.DLC].Cache.FirstOrDefault(y => y.AppId.Equals(x)) var result = _caches[AppType.DLC.Value].Cache.FirstOrDefault(y => y.AppId.Equals(x))
?? new SteamApp {AppId = x, Name = $"Unknown DLC {x}"}; ?? new SteamApp {AppId = x, Name = $"Unknown DLC {x}"};
dlcList.Add(result); dlcList.Add(result);
}); });