Exemplo n.º 1
0
        public override bool Execute(List <string> args)
        {
            if (args.Count != 1)
            {
                return(false);
            }

            var tag = ArgumentParser.ParseTagIndex(_info, args[0]);

            if (tag == null)
            {
                return(false);
            }

            var oldContext = _stack.Context;

            _stack.Push(EditTagContextFactory.Create(_stack, _info, tag));

            var groupName = _info.StringIDs.GetString(tag.Group.Name);
            var tagName   = $"0x{tag.Index:X4}";

            if (_info.TagNames.ContainsKey(tag.Index))
            {
                tagName = _info.TagNames[tag.Index];
                tagName = $"(0x{tag.Index:X4}) {tagName.Substring(tagName.LastIndexOf('\\') + 1)}";
            }

            Console.WriteLine($"Tag {tagName}.{groupName} 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);
        }
Exemplo n.º 2
0
        public override bool Execute(List <string> args)
        {
            if (args.Count != 1)
            {
                return(false);
            }

            var tag = ArgumentParser.ParseTagIndex(_cache, args[0]);

            if (tag == null)
            {
                return(false);
            }

            var oldContext = _stack.Context;

            _stack.Push(EditTagContextFactory.Create(_stack, _info, tag));

            Console.WriteLine("Tag 0x{0:X8}.{1} has been opened for editing.", tag.Index, _info.StringIds.GetString(tag.Group.Name));
            Console.WriteLine("New commands are now available. Enter \"help\" to view them.");
            Console.WriteLine("Use \"exit\" to return to {0}.", oldContext.Name);

            return(true);
        }
Exemplo n.º 3
0
        public override object Execute(List <string> args)
        {
            if (args.Count < 2)
            {
                return(false);
            }

            var isConst = false;

            if (args[0].ToLower() == "const")
            {
                args.RemoveAt(0);
                isConst = true;
            }

            if (args.Count < 2)
            {
                return(false);
            }

            if (!CacheContext.TryParseGroupTag(args[0], out var groupTag))
            {
                Console.WriteLine($"Invalid tag group: {args[0]}");
                return(true);
            }

            args.RemoveAt(0);

            var startFilter = "";
            var endFilter   = "";
            var filter      = "";

            string pattern = null;

            while (args[0].EndsWith(":"))
            {
                switch (args[0].ToLower())
                {
                case "regex:":
                    if (args.Count < 3)
                    {
                        return(false);
                    }
                    pattern = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "starts:":
                case "startswith:":
                case "starts_with:":
                case "starting:":
                case "startingwith:":
                case "starting_with:":
                case "start_filter:":
                case "starting_filter:":
                    startFilter = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "ends:":
                case "ending:":
                case "endingwith:":
                case "ending_with:":
                case "endswith:":
                case "ends_with:":
                case "end_filter:":
                case "ending_filter:":
                    endFilter = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "named:":
                case "filter:":
                case "contains:":
                case "containing:":
                    filter = args[1];
                    args.RemoveRange(0, 2);
                    break;
                }
            }

            var rootContext = ContextStack.Context;

            using (var stream = CacheContext.OpenTagCacheReadWrite())
            {
                foreach (var instance in CacheContext.TagCache.Index)
                {
                    if (instance == null || (groupTag != Tag.Null && !instance.IsInGroup(groupTag)))
                    {
                        continue;
                    }

                    var tagName = instance.Name ?? $"0x{instance.Index:X4}";

                    try
                    {
                        if (pattern != null && !Regex.IsMatch(tagName, pattern, RegexOptions.IgnoreCase))
                        {
                            continue;
                        }
                    }
                    catch
                    {
                        continue;
                    }

                    if (!tagName.StartsWith(startFilter) || !tagName.Contains(filter) || !tagName.EndsWith(endFilter))
                    {
                        continue;
                    }

                    var definition = CacheContext.Deserialize(stream, instance);
                    ContextStack.Push(EditTagContextFactory.Create(ContextStack, CacheContext, instance, definition));

                    Console.WriteLine();
                    Console.WriteLine($"{tagName}.{CacheContext.GetString(instance.Group.Name)}:");
                    ContextStack.Context.GetCommand(args[0]).Execute(args.Skip(1).ToList());

                    while (ContextStack.Context != rootContext)
                    {
                        ContextStack.Pop();
                    }

                    if (!isConst)
                    {
                        CacheContext.Serialize(stream, instance, definition);
                    }
                }

                Console.WriteLine();
            }

            return(true);
        }
Exemplo n.º 4
0
        public override object Execute(List <string> args)
        {
            if (args.Count < 1)
            {
                return(false);
            }

            var isConst = false;

            if (args[0].ToLower() == "const")
            {
                args.RemoveAt(0);
                isConst = true;
            }

            if (args.Count < 1)
            {
                return(false);
            }

            if (!Cache.TryParseGroupTag(args[0], out var groupTag))
            {
                Console.WriteLine($"Invalid tag group: {args[0]}");
                return(true);
            }

            args.RemoveAt(0);

            var startFilter = "";
            var endFilter   = "";
            var filter      = "";
            var filename    = "";

            string pattern = null;

            while (args.Count > 0 && args[0].EndsWith(":"))
            {
                switch (args[0].ToLower())
                {
                case "in_file:":
                    filename = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "regex:":
                    if (args.Count < 3)
                    {
                        return(false);
                    }
                    pattern = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "starts:":
                case "startswith:":
                case "starts_with:":
                case "starting:":
                case "startingwith:":
                case "starting_with:":
                case "start_filter:":
                case "starting_filter:":
                    startFilter = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "ends:":
                case "ending:":
                case "endingwith:":
                case "ending_with:":
                case "endswith:":
                case "ends_with:":
                case "end_filter:":
                case "ending_filter:":
                    endFilter = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "named:":
                case "filter:":
                case "contains:":
                case "containing:":
                    filter = args[1];
                    args.RemoveRange(0, 2);
                    break;
                }
            }

            var commandsToExecute = new List <List <string> >();

            // if no command is given, keep reading commands from stdin until an empty line encountered
            if (args.Count < 1)
            {
                string line;
                while (!string.IsNullOrWhiteSpace(line = Console.ReadLine()))
                {
                    var commandsArgs = ArgumentParser.ParseCommand(line, out string redirectFile);
                    commandsToExecute.Add(commandsArgs);
                }
            }
            else
            {
                commandsToExecute.Add(args);
            }

            List <CachedTag> tags = null;

            // if a file is given use that as the source for tags
            if (!string.IsNullOrWhiteSpace(filename))
            {
                var tagsList = new List <CachedTag>();
                foreach (var line in File.ReadAllLines(filename))
                {
                    tags.Add(Cache.GetTag(line));
                }

                tags = tagsList;
            }
            else
            {
                tags = Cache.TagCache.NonNull().ToList();
            }

            var rootContext = ContextStack.Context;


            foreach (var instance in tags)
            {
                if (instance == null || (groupTag != Tag.Null && !instance.IsInGroup(groupTag)))
                {
                    continue;
                }

                var tagName = instance.Name ?? $"0x{instance.Index:X4}";

                try
                {
                    if (pattern != null && !Regex.IsMatch(tagName, pattern, RegexOptions.IgnoreCase))
                    {
                        continue;
                    }
                }
                catch
                {
                    continue;
                }

                if (!tagName.StartsWith(startFilter) || !tagName.Contains(filter) || !tagName.EndsWith(endFilter))
                {
                    continue;
                }

                object definition = null;
                using (var stream = Cache.OpenCacheRead())
                    definition = Cache.Deserialize(stream, instance);


                ContextStack.Push(EditTagContextFactory.Create(ContextStack, Cache, instance, definition));

                Console.WriteLine();
                Console.WriteLine($"{tagName}.{Cache.StringTable.GetString(instance.Group.Name)}:");
                ContextStack.Context.GetCommand(args[0]).Execute(args.Skip(1).ToList());

                while (ContextStack.Context != rootContext)
                {
                    ContextStack.Pop();
                }

                if (!isConst)
                {
                    using (var stream = Cache.OpenCacheReadWrite())
                        Cache.Serialize(stream, instance, definition);
                }
            }

            Console.WriteLine();
            return(true);
        }