From c057c5793c024e4476b71515bda1dee0c1576f63 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 31 May 2020 11:07:20 -0500 Subject: [PATCH] LuaFileList - simplify --- src/BizHawk.Client.Common/lua/LuaFileList.cs | 76 ++++++++----------- .../tools/Lua/LuaConsole.cs | 2 +- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/src/BizHawk.Client.Common/lua/LuaFileList.cs b/src/BizHawk.Client.Common/lua/LuaFileList.cs index 7c4e4b4562..8caa17301f 100644 --- a/src/BizHawk.Client.Common/lua/LuaFileList.cs +++ b/src/BizHawk.Client.Common/lua/LuaFileList.cs @@ -12,8 +12,6 @@ namespace BizHawk.Client.Common private bool _changes; public Action ChangedCallback { get; set; } - public Action LoadCallback { get; set; } - public bool Changes { get => _changes; @@ -64,52 +62,44 @@ namespace BizHawk.Client.Common return base.Remove(item); } - public new int RemoveAll(Predicate match) - { - return base.RemoveAll(match); - } - public bool LoadLuaSession(string path, bool disableOnLoad) { var file = new FileInfo(path); - if (file.Exists) + if (!file.Exists) { - Clear(); - using (var sr = file.OpenText()) - { - string line; - while ((line = sr.ReadLine()) != null) - { - if (line.StartsWith("---")) - { - Add(LuaFile.SeparatorInstance); - } - else - { - var scriptPath = line.Substring(2, line.Length - 2); - if (!Path.IsPathRooted(scriptPath)) - { - var directory = Path.GetDirectoryName(path); - scriptPath = Path.GetFullPath(Path.Combine(directory ?? "", scriptPath)); - } - - Add(new LuaFile(scriptPath) - { - State = !disableOnLoad && line.Substring(0, 1) == "1" - ? LuaFile.RunState.Running - : LuaFile.RunState.Disabled - }); - } - } - } - - _filename = path; - LoadCallback?.Invoke(); - - return true; + return false; } - - return false; + + Clear(); + using var sr = file.OpenText(); + string line; + while ((line = sr.ReadLine()) != null) + { + if (line.StartsWith("---")) + { + Add(LuaFile.SeparatorInstance); + } + else + { + var scriptPath = line.Substring(2, line.Length - 2); + if (!Path.IsPathRooted(scriptPath)) + { + var directory = Path.GetDirectoryName(path); + scriptPath = Path.GetFullPath(Path.Combine(directory ?? "", scriptPath)); + } + + Add(new LuaFile(scriptPath) + { + State = !disableOnLoad && line.Substring(0, 1) == "1" + ? LuaFile.RunState.Running + : LuaFile.RunState.Disabled + }); + } + } + + _filename = path; + return true; + } public void SaveSession() diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 0884a56571..92381b7acb 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -128,7 +128,6 @@ namespace BizHawk.Client.EmuHawk } LuaImp.ScriptList.ChangedCallback = SessionChangedCallback; - LuaImp.ScriptList.LoadCallback = ClearOutputWindow; if (Config.RecentLuaSession.AutoLoad && !Config.RecentLuaSession.Empty) { @@ -525,6 +524,7 @@ namespace BizHawk.Client.EmuHawk Config.RecentLua.Add(script.Path); } + ClearOutputWindow(); return result; }