Ejemplo n.º 1
0
        /// <summary>
        /// Show list game with achievement.
        /// </summary>
        /// <param name="SearchGameName"></param>
        public void GetListGame(string SearchGameName = "", List <string> SearchSourceName = null)
        {
            logger.Debug("SearchGameName: " + SearchGameName);
            logger.Debug("SearchSourceName: " + JsonConvert.SerializeObject(SearchSourceName));

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

            foreach (var item in PlayniteApiDatabase.Games)
            {
                string GameSourceName = "";
                if (item.SourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
                {
                    GameSourceName = item.Source.Name;
                }
                else
                {
                    GameSourceName = "Playnite";
                }


                bool isFind = false;

                if (SearchSourceName != null)
                {
                    for (int i = 0; i < SearchSourceName.Count; i++)
                    {
                        if (GameSourceName.ToLower().Contains(SearchSourceName[i].ToLower()))
                        {
                            isFind = true;
                        }
                    }
                }

                if (SearchGameName != "")
                {
                    if (item.Name.ToLower().Contains(SearchGameName.ToLower()))
                    {
                        isFind = true;
                    }
                }

                if (SearchGameName != "" && SearchSourceName != null)
                {
                    isFind = false;

                    for (int i = 0; i < SearchSourceName.Count; i++)
                    {
                        if ((GameSourceName.ToLower().Contains(SearchSourceName[i].ToLower())) && (item.Name.ToLower().Contains(SearchGameName.ToLower())))
                        {
                            isFind = true;
                        }
                    }
                }

                if (SearchGameName == "" && SearchSourceName == null)
                {
                    isFind = true;
                }


                if (isFind && AchievementsDatabase.HaveAchievements(item.Id))
                {
                    if (AchievementsDatabase.VerifToAddOrShow(GameSourceName, settings))
                    {
                        string   GameId   = item.Id.ToString();
                        string   GameName = item.Name;
                        string   GameIcon;
                        DateTime?GameLastActivity = null;

                        string SourceName = "";
                        if (item.SourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
                        {
                            SourceName = item.Source.Name;
                        }
                        else
                        {
                            SourceName = "Playnite";
                        }

                        GameAchievements GameAchievements = AchievementsDatabase.Get(item.Id);

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

                        BitmapImage iconImage = new BitmapImage();
                        if (String.IsNullOrEmpty(item.Icon) == false)
                        {
                            iconImage.BeginInit();
                            GameIcon            = PlayniteApiDatabase.GetFullFilePath(item.Icon);
                            iconImage.UriSource = new Uri(GameIcon, UriKind.RelativeOrAbsolute);
                            iconImage.EndInit();
                        }

                        ListGames.Add(new ListGames()
                        {
                            Id               = GameId,
                            Name             = GameName,
                            Icon             = iconImage,
                            LastActivity     = GameLastActivity,
                            SourceName       = SourceName,
                            SourceIcon       = TransformIcon.Get(SourceName),
                            ProgressionValue = GameAchievements.Progression,
                            Total            = GameAchievements.Total,
                            TotalPercent     = GameAchievements.Progression + "%",
                            Unlocked         = GameAchievements.Unlocked
                        });

                        iconImage = null;
                    }
                }
            }

            ListviewGames.ItemsSource = ListGames;

            // Sorting
            try
            {
                var columnBinding = _lastHeaderClicked.Column.DisplayMemberBinding as Binding;
                var sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;

                // Specific sort with another column
                if (_lastHeaderClicked.Name == "lvSourceIcon")
                {
                    columnBinding = lvSourceName.Column.DisplayMemberBinding as Binding;
                    sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;
                }
                if (_lastHeaderClicked.Name == "lvProgression")
                {
                    columnBinding = lvProgressionValue.Column.DisplayMemberBinding as Binding;
                    sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;
                }
                Sort(sortBy, _lastDirection);
            }
            // If first view
            catch
            {
                CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(ListviewGames.ItemsSource);

                logger.Debug("sort - " + settings.NameSorting + " - " + _lastDirection.ToString());

                switch (settings.NameSorting)
                {
                case ("Name"):
                    _lastHeaderClicked = lvName;
                    if (settings.IsAsc)
                    {
                        _lastHeaderClicked.Content += " ▲";
                    }
                    else
                    {
                        _lastHeaderClicked.Content += " ▼";
                    }
                    break;

                case ("LastActivity"):
                    _lastHeaderClicked = lvLastActivity;
                    if (settings.IsAsc)
                    {
                        _lastHeaderClicked.Content += " ▲";
                    }
                    else
                    {
                        _lastHeaderClicked.Content += " ▼";
                    }
                    break;

                case ("SourceName"):
                    _lastHeaderClicked = lvSourceIcon;
                    if (settings.IsAsc)
                    {
                        lvSourceIcon.Content += " ▲";
                    }
                    else
                    {
                        lvSourceIcon.Content += " ▼";
                    }
                    break;

                case ("ProgressionValue"):
                    _lastHeaderClicked = lvProgression;
                    if (settings.IsAsc)
                    {
                        lvProgression.Content += " ▲";
                    }
                    else
                    {
                        lvProgression.Content += " ▼";
                    }
                    break;
                }


                if (settings.IsAsc)
                {
                    _lastDirection = ListSortDirection.Ascending;
                }
                else
                {
                    _lastDirection = ListSortDirection.Descending;
                }


                view.SortDescriptions.Add(new SortDescription(settings.NameSorting, _lastDirection));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Show list game with achievement.
        /// </summary>
        public void GetListGame()
        {
            List <Guid> ListEmulators = new List <Guid>();

            foreach (var item in PlayniteApi.Database.Emulators)
            {
                ListEmulators.Add(item.Id);
            }

            if (ListGames.Count == 0)
            {
                foreach (var item in PlayniteApiDatabase.Games)
                {
                    string GameSourceName = "";
                    if (item.SourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
                    {
                        GameSourceName = item.Source.Name;

                        if (item.PlayAction != null && item.PlayAction.EmulatorId != null && ListEmulators.Contains(item.PlayAction.EmulatorId))
                        {
                            GameSourceName = "RetroAchievements";
                        }
                    }
                    else
                    {
                        if (item.PlayAction != null && item.PlayAction.EmulatorId != null && ListEmulators.Contains(item.PlayAction.EmulatorId))
                        {
                            GameSourceName = "RetroAchievements";
                        }
                        else
                        {
                            GameSourceName = "Playnite";
                        }
                    }

                    if (AchievementsDatabase.HaveAchievements(item.Id))
                    {
                        if (AchievementsDatabase.VerifToAddOrShow(GameSourceName, settings, PluginUserDataPath))
                        {
                            string   GameId   = item.Id.ToString();
                            string   GameName = item.Name;
                            string   GameIcon;
                            DateTime?GameLastActivity = null;

                            string SourceName = "";
                            if (item.SourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
                            {
                                SourceName = item.Source.Name;

                                if (item.PlayAction != null && item.PlayAction.EmulatorId != null && ListEmulators.Contains(item.PlayAction.EmulatorId))
                                {
                                    SourceName = "RetroAchievements";
                                }
                            }
                            else
                            {
                                if (item.PlayAction != null && item.PlayAction.EmulatorId != null && ListEmulators.Contains(item.PlayAction.EmulatorId))
                                {
                                    SourceName = "RetroAchievements";
                                }
                                else
                                {
                                    SourceName = "Playnite";
                                }
                            }

                            GameAchievements GameAchievements = AchievementsDatabase.Get(item.Id);

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

                            BitmapImage iconImage = new BitmapImage();
                            if (String.IsNullOrEmpty(item.Icon) == false)
                            {
                                iconImage.BeginInit();
                                GameIcon            = PlayniteApiDatabase.GetFullFilePath(item.Icon);
                                iconImage.UriSource = new Uri(GameIcon, UriKind.RelativeOrAbsolute);
                                iconImage.EndInit();
                            }

                            ListGames.Add(new ListGames()
                            {
                                Id               = GameId,
                                Name             = GameName,
                                Icon             = iconImage,
                                LastActivity     = GameLastActivity,
                                SourceName       = SourceName,
                                SourceIcon       = TransformIcon.Get(SourceName),
                                ProgressionValue = GameAchievements.Progression,
                                Total            = GameAchievements.Total,
                                TotalPercent     = GameAchievements.Progression + "%",
                                Unlocked         = GameAchievements.Unlocked
                            });

                            iconImage = null;
                        }
                    }
                }
            }


            ListviewGames.ItemsSource = ListGames;
            // Filter
            if (!TextboxSearch.Text.IsNullOrEmpty() && SearchSources.Count != 0)
            {
                ListviewGames.ItemsSource = ListGames.FindAll(
                    x => x.Name.ToLower().IndexOf(TextboxSearch.Text) > -1 && SearchSources.Contains(x.SourceName)
                    );
                return;
            }

            if (!TextboxSearch.Text.IsNullOrEmpty())
            {
                ListviewGames.ItemsSource = ListGames.FindAll(
                    x => x.Name.ToLower().IndexOf(TextboxSearch.Text) > -1
                    );
                return;
            }

            if (SearchSources.Count != 0)
            {
                ListviewGames.ItemsSource = ListGames.FindAll(
                    x => SearchSources.Contains(x.SourceName)
                    );
                return;
            }


            // Sorting
            try
            {
                var columnBinding = _lastHeaderClicked.Column.DisplayMemberBinding as Binding;
                var sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;

                // Specific sort with another column
                if (_lastHeaderClicked.Name == "lvSourceIcon")
                {
                    columnBinding = lvSourceName.Column.DisplayMemberBinding as Binding;
                    sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;
                }
                if (_lastHeaderClicked.Name == "lvProgression")
                {
                    columnBinding = lvProgressionValue.Column.DisplayMemberBinding as Binding;
                    sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;
                }
                Sort(sortBy, _lastDirection);
            }
            // If first view
            catch
            {
                CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(ListviewGames.ItemsSource);

                switch (settings.NameSorting)
                {
                case ("Name"):
                    _lastHeaderClicked = lvName;
                    if (settings.IsAsc)
                    {
                        _lastHeaderClicked.Content += " ▲";
                    }
                    else
                    {
                        _lastHeaderClicked.Content += " ▼";
                    }
                    break;

                case ("LastActivity"):
                    _lastHeaderClicked = lvLastActivity;
                    if (settings.IsAsc)
                    {
                        _lastHeaderClicked.Content += " ▲";
                    }
                    else
                    {
                        _lastHeaderClicked.Content += " ▼";
                    }
                    break;

                case ("SourceName"):
                    _lastHeaderClicked = lvSourceIcon;
                    if (settings.IsAsc)
                    {
                        lvSourceIcon.Content += " ▲";
                    }
                    else
                    {
                        lvSourceIcon.Content += " ▼";
                    }
                    break;

                case ("ProgressionValue"):
                    _lastHeaderClicked = lvProgression;
                    if (settings.IsAsc)
                    {
                        lvProgression.Content += " ▲";
                    }
                    else
                    {
                        lvProgression.Content += " ▼";
                    }
                    break;
                }


                if (settings.IsAsc)
                {
                    _lastDirection = ListSortDirection.Ascending;
                }
                else
                {
                    _lastDirection = ListSortDirection.Descending;
                }


                view.SortDescriptions.Add(new SortDescription(settings.NameSorting, _lastDirection));
            }
        }
Ejemplo n.º 3
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()");
            }
        }