diff --git a/BizHawk.Client.Common/tools/Cheat.cs b/BizHawk.Client.Common/tools/Cheat.cs index ac5ea63ad4..7bd9c2117b 100644 --- a/BizHawk.Client.Common/tools/Cheat.cs +++ b/BizHawk.Client.Common/tools/Cheat.cs @@ -16,7 +16,6 @@ namespace BizHawk.Client.Common } private readonly Watch _watch; - private readonly CompareType _comparisonType; private int? _compare; private int _val; private bool _enabled; @@ -27,7 +26,7 @@ namespace BizHawk.Client.Common _watch = watch; _compare = compare; _val = value; - _comparisonType = comparisonType; + ComparisonType = comparisonType; Pulse(); } @@ -131,7 +130,7 @@ namespace BizHawk.Client.Common } } - public CompareType ComparisonType => _comparisonType; + public CompareType ComparisonType { get; private set; } public void Enable(bool handleChange = true) { @@ -187,7 +186,7 @@ namespace BizHawk.Client.Common { if (_compare.HasValue) { - switch (_comparisonType) + switch (ComparisonType) { default: case CompareType.None: // This should never happen, but it's here just in case. adelikat: And yet it does! Cheat Code converter doesn't do this. Changing this to default to equal since 99.9999% of all cheats are going to be equals @@ -323,12 +322,12 @@ namespace BizHawk.Client.Common else { if (addr == _watch.Address) - { + { return (byte)(_val & 0xFF); } if (addr == _watch.Address + 1) - { + { return (byte)((_val >> 8) & 0xFF); } @@ -396,15 +395,13 @@ namespace BizHawk.Client.Common public override bool Equals(object obj) { - if (obj is Watch) + if (obj is Watch watch) { - var watch = obj as Watch; return Domain == watch.Domain && Address == watch.Address; } - if (obj is Cheat) + if (obj is Cheat cheat) { - var cheat = obj as Cheat; return Domain == cheat.Domain && Address == cheat.Address; } diff --git a/BizHawk.Client.Common/tools/CheatList.cs b/BizHawk.Client.Common/tools/CheatList.cs index 0a857862ce..8cd1eb4736 100644 --- a/BizHawk.Client.Common/tools/CheatList.cs +++ b/BizHawk.Client.Common/tools/CheatList.cs @@ -25,7 +25,6 @@ namespace BizHawk.Client.Common private const string ComparisonType = "ComparisonTypeColumn"; private List _cheatList = new List(); - private string _currentFileName = ""; private string _defaultFileName = ""; private bool _changes; @@ -51,7 +50,7 @@ namespace BizHawk.Client.Common } } - public string CurrentFileName => _currentFileName; + public string CurrentFileName { get; private set; } = ""; public bool IsReadOnly => false; @@ -97,21 +96,26 @@ namespace BizHawk.Client.Common if (_cheatList.Any() && _changes && autosave) { - if (string.IsNullOrEmpty(_currentFileName)) + if (string.IsNullOrEmpty(CurrentFileName)) { - _currentFileName = _defaultFileName; + CurrentFileName = _defaultFileName; } Save(); } _cheatList.Clear(); - _currentFileName = ""; + CurrentFileName = ""; Changes = false; } public void Add(Cheat cheat) { + if (cheat is null) + { + throw new ArgumentNullException($"{nameof(cheat)} can not be null"); + } + if (cheat.IsSeparator) { _cheatList.Add(cheat); @@ -324,28 +328,28 @@ namespace BizHawk.Client.Common { if (Changes && _cheatList.Any()) { - if (string.IsNullOrWhiteSpace(_currentFileName)) + if (string.IsNullOrWhiteSpace(CurrentFileName)) { - _currentFileName = _defaultFileName; + CurrentFileName = _defaultFileName; } - SaveFile(_currentFileName); + SaveFile(CurrentFileName); } - else if (!_cheatList.Any() && !string.IsNullOrWhiteSpace(_currentFileName)) + else if (!_cheatList.Any() && !string.IsNullOrWhiteSpace(CurrentFileName)) { - new FileInfo(_currentFileName).Delete(); + new FileInfo(CurrentFileName).Delete(); } } } public bool Save() { - if (string.IsNullOrWhiteSpace(_currentFileName)) + if (string.IsNullOrWhiteSpace(CurrentFileName)) { - _currentFileName = _defaultFileName; + CurrentFileName = _defaultFileName; } - return SaveFile(_currentFileName); + return SaveFile(CurrentFileName); } public bool SaveFile(string path) @@ -371,7 +375,7 @@ namespace BizHawk.Client.Common else { // Set to hex for saving - var temp_cheat_type = cheat.Type; + var tempCheatType = cheat.Type; cheat.SetType(DisplayType.Hex); @@ -388,7 +392,7 @@ namespace BizHawk.Client.Common .Append(cheat.ComparisonType).Append('\t') .AppendLine(); - cheat.SetType(temp_cheat_type); + cheat.SetType(tempCheatType); } } @@ -396,8 +400,8 @@ namespace BizHawk.Client.Common sw.WriteLine(sb.ToString()); } - _currentFileName = path; - Global.Config.RecentCheats.Add(_currentFileName); + CurrentFileName = path; + Global.Config.RecentCheats.Add(CurrentFileName); Changes = false; return true; } @@ -417,7 +421,7 @@ namespace BizHawk.Client.Common if (!append) { - _currentFileName = path; + CurrentFileName = path; } using (var sr = file.OpenText()) @@ -441,7 +445,7 @@ namespace BizHawk.Client.Common int? compare; var size = WatchSize.Byte; var type = DisplayType.Hex; - var bigendian = false; + var bigEndian = false; Cheat.CompareType comparisonType = Cheat.CompareType.None; if (s.Length < 6) @@ -471,13 +475,13 @@ namespace BizHawk.Client.Common { size = Watch.SizeFromChar(vals[6][0]); type = Watch.DisplayTypeFromChar(vals[7][0]); - bigendian = vals[8] == "1"; + bigEndian = vals[8] == "1"; } // For backwards compatibility, don't assume these values exist if (vals.Length > 9) { - if (!Enum.TryParse(vals[9], out comparisonType)) + if (!Enum.TryParse(vals[9], out comparisonType)) { continue; // Not sure if this is the best answer, could just resort to == } @@ -488,7 +492,7 @@ namespace BizHawk.Client.Common address, size, type, - bigendian, + bigEndian, name); Add(new Cheat(watch, value, compare, !Global.Config.DisableCheatsOnLoad && enabled, comparisonType)); diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs b/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs index 398dce5bbc..b6e48a5617 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs @@ -26,7 +26,7 @@ namespace BizHawk.Client.EmuHawk private Cheat _cheat; private bool _loading; - private bool _editmode; + private bool _editMode; private Action _addCallback; private Action _editCallback; @@ -215,7 +215,7 @@ namespace BizHawk.Client.EmuHawk { var valid = !string.IsNullOrWhiteSpace(AddressBox.Text) && !string.IsNullOrWhiteSpace(ValueBox.Text); AddButton.Enabled = valid; - EditButton.Enabled = _editmode && valid; + EditButton.Enabled = _editMode && valid; } private void SizeDropDown_SelectedIndexChanged(object sender, EventArgs e) @@ -276,7 +276,7 @@ namespace BizHawk.Client.EmuHawk public void SetCheat(Cheat cheat) { - _editmode = true; + _editMode = true; _cheat = cheat; if (cheat.IsSeparator) { @@ -291,7 +291,7 @@ namespace BizHawk.Client.EmuHawk public void ClearForm() { _cheat = Cheat.Separator; - _editmode = false; + _editMode = false; SetFormToDefault(); } diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.Designer.cs b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.Designer.cs index 10fa9bdabe..c16ac816f3 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.Designer.cs @@ -112,7 +112,6 @@ this.CheatListView.UseCustomBackground = true; this.CheatListView.ColumnClick += new BizHawk.Client.EmuHawk.InputRoll.ColumnClickEventHandler(this.CheatListView_ColumnClick); this.CheatListView.SelectedIndexChanged += new System.EventHandler(this.CheatListView_SelectedIndexChanged); - this.CheatListView.Click += new System.EventHandler(this.CheatListView_Click); this.CheatListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.NewCheatForm_DragDrop); this.CheatListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.NewCheatForm_DragEnter); this.CheatListView.DoubleClick += new System.EventHandler(this.CheatListView_DoubleClick); diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 9fff2eadc5..67e0ec4e0b 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -209,7 +209,7 @@ namespace BizHawk.Client.EmuHawk private void SaveConfigSettings() { - Settings.Columns =CheatListView.AllColumns; + Settings.Columns = CheatListView.AllColumns; if (WindowState == FormWindowState.Normal) { @@ -328,15 +328,9 @@ namespace BizHawk.Client.EmuHawk private IEnumerable SelectedIndices => CheatListView.SelectedRows; - private IEnumerable SelectedItems - { - get { return SelectedIndices.Select(index => Global.CheatList[index]); } - } + private IEnumerable SelectedItems => SelectedIndices.Select(index => Global.CheatList[index]); - private IEnumerable SelectedCheats - { - get { return SelectedItems.Where(x => !x.IsSeparator); } - } + private IEnumerable SelectedCheats => SelectedItems.Where(x => !x.IsSeparator); private void DoSelectedIndexChange() { @@ -639,10 +633,6 @@ namespace BizHawk.Client.EmuHawk #region ListView and Dialog Events - private void CheatListView_Click(object sender, EventArgs e) - { - } - private void CheatListView_DoubleClick(object sender, EventArgs e) { ToggleMenuItem_Click(sender, e); diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index 2a16d4d221..7e2574dd52 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -288,6 +288,7 @@ True True True + True True True True