Exemplo n.º 1
0
        public static void CommandExecute(string[] command)
        {
            if (command.Length == 0)
            {
                ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidCommand"), ConsoleColor.Red);
                OutputHelp();
                return;
            }

            //read status
            var  _config      = Config.Read();
            bool HaveGamePath = _config["GamePath"] != "";
            bool HaveDatabase = File.Exists(Information.WorkPath.Enter("package.db").Path);

            var param = new List <string>(command);
            var head  = param[0];

            param.RemoveAt(0);

            void runCode()
            {
                switch (head)
                {
                case "update":
                    if (param.Count() != 0)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidParameterCount"), ConsoleColor.Red);
                    }
                    else
                    {
                        Update.Core();
                    }
                    break;

                case "search":
                    if (!HaveDatabase)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoDatabase"), ConsoleColor.Red);
                    }
                    else if (param.Count() == 0)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidParameterCount"), ConsoleColor.Red);
                    }
                    else
                    {
                        Search.Core(param);
                    }
                    break;

                case "install":
                    if (!HaveDatabase)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoDatabase"), ConsoleColor.Red);
                    }
                    else if (!HaveGamePath)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoGamePath"), ConsoleColor.Red);
                    }
                    else if (param.Count() != 1)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidParameterCount"), ConsoleColor.Red);
                    }
                    else
                    {
                        Install.Core(param[0]);
                    }
                    break;

                case "list":
                    if (!HaveDatabase)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoDatabase"), ConsoleColor.Red);
                    }
                    else if (param.Count() != 0)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidParameterCount"), ConsoleColor.Red);
                    }
                    else
                    {
                        List.Core();
                    }
                    break;

                case "remove":
                    if (!HaveDatabase)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoDatabase"), ConsoleColor.Red);
                    }
                    else if (!HaveGamePath)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoGamePath"), ConsoleColor.Red);
                    }
                    else if (param.Count() != 1)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidParameterCount"), ConsoleColor.Red);
                    }
                    else
                    {
                        Remove.Core(param[0]);
                    }
                    break;

                case "config":
                    switch (param.Count)
                    {
                    case 0:
                        Config.Core();
                        break;

                    case 1:
                        Config.Core(param[0]);
                        break;

                    case 2:
                        Config.Core(param[0], param[1]);
                        break;

                    default:
                        ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidParameterCount"), ConsoleColor.Red);
                        break;
                    }
                    break;

                case "show":
                    if (!HaveDatabase)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoDatabase"), ConsoleColor.Red);
                    }
                    else if (param.Count != 1)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidParameterCount"), ConsoleColor.Red);
                    }
                    else
                    {
                        Show.Core(param[0]);
                    }
                    break;

                case "deploy":
                    if (!HaveDatabase)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoDatabase"), ConsoleColor.Red);
                    }
                    else if (!HaveGamePath)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoGamePath"), ConsoleColor.Red);
                    }
                    else if (param.Count != 2)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidParameterCount"), ConsoleColor.Red);
                    }
                    else
                    {
                        Deploy.Core(param[0], param[1]);
                    }
                    break;

                case "guide":
                    if (!HaveDatabase)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoDatabase"), ConsoleColor.Red);
                    }
                    else if (!HaveGamePath)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoGamePath"), ConsoleColor.Red);
                    }
                    else if (param.Count != 1)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidParameterCount"), ConsoleColor.Red);
                    }
                    else
                    {
                        Guide.Core(param[0]);
                    }
                    break;

                case "clean":
                    if (!HaveDatabase)
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("General_NoDatabase"), ConsoleColor.Red);
                    }
                    else if (param.Count == 1)
                    {
                        Clean.Core(param[0]);
                    }
                    else if (param.Count == 0)
                    {
                        Clean.Core();
                    }
                    else
                    {
                        ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidParameterCount"), ConsoleColor.Red);
                    }
                    break;

                case "help":
                    OutputHelp();
                    break;

                default:
                    ConsoleAssistance.WriteLine(I18N.Core("Command_InvalidCommand"), ConsoleColor.Red);
                    OutputHelp();
                    break;
                }

#if DEBUG
                Console.ReadKey();
#endif
            }

            Thread td = new Thread(runCode);
            td.IsBackground = false;
            td.Start();
        }