diff --git a/HumbleKeysLibrary.cs b/HumbleKeysLibrary.cs index 53e045f..233e501 100644 --- a/HumbleKeysLibrary.cs +++ b/HumbleKeysLibrary.cs @@ -74,6 +74,7 @@ public override IEnumerable ImportGames(LibraryImportGamesArgs args) { var orders = ScrapeOrders(); var selectedTpkds = SelectTpkds(orders); + logger.Trace("ImportGames: Selected Tpkds Count = " + selectedTpkds.Count()); ProcessOrders(orders, selectedTpkds, ref importedGames, ref removedGames); } catch (Exception e) @@ -97,6 +98,7 @@ public override IEnumerable ImportGames(LibraryImportGamesArgs args) PlayniteApi.Notifications.Remove(dbImportMessageId); } + logger.Trace($"ImportGames: Imported {importedGames.Count} games, Removed {removedGames.Count} games"); return importedGames; } @@ -113,7 +115,9 @@ public Dictionary ScrapeOrders() CachePath = $"{PlayniteApi.Paths.ExtensionsDataPath}\\{Id}" }); var keys = api.GetLibraryKeys(); + logger.Trace("ScrapeOrders: Keys Count = " + keys.Count); orders = api.GetOrders(keys, Settings.ImportChoiceKeys); + logger.Trace("ScrapeOrders: Orders Count = " + orders.Count); } return orders; @@ -149,6 +153,7 @@ protected void ProcessOrders(Dictionary orders, IEnumerable platform.SpecificationId == PC_WINDOWS); if (switchPlatform == null) switchPlatform = PlayniteApi.Database.Platforms.FirstOrDefault(platform => platform.SpecificationId == NINTENDO_SWITCH); + logger.Trace("ProcessOrders: DB begin update"); PlayniteApi.Database.BeginBufferUpdate(); try { @@ -251,7 +256,11 @@ protected void ProcessOrders(Dictionary orders, IEnumerable orders, IEnumerable orders, IEnumerable orders, IEnumerable GetLibraryKeys() } } + logger.Trace("Fetching library keys from Humble Bundle"); webView.NavigateAndWait(libraryUrl); - var libSource = webView.GetPageSource(); - var match = Regex.Match(libSource, @"""gamekeys"":\s*(\[.+\])"); - if (!match.Success) throw new Exception("User is not authenticated."); + var libSource = webView.GetPageSource(); + var match = Regex.Match(libSource, @"""gamekeys"":\s*(\[.+\])"); + if (!match.Success) throw new Exception("User is not authenticated."); - var strKeys = match.Groups[1].Value; - logger.Trace( - $"Request:{libraryUrl} Content:{Serialization.ToJson(Serialization.FromJson>(strKeys), true)}"); - if (preferCache) - { - CreateCacheContent(keysCacheFilename,strKeys); - } - return Serialization.FromJson>(strKeys); - + var strKeys = match.Groups[1].Value; + logger.Trace( + $"Request:{libraryUrl} Content:{Serialization.ToJson(Serialization.FromJson>(strKeys), true)}"); + if (preferCache) + { + CreateCacheContent(keysCacheFilename,strKeys); + } + return Serialization.FromJson>(strKeys); } string GetCacheContent(string keysCacheFilename) @@ -121,6 +122,7 @@ string GetCacheContent(string keysCacheFilename) streamReader.Close(); return cacheContent; } + T GetCacheContent(string keysCacheFilename) where T : class { var cacheContent = GetCacheContent(keysCacheFilename); @@ -137,6 +139,8 @@ void CreateCacheContent(string cacheFilename, string strCacheEntry) internal Dictionary GetOrders(List gameKeys, bool includeChoiceMonths = false) { var orders = new Dictionary(); + logger.Trace($"GetOrders: Processing {gameKeys.Count} game keys"); + foreach (var key in gameKeys) { var orderUri = string.Format(orderUrlMask, key); @@ -150,6 +154,7 @@ internal Dictionary GetOrders(List gameKeys, bool include if (order == null) { cacheHit = false; + logger.Trace($"Fetching order details"); webView.NavigateAndWait(orderUri); var strContent = webView.GetPageText(); if (preferCache) @@ -169,8 +174,10 @@ internal Dictionary GetOrders(List gameKeys, bool include AddChoiceMonthlyGames(order); } orders.Add(order.gamekey, order); + logger.Trace($"GetOrders: Added order {order.gamekey} with {order.tpkd_dict.all_tpks.Count} total tpks"); } + logger.Trace($"GetOrders: Completed processing {orders.Count} orders"); return orders; }