コード例 #1
0
ファイル: Runner.cs プロジェクト: ByteChkR/Byt3
        /// <summary>
        /// Runs the Commands with the Passed arguments.
        /// </summary>
        /// <param name="args">The arguments to use</param>
        public static bool RunCommands(string[] args)
        {
            bool didExecute = false;

            for (int i = 0; i < args.Length; i++)
            {
                for (int j = 0; j < Commands.Count; j++)
                {
                    if (Commands[j].CommandKeys.Contains(args[i]))
                    {
                        args[i] = Commands[j].CommandKeys[0]; //Make sure its the first command key.
                    }
                }
            }

            StartupArgumentInfo argumentInfo = new StartupArgumentInfo(args);


            if (argumentInfo.GetCommandEntries("noflag") != 0 ||
                argumentInfo.GetCommandEntries("noflag") == 0 && argumentInfo.CommandCount == 0)
            {
                List <AbstractCommand> cmds = Commands.Where(x => x.DefaultCommand).ToList();
                if (cmds.Count == 0)
                {
                    Logger.Log(LogType.Warning, "No Default Command Found", 1);
                    return(didExecute);
                }

                didExecute = true;

                if (cmds.Count != 1)
                {
                    Logger.Log(LogType.Warning, "Found more than one Default Command.", 1);
                    Logger.Log(LogType.Warning, "Using Command: " + cmds[0].CommandKeys[0], 1);
                }

                if (argumentInfo.GetCommandEntries("noflag") != 0)
                {
                    for (int j = 0; j < argumentInfo.GetCommandEntries("noflag"); j++)
                    {
                        cmds[0].CommandAction?.Invoke(argumentInfo, argumentInfo.GetValues("noflag", j).ToArray());
                    }
                }
                else
                {
                    cmds[0].CommandAction?.Invoke(argumentInfo, new string[0]);
                }
            }

            for (int i = 0; i < Commands.Count; i++)
            {
                if (argumentInfo.GetCommandEntries(Commands[i].CommandKeys[0]) != 0)
                {
                    for (int j = 0; j < argumentInfo.GetCommandEntries(Commands[i].CommandKeys[0]); j++)
                    {
                        didExecute = true;
                        Commands[i].CommandAction?.Invoke(argumentInfo,
                                                          argumentInfo.GetValues(Commands[i].CommandKeys[0], j).ToArray());
                    }
                }
            }

            return(didExecute);
        }