Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions HumbleKeysLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public override IEnumerable<Game> 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)
Expand All @@ -97,6 +98,7 @@ public override IEnumerable<Game> ImportGames(LibraryImportGamesArgs args)
PlayniteApi.Notifications.Remove(dbImportMessageId);
}

logger.Trace($"ImportGames: Imported {importedGames.Count} games, Removed {removedGames.Count} games");
return importedGames;
}

Expand All @@ -113,7 +115,9 @@ public Dictionary<string, Order> 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;
Expand Down Expand Up @@ -149,6 +153,7 @@ protected void ProcessOrders(Dictionary<string,Order> orders, IEnumerable<IGroup
if (winPlatform == null) winPlatform = PlayniteApi.Database.Platforms.FirstOrDefault(platform => 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
{
Expand Down Expand Up @@ -251,7 +256,11 @@ protected void ProcessOrders(Dictionary<string,Order> orders, IEnumerable<IGroup
if (UpdateStoreLinks(alreadyImported.Links, tpkd, true)) otherUpdated = true;
}

if (!tagsUpdated && !otherUpdated) continue;
if (!tagsUpdated && !otherUpdated)
{
logger.Trace($"ProcessOrders: No update needed for '{alreadyImported.Name}' with GameId = {alreadyImported.GameId}");
continue;
}

if (alreadyImported.TagIds != null && alreadyImported.TagIds.Contains(unredeemableTag.Id))
{
Expand Down Expand Up @@ -285,6 +294,7 @@ protected void ProcessOrders(Dictionary<string,Order> orders, IEnumerable<IGroup
else
{
PlayniteApi.Database.Games.Update(alreadyImported);
logger.Trace($"ProcessOrders: Updated '{alreadyImported.Name}' with GameId = {alreadyImported.GameId}");
if (tagsUpdated)
{
PlayniteApi.Notifications.Add(
Expand All @@ -304,7 +314,7 @@ protected void ProcessOrders(Dictionary<string,Order> orders, IEnumerable<IGroup
// Remove Existing Game?
PlayniteApi.Database.Games.Remove(alreadyImported);
logger.Trace(
$"Removing game {alreadyImported.Name} since Settings.IgnoreRedeemedKeys is: [{Settings.IgnoreRedeemedKeys}] and IsKeyPresent() is [{IsKeyPresent(tpkd)}]");
$"Removing game '{alreadyImported.Name}' with GameId = {alreadyImported.GameId} since Settings.IgnoreRedeemedKeys is: [{Settings.IgnoreRedeemedKeys}] and IsKeyPresent() is [{IsKeyPresent(tpkd)}]");
}
}
}
Expand All @@ -313,6 +323,7 @@ protected void ProcessOrders(Dictionary<string,Order> orders, IEnumerable<IGroup
finally
{
PlayniteApi.Database.EndBufferUpdate();
logger.Trace("ProcessOrders: DB update complete");
}
}

Expand Down Expand Up @@ -449,6 +460,7 @@ Game ImportNewGame(Order.TpkdDict.Tpk tpkd, Tag groupTag = null)
PlayniteApi.Database.Games.Update(game);
}

logger.Trace($"ImportNewGame: Added '{game.Name}' with GameId = {game.GameId}");
return game;
}

Expand Down
2 changes: 1 addition & 1 deletion HumbleKeysLibrarySettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void LoadLocalizedResources()
*/

// Log the error
logger.Info($"Failed to load resources for culture '{cultureName}': {ex.Message}");
logger.Warn($"Failed to load resources for culture '{cultureName}': {ex.Message}");
}
}

Expand Down
31 changes: 19 additions & 12 deletions Services/HumbleKeysAccountClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public HumbleKeysAccountClient(IWebView webView, IHumbleKeysAccountClientSetting
Directory.CreateDirectory($"{localCachePath}\\{cachePath}");
}
}
logger.Info("Cache directories prepared");
}
else
{
Expand Down Expand Up @@ -97,20 +98,20 @@ internal List<string> 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<List<string>>(strKeys), true)}");
if (preferCache)
{
CreateCacheContent(keysCacheFilename,strKeys);
}
return Serialization.FromJson<List<string>>(strKeys);

var strKeys = match.Groups[1].Value;
logger.Trace(
$"Request:{libraryUrl} Content:{Serialization.ToJson(Serialization.FromJson<List<string>>(strKeys), true)}");
if (preferCache)
{
CreateCacheContent(keysCacheFilename,strKeys);
}
return Serialization.FromJson<List<string>>(strKeys);
}

string GetCacheContent(string keysCacheFilename)
Expand All @@ -121,6 +122,7 @@ string GetCacheContent(string keysCacheFilename)
streamReader.Close();
return cacheContent;
}

T GetCacheContent<T>(string keysCacheFilename) where T : class
{
var cacheContent = GetCacheContent(keysCacheFilename);
Expand All @@ -137,6 +139,8 @@ void CreateCacheContent(string cacheFilename, string strCacheEntry)
internal Dictionary<string, Order> GetOrders(List<string> gameKeys, bool includeChoiceMonths = false)
{
var orders = new Dictionary<string, Order>();
logger.Trace($"GetOrders: Processing {gameKeys.Count} game keys");

foreach (var key in gameKeys)
{
var orderUri = string.Format(orderUrlMask, key);
Expand All @@ -150,6 +154,7 @@ internal Dictionary<string, Order> GetOrders(List<string> gameKeys, bool include

if (order == null) {
cacheHit = false;
logger.Trace($"Fetching order details");
webView.NavigateAndWait(orderUri);
var strContent = webView.GetPageText();
if (preferCache)
Expand All @@ -169,8 +174,10 @@ internal Dictionary<string, Order> GetOrders(List<string> 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;
}

Expand Down