Represents a single game category
Inheritance: IComparable
Esempio n. 1
0
 /// <summary>
 /// Check whether the game includes the given category
 /// </summary>
 /// <param name="c">Category to look for</param>
 /// <returns>True if category is found</returns>
 public bool ContainsCategory( Category c )
 {
     return Categories.Contains( c );
 }
Esempio n. 2
0
 public GameList()
 {
     Games = new Dictionary<int, GameInfo>();
     Categories = new List<Category>();
     Filters = new List<Filter>();
     favoriteCategory = new Category( FAVORITE_NEW_CONFIG_VALUE );
     Categories.Add( favoriteCategory );
 }
Esempio n. 3
0
 /// <summary>
 /// Removes a single category from a single game.
 /// </summary>
 /// <param name="gameID">Game ID to remove from</param>
 /// <param name="c">Category to remove</param>
 public void RemoveGameCategory( int gameID, Category c )
 {
     GameInfo g = Games[gameID];
     g.RemoveCategory( c );
 }
Esempio n. 4
0
 public void SetGameCategories( int[] gameIDs, Category cat, bool preserveFavorites )
 {
     SetGameCategories( gameIDs, new List<Category>() { cat }, preserveFavorites );
 }
Esempio n. 5
0
 void AddCategoryToSelectedGames( Category cat, bool refreshCatList, bool forceClearOthers )
 {
     if( lstGames.SelectedItems.Count > 0 ) {
         foreach( ListViewItem item in lstGames.SelectedItems ) {
             GameInfo g = item.Tag as GameInfo;
             if( g != null ) {
                 if( forceClearOthers || settings.SingleCatMode ) {
                     g.ClearCategoriesExcept( gameData.FavoriteCategory );
                     if( cat != null ) {
                         g.AddCategory( cat );
                     }
                 } else {
                     g.AddCategory( cat );
                 }
             }
         }
         OnGameChange( refreshCatList, true );
         MakeChange( true );
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Renames a category as specified, displaying an error if the operation fails.
 /// </summary>
 /// <param name="c">Category to rename</param>
 /// <param name="newName">Name to change to</param>
 /// <returns>True if successful, false otherwise.</returns>
 bool RenameCategoryHelper( Category c, string newName )
 {
     if( newName == c.Name ) return true;
     if( CatUtil.ValidateCategoryName( newName ) && gameData.RenameCategory( c, newName ) ) {
         OnCategoryChange();
         MakeChange( true );
         AddStatus( string.Format( GlobalStrings.MainForm_CategoryRenamed, c.Name ) );
         return true;
     } else {
         MessageBox.Show( string.Format( GlobalStrings.MainForm_NameIsInUse, newName ), GlobalStrings.DBEditDlg_Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning );
         return false;
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Check to see if the game has any categories at all, besides the given category
 /// </summary>
 /// <param name="c">Category to except from the check</param>
 /// <returns>True if the game has any categories set besides c</returns>
 public bool HasCategoriesExcept( Category c )
 {
     if( Categories.Count == 0 ) return false;
     if( Categories.Count == 1 && Categories.Contains( c ) ) return false;
     return true;
 }
Esempio n. 8
0
 /// <summary>
 /// Gets a category based on a name. Creates the category if necessary. Displays error message on error.
 /// </summary>
 /// <param name="name">Name of the category to get</param>
 /// <param name="data">Game data object we're referencing</param>
 /// <param name="cat">Resulting category</param>
 /// <returns>True if successful, false otherwise</returns>
 public static bool StringToCategory( string name, GameData data, out Category cat )
 {
     cat = null;
     if( string.IsNullOrWhiteSpace( name ) ) {
         return true;
     }
     if( name == CAT_FAV_NAME || name == CAT_ALL_NAME ) {
         MessageBox.Show(string.Format(GlobalStrings.MainForm_CategoryNameReserved, name), GlobalStrings.DBEditDlg_Warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return false;
     }
     if( name != CAT_UNC_NAME ) {
         cat = data.GetCategory( name );
     }
     return true;
 }
Esempio n. 9
0
 /// <summary>
 /// Remove all categories attached to this game except for the specified one
 /// </summary>
 /// <param name="c">Category to leave in place</param>
 public void ClearCategoriesExcept( Category c )
 {
     bool restore = false;
     if( Categories.Contains( c ) ) {
         restore = true;
     }
     Categories.Clear();
     if( restore ) {
         Categories.Add( c );
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Gets a string listing the game's assigned categories, omitting the given category from the list if it is found.
 /// </summary>
 /// <param name="except">Category to omit</param>
 /// <param name="ifEmpty">Value to return if there are no categories</param>
 /// <returns>List of the game's categories, separated by commas.</returns>
 public string GetCatStringExcept( Category except, string ifEmpty = "" )
 {
     string result = "";
     bool first = true;
     foreach( Category c in Categories ) {
         if( c != except ) {
             if( !first ) {
                 result += ", ";
             }
             result += c.Name;
             first = false;
         }
     }
     return first ? ifEmpty : result;
 }
Esempio n. 11
0
 /// <summary>
 /// Adds a single category to this game. Does nothing if the category is already attached.
 /// </summary>
 /// <param name="newCat">Category to add</param>
 public void AddCategory( Category newCat )
 {
     if( newCat != null ) Categories.Add( newCat );
 }
Esempio n. 12
0
 /// <summary>
 /// Renames the given category.
 /// </summary>
 /// <param name="c">Category to rename.</param>
 /// <param name="newName">Name to assign to the new category.</param>
 /// <returns>True if rename was successful, false otherwise (if name was in use already)</returns>
 public bool RenameCategory( Category c, string newName )
 {
     if( c == favoriteCategory ) return false;
     if( !CategoryExists( newName ) ) {
         c.Name = newName;
         Categories.Sort();
         return true;
     }
     return false;
 }
Esempio n. 13
0
 public Game( int id, string name )
 {
     Id = id;
     Name = name;
     Category = null;
     Favorite = false;
 }
Esempio n. 14
0
 /// <summary>
 /// Adds a single category to a single game
 /// </summary>
 /// <param name="gameID">Game ID to add category to</param>
 /// <param name="c">Category to add</param>
 public void AddGameCategory( int gameID, Category c )
 {
     GameInfo g = Games[gameID];
     g.AddCategory( c );
 }
Esempio n. 15
0
 /// <summary>
 /// Removes a single category from this game. Does nothing if the category is not attached to this game.
 /// </summary>
 /// <param name="remCat">Category to remove</param>
 public void RemoveCategory( Category remCat )
 {
     Categories.Remove( remCat );
 }
Esempio n. 16
0
        // Compare two ListViewItems.
        public int Compare(object object_x, object object_y)
        {
            // Get the objects as ListViewItems.
            ListViewItem item_x = object_x as ListViewItem;
            ListViewItem item_y = object_y as ListViewItem;

            if (item_x == null)
            {
                return(1);
            }

            if (item_y == null)
            {
                return(-1);
            }

            // Handle special categories
            List <string> specialCategories = new List <string>();

            specialCategories.Add(GlobalStrings.MainForm_All);
            specialCategories.Add(GlobalStrings.MainForm_Uncategorized);
            specialCategories.Add(GlobalStrings.MainForm_Hidden);
            specialCategories.Add(GlobalStrings.MainForm_Favorite);
            specialCategories.Add(GlobalStrings.MainForm_VR);

            foreach (string s in specialCategories)
            {
                if (item_x.Tag.ToString() == s)
                {
                    return(-1);
                }

                if (item_y.Tag.ToString() == s)
                {
                    return(1);
                }
            }

            Category cat_x = item_x.Tag as Category;
            Category cat_y = item_y.Tag as Category;

            // Compare categories.
            int result;

            if (SortMode == categorySortMode.Count)
            {
                result = cat_x.Count.CompareTo(cat_y.Count);
            }
            else
            {
                result = string.Compare(cat_x.Name, cat_y.Name, StringComparison.CurrentCultureIgnoreCase);
            }

            // Return the correct result depending on whether
            // we're sorting ascending or descending.
            if (SortOrder == SortOrder.Ascending)
            {
                return(result);
            }

            return(-result);
        }
Esempio n. 17
0
 public GameList()
 {
     Games = new Dictionary<int, GameInfo>();
     Categories = new List<Category>();
     favoriteCategory = new Category( "favorite" );
     Categories.Add( favoriteCategory );
 }
Esempio n. 18
0
 /// <summary>
 /// Assigns the given category to all selected items in the game list.
 /// </summary>
 /// <param name="cat">Category to assign</param>
 void AssignCategoryToSelectedGames( Category cat )
 {
     if( lstGames.SelectedItems.Count > 0 ) {
         foreach( ListViewItem item in lstGames.SelectedItems ) {
             ( item.Tag as Game ).Category = cat;
         }
         UpdateGameListSelected();
         MakeChange( true );
     }
 }
Esempio n. 19
0
 /// <summary>
 /// Adds the given category to all selected games.
 /// </summary>
 /// <param name="cat">Category to add</param>
 /// <param name="refreshCatList">If true, refresh category views afterwards</param>
 /// <param name="forceClearOthers">If true, remove other categories from the affected games.</param>
 void AddCategoryToSelectedGames(Category cat, bool forceClearOthers)
 {
     if (lstGames.SelectedObjects.Count > 0)
     {
         Cursor.Current = Cursors.WaitCursor;
         foreach (GameInfo g in tlstGames.SelectedObjects)
         {
             if (g != null)
             {
                 if (forceClearOthers || Settings.Instance.SingleCatMode)
                 {
                     g.ClearCategories(alsoClearFavorite: false);
                     if (cat != null)
                     {
                         g.AddCategory(cat);
                     }
                 }
                 else
                 {
                     g.AddCategory(cat);
                 }
             }
         }
         FillAllCategoryLists();
         if (forceClearOthers)
         {
             FilterGamelist(false);
         }
         if (lstCategories.SelectedItems[0].Tag.ToString() == GlobalStrings.MainForm_Uncategorized)
         {
             FilterGamelist(false);
         }
         else RebuildGamelist();
         MakeChange(true);
         Cursor.Current = Cursors.Default;
     }
 }
Esempio n. 20
0
 void RemoveCategoryFromSelectedGames( Category cat )
 {
     if( lstGames.SelectedItems.Count > 0 ) {
         foreach( ListViewItem item in lstGames.SelectedItems ) {
             GameInfo g = item.Tag as GameInfo;
             if( g != null ) g.RemoveCategory( cat );
         }
         OnGameChange( false, true );
         MakeChange( true );
     }
 }
Esempio n. 21
0
 /// <summary>
 /// Removes the given category from all selected games.
 /// </summary>
 /// <param name="cat">Category to remove.</param>
 void RemoveCategoryFromSelectedGames(Category cat)
 {
     if (lstGames.SelectedObjects.Count > 0)
     {
         Cursor.Current = Cursors.WaitCursor;
         foreach (GameInfo g in tlstGames.SelectedObjects)
         {
             g.RemoveCategory(cat);
         }
         FillAllCategoryLists();
         if (lstCategories.SelectedItems[0].Tag is Category && (Category) lstCategories.SelectedItems[0].Tag == cat)
         {
             FilterGamelist(false);
         }
         else FilterGamelist(true);
         MakeChange(true);
         Cursor.Current = Cursors.Default;
     }
 }
Esempio n. 22
0
        /// <summary>
        /// Removes the given category.
        /// </summary>
        /// <param name="c">Category to remove.</param>
        /// <returns>True if removal was successful, false if it was not in the list anyway</returns>
        public bool RemoveCategory( Category c )
        {
            // Can't remove favorite category
            if(c == favoriteCategory) return false;

            if( Categories.Remove( c ) ) {
                foreach( GameInfo g in Games.Values ) {
                    g.RemoveCategory( c );
                }
                return true;
            }
            return false;
        }
Esempio n. 23
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);
            }

            LanguageSupport Language = db.Games[game.Id].languageSupport;

            Language.Interface = Language.Interface ?? new List <string>();
            Language.Subtitles = Language.Subtitles ?? new List <string>();
            Language.FullAudio = Language.FullAudio ?? new List <string>();

            IEnumerable <string> interfaceLanguage = Language.Interface.Intersect(IncludedLanguages.Interface);

            foreach (string catString in interfaceLanguage)
            {
                Category c = games.GetCategory(GetProcessedString(catString, "Interface"));
                game.AddCategory(c);
            }

            foreach (string catString in IncludedLanguages.Subtitles)
            {
                if (Language.Subtitles.Contains(catString) || Language.Subtitles.Count == 0 && Language.FullAudio.Contains(catString) || Language.FullAudio.Count == 0 && Language.Interface.Contains(catString))
                {
                    game.AddCategory(games.GetCategory(GetProcessedString(catString, "Subtitles")));
                }
            }

            foreach (string catString in IncludedLanguages.FullAudio)
            {
                if (Language.FullAudio.Contains(catString) || Language.FullAudio.Count == 0 && Language.Subtitles.Contains(catString) || Language.Subtitles.Count == 0 && Language.Interface.Contains(catString))
                {
                    game.AddCategory(games.GetCategory(GetProcessedString(catString, "Full Audio")));
                }
            }

            return(AutoCatResult.Success);
        }
Esempio n. 24
0
 /// <summary>
 /// Renames the given category.
 /// </summary>
 /// <param name="c">Category to rename.</param>
 /// <param name="newName">Name to assign to the new category.</param>
 /// <returns>The new category, if the operation succeeds. Null otherwise.</returns>
 public Category RenameCategory( Category c, string newName )
 {
     if( c == favoriteCategory ) return null;
     Category newCat = AddCategory( newName );
     if( newCat != null ) {
         Categories.Sort();
         foreach( GameInfo game in Games.Values ) {
             if( game.ContainsCategory( c ) ) {
                 game.RemoveCategory( c );
                 game.AddCategory( newCat );
             }
         }
         RemoveCategory( c );
         return newCat;
     }
     return null;
 }
Esempio n. 25
0
 /// <summary>
 /// Gets the category with the given name. If the category does not exist, creates it.
 /// </summary>
 /// <param name="name">Name to get the category for</param>
 /// <returns>A category with the given name. Null if any error is encountered.</returns>
 public Category GetCategory( string name ) {
     // Categories must have a name
     if( string.IsNullOrEmpty( name ) ) return null;
     // Look for a matching category in the list and return if found
     foreach( Category c in Categories ) {
         if( String.Equals( c.Name, name, StringComparison.OrdinalIgnoreCase ) ) return c;
     }
     // Create a new category and return it
     Category newCat = new Category( name );
     Categories.Add( newCat );
     return newCat;
 }
Esempio n. 26
0
 /// <summary>
 /// Adds a single category to this game. Does nothing if the category is already attached.
 /// </summary>
 /// <param name="newCat">Category to add</param>
 public void AddCategory( Category newCat )
 {
     if (newCat != null && Categories.Add(newCat) && !this.Hidden)
     {
         newCat.Count++;
     }
 }
Esempio n. 27
0
 private ListViewItem CreateCategoryListViewItem( Category c ) {
     ListViewItem i = new ListViewItem(c.Name + " (" + c.Count + ")");
     i.Tag = c;
     return i;
 }
Esempio n. 28
0
 /// <summary>
 /// Removes a single category from this game. Does nothing if the category is not attached to this game.
 /// </summary>
 /// <param name="remCat">Category to remove</param>
 public void RemoveCategory( Category remCat )
 {
     if (Categories.Remove(remCat) && !this.Hidden)
         remCat.Count--;
 }
Esempio n. 29
0
 /// <summary>
 /// Adds the given category to all selected games.
 /// </summary>
 /// <param name="cat">Category to add</param>
 /// <param name="refreshCatList">If true, refresh category views afterwards</param>
 /// <param name="forceClearOthers">If true, remove other categories from the affected games.</param>
 void AddCategoryToSelectedGames( Category cat, bool refreshCatList, bool forceClearOthers ) {
     if (lstGames.SelectedObjects.Count > 0)
     {
         foreach( GameInfo g in tlstGames.SelectedObjects ) {
             if( g != null ) {
                 if( forceClearOthers || Settings.Instance.SingleCatMode ) {
                     g.ClearCategories( alsoClearFavorite: false );
                     if( cat != null ) {
                         g.AddCategory( cat );
                     }
                 } else {
                     g.AddCategory( cat );
                 }
             }
         }
         OnGameChange( refreshCatList );
         MakeChange( true );
     }
 }
Esempio n. 30
0
 /// <summary>
 /// Adds a new category to the list.
 /// </summary>
 /// <param name="name">Name of the category to add</param>
 /// <returns>The added category. Returns null if the category already exists.</returns>
 public Category AddCategory( string name )
 {
     if( string.IsNullOrEmpty( name ) || CategoryExists( name ) ) {
         return null;
     } else {
         Category newCat = new Category( name );
         Categories.Add( newCat );
         return newCat;
     }
 }
Esempio n. 31
0
 /// <summary>
 /// Removes the given category from all selected games.
 /// </summary>
 /// <param name="cat">Category to remove.</param>
 void RemoveCategoryFromSelectedGames( Category cat ) {
     if (lstGames.SelectedObjects.Count > 0)
     {
         foreach (GameInfo g in tlstGames.SelectedObjects)
         {
             g.RemoveCategory( cat );
         }
         OnGameChange( false );
         MakeChange( true );
     }
 }
Esempio n. 32
0
 /// <summary>
 /// Adds a single category to each member of a list of games
 /// </summary>
 /// <param name="gameIDs">List of game IDs to add to</param>
 /// <param name="c">Category to add</param>
 public void AddGameCategory( int[] gameIDs, Category c )
 {
     for( int i = 0; i < gameIDs.Length; i++ ) {
         AddGameCategory( gameIDs[i], c );
     }
 }
Esempio n. 33
0
        /// <summary>
        /// Loads in games from an node containing a list of games.
        /// </summary>
        /// <param name="appsNode">Node containing the game nodes</param>
        /// <param name="ignore">Set of games to ignore</param>
        /// <returns>Number of games loaded</returns>
        private int GetDataFromVdf(VdfFileNode appsNode, SortedSet <int> ignore, bool ignoreDlc)
        {
            int loadedGames = 0;

            Dictionary <string, VdfFileNode> gameNodeArray = appsNode.NodeArray;

            if (gameNodeArray != null)
            {
                foreach (KeyValuePair <string, VdfFileNode> gameNodePair in gameNodeArray)
                {
                    int gameId;
                    if (int.TryParse(gameNodePair.Key, out gameId))
                    {
                        if ((ignore != null && ignore.Contains(gameId)) || (ignoreDlc && Program.GameDB.IsDlc(gameId)))
                        {
                            Program.Logger.Write(LoggerLevel.Verbose, GlobalStrings.GameData_SkippedProcessingGame, gameId);
                            continue;
                        }
                        if (gameNodePair.Value != null && gameNodePair.Value.ContainsKey("tags"))
                        {
                            Category cat = null;
                            bool     fav = false;
                            loadedGames++;
                            VdfFileNode tagsNode = gameNodePair.Value["tags"];
                            Dictionary <string, VdfFileNode> tagArray = tagsNode.NodeArray;
                            if (tagArray != null)
                            {
                                foreach (VdfFileNode tag in tagArray.Values)
                                {
                                    string tagName = tag.NodeString;
                                    if (tagName != null)
                                    {
                                        if (tagName == "favorite")
                                        {
                                            fav = true;
                                        }
                                        else
                                        {
                                            cat = GetCategory(tagName);
                                        }
                                    }
                                }
                            }

                            if (!Games.ContainsKey(gameId))
                            {
                                Game newGame = new Game(gameId, string.Empty);
                                Games.Add(gameId, newGame);
                                newGame.Name = Program.GameDB.GetName(gameId);
                                Program.Logger.Write(LoggerLevel.Verbose, GlobalStrings.GameData_AddedNewGame, gameId, newGame.Name);
                            }
                            Games[gameId].Category = cat;
                            Games[gameId].Favorite = fav;
                            Program.Logger.Write(LoggerLevel.Verbose, GlobalStrings.GameData_ProcessedGame, gameId, (cat == null) ? "~none~" : cat.ToString(), fav);
                        }
                    }
                }
            }

            return(loadedGames);
        }