Ejemplo n.º 1
0
 private void RunLuaScripts()
 {
     foreach (var file in LuaImp.ScriptList)
     {
         if (!file.Enabled && file.Thread == null)
         {
             try
             {
                 LuaSandbox.Sandbox(null, () =>
                 {
                     string pathToLoad = ProcessPath(file.Path);
                     file.Thread       = LuaImp.SpawnCoroutine(file.Path);
                     LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad));
                 }, () =>
                 {
                     file.State = LuaFile.RunState.Disabled;
                 });
             }
             catch (Exception e)
             {
                 MessageBox.Show(e.ToString());
             }
         }
         else
         {
             file.Stop();
         }
     }
 }
Ejemplo n.º 2
0
 public void RunLuaScripts()
 {
     foreach (var file in _luaList)
     {
         if (!file.Enabled && file.Thread == null)
         {
             try
             {
                 LuaSandbox.Sandbox(null, () =>
                 {
                     string pathToLoad = Path.IsPathRooted(file.Path) ? file.Path : PathManager.MakeProgramRelativePath(file.Path);                             //JUNIPIER SQUATCHBOX COMPLEX
                     file.Thread       = LuaImp.SpawnCoroutine(file.Path);
                     LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad));
                 }, () =>
                 {
                     file.State = LuaFile.RunState.Disabled;
                 });
             }
             catch (Exception e)
             {
                 MessageBox.Show(e.ToString());
             }
         }
         else
         {
             file.Stop();
         }
     }
 }
Ejemplo n.º 3
0
 public void RunLuaScripts()
 {
     foreach (var file in _luaList)
     {
         if (file.Enabled && file.Thread == null)
         {
             try
             {
                 LuaSandbox.Sandbox(() =>
                 {
                     file.Thread = LuaImp.SpawnCoroutine(file.Path);
                 }, () =>
                 {
                     file.Enabled = false;
                 });
             }
             catch (Exception e)
             {
                 MessageBox.Show(e.ToString());
             }
         }
         else
         {
             file.Stop();
         }
     }
 }
Ejemplo n.º 4
0
        private void EnableLuaFile(LuaFile item)
        {
            try
            {
                LuaSandbox.Sandbox(null, () =>
                {
                    string pathToLoad = Path.IsPathRooted(item.Path)
                                        ? item.Path
                                        : PathManager.MakeProgramRelativePath(item.Path);

                    item.Thread = LuaImp.SpawnCoroutine(pathToLoad);
                    LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(pathToLoad));
                }, () =>
                {
                    item.State = LuaFile.RunState.Disabled;
                });

                // Shenanigans
                // We want any gui.text messages from a script to immediately update even when paused
                GlobalWin.OSD.ClearGUIText();
                GlobalWin.Tools.UpdateToolsAfter();
                LuaImp.EndLuaDrawing();
                LuaImp.StartLuaDrawing();
            }
            catch (IOException)
            {
                ConsoleLog("Unable to access file " + item.Path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 5
0
 public void RunLuaScripts()
 {
     foreach (var file in _luaList)
     {
         if (file.Enabled && file.Thread == null)
         {
             try
             {
                 file.Thread = LuaImp.SpawnCoroutine(file.Path);
             }
             catch (Exception e)
             {
                 if (e.ToString().Substring(0, 32) == "LuaInterface.LuaScriptException:")
                 {
                     file.Enabled = false;
                     ConsoleLog(e.Message);
                 }
                 else
                 {
                     MessageBox.Show(e.ToString());
                 }
             }
         }
         else
         {
             file.Stop();
         }
     }
 }
Ejemplo n.º 6
0
        public void LoadLuaFile(string path)
        {
            var    processedPath = PathManager.TryMakeRelative(path);
            string pathToLoad    = Path.IsPathRooted(processedPath) ? processedPath : PathManager.MakeProgramRelativePath(processedPath);          //JUNIPIER SQUATCHBOX COMPLEX

            if (LuaAlreadyInSession(processedPath) == false)
            {
                var luaFile = new LuaFile(string.Empty, processedPath);

                _luaList.Add(luaFile);
                LuaListView.ItemCount = _luaList.Count;
                Global.Config.RecentLua.Add(processedPath);

                if (!Global.Config.DisableLuaScriptsOnLoad)
                {
                    try
                    {
                        LuaSandbox.Sandbox(null, () =>
                        {
                            luaFile.Thread = LuaImp.SpawnCoroutine(pathToLoad);
                            LuaSandbox.CreateSandbox(luaFile.Thread, Path.GetDirectoryName(pathToLoad));
                            luaFile.State = LuaFile.RunState.Running;
                        }, () =>
                        {
                            luaFile.State = LuaFile.RunState.Disabled;
                        });
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString());
                    }
                }
                else
                {
                    luaFile.State = LuaFile.RunState.Disabled;
                }

                if (Global.Config.LuaReloadOnScriptFileChange)
                {
                    CreateFileWatcher(processedPath);
                }

                //luaFile.Paused = false;
            }
            else
            {
                foreach (var file in _luaList.Where(file => processedPath == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad))
                {
                    file.Toggle();
                    break;
                }

                RunLuaScripts();
            }

            UpdateDialog();
        }
Ejemplo n.º 7
0
        private void ToggleScriptMenuItem_Click(object sender, EventArgs e)
        {
            var files = !SelectedFiles.Any() && Global.Config.ToggleAllIfNoneSelected ? _luaList : SelectedFiles;

            foreach (var item in files)
            {
                item.Toggle();

                if (item.Enabled && item.Thread == null)
                {
                    try
                    {
                        LuaSandbox.Sandbox(() =>
                        {
                            item.Thread = LuaImp.SpawnCoroutine(item.Path);
                        }, () =>
                        {
                            item.State = LuaFile.RunState.Disabled;
                        });
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
                else if (!item.Enabled && item.Thread != null)
                {
                    LuaImp.CallExitEvent(item.Thread);

                    var items = SelectedItems.ToList();
                    foreach (var sitem in items)
                    {
                        var temp      = sitem;
                        var functions = LuaImp.RegisteredFunctions.Where(x => x.Lua == temp.Thread).ToList();
                        foreach (var function in functions)
                        {
                            LuaImp.RegisteredFunctions.Remove(function);
                        }

                        UpdateRegisteredFunctionsDialog();
                    }

                    LuaImp.CallExitEvent(item.Thread);
                    item.Stop();
                    if (Global.Config.RemoveRegisteredFunctionsOnToggle)
                    {
                        GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions.ClearAll();
                    }
                }
            }

            UpdateDialog();
            UpdateNumberOfScripts();
            LuaListView.Refresh();
        }
Ejemplo n.º 8
0
        public void LoadLuaFile(string path)
        {
            var processedPath = PathManager.TryMakeRelative(path);

            if (LuaAlreadyInSession(processedPath) == false)
            {
                var luaFile = new LuaFile(string.Empty, processedPath);

                _luaList.Add(luaFile);
                LuaListView.ItemCount = _luaList.Count;
                Global.Config.RecentLua.Add(processedPath);


                if (!Global.Config.DisableLuaScriptsOnLoad)
                {
                    try
                    {
                        luaFile.Thread  = LuaImp.SpawnCoroutine(processedPath);
                        luaFile.Enabled = true;
                    }
                    catch (Exception e)
                    {
                        if (e.GetType() == typeof(LuaInterface.LuaScriptException))
                        {
                            luaFile.Enabled = false;
                            ConsoleLog(e.Message);
                        }
                        else
                        {
                            MessageBox.Show(e.ToString());
                        }
                    }
                }
                else
                {
                    luaFile.Enabled = false;
                }

                luaFile.Paused = false;
            }
            else
            {
                foreach (var file in _luaList.Where(file => processedPath == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad))
                {
                    file.Toggle();
                    break;
                }

                RunLuaScripts();
            }

            UpdateDialog();
        }
Ejemplo n.º 9
0
        public void LoadLuaFile(string path)
        {
            var processedPath = PathManager.TryMakeRelative(path);

            if (LuaAlreadyInSession(processedPath) == false)
            {
                var luaFile = new LuaFile(string.Empty, processedPath);

                _luaList.Add(luaFile);
                LuaListView.ItemCount = _luaList.Count;
                Global.Config.RecentLua.Add(processedPath);


                if (!Global.Config.DisableLuaScriptsOnLoad)
                {
                    try
                    {
                        LuaSandbox.Sandbox(() =>
                        {
                            luaFile.Thread = LuaImp.SpawnCoroutine(processedPath);
                            luaFile.State  = LuaFile.RunState.Running;
                        }, () =>
                        {
                            luaFile.State = LuaFile.RunState.Disabled;
                        });
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString());
                    }
                }
                else
                {
                    luaFile.State = LuaFile.RunState.Disabled;
                }

                //luaFile.Paused = false;
            }
            else
            {
                foreach (var file in _luaList.Where(file => processedPath == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad))
                {
                    file.Toggle();
                    break;
                }

                RunLuaScripts();
            }

            UpdateDialog();
        }
Ejemplo n.º 10
0
        private void ToggleScriptMenuItem_Click(object sender, EventArgs e)
        {
            foreach (var item in SelectedFiles)
            {
                item.Toggle();

                if (item.Enabled && item.Thread == null)
                {
                    try
                    {
                        item.Thread = LuaImp.SpawnCoroutine(item.Path);
                    }
                    catch (Exception ex)
                    {
                        if (ex.ToString().Substring(0, 32) == "LuaInterface.LuaScriptException:")
                        {
                            item.Enabled = false;
                            ConsoleLog(ex.Message);
                        }
                        else
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
                else if (!item.Enabled && item.Thread != null)
                {
                    LuaImp.CallExitEvent(item.Thread);

                    var items = SelectedItems.ToList();
                    foreach (var sitem in items)
                    {
                        var temp      = sitem;
                        var functions = LuaImp.RegisteredFunctions.Where(x => x.Lua == temp.Thread).ToList();
                        foreach (var function in functions)
                        {
                            LuaImp.RegisteredFunctions.Remove(function);
                        }

                        UpdateRegisteredFunctionsDialog();
                    }

                    LuaImp.CallExitEvent(item.Thread);
                    item.Stop();
                }
            }

            UpdateDialog();
        }
Ejemplo n.º 11
0
        private void ToggleScriptMenuItem_Click(object sender, EventArgs e)
        {
            var files = !SelectedFiles.Any() && Global.Config.ToggleAllIfNoneSelected ? _luaList : SelectedFiles;

            foreach (var item in files)
            {
                item.Toggle();

                if (item.Enabled && item.Thread == null)
                {
                    try
                    {
                        LuaSandbox.Sandbox(null, () =>
                        {
                            string pathToLoad = Path.IsPathRooted(item.Path) ? item.Path : PathManager.MakeProgramRelativePath(item.Path);                             //JUNIPIER SQUATCHBOX COMPLEX
                            item.Thread       = LuaImp.SpawnCoroutine(pathToLoad);
                            LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(pathToLoad));
                        }, () =>
                        {
                            item.State = LuaFile.RunState.Disabled;
                        });
                    }
                    catch (IOException)
                    {
                        ConsoleLog("Unable to access file " + item.Path);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
                else if (!item.Enabled && item.Thread != null)
                {
                    LuaImp.CallExitEvent(item.Thread);

                    var items = SelectedItems.ToList();
                    foreach (var sitem in items)
                    {
                        var temp      = sitem;
                        var functions = LuaImp.RegisteredFunctions.Where(x => x.Lua == temp.Thread).ToList();
                        foreach (var function in functions)
                        {
                            LuaImp.RegisteredFunctions.Remove(function);
                        }

                        UpdateRegisteredFunctionsDialog();
                    }

                    LuaImp.CallExitEvent(item.Thread);
                    item.Stop();
                    if (Global.Config.RemoveRegisteredFunctionsOnToggle)
                    {
                        GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions.ClearAll();
                    }
                }
            }

            UpdateDialog();
            UpdateNumberOfScripts();
            LuaListView.Refresh();
        }
Ejemplo n.º 12
0
        private void ToggleScriptMenuItem_Click(object sender, EventArgs e)
        {
            var files = !SelectedFiles.Any() && Global.Config.ToggleAllIfNoneSelected ? LuaImp.ScriptList : SelectedFiles;

            foreach (var item in files)
            {
                item.Toggle();

                if (item.Enabled && item.Thread == null)
                {
                    try
                    {
                        LuaSandbox.Sandbox(null, () =>
                        {
                            string pathToLoad = Path.IsPathRooted(item.Path)
                                                        ? item.Path
                                                        : PathManager.MakeProgramRelativePath(item.Path);

                            item.Thread = LuaImp.SpawnCoroutine(pathToLoad);
                            LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(pathToLoad));
                        }, () =>
                        {
                            item.State = LuaFile.RunState.Disabled;
                        });

                        // Shenanigans
                        // We want any gui.text messages from a script to immediately update even when paused
                        GlobalWin.OSD.ClearGUIText();
                        GlobalWin.Tools.UpdateToolsAfter();
                        LuaImp.EndLuaDrawing();
                        LuaImp.StartLuaDrawing();
                    }
                    catch (IOException)
                    {
                        ConsoleLog("Unable to access file " + item.Path);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
                else if (!item.Enabled && item.Thread != null)
                {
                    LuaImp.CallExitEvent(item.Thread);

                    var items = SelectedItems.ToList();
                    foreach (var sitem in items)
                    {
                        var temp      = sitem;
                        var functions = LuaImp.RegisteredFunctions.Where(lf => lf.Lua == temp.Thread).ToList();
                        foreach (var function in functions)
                        {
                            LuaImp.RegisteredFunctions.Remove(function);
                        }

                        UpdateRegisteredFunctionsDialog();
                    }

                    LuaImp.CallExitEvent(item.Thread);
                    item.Stop();
                    if (Global.Config.RemoveRegisteredFunctionsOnToggle)
                    {
                        LuaImp.RegisteredFunctions.ClearAll();
                    }
                }
            }

            UpdateDialog();
            UpdateNumberOfScripts();
            LuaListView.Refresh();
        }