Esempio n. 1
0
        protected void ExecuteFileToMainScriptCommandHandler(ExecuteFileToMainScriptCommand cmd)
        {
#if PERFORMANCE_TEST
            var ptest = Service.Performance.PerformanceTest.Get();
            ptest.Start("ExecuteFileToMainScriptCommand");
#endif

            cmd.result = _service.ExecuteFileToMainScript(cmd.fileName);
#if PERFORMANCE_TEST
            // now stop the watches
            ptest.Stop("ExecuteFileToMainScriptCommand");
#endif
        }
        public void ProcessInput(string input)
        {
            consoleInput.DeactivateInputField();

            if (input.ToLower() == "help")
            {
                AddToText("help\ncommands: close,save [relative filename],... plus service-commands");
                // TODO: Make this better
            }
            else if (input.ToLower() == "clear")
            {
                currentViewText  = "";
                consoleText.text = currentViewText;
            }
            else if (input.ToLower() == "close")
            {
                gameObject.SetActive(false);
            }
            else if (input.ToLower().StartsWith("save"))
            {
                // save current history to file
                string[] splits = input.Split(' ');
                if (splits.Length < 2)
                {
                    AddToText("'save' needs a path (relative to the scripting folder)\ne.g.: save test.lua");
                }
                else
                {
                    // save the history
                    string path = splits[1];
                    if (path.StartsWith("/") || path.StartsWith("\\"))
                    {
                        AddToText("Warning: Using absolute path not allowed!! files are saved relative to scripting folder:" + scriptingPath);
                        path = path.Substring(1);
                    }

                    filesystem.WriteStringToFile(scriptingPath + "/" + path, history.Aggregate((i, j) => j + " \n" + i));
                    AddToText("saved\n");
                }
            }
            else if (input.ToLower().StartsWith("load"))
            {
                // save current history to file
                string[] splits = input.Split(' ');
                if (splits.Length < 2)
                {
                    AddToText("'load' needs a path (relative to the scripting folder)\ne.g.: load test.lua");
                }
                else
                {
                    // save the history
                    string path = splits[1];
                    if (path.StartsWith("/") || path.StartsWith("\\"))
                    {
                        path = path.Substring(1);
                    }
                    string result = scripting.ExecuteFileToMainScript(scriptingPath + "/" + path);
                    if (result != "void")
                    {
                        AddToText(result);
                    }
                    else
                    {
                        AddToText("\nloaded");
                    }
                }
            }
            else if (input.ToLower().StartsWith("dir"))
            {
                // save current history to file
                string[] splits = input.Split(' ');

                string path     = splits.Length < 2 ? "" : (splits[1].StartsWith("/") ? splits[1] : splits[1].Substring(1));
                string filePath = scriptingPath + path;

                try {
                    if (!Directory.Exists(filePath))
                    {
                        AddToText("Directory " + path + " does not exist");
                    }
                    else
                    {
                        string[] dir = Directory.GetFiles(filePath);

                        AddToText("Directory:" + (path == "" ? "/" : path));
                        if (dir.Length == 0)
                        {
                            AddToText("NO FILES (in folder" + filePath + ")");
                        }
                        else
                        {
                            foreach (string entry in dir)
                            {
                                AddToText(entry.Replace(scriptingPath, "").Substring(1));
                            }
                        }
                    }
                } catch (Exception e) {
                    Debug.LogError("Something went wrong using 'dir'-command");
                    Debug.LogException(e);
                }
            }
            else
            {
                currentViewText += input + "\n";
                var scriptService = Kernel.Instance.Container.Resolve <Service.Scripting.IScriptingService>();
                var result        = scriptService.ExecuteStringOnMainScript(input);

                if (result != "void")
                {
                    currentViewText += result + "\n";
                }
                consoleText.text = currentViewText;
                consoleInput.ActivateInputField();
            }

            history.Insert(0, input);

            consoleInput.text = "";
            autoCompleteWindow.ClearItems();
            consoleInput.ActivateInputField();
            // always be at the end of the history after execution
            historyID = -1;
        }