Ejemplo n.º 1
0
        private void RemoveScriptMenuItem_Click(object sender, EventArgs e)
        {
            var items = SelectedItems.ToList();

            if (items.Any())
            {
                foreach (var item in items)
                {
                    var temp = item;
                    LuaImp.GetRegisteredFunctions().RemoveAll(x => x.Lua == temp.Thread);

                    LuaImp.ScriptList.Remove(item);
                }

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

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

                if (file.Enabled && file.Thread == null)
                {
                    EnableLuaFile(file);
                }

                else if (!file.Enabled && file.Thread != null)
                {
                    LuaImp.CallExitEvent(file);

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

                        UpdateRegisteredFunctionsDialog();
                    }

                    LuaImp.CallExitEvent(file);
                    file.Stop();
                    if (Global.Config.RemoveRegisteredFunctionsOnToggle)
                    {
                        LuaImp.GetRegisteredFunctions().ClearAll();
                    }
                }
            }

            UpdateDialog();
            UpdateNumberOfScripts();
            LuaListView.Refresh();
        }
Ejemplo n.º 3
0
        private void RegisteredFunctionsMenuItem_Click(object sender, EventArgs e)
        {
            if (LuaImp.GetRegisteredFunctions().Any())
            {
                var alreadyOpen = false;
                foreach (Form form in Application.OpenForms)
                {
                    if (form is LuaRegisteredFunctionsList)
                    {
                        alreadyOpen = true;
                        form.Focus();
                    }
                }

                if (!alreadyOpen)
                {
                    new LuaRegisteredFunctionsList
                    {
                        StartLocation = this.ChildPointToScreen(LuaListView)
                    }.Show();
                }
            }
        }
Ejemplo n.º 4
0
        public void Restart()
        {
            var runningScripts = new List <LuaFile>();

            if (LuaImp != null)             // Things we need to do with the existing LuaImp before we can make a new one
            {
                if (LuaImp.IsRebootingCore)
                {
                    // Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies
                    LuaImp.Restart(Emulator.ServiceProvider);
                    return;
                }

                if (LuaImp.GuiLibrary != null && LuaImp.GuiLibrary.HasLuaSurface)
                {
                    LuaImp.GuiLibrary.DrawFinish();
                }

                runningScripts = LuaImp.RunningScripts.ToList();

                foreach (var file in runningScripts)
                {
                    LuaImp.CallExitEvent(file);

                    LuaImp.GetRegisteredFunctions().RemoveAll(lf => lf.Lua == file.Thread);

                    UpdateRegisteredFunctionsDialog();

                    file.Stop();
                }
            }

            var currentScripts = LuaImp?.ScriptList;             // Temp fix for now

            LuaImp = OSTailoredCode.IsWindows()
                                ? (PlatformEmuLuaLibrary) new EmuLuaLibrary(Emulator.ServiceProvider)
                                : (PlatformEmuLuaLibrary) new NotReallyLuaLibrary();
            if (currentScripts != null)
            {
                LuaImp.ScriptList.AddRange(currentScripts);
            }

            InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => $"{a.Library}.{a.Name}").ToArray());

            foreach (var file in runningScripts)
            {
                string pathToLoad = ProcessPath(file.Path);

                try
                {
                    LuaSandbox.Sandbox(file.Thread, () =>
                    {
                        LuaImp.SpawnAndSetFileThread(pathToLoad, file);
                        LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad));
                        file.State = LuaFile.RunState.Running;
                    }, () =>
                    {
                        file.State = LuaFile.RunState.Disabled;
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            UpdateDialog();
        }