public List <GameInfo> GetLibraryGames() { using (var view = PlayniteApi.WebViews.CreateOffscreenView()) { var api = new BattleNetAccountClient(view); var games = new List <GameInfo>(); if (!api.GetIsUserLoggedIn()) { throw new Exception("User is not logged in."); } var accountGames = api.GetOwnedGames(); if (accountGames?.Any() == true) { foreach (var product in accountGames) { var gameInfo = BattleNetGames.Games.FirstOrDefault(a => a.ApiId == product.titleId); if (gameInfo == null) { logger.Warn($"Unknown game found on the account: {product.localizedGameName}/{product.titleId}, skipping import."); continue; } // To avoid duplicates like multiple WoW accounts if (!games.Any(a => a.GameId == gameInfo.ProductId)) { games.Add(new GameInfo() { Source = "Battle.net", GameId = gameInfo.ProductId, Name = gameInfo.Name.RemoveTrademarks(), Platform = "PC" }); } } } var classicGames = api.GetOwnedClassicGames(); if (classicGames?.Any() == true) { // W3 var w3Games = classicGames.Where(a => a.regionalGameFranchiseIconFilename.Contains("warcraft-iii")); if (w3Games.Any()) { var w3 = BattleNetGames.Games.FirstOrDefault(a => a.ProductId == "W3"); games.Add(new GameInfo() { Source = "Battle.net", GameId = w3.ProductId, Name = w3.Name }); if (w3Games.Count() == 2) { var w3x = BattleNetGames.Games.FirstOrDefault(a => a.ProductId == "W3X"); games.Add(new GameInfo() { Source = "Battle.net", GameId = w3x.ProductId, Name = w3x.Name, Platform = "PC" }); } } // D2 var d2Games = classicGames.Where(a => a.regionalGameFranchiseIconFilename.Contains("diablo-ii")); if (d2Games.Any()) { var d2 = BattleNetGames.Games.FirstOrDefault(a => a.ProductId == "D2"); games.Add(new GameInfo() { Source = "Battle.net", GameId = d2.ProductId, Name = d2.Name }); if (d2Games.Count() == 2) { var d2x = BattleNetGames.Games.FirstOrDefault(a => a.ProductId == "D2X"); games.Add(new GameInfo() { Source = "Battle.net", GameId = d2x.ProductId, Name = d2x.Name, Platform = "PC" }); } } } return(games); } }
public void GetLoginUrlTest() { Assert.IsNotNull(BattleNetAccountClient.GetDefaultApiStatus()); }