Example #1
0
        public static void InvokeAutoExec()
        {
            var console = QFSW.QC.QuantumConsole.Instance ? QFSW.QC.QuantumConsole.Instance : Object.FindObjectOfType <QFSW.QC.QuantumConsole>();

            if (!console)
            {
                return;
            }
            InvokeMethod(console, "Initialize");
            QuantumConsoleProcessor.GenerateCommandTable(); // Ensures the command table is generated
            try {
                InvokeConfigStreamingAssets(AUTOEXEC_NAME);
            } catch (FileNotFoundException) {
                // Ignore
            } catch (DirectoryNotFoundException) {
                // Ignore
            }
            try {
                InvokeConfig(Path.Combine(Directory.GetParent(Application.dataPath).ToString(), AUTOEXEC_NAME));
            } catch (FileNotFoundException) {
                // Ignore
            } catch (DirectoryNotFoundException) {
                // Ignore
            }

            try {
                var customExecPath = CommandLineArguments.ReadArgValue("-ExecConfig");
                customExecPath = customExecPath.Replace("{StreamingAssets}", Application.streamingAssetsPath);
                customExecPath = customExecPath.Replace("{DataPath}", Application.dataPath);
                customExecPath = customExecPath.Replace("{Root}", Directory.GetParent(Application.dataPath).ToString());
                InvokeConfig(customExecPath);
            } catch (CommandLineArguments.CommandLineArgumentNotFoundException) {
                // Ignore
            } catch (Exception ex) {
                Debug.LogError(ex.ToString());
            }

            try {
                foreach (var command in CommandLineArguments.ReadArgValues("-Exec"))
                {
                    try {
                        QuantumConsoleProcessor.InvokeCommand(command.Trim('"'));
                    } catch (Exception ex) {
                        Debug.LogError(ex.ToString());
                    }
                }
            } catch (CommandLineArguments.CommandLineArgumentNotFoundException) {
                // Ignore
            } catch (Exception ex) {
                Debug.LogError(ex.ToString());
            }
        }
Example #2
0
        public static string GetCommandList(bool forceReload)
        {
            QuantumConsoleProcessor.GenerateCommandTable(false, forceReload);
            var sb = new StringBuilder();

            foreach (var command in GetOrderedCommands())
            {
                // Name line
                sb.Append(command.CommandName);
                sb.Append(' ');
                sb.Append(command.IsStatic ? "[Static]" : "[Instance]");
                if (!command.IsStatic)
                {
                    sb.Append(' ');
                    sb.Append($"[{command.MonoTarget.ToString()}]");
                }
                sb.AppendLine();

                // Description Line
                if (command.HasDescription)
                {
                    sb.Append('\t');
                    sb.Append("description: ");
                    var desc = command.CommandDescription;
                    // If it's a multiline description put it on a new line
                    if (desc.Contains('\n'))
                    {
                        desc = desc.Insert(0, "\n");
                        // Tab any new lines to match the current indent
                        desc = desc.Replace("\n", $"\n\t\t");
                    }

                    sb.AppendLine(desc);
                }

                // Signature Line
                if (command.ParamCount > 0)
                {
                    sb.Append("\tsignature: ");
                    var paramNames = command.ParameterSignature.Split(' ');
                    var paramTypes = command.ParamTypes.Select(x => x.Name).ToArray();
                    for (var i = 0; i < paramNames.Length; i++)
                    {
                        sb.Append($"<{paramTypes[i]}> {paramNames[i]}");
                        if (i < paramNames.Length - 1)
                        {
                            sb.Append($", ");
                        }
                    }

                    sb.AppendLine();
                }

                // Return Line
                try {
                    if (command.MethodData.ReturnType != typeof(void))
                    {
                        sb.Append("\treturns: ");
                        sb.Append($"<{command.MethodData.ReturnType.Name}>");
                        sb.AppendLine();
                    }
                } catch (NotImplementedException) {
                    // Ignore
                }

                sb.AppendLine();
            }

            return(sb.ToString());
        }