From 80150f70be210e8cdce117678476428865e9bde9 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 4 Oct 2019 12:06:23 -0500 Subject: [PATCH] Lua console - misc cleanups, remove some unused code --- .../tools/Lua/LuaConsole.cs | 55 +++++++------------ BizHawk.sln.DotSettings | 2 + 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 7789dce284..7ea1f41fda 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -149,11 +149,11 @@ namespace BizHawk.Client.EmuHawk public void Restart() { - List runningScripts = new List(); + var runningScripts = new List(); if (LuaImp != null) // Things we need to do with the existing LuaImp before we can make a new one { - if (LuaImp.IsRebootingCore == true) + 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); @@ -188,8 +188,8 @@ namespace BizHawk.Client.EmuHawk var currentScripts = LuaImp?.ScriptList; // Temp fix for now LuaImp = OSTailoredCode.CurrentOS == OSTailoredCode.DistinctOS.Windows - ? (PlatformEmuLuaLibrary) new EmuLuaLibrary(Emulator.ServiceProvider) - : (PlatformEmuLuaLibrary) new NotReallyLuaLibrary(); + ? (PlatformEmuLuaLibrary)new EmuLuaLibrary(Emulator.ServiceProvider) + : (PlatformEmuLuaLibrary)new NotReallyLuaLibrary(); if (currentScripts != null) { LuaImp.ScriptList.AddRange(currentScripts); @@ -255,7 +255,6 @@ namespace BizHawk.Client.EmuHawk private void OnChanged(object source, FileSystemEventArgs e) { - string message = $"File: {e.FullPath} {e.ChangeType}"; Invoke(new MethodInvoker(delegate { RefreshScriptMenuItem_Click(null, null); @@ -265,7 +264,6 @@ namespace BizHawk.Client.EmuHawk public void LoadLuaFile(string path) { var processedPath = PathManager.TryMakeRelative(path); - string pathToLoad = ProcessPath(processedPath); if (LuaAlreadyInSession(processedPath) == false) { @@ -591,16 +589,6 @@ namespace BizHawk.Client.EmuHawk } } - public bool WaitOne(int timeout) - { - if (!IsHandleCreated || IsDisposed) - { - return true; - } - - return LuaImp.LuaWait.WaitOne(timeout); - } - private FileInfo GetSaveFileFromUser() { var sfd = new SaveFileDialog(); @@ -643,13 +631,13 @@ namespace BizHawk.Client.EmuHawk private void LoadSessionFromRecent(string path) { - var doload = true; + var load = true; if (LuaImp.ScriptList.Changes) { - doload = AskSaveChanges(); + load = AskSaveChanges(); } - if (doload) + if (load) { if (!LuaImp.ScriptList.LoadLuaSession(path)) { @@ -829,7 +817,7 @@ namespace BizHawk.Client.EmuHawk File.WriteAllText(sfd.FileName, defaultTemplate); LuaImp.ScriptList.Add(new LuaFile(Path.GetFileNameWithoutExtension(sfd.FileName), sfd.FileName)); UpdateDialog(); - System.Diagnostics.Process.Start(sfd.FileName); + Process.Start(sfd.FileName); } } @@ -854,15 +842,14 @@ namespace BizHawk.Client.EmuHawk { EnableLuaFile(file); } - else if (!file.Enabled && file.Thread != null) { LuaImp.CallExitEvent(file); var items = SelectedItems.ToList(); - foreach (var sitem in items) + foreach (var selectedItem in items) { - var temp = sitem; + var temp = selectedItem; var functions = LuaImp.GetRegisteredFunctions().Where(lf => lf.Lua == temp.Thread).ToList(); foreach (var function in functions) { @@ -988,7 +975,7 @@ namespace BizHawk.Client.EmuHawk File.WriteAllText(sfd.FileName, text); LuaImp.ScriptList.Add(new LuaFile(Path.GetFileNameWithoutExtension(sfd.FileName), sfd.FileName)); UpdateDialog(); - System.Diagnostics.Process.Start(sfd.FileName); + Process.Start(sfd.FileName); } } } @@ -1023,12 +1010,12 @@ namespace BizHawk.Client.EmuHawk LuaImp.ScriptList.Insert(index - 1, file); } - var newindices = indices.Select(t => t - 1).ToList(); + var newIndices = indices.Select(t => t - 1).ToList(); LuaListView.SelectedIndices.Clear(); - foreach (var newi in newindices) + foreach (var i in newIndices) { - LuaListView.SelectItem(newi, true); + LuaListView.SelectItem(i, true); } UpdateDialog(); @@ -1049,12 +1036,12 @@ namespace BizHawk.Client.EmuHawk LuaImp.ScriptList.Insert(indices[i] + 1, file); } - var newindices = indices.Select(t => t + 1).ToList(); + var newIndices = indices.Select(t => t + 1).ToList(); LuaListView.SelectedIndices.Clear(); - foreach (var newi in newindices) + foreach (var i in newIndices) { - LuaListView.SelectItem(newi, true); + LuaListView.SelectItem(i, true); } UpdateDialog(); @@ -1208,7 +1195,7 @@ namespace BizHawk.Client.EmuHawk private void OnlineDocsMenuItem_Click(object sender, EventArgs e) { - System.Diagnostics.Process.Start("http://tasvideos.org/BizHawk/LuaFunctions.html"); + Process.Start("http://tasvideos.org/BizHawk/LuaFunctions.html"); } #endregion @@ -1262,12 +1249,12 @@ namespace BizHawk.Client.EmuHawk { foreach (var path in filePaths) { - if (Path.GetExtension(path).ToLower() == ".lua" || Path.GetExtension(path).ToLower() == ".txt") + if (Path.GetExtension(path)?.ToLower() == ".lua" || Path.GetExtension(path)?.ToLower() == ".txt") { LoadLuaFile(path); UpdateDialog(); } - else if (Path.GetExtension(path).ToLower() == ".luases") + else if (Path.GetExtension(path)?.ToLower() == ".luases") { LuaImp.ScriptList.LoadLuaSession(path); RunLuaScripts(); @@ -1453,7 +1440,7 @@ namespace BizHawk.Client.EmuHawk // Stupid designer protected void DragEnterWrapper(object sender, DragEventArgs e) { - base.GenericDragEnter(sender, e); + GenericDragEnter(sender, e); } #endregion diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index d39322b633..2356f4a223 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -180,10 +180,12 @@ True True True + True True True True True + True True True True