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> 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()); }