public List <IGame> GetLibraryGames() { var api = new WebApiClient(); if (api.GetLoginRequired()) { throw new Exception("User is not logged in."); } var games = new List <IGame>(); foreach (var game in api.GetOwnedGames()) { games.Add(new Game() { Provider = Provider.GOG, ProviderId = game.id.ToString(), Name = game.title, ReleaseDate = game.releaseDate.date, Links = new ObservableCollection <Link>() { new Link("Store", @"https://www.gog.com" + game.url) } }); } return(games); }
public List <Game> GetLibraryGames() { using (var api = new WebApiClient()) { if (api.GetLoginRequired()) { throw new Exception("User is not logged in."); } var games = new List <Game>(); var acc = api.GetAccountInfo(); var libGames = api.GetOwnedGames(acc); if (libGames == null) { throw new Exception("Failed to obtain libary data."); } foreach (var game in libGames) { var newGame = new Game() { Provider = Provider.GOG, Source = Enums.GetEnumDescription(Provider.GOG), ProviderId = game.game.id, Name = game.game.title, Links = new ObservableCollection <Link>() { new Link("Store", @"https://www.gog.com" + game.game.url) } }; if (game.stats != null && game.stats.ContainsKey(acc.userId)) { newGame.Playtime = game.stats[acc.userId].playtime * 60; newGame.LastActivity = game.stats[acc.userId].lastSession; } games.Add(newGame); } return(games); } }