public GameRequierements GetFromWeb(Game game)
        {
            GameRequierements gameRequierements = GetDefault(game);

            string SourceName = string.Empty;

            try
            {
                SourceName = PlayniteTools.GetSourceName(_PlayniteApi, game);

                // Search datas
                logger.Info($"SystemChecker - Try find with PCGamingWikiRequierements for {game.Name}");
                gameRequierements = pCGamingWikiRequierements.GetRequirements(game);

                if (!pCGamingWikiRequierements.IsFind())
                {
                    logger.Info($"SystemChecker - Try find with SteamRequierements for {game.Name}");
                    switch (SourceName.ToLower())
                    {
                    case "steam":
                        gameRequierements      = steamRequierements.GetRequirements(game);
                        gameRequierements.Link = "https://store.steampowered.com/app/" + game.GameId;
                        break;

                    default:
                        SteamApi steamApi = new SteamApi(PluginUserDataPath);
                        int      SteamID  = steamApi.GetSteamId(game.Name);
                        if (SteamID != 0)
                        {
                            gameRequierements      = steamRequierements.GetRequirements(game, (uint)SteamID);
                            gameRequierements.Link = "https://store.steampowered.com/app/" + SteamID;
                        }
                        break;
                    }
                }

                gameRequierements = NormalizeRecommanded(gameRequierements);
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "SystemChecker");
            }

            return(gameRequierements);
        }
        private void ButtonRemove_Click(object sender, RoutedEventArgs e)
        {
            int index = int.Parse(((Button)sender).Tag.ToString());

            var item         = ((List <ListGameScreenshot>)PART_ListGameScreenshot.ItemsSource)[index];
            int ControlIndex = listGameScreenshots.FindIndex(x => x == item);

            PART_ListGameScreenshot.ItemsSource = null;
            listGameScreenshots.RemoveAt(ControlIndex);
            PART_ListGameScreenshot.ItemsSource = listGameScreenshots;
            TextboxSearch_TextChanged(null, null);

            var TaskView = Task.Run(() =>
            {
                var DbWithoutAlready = PluginDatabase.PlayniteApi.Database.Games.Where(x => !listGameScreenshots.Any(y => x.Id == y.Id));
                listGames            = new List <ListGame>();
                foreach (Game game in DbWithoutAlready)
                {
                    string Icon = string.Empty;
                    if (!game.Icon.IsNullOrEmpty())
                    {
                        Icon = PluginDatabase.PlayniteApi.Database.GetFullFilePath(game.Icon);
                    }

                    listGames.Add(new ListGame
                    {
                        Id         = game.Id,
                        Icon       = Icon,
                        Name       = game.Name,
                        SourceName = PlayniteTools.GetSourceName(game.Id)
                    });
                }

                this.Dispatcher.BeginInvoke((Action) delegate
                {
                    listGames.Sort((x, y) => x.Name.CompareTo(y.Name));
                    PART_ListGame.ItemsSource = null;
                    PART_ListGame.ItemsSource = listGames;

                    PART_ListGameScreenshot.ItemsSource = null;
                    PART_ListGameScreenshot.ItemsSource = listGameScreenshots;
                });
            });
        }
Esempio n. 3
0
        private void SetData(int index = -1)
        {
            PART_DataLoad.Visibility = Visibility.Visible;
            PART_Data.Visibility     = Visibility.Hidden;

            Task.Run(() =>
            {
                ObservableCollection <LveGame> LveGames = PluginDatabase.Database.Where(x => x.HasData)
                                                          .Select(x => new LveGame
                {
                    Id           = x.Id,
                    Icon         = PluginDatabase.PlayniteApi.Database.GetFullFilePath(x.Icon),
                    Name         = x.Name,
                    LastActivity = x.LastActivity,
                    SourceName   = PlayniteTools.GetSourceName(x.Id),

                    LastSsv = x.Items.Select(y => y.Modifed).Max(),
                    Total   = x.Items.Count
                }).ToObservable();
                return(LveGames);
            }).ContinueWith(antecedent =>
            {
                this.Dispatcher?.BeginInvoke(DispatcherPriority.Loaded, new ThreadStart(delegate
                {
                    ((SsvScreenshotsManagerData)DataContext).LveGames = antecedent.Result;

                    PART_LveGames.Sorting();
                    if (index != -1)
                    {
                        PART_LveGames.SelectedIndex = index;
                    }

                    PART_DataLoad.Visibility = Visibility.Hidden;
                    PART_Data.Visibility     = Visibility.Visible;
                }));
            });
        }
        // 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);
        }
Esempio n. 5
0
        public AchievementsGraphicsDataCountSources GetCountBySources()
        {
            List <string> tempSourcesLabels = new List <string>();

            if (PluginSettings.EnableRetroAchievementsView && PluginSettings.EnableRetroAchievements)
            {
                if (_isRetroachievements)
                {
                    if (PluginSettings.EnableRetroAchievements)
                    {
                        tempSourcesLabels.Add("RetroAchievements");
                    }
                }
                else
                {
                    if (PluginSettings.EnableGog)
                    {
                        tempSourcesLabels.Add("GOG");
                    }
                    if (PluginSettings.EnableSteam)
                    {
                        tempSourcesLabels.Add("Steam");
                    }
                    if (PluginSettings.EnableOrigin)
                    {
                        tempSourcesLabels.Add("Origin");
                    }
                    if (PluginSettings.EnableXbox)
                    {
                        tempSourcesLabels.Add("Xbox");
                    }
                    if (PluginSettings.EnableLocal)
                    {
                        tempSourcesLabels.Add("Playnite");
                        tempSourcesLabels.Add("Hacked");
                    }
                    if (PluginSettings.EnableRpcs3Achievements)
                    {
                        tempSourcesLabels.Add("RPCS3");
                    }
                }
            }
            else
            {
                if (PluginSettings.EnableGog)
                {
                    tempSourcesLabels.Add("GOG");
                }
                if (PluginSettings.EnableSteam)
                {
                    tempSourcesLabels.Add("Steam");
                }
                if (PluginSettings.EnableOrigin)
                {
                    tempSourcesLabels.Add("Origin");
                }
                if (PluginSettings.EnableXbox)
                {
                    tempSourcesLabels.Add("Xbox");
                }
                if (PluginSettings.EnableRetroAchievements)
                {
                    tempSourcesLabels.Add("RetroAchievements");
                }
                if (PluginSettings.EnableRpcs3Achievements)
                {
                    tempSourcesLabels.Add("RPCS3");
                }
                if (PluginSettings.EnableLocal)
                {
                    tempSourcesLabels.Add("Playnite");
                    tempSourcesLabels.Add("Hacked");
                }
            }

            tempSourcesLabels.Sort((x, y) => x.CompareTo(y));

            string[] GraphicsAchievementsLabels = new string[tempSourcesLabels.Count];
            List <AchievementsGraphicsDataSources> tempDataUnlocked = new List <AchievementsGraphicsDataSources>();
            List <AchievementsGraphicsDataSources> tempDataLocked   = new List <AchievementsGraphicsDataSources>();
            List <AchievementsGraphicsDataSources> tempDataTotal    = new List <AchievementsGraphicsDataSources>();

            for (int i = 0; i < tempSourcesLabels.Count; i++)
            {
                GraphicsAchievementsLabels[i] = TransformIcon.Get(tempSourcesLabels[i]);
                tempDataLocked.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
                tempDataUnlocked.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
                tempDataTotal.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
            }


            foreach (var item in Database.Items)
            {
                if (!item.Value.HaveAchivements || item.Value.IsDeleted)
                {
                    continue;
                }

                try
                {
                    string SourceName = PlayniteTools.GetSourceName(_PlayniteApi, item.Key);

                    foreach (Achievements achievements in item.Value.Items)
                    {
                        for (int i = 0; i < tempDataUnlocked.Count; i++)
                        {
                            if (tempDataUnlocked[i].source == SourceName)
                            {
                                tempDataTotal[i].value += 1;
                                if (achievements.DateUnlocked != default(DateTime))
                                {
                                    tempDataUnlocked[i].value += 1;
                                }
                                if (achievements.DateUnlocked == default(DateTime))
                                {
                                    tempDataLocked[i].value += 1;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "SuccessStory", $"Error on GetCountBySources() for {item.Key}");
                }
            }

            ChartValues <CustomerForSingle> SourceAchievementsSeriesUnlocked = new ChartValues <CustomerForSingle>();
            ChartValues <CustomerForSingle> SourceAchievementsSeriesLocked   = new ChartValues <CustomerForSingle>();
            ChartValues <CustomerForSingle> SourceAchievementsSeriesTotal    = new ChartValues <CustomerForSingle>();

            for (int i = 0; i < tempDataUnlocked.Count; i++)
            {
                SourceAchievementsSeriesUnlocked.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataUnlocked[i].source),
                    Values = tempDataUnlocked[i].value
                });
                SourceAchievementsSeriesLocked.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataLocked[i].source),
                    Values = tempDataLocked[i].value
                });
                SourceAchievementsSeriesTotal.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataTotal[i].source),
                    Values = tempDataTotal[i].value
                });
            }


            return(new AchievementsGraphicsDataCountSources
            {
                Labels = GraphicsAchievementsLabels,
                SeriesLocked = SourceAchievementsSeriesLocked,
                SeriesUnlocked = SourceAchievementsSeriesUnlocked,
                SeriesTotal = SourceAchievementsSeriesTotal
            });
        }
Esempio n. 6
0
        /// <summary>
        /// Generate database achivements for the game if achievement exist and game not exist in database.
        /// </summary>
        /// <param name="game"></param>
        public GameAchievements GetFromWeb(Game game)
        {
            GameAchievements gameAchievements = GetDefault(game);

            Guid   GameId         = game.Id;
            Guid   GameSourceId   = game.SourceId;
            string GameSourceName = PlayniteTools.GetSourceName(_PlayniteApi, game);

            List <Achievements> Achievements = new List <Achievements>();

            // Generate database only this source
            if (VerifToAddOrShow(_plugin, _PlayniteApi, PluginSettings, PluginUserDataPath, GameSourceName))
            {
#if DEBUG
                logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShow({game.Name}, {GameSourceName}) - OK");
#endif

                // TODO one func
                if (GameSourceName.ToLower() == "gog")
                {
                    if (gogAPI == null)
                    {
                        gogAPI = new GogAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    }
                    gameAchievements = gogAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "steam")
                {
                    SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    gameAchievements = steamAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "origin")
                {
                    if (originAPI == null)
                    {
                        originAPI = new OriginAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    }
                    gameAchievements = originAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "xbox")
                {
                    if (xboxAPI == null)
                    {
                        xboxAPI = new XboxAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    }
                    gameAchievements = xboxAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "playnite" || GameSourceName.ToLower() == "hacked")
                {
                    SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    steamAPI.SetLocal();
                    gameAchievements = steamAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "retroachievements")
                {
                    RetroAchievements retroAchievementsAPI = new RetroAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    gameAchievements = retroAchievementsAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "rpcs3")
                {
                    Rpcs3Achievements rpcs3Achievements = new Rpcs3Achievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    gameAchievements = rpcs3Achievements.GetAchievements(game);
                }

#if DEBUG
                logger.Debug($"SuccessStory [Ignored] - Achievements for {game.Name} - {GameSourceName} - {JsonConvert.SerializeObject(gameAchievements)}");
#endif
            }
            else
            {
#if DEBUG
                logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShow({game.Name}, {GameSourceName}) - KO");
#endif
            }

            return(gameAchievements);
        }
Esempio n. 7
0
        private void SetTotal()
        {
            SteamTotal             = 0;
            SteamTotalAchievements = 0;
            GogTotal                           = 0;
            GogTotalAchievements               = 0;
            OriginTotal                        = 0;
            OriginTotalAchievements            = 0;
            XboxTotal                          = 0;
            XboxTotalAchievements              = 0;
            RetroAchievementsTotal             = 0;
            RetroAchievementsTotalAchievements = 0;
            Rpcs3Total                         = 0;
            Rpcs3TotalAchievements             = 0;

            LocalTotal             = 0;
            LocalTotalAchievements = 0;

            try
            {
                foreach (var game in _PlayniteApi.Database.Games)
                {
                    string GameSourceName = PlayniteTools.GetSourceName(_PlayniteApi, game);

                    switch (GameSourceName.ToLower())
                    {
                    case "steam":
                        SteamTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            SteamTotalAchievements += 1;
                        }
                        break;

                    case "gog":
                        GogTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            GogTotalAchievements += 1;
                        }
                        break;

                    case "origin":
                        OriginTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            OriginTotalAchievements += 1;
                        }
                        break;

                    case "xbox":
                        XboxTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            XboxTotalAchievements += 1;
                        }
                        break;

                    case "retroachievements":
                        RetroAchievementsTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            RetroAchievementsTotalAchievements += 1;
                        }
                        break;

                    case "rpcs3":
                        Rpcs3Total += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            Rpcs3TotalAchievements += 1;
                        }
                        break;

                    case "playnite":
                        LocalTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            LocalTotalAchievements += 1;
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "SuccessStory", $"Error on SetTotal()");
            }

            SteamLoad.Content             = SteamTotalAchievements + "/" + SteamTotal;
            GogLoad.Content               = GogTotalAchievements + "/" + GogTotal;
            OriginLoad.Content            = OriginTotalAchievements + "/" + OriginTotal;
            XboxLoad.Content              = XboxTotalAchievements + "/" + XboxTotal;
            RetroAchievementsLoad.Content = RetroAchievementsTotalAchievements + "/" + RetroAchievementsTotal;
            LocalLoad.Content             = LocalTotalAchievements + "/" + LocalTotal;
            Rpcs3Load.Content             = Rpcs3TotalAchievements + "/" + Rpcs3Total;
        }
Esempio n. 8
0
        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>
        /// Generate database achivements for the game if achievement exist and game not exist in database.
        /// </summary>
        /// <param name="GameAdded"></param>
        public void Add(Game GameAdded, SuccessStorySettings settings)
        {
            GameAchievements GameAchievements = new GameAchievements();

            Guid   GameId                 = GameAdded.Id;
            Guid   GameSourceId           = GameAdded.SourceId;
            string GameSourceName         = PlayniteTools.GetSourceName(GameAdded, _PlayniteApi);
            string PluginDatabaseGamePath = PluginDatabasePath + GameId.ToString() + ".json";

            List <Achievements> Achievements = new List <Achievements>();

            // Generate database only this source
            if (VerifToAddOrShow(_plugin, _PlayniteApi, GameSourceName, settings, _PluginUserDataPath))
            {
                // Generate only not exist
                if (!File.Exists(PluginDatabaseGamePath))
                {
#if DEBUG
                    logger.Debug($"SuccessStory - VerifToAddOrShow({GameAdded.Name}, {GameSourceName}) - OK");
#endif

                    // TODO one func
                    if (GameSourceName.ToLower() == "gog")
                    {
                        if (gogAPI == null)
                        {
                            gogAPI = new GogAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        }
                        GameAchievements = gogAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "steam")
                    {
                        SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        GameAchievements = steamAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "origin")
                    {
                        if (originAPI == null)
                        {
                            originAPI = new OriginAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        }
                        GameAchievements = originAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "xbox")
                    {
                        if (xboxAPI == null)
                        {
                            xboxAPI = new XboxAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        }
                        GameAchievements = xboxAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "playnite")
                    {
                        SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        steamAPI.SetLocal();
                        GameAchievements = steamAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "retroachievements")
                    {
                        RetroAchievements retroAchievementsAPI = new RetroAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        GameAchievements = retroAchievementsAPI.GetAchievements(GameAdded);
                    }

#if DEBUG
                    logger.Debug($"SuccessStory - Achievements for {GameAdded.Name} - {GameSourceName} - {JsonConvert.SerializeObject(GameAchievements)}");
#endif

                    if (GameAchievements != null)
                    {
                        File.WriteAllText(PluginDatabaseGamePath, JsonConvert.SerializeObject(GameAchievements));
                    }
                }
            }
            else
            {
#if DEBUG
                logger.Debug($"SuccessStory - VerifToAddOrShow({GameAdded.Name}, {GameSourceName}) - KO");
#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()");
            }
        }
        private void LoadData(IPlayniteAPI PlayniteApi)
        {
            listGameScreenshots = new List <ListGameScreenshot>();
            foreach (var item in ScreenshotsVisualizer.PluginDatabase.PluginSettings.Settings.gameSettings)
            {
                Game game = PlayniteApi.Database.Games.Get(item.Id);

                if (game != null)
                {
                    string Icon = string.Empty;
                    if (!game.Icon.IsNullOrEmpty())
                    {
                        Icon = PlayniteApi.Database.GetFullFilePath(game.Icon);
                    }

                    // TEMP
                    List <FolderSettings> ScreenshotsFolders = new List <FolderSettings>();
                    if (!item.ScreenshotsFolder.IsNullOrEmpty())
                    {
                        ScreenshotsFolders.Add(new FolderSettings
                        {
                            UsedFilePattern   = item.UsedFilePattern,
                            FilePattern       = item.FilePattern,
                            ScreenshotsFolder = item.ScreenshotsFolder,
                            ScanSubFolders    = item.ScanSubFolders
                        });
                    }
                    else
                    {
                        ScreenshotsFolders = item.ScreenshotsFolders;
                    }

                    listGameScreenshots.Add(new ListGameScreenshot
                    {
                        Id   = item.Id,
                        Icon = Icon,
                        Name = game.Name,
                        ScreenshotsFolders = ScreenshotsFolders,
                        UsedFilePattern    = item.UsedFilePattern,
                        ScanSubFolders     = item.ScanSubFolders,
                        FilePattern        = item.FilePattern,
                        SourceName         = PlayniteTools.GetSourceName(item.Id),
                        SourceIcon         = TransformIcon.Get(PlayniteTools.GetSourceName(item.Id))
                    });
                }
                else
                {
                    logger.Warn($"Game is deleted - {item.Id}");
                }
            }

            var DbWithoutAlready = PlayniteApi.Database.Games.Where(x => !listGameScreenshots.Any(y => x.Id == y.Id));

            listGames = new List <ListGame>();
            foreach (Game item in DbWithoutAlready)
            {
                string Icon = string.Empty;
                if (!item.Icon.IsNullOrEmpty())
                {
                    Icon = PlayniteApi.Database.GetFullFilePath(item.Icon);
                }

                listGames.Add(new ListGame
                {
                    Id         = item.Id,
                    Icon       = Icon,
                    Name       = item.Name,
                    SourceName = PlayniteTools.GetSourceName(item.Id),
                    SourceIcon = TransformIcon.Get(PlayniteTools.GetSourceName(item.Id))
                });
            }

            listGames.Sort((x, y) => x.Name.CompareTo(y.Name));
            listGameScreenshots.Sort((x, y) => x.Name.CompareTo(y.Name));
        }
        public override void RefreshElements(Game GameSelected, bool force = false)
        {
#if DEBUG
            logger.Debug($"SuccessStory - RefreshElements({GameSelected.Name})");
#endif

            CancellationTokenSource tokenSource = new CancellationTokenSource();
            CancellationToken       ct          = tokenSource.Token;

            Task TaskRefresh = Task.Run(() =>
            {
#if DEBUG
                string IsCanceld = string.Empty;

                logger.Debug($"SuccessStory - TaskRefresh() - Start");
                Stopwatch stopwatch = new Stopwatch();
                TimeSpan ts;
                stopwatch.Start();
#endif
                try
                {
                    Initial();

                    // Reset resources
                    List <ResourcesList> resourcesLists = new List <ResourcesList>();
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_HasData", Value = false
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Is100Percent", Value = false
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Total", Value = 0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_TotalDouble", Value = (double)0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_TotalString", Value = "0"
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Unlocked", Value = 0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_UnlockedDouble", Value = (double)0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_UnlockedString", Value = "0"
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Locked", Value = 0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_LockedDouble", Value = (double)0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_LockedString", Value = "0"
                    });

                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_EnableIntegrationInCustomTheme", Value = _Settings.EnableIntegrationInCustomTheme
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_IntegrationShowGraphic", Value = _Settings.IntegrationShowGraphic
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_IntegrationShowAchievements", Value = _Settings.IntegrationShowAchievements
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_IntegrationShowProgressBar", Value = _Settings.IntegrationShowProgressBar
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_IntegrationShowAchievementsCompactLocked", Value = _Settings.IntegrationShowAchievementsCompactLocked
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_IntegrationShowAchievementsCompactUnlocked", Value = _Settings.IntegrationShowAchievementsCompactUnlocked
                    });
                    ui.AddResources(resourcesLists);


                    // Load data
                    SuccessStory.SelectedGameAchievements = null;
                    string GameSourceName = string.Empty;

                    try
                    {
                        SuccessStory.SelectedGameAchievements = SuccessStory.achievementsDatabase.Get(GameSelected.Id);
                        GameSourceName = PlayniteTools.GetSourceName(GameSelected, _PlayniteApi);
                    }
                    catch (Exception ex)
                    {
                        Common.LogError(ex, "SuccessStory", "Error to load data");
                        _PlayniteApi.Dialogs.ShowErrorMessage(resources.GetString("LOCDatabaseErroTitle"), "SuccessStory");
                    }

                    // Download Achievements if not exist in database.
                    if (SuccessStory.SelectedGameAchievements == null)
                    {
                        logger.Info($"SuccessStory - Download achievements for {GameSelected.Name} - {GameSourceName}");
                        SuccessStory.achievementsDatabase.Add(GameSelected, _Settings);
                        SuccessStory.achievementsDatabase.Initialize();
                        SuccessStory.SelectedGameAchievements = SuccessStory.achievementsDatabase.Get(GameSelected.Id);
                    }

                    if (SuccessStory.SelectedGameAchievements == null)
                    {
                        logger.Warn("SuccessStory - No data for " + GameSelected.Name);
#if DEBUG
                        stopwatch.Stop();
                        ts = stopwatch.Elapsed;
                        logger.Debug($"SuccessStory - TaskRefresh(){IsCanceld} - End - {String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)}");
#endif
                        return;
                    }

                    if (!SuccessStory.SelectedGameAchievements.HaveAchivements)
                    {
                        logger.Warn("SuccessStory - No achievements for " + GameSelected.Name);
#if DEBUG
                        stopwatch.Stop();
                        ts = stopwatch.Elapsed;
                        logger.Debug($"SuccessStory - TaskRefresh(){IsCanceld} - End - {String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)}");
#endif
                        return;
                    }

#if DEBUG
                    logger.Debug($"SuccessStory - SuccessStory.SelectedGameAchievements: ({JsonConvert.SerializeObject(SuccessStory.SelectedGameAchievements)})");
#endif
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_HasData", Value = true
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Is100Percent", Value = SuccessStory.SelectedGameAchievements.Is100Percent
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Total", Value = SuccessStory.SelectedGameAchievements.Total
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_TotalDouble", Value = double.Parse(SuccessStory.SelectedGameAchievements.Total.ToString())
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_TotalString", Value = SuccessStory.SelectedGameAchievements.Total.ToString()
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Unlocked", Value = SuccessStory.SelectedGameAchievements.Unlocked
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_UnlockedDouble", Value = double.Parse(SuccessStory.SelectedGameAchievements.Unlocked.ToString())
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_UnlockedString", Value = SuccessStory.SelectedGameAchievements.Unlocked.ToString()
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Locked", Value = SuccessStory.SelectedGameAchievements.Locked
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_LockedDouble", Value = double.Parse(SuccessStory.SelectedGameAchievements.Locked.ToString())
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_LockedString", Value = SuccessStory.SelectedGameAchievements.Locked.ToString()
                    });


                    // If not cancel, show
                    if (!ct.IsCancellationRequested && _PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Desktop)
                    {
                        ui.AddResources(resourcesLists);

                        if (SuccessStory.SelectedGameAchievements != null && SuccessStory.SelectedGameAchievements.HaveAchivements)
                        {
                            Application.Current.Dispatcher.BeginInvoke((Action) delegate
                            {
                                if (_Settings.EnableIntegrationButton)
                                {
#if DEBUG
                                    logger.Debug($"SuccessStory - RefreshBtActionBar()");
#endif
                                    try
                                    {
                                        RefreshBtActionBar();
                                    }
                                    catch (Exception ex)
                                    {
                                        Common.LogError(ex, "SuccessStory", $"Error on RefreshBtActionBar()");
                                    }
                                }

                                if (_Settings.EnableIntegrationInDescription)
                                {
#if DEBUG
                                    logger.Debug($"SuccessStory - RefreshSpDescription()");
#endif
                                    try
                                    {
                                        RefreshSpDescription();
                                    }
                                    catch (Exception ex)
                                    {
                                        Common.LogError(ex, "SuccessStory", $"Error on RefreshSpDescription()");
                                    }
                                }

                                if (_Settings.EnableIntegrationInCustomTheme)
                                {
#if DEBUG
                                    logger.Debug($"SuccessStory - RefreshCustomElements()");
#endif
                                    try
                                    {
                                        RefreshCustomElements();
                                    }
                                    catch (Exception ex)
                                    {
                                        Common.LogError(ex, "SuccessStory", $"Error on RefreshCustomElements()");
                                    }
                                }
                            });
                        }
                        else
                        {
#if DEBUG
                            logger.Debug($"SuccessStory - No data for {SuccessStory.GameSelected.Name}");
#endif
                        }
                    }
                    else
                    {
#if DEBUG
                        IsCanceld = " canceled";
#endif
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "SuccessStory", $"Error on TaskRefreshBtActionBar()");
                }
#if DEBUG
                stopwatch.Stop();
                ts = stopwatch.Elapsed;
                logger.Debug($"SuccessStory - TaskRefresh(){IsCanceld} - End - {String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)}");
#endif
            }, ct);

            taskHelper.Add(TaskRefresh, tokenSource);
        }
Esempio n. 13
0
        /// <summary>
        /// Show list game with achievement.
        /// </summary>
        public void GetListGame()
        {
            string pluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            try
            {
                if (ListGames.Count == 0)
                {
                    var dataGameAchievements = AchievementsDb.gameAchievements.Where(x => x.Value.HaveAchivements);
                    foreach (var item in dataGameAchievements)
                    {
                        Game   game       = _PlayniteApiDatabase.Games.Get(item.Key);
                        string SourceName = PlayniteTools.GetSourceName(game, _PlayniteApi);

                        if (AchievementsDatabase.VerifToAddOrShow(plugin, _PlayniteApi, SourceName, settings, PluginUserDataPath))
                        {
                            string   GameId           = game.Id.ToString();
                            string   GameName         = game.Name;
                            string   GameIcon         = string.Empty;
                            string   Icon100          = string.Empty;
                            DateTime?GameLastActivity = null;

                            GameAchievements GameAchievements = AchievementsDb.Get(game.Id);

                            if (game.LastActivity != null)
                            {
                                GameLastActivity = ((DateTime)game.LastActivity).ToLocalTime();
                            }

                            if (!game.Icon.IsNullOrEmpty())
                            {
                                GameIcon = _PlayniteApiDatabase.GetFullFilePath(game.Icon);
                            }

                            if (GameAchievements.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 = GameAchievements.Progression,
                                Total            = GameAchievements.Total,
                                TotalPercent     = GameAchievements.Progression + "%",
                                Unlocked         = GameAchievements.Unlocked
                            });
                        }
                    }
                }

                Application.Current.Dispatcher.BeginInvoke((Action) delegate
                {
                    ListviewGames.ItemsSource = ListGames;
                    Sorting();
                });
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "SuccessStory", "Errorn on GetListGames()");
            }
        }