private void EnableLuaFile(LuaFile item) { try { LuaSandbox.Sandbox(null, () => { string pathToLoad = Path.IsPathRooted(item.Path) ? item.Path : PathManager.MakeProgramRelativePath(item.Path); LuaImp.SpawnAndSetFileThread(pathToLoad, item); 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()); } }
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(); }