Пример #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 (db == null)
            {
                Logger.Error(GlobalStrings.Log_AutoCat_DBNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameDB);
            }

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

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

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

            if (RemoveAllCategories)
            {
                game.ClearCategories();
            }
            else if (RemoveCategories != null)
            {
                List <Category> removed = new List <Category>();

                foreach (string category in RemoveCategories)
                {
                    Category c = gamelist.GetCategory(category);
                    if (!game.ContainsCategory(c))
                    {
                        continue;
                    }

                    game.RemoveCategory(c);
                    removed.Add(c);
                }

                foreach (Category c in removed)
                {
                    if (c.Count == 0)
                    {
                        gamelist.RemoveCategory(c);
                    }
                }
            }

            if (AddCategories == null)
            {
                return(AutoCatResult.Success);
            }

            foreach (string category in AddCategories)
            // add Category, or create it if it doesn't exist
            {
                game.AddCategory(gamelist.GetCategory(GetCategoryName(category)));
            }

            return(AutoCatResult.Success);
        }
Пример #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 (RemoveAllCategories)
            {
                game.ClearCategories();
            }
            else if (RemoveCategories != null)
            {
                List <Category> removed = new List <Category>();

                foreach (string category in RemoveCategories)
                {
                    Category c = _gamelist.GetCategory(category);
                    if (game.ContainsCategory(c))
                    {
                        game.RemoveCategory(c);
                        removed.Add(c);
                    }
                }

                foreach (Category c in removed)
                {
                    if (c.Count == 0)
                    {
                        _gamelist.RemoveCategory(c);
                    }
                }
            }

            if (AddCategories != null)
            {
                foreach (string category in AddCategories)
                {
                    // add Category, or create it if it doesn't exist
                    game.AddCategory(_gamelist.GetCategory(GetProcessedString(category)));
                }
            }

            return(AutoCatResult.Success);
        }