/// <summary> /// Prepares to categorize games. Prepares a list of genre categories to remove. Does nothing if removeothergenres is /// false. /// </summary> public override void PreProcess(IGameList games) { base.PreProcess(games); if (!RemoveOtherGenres) { return; } genreCategories = new SortedSet <Category>(); foreach (string genre in Database.AllGenres) { if (games.CategoryExists(string.IsNullOrEmpty(Prefix) ? genre : Prefix + genre) && !IgnoredGenres.Contains(genre)) { genreCategories.Add(games.GetCategory(genre)); } } }
/// <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 (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); }