public override void OnGameStopped(Game game, long elapsedSeconds) { // Add code to be executed when game is preparing to be started. // Refresh Achievements database for game played. achievementsDatabase.Remove(game); achievementsDatabase.Add(game, settings); // Refresh integration interface SuccessStory.isFirstLoad = true; Integration(); }
// 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> { new GameMenuItem { MenuSection = resources.GetString("LOCSuccessStory"), Description = resources.GetString("LOCSuccessStoryViewGame"), Action = (gameMenuItem) => { var ViewExtension = new SuccessView(this, settings, PlayniteApi, this.GetPluginUserDataPath(), false, GameMenu); Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension); windowExtension.ShowDialog(); } }, new GameMenuItem { MenuSection = resources.GetString("LOCSuccessStory"), Description = resources.GetString("LOCSuccessStoryRefreshData"), Action = (gameMenuItem) => { if (settings.EnableIntegrationInCustomTheme || settings.EnableIntegrationInDescription) { PlayniteUiHelper.ResetToggle(); } var TaskIntegrationUI = Task.Run(() => { achievementsDatabase.Remove(GameMenu); successStoryUI.AddElements(); successStoryUI.RefreshElements(GameSelected); }); } } }; #if DEBUG gameMenuItems.Add(new GameMenuItem { MenuSection = resources.GetString("LOCSuccessStory"), Description = "Test", Action = (mainMenuItem) => { } }); #endif return(gameMenuItems); }
public override void OnGameStopped(Game game, long elapsedSeconds) { // Add code to be executed when game is preparing to be started. // Refresh Achievements database for game played. AchievementsDatabase AchievementsDatabase = new AchievementsDatabase(PlayniteApi, this.GetPluginUserDataPath()); AchievementsDatabase.Remove(game); AchievementsDatabase.Add(game, settings); // REfresh integration interface Integration(); }
public override void OnLibraryUpdated() { // Add code to be executed when library is updated. // Get achievements for the new game added int he library. AchievementsDatabase AchievementsDatabase = new AchievementsDatabase(PlayniteApi, this.GetPluginUserDataPath()); foreach (var game in PlayniteApi.Database.Games) { if (game.Added == null && ((DateTime)game.Added).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")) { AchievementsDatabase.Remove(game); AchievementsDatabase.Add(game, settings); } } }
private void RefreshData(string SourceName, bool IsGet = false) { #if DEBUG logger.Info($"SuccessStory - 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(x, PlayniteApi).ToLower() == SourceName.ToLower() ); break; } Application.Current.Dispatcher.BeginInvoke((Action) delegate { pbDataLoad.Maximum = FilterDatabaseGame.Count(); }); #if DEBUG logger.Debug($"SuccessStory - FilterDatabaseGame: {FilterDatabaseGame.Count()}"); #endif foreach (var game in FilterDatabaseGame) { try { if (SourceName.ToLower() == "steam" && IsFirstLoop) { #if DEBUG logger.Debug($"SuccessStory - Check Steam profil with {game.GameId}"); #endif SteamAchievements steamAPI = new SteamAchievements(PlayniteApi, settings, PluginUserDataPath); int AppId = 0; int.TryParse(game.GameId, out AppId); if (!steamAPI.CheckIsPublic(AppId)) { AchievementsDatabase.ListErrors.Add(resources.GetString("LOCSuccessStoryNotificationsSteamPrivate")); break; } IsFirstLoop = false; } // Respect API limitation Thread.Sleep(1000); if (IsGet) { // Add only it's not loaded if (!achievementsDatabase.VerifAchievementsLoad(game.Id)) { achievementsDatabase.Add(game, settings); } } else { achievementsDatabase.Remove(game); achievementsDatabase.Add(game, settings); } 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; } } achievementsDatabase.Initialize(); } 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 (AchievementsDatabase.ListErrors.Get() != string.Empty) { PlayniteApi.Dialogs.ShowErrorMessage(AchievementsDatabase.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 - RefreshData() - End - {stopwatch.Elapsed}"); #endif }); }); }
internal void RefreshData(string SourceName, bool IsGet = false) { // ProgressBar SuccessStoryLoad.Visibility = Visibility.Visible; SuccessStoryLoad.Value = 0; SuccessStoryLoad.Maximum = PlayniteApi.Database.Games.Count; SuccessStorySettings.IsEnabled = false; foreach (var game in PlayniteApi.Database.Games) { string GameSourceName = ""; if (game.SourceId != Guid.Parse("00000000-0000-0000-0000-000000000000")) { GameSourceName = game.Source.Name; } else { GameSourceName = "Playnite"; } if (GameSourceName.ToLower() == SourceName.ToLower() || SourceName.ToLower() == "all" || SourceName.ToLower() == "allrecent" || SourceName.ToLower() == "allinstalled") { bool isOK = true; if (SourceName.ToLower() == "allrecent") { if ((game.LastActivity != null && game.LastActivity > DateTime.Now.AddMonths(-1)) || (game.Added != null && game.Added > DateTime.Now.AddMonths(-1))) { isOK = true; } else { isOK = false; } } if (SourceName.ToLower() == "allinstalled") { if (game.IsInstalled) { isOK = true; } else { isOK = false; } } if (isOK) { Dispatcher.Invoke(new Action(() => { // Prevent HTTP 429 with limit request per minutes. Thread.Sleep(1000); if (IsGet) { // Add only it's not loaded if (!AchievementsDatabase.VerifAchievementsLoad(game.Id)) { AchievementsDatabase.Add(game, settings); } } else { AchievementsDatabase.Remove(game); AchievementsDatabase.Add(game, settings); } }), DispatcherPriority.ContextIdle, null); } } SuccessStoryLoad.Value += 1; } if (AchievementsDatabase.ListErrors.Get() != "") { PlayniteApi.Dialogs.ShowErrorMessage(AchievementsDatabase.ListErrors.Get(), "SuccesStory errors"); } else { PlayniteApi.Dialogs.ShowMessage((string)ResourceProvider.GetResource("LOCSucessStoryRefreshDataMessage"), "Success Story"); } SuccessStoryLoad.Visibility = Visibility.Hidden; SuccessStorySettings.IsEnabled = true; }