public IsThereAnyDealSettingsView(IsThereAnyDealSettings settings) { this.settings = settings; RegionsData = isThereAnyDealApi.GetCoveredRegions(); InitializeComponent(); ItadSelectRegion.ItemsSource = RegionsData; ItadSelectRegion.Text = GetInfosRegion(settings.Region); ItadSelectCountry.Text = settings.Country; StoresItems = settings.Stores; //logger.Debug(JsonConvert.SerializeObject((object)settings.Stores)); ListStores.ItemsSource = StoresItems; foreach (ItadStore store in StoresItems) { if (store.IsCheck) { if (ListStores.Text == "") { ListStores.Text += store.Title; } else { ListStores.Text += ", " + store.Title; } } } lLimitNotification.Content = settings.LimitNotification + "%"; DataContext = this; IsFirst = false; }
public IsThereAnyDealView(IsThereAnyDeal plugin, IPlayniteAPI PlayniteApi, string PluginUserDataPath, IsThereAnyDealSettings settings, string PlainSelected = "") { InitializeComponent(); this.PreviewKeyDown += new KeyEventHandler(HandleEsc); this.PlainSelected = PlainSelected; this.settings = settings; this.plugin = plugin; // Load data dpData.IsEnabled = false; var task = Task.Run(() => LoadData(PlayniteApi, PluginUserDataPath, settings, PluginUserDataPath)) .ContinueWith(antecedent => { Application.Current.Dispatcher.Invoke(new Action(() => { lbWishlistItems = antecedent.Result; lbWishlist.ItemsSource = lbWishlistItems; if (!PlainSelected.IsNullOrEmpty()) { int index = 0; foreach (Wishlist wishlist in antecedent.Result) { if (wishlist.Plain == PlainSelected) { lbWishlist.SelectedIndex = index; lbWishlist.ScrollIntoView(lbWishlist.SelectedItem); break; } index += 1; } } DataLoadWishlist.Visibility = Visibility.Collapsed; dpData.IsEnabled = true; })); }); GetListGiveaways(PlayniteApi, PluginUserDataPath); SetFilterStore(); DataContext = this; }
public List <Wishlist> GetWishlist(IPlayniteAPI PlayniteApi, Guid SourceId, string HumbleBundleId, string PluginUserDataPath, IsThereAnyDealSettings settings, bool CacheOnly = false, bool Force = false) { List <Wishlist> Result = new List <Wishlist>(); List <Wishlist> ResultLoad = LoadWishlists("HumbleBundle", PluginUserDataPath); if (ResultLoad != null && !Force) { ResultLoad = SetCurrentPrice(ResultLoad, settings, PlayniteApi); SaveWishlist("HumbleBundle", PluginUserDataPath, ResultLoad); return(ResultLoad); } if (CacheOnly) { return(Result); } if (HumbleBundleId.IsNullOrEmpty()) { return(Result); } string ResultWeb = ""; string url = string.Format(@"https://www.humblebundle.com/store/wishlist/{0}", HumbleBundleId); try { ResultWeb = HttpDownloader.DownloadString(url, Encoding.UTF8); if (ResultWeb != "") { int startSub = ResultWeb.IndexOf("<script id=\"storefront-webpack-json-data\" type=\"application/json\">"); ResultWeb = ResultWeb.Substring(startSub, (ResultWeb.Length - startSub)); int endSub = ResultWeb.IndexOf("</script>"); ResultWeb = ResultWeb.Substring(0, endSub); ResultWeb = ResultWeb.Replace("<script id=\"storefront-webpack-json-data\" type=\"application/json\">", ""); JObject dataObj = JObject.Parse(ResultWeb); IsThereAnyDealApi isThereAnyDealApi = new IsThereAnyDealApi(); foreach (JObject gameWish in dataObj["products_json"]) { int StoreId = 0; string StoreUrl = "https://www.humblebundle.com/store/" + gameWish["human_url"]; string Name = (string)gameWish["human_name"]; DateTime ReleaseDate = default(DateTime); string Capsule = (string)gameWish["standard_carousel_image"]; Result.Add(new Wishlist { StoreId = StoreId, StoreName = "Humble", StoreUrl = StoreUrl, Name = WebUtility.HtmlDecode(Name), SourceId = SourceId, ReleaseDate = ReleaseDate.ToUniversalTime(), Capsule = Capsule, Plain = isThereAnyDealApi.GetPlain(Name) }); } } } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { Common.LogError(ex, "IsThereAnyDeal", "Error in download HumbleBundle wishlist"); return(Result); } } Result = SetCurrentPrice(Result, settings, PlayniteApi); SaveWishlist("HumbleBundle", PluginUserDataPath, Result); return(Result); }
public List <Wishlist> LoadWishlist(IsThereAnyDeal plugin, IPlayniteAPI PlayniteApi, IsThereAnyDealSettings settings, string PluginUserDataPath, bool CacheOnly = false, bool Force = false) { Guid SteamId = new Guid(); Guid GogId = new Guid(); Guid EpicId = new Guid(); Guid HumbleId = new Guid(); foreach (var Source in PlayniteApi.Database.Sources) { if (Source.Name.ToLower() == "steam") { SteamId = Source.Id; } if (Source.Name.ToLower() == "gog") { GogId = Source.Id; } if (Source.Name.ToLower() == "epic") { EpicId = Source.Id; } if (Source.Name.ToLower() == "humble") { HumbleId = Source.Id; } } List <Wishlist> ListWishlistSteam = new List <Wishlist>(); if (settings.EnableSteam) { if (!Tools.IsDisabledPlaynitePlugins("SteamLibrary", PluginUserDataPath)) { SteamWishlist steamWishlist = new SteamWishlist(); ListWishlistSteam = steamWishlist.GetWishlist(PlayniteApi, SteamId, PluginUserDataPath, settings, CacheOnly, Force); } else { logger.Warn("IsThereAnyDeal - Steam is enable then disabled"); PlayniteApi.Notifications.Add(new NotificationMessage( $"IsThereAnyDeal-Steam-disabled", "Steam is enable then disabled", NotificationType.Error, () => plugin.OpenSettingsView() )); } } List <Wishlist> ListWishlistGog = new List <Wishlist>(); if (settings.EnableGog) { if (!Tools.IsDisabledPlaynitePlugins("GogLibrary", PluginUserDataPath)) { GogWishlist gogWishlist = new GogWishlist(PlayniteApi); ListWishlistGog = gogWishlist.GetWishlist(PlayniteApi, GogId, PluginUserDataPath, settings, CacheOnly, Force); } else { logger.Warn("IsThereAnyDeal - GOG is enable then disabled"); PlayniteApi.Notifications.Add(new NotificationMessage( $"IsThereAnyDeal-GOG-disabled", "GOG is enable then disabled", NotificationType.Error, () => plugin.OpenSettingsView() )); } } List <Wishlist> ListWishlistEpic = new List <Wishlist>(); if (settings.EnableEpic) { if (!Tools.IsDisabledPlaynitePlugins("EpicLibrary", PluginUserDataPath)) { EpicWishlist epicWishlist = new EpicWishlist(); ListWishlistEpic = epicWishlist.GetWishlist(PlayniteApi, GogId, PluginUserDataPath, settings, CacheOnly, Force); } else { logger.Warn("IsThereAnyDeal - Epic Game Store is enable then disabled"); PlayniteApi.Notifications.Add(new NotificationMessage( $"IsThereAnyDeal-EpicGameStore-disabled", "Epic Game Store is enable then disabled", NotificationType.Error, () => plugin.OpenSettingsView() )); } } List <Wishlist> ListWishlistHumble = new List <Wishlist>(); if (settings.EnableHumble) { if (!Tools.IsDisabledPlaynitePlugins("HumbleLibrary", PluginUserDataPath)) { HumbleBundleWishlist humbleBundleWishlist = new HumbleBundleWishlist(); ListWishlistHumble = humbleBundleWishlist.GetWishlist(PlayniteApi, HumbleId, settings.HumbleKey, PluginUserDataPath, settings, CacheOnly, Force); } else { logger.Warn("IsThereAnyDeal - Humble Bundle is enable then disabled"); PlayniteApi.Notifications.Add(new NotificationMessage( $"IsThereAnyDeal-HumbleBundle-disabled", "Humble Bundle is enable then disabled", NotificationType.Error, () => plugin.OpenSettingsView() )); } } List <Wishlist> ListWishlist = ListWishlistSteam.Concat(ListWishlistGog).Concat(ListWishlistHumble) .Concat(ListWishlistEpic).ToList(); // Group same game var listDuplicates = ListWishlist.GroupBy(c => c.Name.ToLower()).Where(g => g.Skip(1).Any()); foreach (var duplicates in listDuplicates) { bool isFirst = true; Wishlist keep = new Wishlist(); foreach (var wish in duplicates) { if (isFirst) { keep = wish; isFirst = false; } else { List <Wishlist> keepDuplicates = keep.Duplicates; keepDuplicates.Add(wish); keep.Duplicates = keepDuplicates; ListWishlist.Find(x => x == keep).Duplicates = keepDuplicates; ListWishlist.Find(x => x == keep).hasDuplicates = true; ListWishlist.Remove(wish); } } } return(ListWishlist.OrderBy(wishlist => wishlist.Name).ToList()); }
public List <Wishlist> GetCurrentPrice(List <Wishlist> wishlists, IsThereAnyDealSettings settings, IPlayniteAPI PlayniteApi) { // IS allready load? if (wishlists.Count > 0) { foreach (Wishlist wishlist in wishlists) { if (wishlist.itadGameInfos != null && wishlist.itadGameInfos.Keys.Contains(DateTime.Now.ToString("yyyy-MM-dd"))) { #if DEBUG logger.Debug("IsThereAnyDeal - Current price is allready load"); #endif return(wishlists); } } } List <Wishlist> Result = new List <Wishlist>(); string plains = string.Empty; foreach (Wishlist wishlist in wishlists) { if (plains == string.Empty) { plains += wishlist.Plain; } else { plains += "," + wishlist.Plain; } } #if DEBUG logger.Debug($"IsThereAnyDeal - GetCurrentPrice({plains})"); #endif string shops = string.Empty; foreach (ItadStore Store in settings.Stores) { if (Store.IsCheck) { if (shops == string.Empty) { shops += Store.Id; } else { shops += "," + Store.Id; } } } if (!plains.IsNullOrEmpty()) { try { string url = baseAddress + $"v01/game/prices/?key={key}&plains={plains}®ion{settings.Region}&country={settings.Country}&shops={shops}"; string responseData = DownloadStringData(url).GetAwaiter().GetResult(); foreach (Wishlist wishlist in wishlists) { ConcurrentDictionary <string, List <ItadGameInfo> > itadGameInfos = new ConcurrentDictionary <string, List <ItadGameInfo> >(); List <ItadGameInfo> dataCurrentPrice = new List <ItadGameInfo>(); JObject datasObj = JObject.Parse(responseData); // Check if in library (exclude game emulated) List <Guid> ListEmulators = new List <Guid>(); foreach (var item in PlayniteApi.Database.Emulators) { ListEmulators.Add(item.Id); } bool InLibrary = false; foreach (var game in PlayniteApi.Database.Games.Where(a => a.Name.ToLower() == wishlist.Name.ToLower())) { if (game.PlayAction != null && game.PlayAction.EmulatorId != null && ListEmulators.Contains(game.PlayAction.EmulatorId)) { InLibrary = false; } else { InLibrary = true; } } wishlist.InLibrary = InLibrary; if (((JArray)datasObj["data"][wishlist.Plain]["list"]).Count > 0) { foreach (JObject dataObj in ((JArray)datasObj["data"][wishlist.Plain]["list"])) { dataCurrentPrice.Add(new ItadGameInfo { Plain = wishlist.Plain, PriceNew = Math.Round((double)dataObj["price_new"], 2), PriceOld = Math.Round((double)dataObj["price_old"], 2), PriceCut = (double)dataObj["price_cut"], CurrencySign = settings.CurrencySign, ShopName = (string)dataObj["shop"]["name"], ShopColor = GetShopColor((string)dataObj["shop"]["name"], settings.Stores), UrlBuy = (string)dataObj["url"] }); } } itadGameInfos.TryAdd(DateTime.Now.ToString("yyyy-MM-dd"), dataCurrentPrice); wishlist.itadGameInfos = itadGameInfos; Result.Add(wishlist); } } catch (Exception ex) { Common.LogError(ex, "IsThereAnyDeal", $"Error in GetCurrentPrice({plains})"); } } else { #if DEBUG logger.Debug("IsThereAnyDeal - No plain"); #endif } return(Result); }
public List <Wishlist> SetCurrentPrice(List <Wishlist> ListWishlist, IsThereAnyDealSettings settings, IPlayniteAPI PlayniteApi) { IsThereAnyDealApi isThereAnyDealApi = new IsThereAnyDealApi(); return(isThereAnyDealApi.GetCurrentPrice(ListWishlist, settings, PlayniteApi)); }
private async Task <List <Wishlist> > LoadData(IPlayniteAPI PlayniteApi, string PluginUserDataPath, IsThereAnyDealSettings settings, string PlainSelected = "") { //logger.Debug("LoadData"); IsThereAnyDealApi isThereAnyDealApi = new IsThereAnyDealApi(); List <Wishlist> ListWishlist = isThereAnyDealApi.LoadWishlist(plugin, PlayniteApi, settings, PluginUserDataPath); return(ListWishlist); }
public List <Wishlist> GetWishlist(IPlayniteAPI PlayniteApi, Guid SourceId, string PluginUserDataPath, IsThereAnyDealSettings settings, bool CacheOnly = false, bool Force = false) { List <Wishlist> Result = new List <Wishlist>(); List <Wishlist> ResultLoad = LoadWishlists("Epic", PluginUserDataPath); if (ResultLoad != null && !Force) { ResultLoad = SetCurrentPrice(ResultLoad, settings, PlayniteApi); SaveWishlist("Epic", PluginUserDataPath, ResultLoad); return(ResultLoad); } if (CacheOnly) { return(Result); } // Get Epic configuration if exist. string access_token = ""; try { JObject EpicConfig = JObject.Parse(File.ReadAllText(PluginUserDataPath + "\\..\\00000002-DBD1-46C6-B5D0-B1BA559D10E4\\tokens.json")); access_token = (string)EpicConfig["access_token"]; } catch { } if (access_token.IsNullOrEmpty()) { logger.Error($"ISThereAnyDeal - No Epic configuration."); return(Result); } // Get wishlist string ResultWeb = ""; ResultWeb = QuerySearchWishList(access_token).GetAwaiter().GetResult(); if (ResultWeb != "") { JObject resultObj = new JObject(); logger.Debug(ResultWeb); try { resultObj = JObject.Parse(ResultWeb); if (resultObj["data"]["Wishlist"]["wishlistItems"]["elements"] != null) { IsThereAnyDealApi isThereAnyDealApi = new IsThereAnyDealApi(); foreach (JObject gameWishlist in resultObj["data"]["Wishlist"]["wishlistItems"]["elements"]) { int StoreId = 0; string Name = ""; DateTime ReleaseDate = default(DateTime); string Capsule = ""; Name = (string)gameWishlist["offer"]["title"]; foreach (var keyImages in gameWishlist["offer"]["keyImages"]) { if ((string)keyImages["type"] == "Thumbnail") { Capsule = (string)keyImages["url"]; } } Result.Add(new Wishlist { StoreId = StoreId, StoreName = "Epic", StoreUrl = "", Name = WebUtility.HtmlDecode(Name), SourceId = SourceId, ReleaseDate = ReleaseDate.ToUniversalTime(), Capsule = Capsule, Plain = isThereAnyDealApi.GetPlain(Name) }); } } } catch (Exception ex) { Common.LogError(ex, "IsThereAnyDeal", "Error io parse Epic wishlist"); return(Result); } } Result = SetCurrentPrice(Result, settings, PlayniteApi); SaveWishlist("Epic", PluginUserDataPath, Result); return(Result); }
public List <Wishlist> GetWishlist(IPlayniteAPI PlayniteApi, Guid SourceId, string PluginUserDataPath, IsThereAnyDealSettings settings, bool CacheOnly = false, bool Force = false) { List <Wishlist> Result = new List <Wishlist>(); List <Wishlist> ResultLoad = LoadWishlists("Gog", PluginUserDataPath); if (ResultLoad != null && !Force) { ResultLoad = SetCurrentPrice(ResultLoad, settings, PlayniteApi); SaveWishlist("Gog", PluginUserDataPath, ResultLoad); return(ResultLoad); } if (CacheOnly) { return(Result); } if (gogAPI != null && gogAPI.GetIsUserLoggedIn()) { string ResultWeb = ""; try { // Get wishlist ResultWeb = gogAPI.GetWishList(); // Get game information for wishlist if (ResultWeb != "") { JObject resultObj = JObject.Parse(ResultWeb); try { if (((JObject)resultObj["wishlist"]).Count > 0) { IsThereAnyDealApi isThereAnyDealApi = new IsThereAnyDealApi(); foreach (var gameWishlist in (JObject)resultObj["wishlist"]) { if (((bool)gameWishlist.Value)) { int StoreId = int.Parse(gameWishlist.Key); //Download game information string url = string.Format(@"https://api.gog.com/products/{0}", StoreId); ResultWeb = HttpDownloader.DownloadString(url, Encoding.UTF8); try { JObject resultObjGame = JObject.Parse(ResultWeb); DateTime ReleaseDate = (DateTime)resultObjGame["release_date"]; string Name = (string)resultObjGame["title"]; string Capsule = "http:" + (string)resultObjGame["images"]["logo2x"]; Result.Add(new Wishlist { StoreId = StoreId, StoreName = "GOG", StoreUrl = (string)resultObjGame["links"]["product_card"], Name = WebUtility.HtmlDecode(Name), SourceId = SourceId, ReleaseDate = ReleaseDate.ToUniversalTime(), Capsule = Capsule, Plain = isThereAnyDealApi.GetPlain(Name) }); } catch (Exception ex) { Common.LogError(ex, "IsThereAnyDeal", $"Failed to download game inforamtion for {StoreId}"); return(Result); } } } } } catch (Exception ex) { Common.LogError(ex, "IsThereAnyDeal", $"Error io parse GOG wishlist"); return(Result); } } } catch (WebException ex) { Common.LogError(ex, "IsThereAnyDeal", "Error in download GOG wishlist"); return(Result); } } Result = SetCurrentPrice(Result, settings, PlayniteApi); SaveWishlist("Gog", PluginUserDataPath, Result); return(Result); }
public List <Wishlist> GetWishlist(IPlayniteAPI PlayniteApi, Guid SourceId, string PluginUserDataPath, IsThereAnyDealSettings settings, bool CacheOnly = false, bool Force = false) { List <Wishlist> Result = new List <Wishlist>(); List <Wishlist> ResultLoad = LoadWishlists("Steam", PluginUserDataPath); if (ResultLoad != null && !Force) { ResultLoad = SetCurrentPrice(ResultLoad, settings, PlayniteApi); SaveWishlist("Steam", PluginUserDataPath, ResultLoad); return(ResultLoad); } if (CacheOnly) { return(Result); } // Get Steam configuration if exist. string userId = ""; string apiKey = ""; try { JObject SteamConfig = JObject.Parse(File.ReadAllText(PluginUserDataPath + "\\..\\CB91DFC9-B977-43BF-8E70-55F46E410FAB\\config.json")); userId = (string)SteamConfig["UserId"]; apiKey = (string)SteamConfig["ApiKey"]; } catch { } if (userId.IsNullOrEmpty() || apiKey.IsNullOrEmpty()) { logger.Error($"ISThereAnyDeal - No Steam configuration."); return(Result); } string ResultWeb = ""; string url = string.Format(@"https://store.steampowered.com/wishlist/profiles/{0}/wishlistdata/", userId); ResultWeb = ""; try { ResultWeb = HttpDownloader.DownloadString(url, Encoding.UTF8); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { Common.LogError(ex, "IsThereAnyDeal", "Error in download Steam wishlist"); return(Result); } } if (ResultWeb != "") { JObject resultObj = new JObject(); JArray resultItems = new JArray(); try { resultObj = JObject.Parse(ResultWeb); IsThereAnyDealApi isThereAnyDealApi = new IsThereAnyDealApi(); foreach (var gameWishlist in resultObj) { JObject gameWishlistData = (JObject)gameWishlist.Value; int StoreId = int.Parse(gameWishlist.Key); string Name = (string)gameWishlistData["name"]; DateTime ReleaseDate = ((int)gameWishlistData["release_date"] == 0) ? default(DateTime) : new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds((int)gameWishlistData["release_date"]); string Capsule = (string)gameWishlistData["capsule"]; Result.Add(new Wishlist { StoreId = StoreId, StoreName = "Steam", StoreUrl = "https://store.steampowered.com/app/" + StoreId, Name = WebUtility.HtmlDecode(Name), SourceId = SourceId, ReleaseDate = ReleaseDate.ToUniversalTime(), Capsule = Capsule, Plain = isThereAnyDealApi.GetPlain(Name) }); } } catch (Exception ex) { Common.LogError(ex, "IsThereAnyDeal", "Error io parse Steam wishlist"); return(Result); } } Result = SetCurrentPrice(Result, settings, PlayniteApi); SaveWishlist("Steam", PluginUserDataPath, Result); return(Result); }