private void RefreshData(string SourceName, bool IsGet = false) { SuccessStoryDatabase.ListErrors = new CumulErrors(); #if DEBUG logger.Info($"SuccessStory [Ignored] - RefreshData() - Start"); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); #endif SuccessStorySettings.IsEnabled = false; pbDataLoad.IsIndeterminate = false; pbDataLoad.Minimum = 0; pbDataLoad.Value = 0; DataLoad.Visibility = Visibility.Visible; tcSettings.Visibility = Visibility.Hidden; tokenSource = new CancellationTokenSource(); ct = tokenSource.Token; bool IsFirstLoop = true; var taskSystem = Task.Run(() => { try { // filter games IEnumerable <Game> FilterDatabaseGame = null; switch (SourceName.ToLower()) { case "all": FilterDatabaseGame = _PlayniteApi.Database.Games; break; case "allrecent": FilterDatabaseGame = _PlayniteApi.Database.Games.Where( x => x.LastActivity > DateTime.Now.AddMonths(-2) || (x.Added != null && x.Added > DateTime.Now.AddMonths(-2)) ); break; case "allinstalled": FilterDatabaseGame = _PlayniteApi.Database.Games.Where(x => x.IsInstalled); break; default: FilterDatabaseGame = _PlayniteApi.Database.Games.Where( x => PlayniteTools.GetSourceName(_PlayniteApi, x).ToLower() == SourceName.ToLower() ); break; } Application.Current.Dispatcher.BeginInvoke((Action) delegate { pbDataLoad.Maximum = FilterDatabaseGame.Count(); }); #if DEBUG logger.Debug($"SuccessStory [Ignored] - FilterDatabaseGame: {FilterDatabaseGame.Count()}"); #endif foreach (var game in FilterDatabaseGame) { try { if (SourceName.ToLower() == "steam" && IsFirstLoop) { #if DEBUG logger.Debug($"SuccessStory [Ignored] - Check Steam profil with {game.GameId}"); #endif SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginDatabase.PluginSettings, _PluginUserDataPath); int AppId = 0; int.TryParse(game.GameId, out AppId); if (!steamAPI.CheckIsPublic(AppId)) { SuccessStoryDatabase.ListErrors.Add(resources.GetString("LOCSuccessStoryNotificationsSteamPrivate")); break; } IsFirstLoop = false; } // Respect API limitation Thread.Sleep(1000); if (IsGet) { // Add only it's not loaded if (!PluginDatabase.VerifAchievementsLoad(game.Id)) { PluginDatabase.Get(game); } } else { PluginDatabase.Remove(game); PluginDatabase.Get(game); } Application.Current.Dispatcher.BeginInvoke((Action) delegate { pbDataLoad.Value += 1; }); } catch (Exception ex) { Common.LogError(ex, "SuccessStory", $"Error on RefreshData({SourceName}, {IsGet}) for {game.Name}"); } if (ct.IsCancellationRequested) { logger.Info($"IsCancellationRequested for RefreshData({ SourceName}, { IsGet})"); break; } } } catch (Exception ex) { Common.LogError(ex, "SuccessStory", $"Error on RefreshData({SourceName}, {IsGet})"); } }, tokenSource.Token) .ContinueWith(antecedent => { Application.Current.Dispatcher.BeginInvoke((Action) delegate { DataLoad.Visibility = Visibility.Collapsed; tcSettings.Visibility = Visibility.Visible; if (!WithoutMessage) { if (SuccessStoryDatabase.ListErrors.Get() != string.Empty) { _PlayniteApi.Dialogs.ShowErrorMessage(SuccessStoryDatabase.ListErrors.Get(), "SuccessStory errors"); } else { _PlayniteApi.Dialogs.ShowMessage((string)ResourceProvider.GetResource("LOCSuccessStoryRefreshDataMessage"), "Success Story"); } } SetTotal(); SuccessStorySettings.IsEnabled = true; #if DEBUG stopwatch.Stop(); logger.Debug($"SuccessStory [Ignored] - RefreshData() - End - {stopwatch.Elapsed}"); #endif }); }); }
// To add new game menu items override GetGameMenuItems public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args) { Game GameMenu = args.Games.First(); string SourceName = PlayniteTools.GetSourceName(PlayniteApi, GameMenu); bool IsAddOrShowManual = SuccessStoryDatabase.IsAddOrShowManual(GameMenu, SourceName); GameAchievements gameAchievements = PluginDatabase.Get(GameMenu, true); List <GameMenuItem> gameMenuItems = new List <GameMenuItem>(); if (!settings.EnableOneGameView || (settings.EnableOneGameView && gameAchievements.HasData)) { // Show list achievements for the selected game gameMenuItems.Add(new GameMenuItem { MenuSection = resources.GetString("LOCSuccessStory"), Description = resources.GetString("LOCSuccessStoryViewGame"), Action = (gameMenuItem) => { dynamic ViewExtension = null; PluginDatabase.IsViewOpen = true; if (PluginDatabase.PluginSettings.EnableOneGameView) { ViewExtension = new SuccessStoryOneGameView(GameMenu); } else { ViewExtension = new SuccessView(this, PlayniteApi, this.GetPluginUserDataPath(), false, GameMenu); } Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension); windowExtension.ShowDialog(); PluginDatabase.IsViewOpen = false; } }); } if (!IsAddOrShowManual) { gameMenuItems.Add(new GameMenuItem { MenuSection = resources.GetString("LOCSuccessStory"), Description = resources.GetString("LOCCommonRefreshGameData"), Action = (gameMenuItem) => { if (settings.EnableIntegrationInCustomTheme || settings.EnableIntegrationInDescription) { PlayniteUiHelper.ResetToggle(); } var TaskIntegrationUI = Task.Run(() => { PluginDatabase.Remove(GameMenu); var dispatcherOp = successStoryUI.AddElements(); dispatcherOp.Completed += (s, e) => { successStoryUI.RefreshElements(GameMenu); }; }); } }); } if (settings.EnableManual && IsAddOrShowManual) { if (!gameAchievements.HasData) { gameMenuItems.Add(new GameMenuItem { MenuSection = resources.GetString("LOCSuccessStory"), Description = resources.GetString("LOCAddTitle"), Action = (mainMenuItem) => { var TaskIntegrationUI = Task.Run(() => { PluginDatabase.Remove(GameMenu); PluginDatabase.GetManual(GameMenu); var dispatcherOp = successStoryUI.AddElements(); dispatcherOp.Completed += (s, e) => { successStoryUI.RefreshElements(GameMenu); }; }); } }); } else { gameMenuItems.Add(new GameMenuItem { MenuSection = resources.GetString("LOCSuccessStory"), Description = resources.GetString("LOCEditGame"), Action = (mainMenuItem) => { var ViewExtension = new SuccessStoryEditManual(GameMenu); Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension); windowExtension.ShowDialog(); } }); gameMenuItems.Add(new GameMenuItem { MenuSection = resources.GetString("LOCSuccessStory"), Description = resources.GetString("LOCRemoveTitle"), Action = (gameMenuItem) => { if (settings.EnableIntegrationInCustomTheme || settings.EnableIntegrationInDescription) { PlayniteUiHelper.ResetToggle(); } var TaskIntegrationUI = Task.Run(() => { PluginDatabase.Remove(GameMenu); var dispatcherOp = successStoryUI.AddElements(); dispatcherOp.Completed += (s, e) => { successStoryUI.RefreshElements(GameMenu); }; }); } }); } } #if DEBUG gameMenuItems.Add(new GameMenuItem { MenuSection = resources.GetString("LOCSuccessStory"), Description = "Test", Action = (mainMenuItem) => { } }); #endif return(gameMenuItems); }
// To add new game menu items override GetGameMenuItems public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args) { var GameMenu = args.Games.First(); List <GameMenuItem> gameMenuItems = new List <GameMenuItem>(); if (!PluginDatabase.PluginSettings.EnableOneGameView || (PluginDatabase.PluginSettings.EnableOneGameView && PluginDatabase.Get(GameMenu, true).HasData)) { // Show list achievements for the selected game gameMenuItems.Add(new GameMenuItem { MenuSection = resources.GetString("LOCSuccessStory"), Description = resources.GetString("LOCSuccessStoryViewGame"), Action = (gameMenuItem) => { dynamic ViewExtension = null; PluginDatabase.IsViewOpen = true; if (PluginDatabase.PluginSettings.EnableOneGameView) { ViewExtension = new SuccessStoryOneGameView(GameMenu); } else { ViewExtension = new SuccessView(this, PlayniteApi, this.GetPluginUserDataPath(), false, GameMenu); } Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension); windowExtension.ShowDialog(); PluginDatabase.IsViewOpen = false; } }); } gameMenuItems.Add(new GameMenuItem { // Delete & download localizations data for the selected game MenuSection = resources.GetString("LOCSuccessStory"), Description = resources.GetString("LOCCommonRefreshGameData"), Action = (gameMenuItem) => { if (settings.EnableIntegrationInCustomTheme || settings.EnableIntegrationInDescription) { PlayniteUiHelper.ResetToggle(); } var TaskIntegrationUI = Task.Run(() => { PluginDatabase.Remove(GameMenu); var dispatcherOp = successStoryUI.AddElements(); dispatcherOp.Completed += (s, e) => { successStoryUI.RefreshElements(GameMenu); }; }); } }); #if DEBUG gameMenuItems.Add(new GameMenuItem { MenuSection = resources.GetString("LOCSuccessStory"), Description = "Test", Action = (mainMenuItem) => { } }); #endif return(gameMenuItems); }