Пример #1
0
        // Find classname
        private void PreParseScripts()
        {
            foreach (String script in Scripts)
            {
                if (!File.Exists(script))
                {
                    continue;
                }

                List <String> lines = new List <string>(File.ReadAllLines(script));

                ScriptExtension Ext = new ScriptExtension();
                Ext.FileName = script;

                foreach (String line in lines)
                {
                    if (line.Contains("public class"))
                    {
                        string[] param = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        for (uint i = 0; i < param.Length; i++)
                        {
                            if (param[i] == "public" && param.Length >= i + 4 && param[i + 1] == "class" && param[i + 4] == "IScript")
                            {
                                Ext.ClassName  = param[i + 2];
                                Ext.Code       = lines;
                                Ext.UpdateTime = 0;
                                Extensions.Add(Ext);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
 public void update(ScriptExtension Ext)
 {
     Ext.UpdateTime = Ext.Handle.update();
 }
Пример #3
0
        public bool Reload()
        {
            frmScriptLoad frmLoad = new frmScriptLoad(ScriptPath);
            TextBox       txt     = frmLoad.GetTextBox();

            ParseScriptsList(ScriptPath);
            PreParseScripts();

            bool Success = false;

            DialogResult Ret         = DialogResult.Cancel;
            bool         RetryDialog = false;

            do
            {
                Ret = DialogResult.Cancel;
                try
                {
                    RetryDialog = false;
                    CSScriptLibrary.CSScript.ShareHostRefAssemblies = true;

                    bool Error = false;

                    foreach (String path in Scripts)
                    {
                        if (Path.GetFileName(path) == "main.cs")
                        {
                            continue;
                        }

                        txt.Text += "Compiling " + Path.GetFileName(path) + "... ";
                        try
                        {
                            ScriptExtension Ext = Extensions.Find(i => i.FileName == path);
                            if (Ext != null)
                            {
                                Log("Loading extension " + Ext.FileName + "...");
                                string Code = File.ReadAllText(Ext.FileName);
                                Log("Preprocessing " + Ext.FileName + "...");
                                Preprocess(ref Code);
                                PreprocessEvents(ref Code);
                                Log("Compiling " + Ext.FileName + "...");
                                Ext.Handle = CSScript.LoadCode(Code).CreateObject(Ext.ClassName);
                            }
                            else
                            {
                                CSScript.Load(path);
                            }

                            txt.Text += "Ok" + Environment.NewLine;
                        }
                        catch (Exception e)
                        {
                            txt.Text += "Error!" + Environment.NewLine;
                            txt.Text += e.Message;
                            Error     = true;
                        }
                    }

                    if (!Error)
                    {
                        // init all loaded extensions
                        init(fMain);

                        get_author();
                        get_name();
                        get_description();
                        get_version();

                        foreach (ScriptExtension Ext in Extensions)
                        {
                            update(Ext);
                        }

                        Success = true;
                    }
                    if (Error)
                    {
                        frmLoad.ShowDialog();
                        if (frmLoad.IsRetry())
                        {
                            RetryDialog = true;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                catch (Exception e)
                {
                    Ret = MessageBox.Show("Exception occured when loading scripts: " + Environment.NewLine +
                                          e.Message, "ScriptEngine", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    Log(e.Message);
                }
            } while (Ret == DialogResult.Retry || RetryDialog);
            return(Success);
        }
Пример #4
0
        // Find classname
        private void PreParseScripts()
        {
            foreach (String script in Scripts)
            {
                if (!File.Exists(script))
                {
                    continue;
                }

                List<String> lines = new List<string>(File.ReadAllLines(script));

                ScriptExtension Ext = new ScriptExtension();
                Ext.FileName = script;

                foreach (String line in lines)
                {
                    if (line.Contains("public class"))
                    {
                        string[] param = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        for (uint i = 0; i < param.Length; i++)
                        {
                            if (param[i] == "public" && param.Length >= i + 4 && param[i + 1] == "class" && param[i + 4] == "IScript")
                            {
                                Ext.ClassName = param[i + 2];
                                Ext.Code = lines;
                                Ext.UpdateTime = 0;
                                Extensions.Add(Ext);
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
 public void update(ScriptExtension Ext)
 {
     Ext.UpdateTime = Ext.Handle.update();
 }