Esempio n. 1
0
        /// <inheritdoc />
        public override AutoCatResult CategorizeGame(GameInfo game, Filter filter)
        {
            if (games == null)
            {
                Logger.Error(GlobalStrings.Log_AutoCat_GamelistNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameList);
            }

            if (game == null)
            {
                Logger.Error(GlobalStrings.Log_AutoCat_GameNull);
                return(AutoCatResult.Failure);
            }

            if (!game.IncludeGame(filter))
            {
                return(AutoCatResult.Filtered);
            }

            if (!Database.Contains(game.Id, out DatabaseEntry entry) || entry.LastStoreScrape == 0)
            {
                return(AutoCatResult.NotInDatabase);
            }

            if (RemoveOtherGenres && genreCategories != null)
            {
                game.RemoveCategory(genreCategories);
            }

            ICollection <string> genreList = Database.GetGenreList(game.Id, MAX_PARENT_DEPTH, TagFallback);

            List <Category> categories = new List <Category>();
            int             max        = MaxCategories;

            int i = 0;

            foreach (string genre in genreList)
            {
                if (MaxCategories != 0 && i >= max)
                {
                    continue;
                }

                if (!IgnoredGenres.Contains(genre))
                {
                    categories.Add(games.GetCategory(GetCategoryName(genre)));
                }
                else
                {
                    max++; // ignored genres don't contribute to max
                }

                i++;
            }

            game.AddCategory(categories);

            return(AutoCatResult.Success);
        }
Esempio n. 2
0
        public override AutoCatResult CategorizeGame(GameInfo game, Filter filter)
        {
            if (games == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameList);
            }

            if (db == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameDB);
            }

            if (game == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull);
                return(AutoCatResult.Failure);
            }

            if (!db.Contains(game.Id) || db.Games[game.Id].LastStoreScrape == 0)
            {
                return(AutoCatResult.NotInDatabase);
            }

            if (!game.IncludeGame(filter))
            {
                return(AutoCatResult.Filtered);
            }

            if (RemoveOtherGenres && genreCategories != null)
            {
                game.RemoveCategory(genreCategories);
            }

            List <string> genreList = db.GetGenreList(game.Id, MAX_PARENT_DEPTH, TagFallback);

            if (genreList != null && genreList.Count > 0)
            {
                List <Category> categories = new List <Category>();
                int             max        = MaxCategories;
                for (int i = 0; i < genreList.Count && (MaxCategories == 0 || i < max); i++)
                {
                    if (!IgnoredGenres.Contains(genreList[i]))
                    {
                        categories.Add(games.GetCategory(GetProcessedString(genreList[i])));
                    }
                    else
                    {
                        max++; // ignored genres don't contribute to max
                    }
                }

                game.AddCategory(categories);
            }

            return(AutoCatResult.Success);
        }
Esempio n. 3
0
        /// <summary>
        ///     Prepares to categorize games. Prepares a list of genre categories to remove. Does nothing if removeothergenres is
        ///     false.
        /// </summary>
        public override void PreProcess(GameList games, Database db)
        {
            base.PreProcess(games, db);
            if (!RemoveOtherGenres)
            {
                return;
            }

            genreCategories = new SortedSet <Category>();

            foreach (string genre in db.AllGenres)
            {
                if (games.CategoryExists(string.IsNullOrEmpty(Prefix) ? genre : Prefix + genre) && !IgnoredGenres.Contains(genre))
                {
                    genreCategories.Add(games.GetCategory(genre));
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     Prepares to categorize games. Prepares a list of genre categories to remove. Does nothing if removeothergenres is
        ///     false.
        /// </summary>
        public override void PreProcess(GameList games, Database db)
        {
            base.PreProcess(games, db);
            if (RemoveOtherGenres)
            {
                SortedSet <string> genreStrings = db.GetAllGenres();
                genreCategories = new SortedSet <Category>();

                foreach (string cStr in genreStrings)
                {
                    if (games.CategoryExists(string.IsNullOrEmpty(Prefix) ? cStr : Prefix + cStr) && !IgnoredGenres.Contains(cStr))
                    {
                        genreCategories.Add(games.GetCategory(cStr));
                    }
                }
            }
        }