SetCategories() публичный Метод

Sets the categories for this game to exactly match the given list. Missing categories will be added and extra ones will be removed.
public SetCategories ( ICollection cats, bool preserveFavorite ) : void
cats ICollection Set of categories to apply to this game
preserveFavorite bool
Результат void
Пример #1
0
        /// <summary>
        /// Adds a non-steam game to the gamelist.
        /// </summary>
        /// <param name="gameId">ID of the game in the steam config file</param>
        /// <param name="gameNode">Node for the game in the steam config file</param>
        /// <param name="oldShortcuts">List of un-matched non-steam games from the gamelist before the update</param>
        /// <param name="launchIds">Dictionary of launch ids (name:launchId)</param>
        /// <param name="newGames">Number of NEW games that have been added to the list</param>
        /// <param name="preferSteamCategories">If true, prefers to use the categories from the steam config if there is a conflict. If false, prefers to use the categories from the existing gamelist.</param>
        /// <returns>True if the game was successfully added</returns>
        private bool IntegrateShortcut( int gameId, VdfFileNode gameNode, List<GameInfo> oldShortcuts, StringDictionary launchIds, ref int newGames, bool preferSteamCategories = true )
        {
            VdfFileNode nodeName = gameNode.GetNodeAt( new string[] { "appname" }, false );
            string gameName = ( nodeName != null ) ? nodeName.NodeString : null;
            // The ID of the created game must be negative
            int newId = -( gameId + 1 );

            // This should never happen, but just in case
            if( Games.ContainsKey( newId ) ) {
                return false;
            }

            GameInfo game = new GameInfo( newId, gameName );
            Games.Add( newId, game );

            game.LaunchString = launchIds[gameName];

            int oldShortcutId = FindMatchingShortcut( gameId, gameNode, oldShortcuts, launchIds );
            bool oldCatSet = ( oldShortcutId != -1 ) && oldShortcuts[oldShortcutId].Categories.Count > 0;
            if( oldShortcutId == -1 ) newGames++;

            VdfFileNode tagsNode = gameNode.GetNodeAt( new string[] { "tags" }, false );
            bool steamCatSet = ( tagsNode != null && tagsNode.NodeType == ValueType.Array && tagsNode.NodeArray.Count > 0 );

            //fill in categories
            if( steamCatSet && ( preferSteamCategories || !oldCatSet ) ) {
                // Fill in categories from the Steam shortcut file
                foreach( KeyValuePair<string, VdfFileNode> tag in tagsNode.NodeArray ) {
                    string tagName = tag.Value.NodeString;
                    game.AddCategory( this.GetCategory( tagName ) );
                }

            } else if( oldShortcutId >= 0 && oldShortcutId < oldShortcuts.Count ) {
                // Fill in categories from the game list
                game.SetCategories( oldShortcuts[oldShortcutId].Categories );
            }

            game.Hidden = false;
            if( gameNode.ContainsKey( "hidden" ) ) {
                VdfFileNode hiddenNode = gameNode["hidden"];
                game.Hidden = ( hiddenNode.NodeString == "1" || hiddenNode.NodeInt == 1 );
            }

            if( oldShortcutId != -1 ) oldShortcuts.RemoveAt( oldShortcutId );
            return true;
        }