Esempio n. 1
0
        public static string ExecuteEndscriptLine(string line, BasicBase db, string filedir = "")
        {
            string error = "Incorrect amount of passed script parameters.";
            var    words = DisperseLine(line, new char[] { ' ', '\t', '\n' });

            if (!Enum.TryParse(words[0], out eCommands command))
            {
                return($"Unrecognized command {words[0]}; unable to process.");
            }

            int len = words.Length;

            switch (command)
            {
            case eCommands.update:
                if (len == 5)
                {
                    return(ExecuteUpdateCollection(db, words[1], words[2],
                                                   words[3], words[4]));
                }
                else if (len == 6)
                {
                    return(ExecuteUpdateTPKSTR(db, words[1], words[2],
                                               words[3], words[4], words[5]));
                }
                else if (len == 7)
                {
                    return(ExecuteUpdateSubNode(db, words[1], words[2],
                                                words[3], words[4], words[5], words[6]));
                }
                else
                {
                    goto default;
                }

            case eCommands.add:
                if (len == 3)
                {
                    return(ExecuteAddCollection(db, words[1], words[2]));
                }
                else if (len == 4)
                {
                    return(ExecuteAddTexture(db, words[1], words[2],
                                             Path.Combine(filedir, words[3])));
                }
                else if (len == 6)
                {
                    return(ExecuteAddString(db, words[1], words[2],
                                            words[3], words[4], words[5]));
                }
                else
                {
                    goto default;
                }

            case eCommands.delete:
                if (len == 3)
                {
                    return(ExecuteDeleteCollection(db, words[1], words[2]));
                }
                else if (len == 4)
                {
                    return(ExecuteDeleteTPKSTR(db, words[1], words[2], words[3]));
                }
                else
                {
                    goto default;
                }

            case eCommands.copy:
                if (len == 4)
                {
                    return(ExecuteCopyCollection(db, words[1], words[2], words[3]));
                }
                else if (len == 5)
                {
                    return(ExecuteCopyTexture(db, words[1], words[2],
                                              words[3], words[4]));
                }
                else
                {
                    goto default;
                }

            case eCommands.@static:
                if (!Settings.Default.EnableStaticEnd)
                {
                    return("Static command execution is not enabled. Unable to process.");
                }
                if (len == 4)
                {
                    return(ExecuteStaticCollection(db, words[1], words[2], words[3]));
                }
                else
                {
                    goto default;
                }

            case eCommands.replace:
                if (len == 5)
                {
                    return(ExecuteReplaceTexture(db, words[1], words[2],
                                                 words[3], Path.Combine(filedir, words[4])));
                }
                else
                {
                    goto default;
                }

            case eCommands.import:
                if (len == 3)
                {
                    return(ExecuteImportCollection(db, words[1],
                                                   Path.Combine(filedir, words[2])));
                }
                else
                {
                    goto default;
                }

            case eCommands.move:
                if (string.IsNullOrWhiteSpace(GlobalDir))
                {
                    return("This command can be executed only through endscript.");
                }
                if (len == 5)
                {
                    return(ExecuteMoveCommand(words[1], words[2], filedir,
                                              words[3], words[4]));
                }
                else
                {
                    goto default;
                }

            case eCommands.erase:
                if (string.IsNullOrWhiteSpace(GlobalDir))
                {
                    return("This command can be executed only through endscript.");
                }
                if (len == 4)
                {
                    return(ExecuteEraseCommand(words[1], words[2], filedir, words[3]));
                }
                else
                {
                    goto default;
                }

            case eCommands.create:
                if (string.IsNullOrWhiteSpace(GlobalDir))
                {
                    return("This command can be executed only through endscript.");
                }
                if (len == 4)
                {
                    return(ExecuteCreateCommand(words[1], words[2], filedir, words[3]));
                }
                else
                {
                    goto default;
                }

            case eCommands.attach:
                return("This command can be executed only through endscript.");

            case eCommands.execute:
                if (string.IsNullOrWhiteSpace(GlobalDir))
                {
                    return("This command can be executed only through endscript.");
                }
                if (len == 2)
                {
                    watch.Stop();
                    error = Linear.LaunchProcess(Path.Combine(filedir, words[1]), filedir);
                    watch.Start();
                    return(error);
                }
                else
                {
                    goto default;
                }

            case eCommands.@switch:
                if (len == 3)
                {
                    return(ExecuteSwitchSetting(words[1], words[2]));
                }
                else
                {
                    goto default;
                }

            default:
                return(error);
            }
        }