Exemplo n.º 1
0
        bool Execute(string filename)
        {
            IList <string> lines = ReusableLists.NextAutoRecycleList <string>();

            // cvars
            AddEntries(lines, ListCvars(), "cvars");

            // bindings
            AddEntries(lines, ListBindings(), "bindings");

            // aliases
            AddEntries(lines, ListAliases(), "aliases");

            try
            {
                ConfigHelper.WriteConfig(filename, lines);
                return(true);
            }
            catch (Exception e)
            {
                if (this.IsManualMode)
                {
                    PrintError("Can't write config: " + e.Message);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
 internal IList <Option> ListOptions(string prefix = null)
 {
     return(ListOptions(ReusableLists.NextAutoRecycleList <Option>(), prefix));
 }
Exemplo n.º 3
0
        private bool ExecuteGuarded(IList <string> tokens, string commandLine = null)
        {
            ResetOptions();

            Iterator <string> iter = new Iterator <string>(tokens);

            iter.Next(); // first token is a command name

            if (this.IsManualMode)
            {
                PrintPrompt(commandLine);
            }

            if (this.IsPlayModeOnly && !Runtime.IsPlaying)
            {
                PrintError("Command is available in the play mode only");
                return(false);
            }

            ReusableList <string> argsList = ReusableLists.NextAutoRecycleList <string>();

            while (iter.HasNext())
            {
                string token = StringUtils.UnArg(iter.Next());

                // first, try to parse options
                if (!TryParseOption(iter, token))
                {
                    // consume the rest of the args
                    argsList.Add(token);
                    while (iter.HasNext())
                    {
                        token = StringUtils.UnArg(iter.Next());
                        argsList.Add(token);
                    }

                    break;
                }
            }

            if (m_values != null)
            {
                if (argsList.Count != 1)
                {
                    PrintError("Unexpected arguments count {0}", argsList.Count);
                    PrintUsage();
                    return(false);
                }

                string arg = argsList[0];
                if (Array.IndexOf(m_values, arg) == -1)
                {
                    PrintError("Unexpected argument '{0}'", arg);
                    PrintUsage();
                    return(false);
                }
            }

            if (m_options != null)
            {
                for (int i = 0; i < m_options.Count; ++i)
                {
                    Option opt = m_options[i];
                    if (opt.IsRequired && !opt.IsHandled)
                    {
                        PrintError("Missing required option --{0}{1}", opt.Name, opt.ShortName != null ? "(-" + opt.ShortName + ")" : "");
                        PrintUsage();
                        return(false);
                    }
                }
            }

            string[]   args          = argsList.Count > 0 ? argsList.ToArray() : EMPTY_COMMAND_ARGS;
            MethodInfo executeMethod = resolveExecuteMethod(args);

            if (executeMethod == null)
            {
                PrintError("Wrong arguments");
                PrintUsage();
                return(false);
            }

            return(CCommandUtils.Invoke(this, executeMethod, args));
        }
Exemplo n.º 4
0
 internal static IList <LogLevel> ListLevels()
 {
     return(ListLevels(ReusableLists.NextAutoRecycleList <LogLevel>()));
 }
Exemplo n.º 5
0
 internal static IList <Tag> ListTags()
 {
     return(ListTags(ReusableLists.NextAutoRecycleList <Tag>()));
 }
Exemplo n.º 6
0
        public static StackTraceLine[] ParseStackTrace(string stackTrace)
        {
            if (stackTrace != null)
            {
                ReusableList <StackTraceLine> list = ReusableLists.NextList <StackTraceLine>();

                int lineStart = 0;
                int lineEnd;

                while (lineStart < stackTrace.Length)
                {
                    // extract next line
                    lineEnd = StringUtils.EndOfLineIndex(stackTrace, lineStart);
                    string line = stackTrace.Substring(lineStart, lineEnd - lineStart);
                    lineStart = lineEnd + 1;

                    // extract data
                    Match m;
                    if ((m = PatternUnityStackTrace.Match(line)).Success)
                    {
                        GroupCollection groups        = m.Groups;
                        string          sourcePath    = groups[2].Value;
                        string          lineNumberStr = groups[3].Value;
                        int             lineNumber    = StringUtils.ParseInt(lineNumberStr, -1);

                        list.Add(new StackTraceLine(line, string.IsNullOrEmpty(sourcePath) ? null : sourcePath, lineNumber, lineNumberStr.Length));
                    }
                    else if ((m = PatternSystemStackTrace.Match(line)).Success)
                    {
                        GroupCollection groups = m.Groups;

                        string method        = groups[1].Value;
                        string args          = OptimizeArgs(groups[2].Value);
                        string path          = OptimizePath(groups[4].Value);
                        string lineNumberStr = groups[5].Value;
                        int    lineNumber    = StringUtils.ParseInt(lineNumberStr, -1);

                        if (!string.IsNullOrEmpty(path) && lineNumber != -1)
                        {
                            line = StringUtils.TryFormat("{0}({1}) (at {2}:{3})", method, args, path, lineNumberStr);
                        }
                        else
                        {
                            line = StringUtils.TryFormat("{0}({1})", method, args);
                        }

                        list.Add(new StackTraceLine(line, path, lineNumber, lineNumberStr.Length));
                    }
                    else
                    {
                        list.Add(new StackTraceLine(line));
                    }
                }

                StackTraceLine[] lines = list.ToArray();
                list.Recycle();
                return(lines);
            }

            return(StackTraceLine.kEmptyLinesArray);
        }