コード例 #1
0
        public override object Execute(List <string> args)
        {
            if (args.Count != 2)
            {
                return(false);
            }

            var groupTagInput = args[0];
            var blamTagName   = args[1];
            var groupTag      = Tag.Null;

            if (TagDefinition.Exists(groupTagInput))
            {
                groupTag = new Tag(groupTagInput);
            }
            else
            {
                foreach (var tagGroup in BlamCache.IndexItems.ClassList)
                {
                    if (groupTagInput == BlamCache.Strings.GetItemByID(tagGroup.StringID))
                    {
                        var chars = new char[4] {
                            ' ', ' ', ' ', ' '
                        };

                        for (var i = 0; i < 4; i++)
                        {
                            chars[i] = tagGroup.ClassCode[i];
                        }

                        groupTag = new Tag(new string(chars));
                        break;
                    }
                }
            }

            CacheFile.IndexItem tag = null;

            foreach (var blamTag in BlamCache.IndexItems)
            {
                if ((blamTag.GroupTag == groupTag.ToString()) && (blamTagName == "*" || blamTag.Name == blamTagName))
                {
                    tag = blamTag;
                    break;
                }
            }

            if (tag == null)
            {
                throw new Exception();
            }

            var tagName = $"(0x{tag.ID:X8}) {tag.Name.Substring(tag.Name.LastIndexOf('\\') + 1)}";

            var tagType    = TagDefinition.Find(groupTag);
            var definition = (TagStructure)BlamCache.Deserializer.Deserialize(new CacheSerializationContext(ref BlamCache, tag), tagType);
            var structure  = definition.GetTagStructureInfo(BlamCache.Version);

            var oldContext = ContextStack.Context;

            var commandContext = new CommandContext(ContextStack.Context, string.Format("{0}.{1}", tagName, groupTagInput));

            commandContext.AddCommand(new ListFieldsCommand(BlamCache, structure, definition));
            commandContext.AddCommand(new EditBlockCommand(ContextStack, BlamCache, tag, definition));
            commandContext.AddCommand(new CopyBlockElementsCommand(ContextStack, BlamCache, tag, structure, definition));
            commandContext.AddCommand(new Editing.ExitToCommand(ContextStack));
            ContextStack.Push(commandContext);

            Console.WriteLine($"Tag {tagName}.{groupTagInput} has been opened for editing.");
            Console.WriteLine("New commands are now available. Enter \"help\" to view them.");
            Console.WriteLine("Use \"exit\" to return to {0}.", oldContext.Name);

            return(true);
        }