diff --git a/BizHawk.Client.Common/lua/LuaFileList.cs b/BizHawk.Client.Common/lua/LuaFileList.cs index f7d5c30d66..666998b46b 100644 --- a/BizHawk.Client.Common/lua/LuaFileList.cs +++ b/BizHawk.Client.Common/lua/LuaFileList.cs @@ -90,12 +90,14 @@ namespace BizHawk.Client.Common { Add(LuaFile.SeparatorInstance); } - - Add(new LuaFile(line.Substring(2, line.Length - 2)) + else { - Enabled = !Global.Config.DisableLuaScriptsOnLoad && - line.Substring(0, 1) == "1", - }); + Add(new LuaFile(line.Substring(2, line.Length - 2)) + { + Enabled = !Global.Config.DisableLuaScriptsOnLoad && + line.Substring(0, 1) == "1", + }); + } } } diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 32a7e49ab2..a403868b86 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -340,26 +340,20 @@ namespace BizHawk.Client.EmuHawk private void MoveUp() { - var indices = CheatListView.SelectedIndices; + var indices = SelectedIndices.ToList(); if (indices.Count == 0 || indices[0] == 0) { return; } - foreach (int index in indices) + foreach (var index in indices) { var cheat = Global.CheatList[index]; - Global.CheatList.Remove(Global.CheatList[index]); + Global.CheatList.Remove(cheat); Global.CheatList.Insert(index - 1, cheat); } - UpdateMessageLabel(); - - var newindices = new List(); - for (var i = 0; i < indices.Count; i++) - { - newindices.Add(indices[i] - 1); - } + var newindices = indices.Select(t => t - 1).ToList(); CheatListView.SelectedIndices.Clear(); foreach (var newi in newindices) @@ -367,35 +361,28 @@ namespace BizHawk.Client.EmuHawk CheatListView.SelectItem(newi, true); } + UpdateMessageLabel(); UpdateDialog(); } private void MoveDown() { - var indices = CheatListView.SelectedIndices; - if (indices.Count == 0) + var indices = SelectedIndices.ToList(); + if (indices.Count == 0 || indices.Last() == Global.CheatList.Count - 1) { return; } - foreach (int index in indices) + for (var i = indices.Count - 1; i >= 0; i--) { - var cheat = Global.CheatList[index]; - - if (index < Global.CheatList.Count - 1) - { - Global.CheatList.Remove(Global.CheatList[index]); - Global.CheatList.Insert(index + 1, cheat); - } + var cheat = Global.CheatList[indices[i]]; + Global.CheatList.Remove(cheat); + Global.CheatList.Insert(indices[i] + 1, cheat); } UpdateMessageLabel(); - var newindices = new List(); - for (var i = 0; i < indices.Count; i++) - { - newindices.Add(indices[i] + 1); - } + var newindices = indices.Select(t => t + 1).ToList(); CheatListView.SelectedIndices.Clear(); foreach (var newi in newindices) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index d571cfa3e0..f913208da2 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Windows.Forms; using System.IO; +using BizHawk.Common; using BizHawk.Client.Common; using BizHawk.Emulation.Common; @@ -22,7 +23,7 @@ namespace BizHawk.Client.EmuHawk private int _defaultWidth; private int _defaultHeight; - private LuaFileList _luaList; + private readonly LuaFileList _luaList; public bool UpdateBefore { get { return true; } } public void UpdateValues() { } @@ -38,7 +39,7 @@ namespace BizHawk.Client.EmuHawk public LuaConsole() { - _luaList = new LuaFileList() + _luaList = new LuaFileList { ChangedCallback = SessionChangedCallback, LoadCallback = ClearOutputWindow @@ -126,19 +127,19 @@ namespace BizHawk.Client.EmuHawk public void RunLuaScripts() { - for (var i = 0; i < _luaList.Count; i++) + foreach (var t in _luaList) { - if (_luaList[i].Enabled && _luaList[i].Thread == null) + if (t.Enabled && t.Thread == null) { try { - _luaList[i].Thread = LuaImp.SpawnCoroutine(_luaList[i].Path); + t.Thread = LuaImp.SpawnCoroutine(t.Path); } catch (Exception e) { if (e.ToString().Substring(0, 32) == "LuaInterface.LuaScriptException:") { - _luaList[i].Enabled = false; + t.Enabled = false; ConsoleLog(e.Message); } else MessageBox.Show(e.ToString()); @@ -146,7 +147,7 @@ namespace BizHawk.Client.EmuHawk } else { - _luaList[i].Stop(); + t.Stop(); _luaList.Changes = true; } } @@ -217,24 +218,25 @@ namespace BizHawk.Client.EmuHawk } } - private FileInfo GetFileFromUser(string filter) + private static FileInfo GetFileFromUser(string filter) { - var ofd = new OpenFileDialog(); - ofd.InitialDirectory = PathManager.GetLuaPath(); - ofd.Filter = filter; - ofd.RestoreDirectory = true; + var ofd = new OpenFileDialog + { + InitialDirectory = PathManager.GetLuaPath(), + Filter = filter, RestoreDirectory = true + }; if (!Directory.Exists(ofd.InitialDirectory)) + { Directory.CreateDirectory(ofd.InitialDirectory); + } GlobalWin.Sound.StopSound(); var result = ofd.ShowDialog(); GlobalWin.Sound.StartSound(); - if (result != DialogResult.OK) - return null; - var file = new FileInfo(ofd.FileName); - return file; + + return result == DialogResult.OK ? new FileInfo(ofd.FileName) : null; } private void UpdateNumberOfScripts() @@ -750,11 +752,11 @@ namespace BizHawk.Client.EmuHawk return; } - foreach (var index in indices) + for (var i = indices.Count - 1; i >= 0; i--) { - var file = _luaList[index]; + var file = _luaList[indices[i]]; _luaList.Remove(file); - _luaList.Insert(index + 1, file); + _luaList.Insert(indices[i] + 1, file); } var newindices = indices.Select(t => t + 1).ToList(); diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 583d241b8f..d52d14564d 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -406,33 +406,28 @@ namespace BizHawk.Client.EmuHawk private void MoveDown() { - var indexes = SelectedIndices.ToList(); - if (!indexes.Any()) + var indices = SelectedIndices.ToList(); + if (indices.Count == 0 || indices.Last() == _watches.Count - 1) { return; } - foreach (var index in indexes) + for (var i = indices.Count - 1; i >= 0; i--) { - var watch = _watches[index]; - - if (index < _watches.Count - 1) - { - _watches.Remove(_watches[index]); - _watches.Insert(index + 1, watch); - } + var watch = _watches[indices[i]]; + _watches.Remove(watch); + _watches.Insert(indices[i] + 1, watch); } - Changes(); - - var indices = indexes.Select(t => t + 1).ToList(); + var newindices = indices.Select(t => t + 1).ToList(); WatchListView.SelectedIndices.Clear(); - foreach (var t in indices) + foreach (var t in newindices) { WatchListView.SelectItem(t, true); } + Changes(); WatchListView.ItemCount = _watches.ItemCount; } @@ -447,7 +442,7 @@ namespace BizHawk.Client.EmuHawk foreach (var index in indexes) { var watch = _watches[index]; - _watches.Remove(_watches[index]); + _watches.Remove(watch); _watches.Insert(index - 1, watch); }