public SuccessStoryEditManual(Game game) { InitializeComponent(); gameAchievements = PluginDatabase.Get(game, true); LoadData(game); }
private void LoadData(Game GameSelected) { Guid GameId = GameSelected.Id; GameAchievements successStories = PluginDatabase.Get(GameSelected); List <Achievements> ListAchievements = successStories.Items; List <GameStats> ListGameStats = successStories.ItemsStats; // List Achievements SuccessStoryAchievementsList successStoryAchievementsList = new SuccessStoryAchievementsList(true); successStoryAchievementsList.SetScData(successStories); PART_Achievements_List.Children.Add(successStoryAchievementsList); // Chart achievements int limit = 0; if (!PluginDatabase.PluginSettings.GraphicAllUnlockedByDay) { PART_ChartTitle.Content = resources.GetString("LOCSuccessStoryGraphicTitle"); limit = 20; } else { PART_ChartTitle.Content = resources.GetString("LOCSuccessStoryGraphicTitleDay"); limit = 16; } PluginDatabase.PluginSettings.IgnoreSettings = true; SuccessStoryAchievementsGraphics successStoryAchievementsGraphics = new SuccessStoryAchievementsGraphics(); successStoryAchievementsGraphics.SetScData(GameId, limit); PART_Achievements_Graphics.Children.Add(successStoryAchievementsGraphics); // User stats SuccessStoryUserStats successStoryUserStats = new SuccessStoryUserStats(); successStoryUserStats.SetScData(ListGameStats); PART_ScUserStats.Children.Add(successStoryUserStats); }
// 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); }
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 }); }); }
/// <summary> /// Show list game with achievement. /// </summary> public void GetListGame() { string pluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); try { if (ListGames.Count == 0) { var dataGameAchievements = PluginDatabase.Database.Where(x => x.HaveAchivements && x.IsDeleted == false); foreach (GameAchievements item in dataGameAchievements) { string SourceName = PlayniteTools.GetSourceName(_PlayniteApi, item.Id); string GameId = item.Id.ToString(); string GameName = item.Name; string GameIcon = string.Empty; string Icon100 = string.Empty; DateTime?GameLastActivity = null; GameAchievements successStories = PluginDatabase.Get(item.Id); if (item.LastActivity != null) { GameLastActivity = ((DateTime)item.LastActivity).ToLocalTime(); } if (!item.Icon.IsNullOrEmpty()) { GameIcon = _PlayniteApiDatabase.GetFullFilePath(item.Icon); } if (successStories.Is100Percent) { Icon100 = Path.Combine(pluginFolder, "Resources\\badge.png"); } ListGames.Add(new ListViewGames() { Icon100Percent = Icon100, Id = GameId, Name = GameName, Icon = GameIcon, LastActivity = GameLastActivity, SourceName = SourceName, SourceIcon = TransformIcon.Get(SourceName), ProgressionValue = successStories.Progression, Total = successStories.Total, TotalPercent = successStories.Progression + "%", Unlocked = successStories.Unlocked, IsManual = successStories.IsManual }); } #if DEBUG logger.Debug($"SuccessStory [Ignored] - ListGames: {JsonConvert.SerializeObject(ListGames)}"); #endif } Application.Current.Dispatcher.BeginInvoke((Action) delegate { ListviewGames.ItemsSource = ListGames; Sorting(); }); } catch (Exception ex) { Common.LogError(ex, "SuccessStory", "Errorn on GetListGames()"); } }
// 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); }