From 8f3d1613a079849ee7e77559948f6414a04e1d91 Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 19 Apr 2017 07:50:25 -0500 Subject: [PATCH] misc code cleanups in ram watch tool files --- BizHawk.Client.EmuHawk/tools/Watch/RamPoke.cs | 7 +-- .../tools/Watch/RamSearch.cs | 61 ++++++++----------- .../tools/Watch/RamWatch.cs | 15 +++-- .../tools/Watch/WatchEditor.cs | 16 +++-- .../tools/Watch/WatchValueBox.cs | 46 +++++--------- 5 files changed, 58 insertions(+), 87 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamPoke.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamPoke.cs index 1d0fbd7208..680ae0fb7c 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamPoke.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamPoke.cs @@ -13,7 +13,7 @@ namespace BizHawk.Client.EmuHawk // TODO: don't use textboxes as labels private List _watchList = new List(); - public Point InitialLocation = new Point(0, 0); + public Point InitialLocation { get; set; } = new Point(0, 0); public RamPoke() { @@ -104,10 +104,7 @@ namespace BizHawk.Client.EmuHawk { var success = _watchList.All(watch => watch.Poke(ValueBox.Text)); - if (ParentTool != null) - { - ParentTool.UpdateValues(); - } + ParentTool?.UpdateValues(); if (success) { diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index 387c3b748b..58244e6f08 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -27,7 +27,6 @@ namespace BizHawk.Client.EmuHawk public partial class RamSearch : ToolFormBase, IToolForm { // TODO: DoSearch grabs the state of widgets and passes it to the engine before running, so rip out code that is attempting to keep the state up to date through change events - private string _currentFileName = string.Empty; private RamSearchEngine _searches; @@ -42,8 +41,8 @@ namespace BizHawk.Client.EmuHawk private bool _dropdownDontfire; // Used as a hack to get around lame .net dropdowns, there's no way to set their index without firing the selectedindexchanged event! - public const int MaxDetailedSize = 1024 * 1024; // 1mb, semi-arbituary decision, sets the size to check for and automatically switch to fast mode for the user - public const int MaxSupportedSize = 1024 * 1024 * 64; // 64mb, semi-arbituary decision, sets the maximum size RAM Search will support (as it will crash beyond this) + private const int MaxDetailedSize = 1024 * 1024; // 1mb, semi-arbituary decision, sets the size to check for and automatically switch to fast mode for the user + private const int MaxSupportedSize = 1024 * 1024 * 64; // 64mb, semi-arbituary decision, sets the maximum size RAM Search will support (as it will crash beyond this) #region Initialize, Load, and Save @@ -81,10 +80,7 @@ namespace BizHawk.Client.EmuHawk return true; } - public bool UpdateBefore - { - get { return false; } - } + public bool UpdateBefore => false; private void HardSetDisplayTypeDropDown(BizHawk.Client.Common.DisplayType type) { @@ -261,10 +257,12 @@ namespace BizHawk.Client.EmuHawk SetTotal(); } - public void NewUpdate(ToolFormUpdateType type) { } + public void NewUpdate(ToolFormUpdateType type) + { + } /// - /// This should only be called when the values of the list need an update such as after a poke or emulation occured + /// This should only be called when the values of the list need an update such as after a poke or emulation occurred /// public void UpdateValues() { @@ -315,7 +313,7 @@ namespace BizHawk.Client.EmuHawk HardSetDisplayTypeDropDown(_settings.Type); } - public void SaveConfigSettings() + private void SaveConfigSettings() { SaveColumnInfo(WatchListView, Settings.Columns); @@ -472,13 +470,7 @@ namespace BizHawk.Client.EmuHawk } } - private int? DifferentByValue - { - get - { - return DifferentByRadio.Checked ? DifferentByBox.ToRawInt() : null; - } - } + private int? DifferentByValue => DifferentByRadio.Checked ? DifferentByBox.ToRawInt() : null; private RamSearchEngine.ComparisonOperator Operator { @@ -560,10 +552,7 @@ namespace BizHawk.Client.EmuHawk _forcePreviewClear = true; } - private IEnumerable SelectedIndices - { - get { return WatchListView.SelectedIndices.Cast(); } - } + private IEnumerable SelectedIndices => WatchListView.SelectedIndices.Cast(); private IEnumerable SelectedItems { @@ -582,7 +571,7 @@ namespace BizHawk.Client.EmuHawk private void SetTotal() { - TotalSearchLabel.Text = string.Format("{0:n0}", _searches.Count) + " addresses"; + TotalSearchLabel.Text = $"{_searches.Count:n0}" + " addresses"; } private void SetDomainLabel() @@ -628,11 +617,19 @@ namespace BizHawk.Client.EmuHawk if (_settings.Type != type) { if (!string.IsNullOrEmpty(SpecificValueBox.Text)) + { SpecificValueBox.Text = "0"; + } + if (!string.IsNullOrEmpty(DifferenceBox.Text)) + { DifferenceBox.Text = "0"; + } + if (!string.IsNullOrEmpty(DifferentByBox.Text)) + { DifferentByBox.Text = "0"; + } } SpecificValueBox.Type = _settings.Type = type; @@ -701,7 +698,7 @@ namespace BizHawk.Client.EmuHawk private void PopulateTypeDropDown() { - var previous = DisplayTypeDropdown.SelectedItem != null ? DisplayTypeDropdown.SelectedItem.ToString() : string.Empty; + var previous = DisplayTypeDropdown.SelectedItem?.ToString() ?? string.Empty; var next = string.Empty; DisplayTypeDropdown.Items.Clear(); @@ -817,7 +814,7 @@ namespace BizHawk.Client.EmuHawk } } - public void LoadWatchFile(FileInfo file, bool append, bool truncate = false) + private void LoadWatchFile(FileInfo file, bool append, bool truncate = false) { if (file != null) { @@ -971,7 +968,7 @@ namespace BizHawk.Client.EmuHawk AutoSearchTakeLagFramesIntoAccount = true; } - public ColumnList Columns { get; set; } + public ColumnList Columns { get; } public bool PreviewMode { get; set; } public bool AlwaysExcludeRamWatch { get; set; } public bool AutoSearchTakeLagFramesIntoAccount { get; set; } @@ -1000,8 +997,7 @@ namespace BizHawk.Client.EmuHawk LoadWatchFile( GetWatchFileFromUser(string.Empty), sender == AppendFileMenuItem, - sender == TruncateFromFileMenuItem - ); + sender == TruncateFromFileMenuItem); } private void SaveMenuItem_Click(object sender, EventArgs e) @@ -1250,7 +1246,7 @@ namespace BizHawk.Client.EmuHawk ToggleSearchDependentToolBarItems(); _forcePreviewClear = true; UpdateUndoToolBarButtons(); - MessageLabel.Text = restoredCount.ToString() + " address" + (restoredCount != 1 ? "es" : "") + " restored"; + MessageLabel.Text = restoredCount + " address" + (restoredCount != 1 ? "es" : string.Empty) + " restored"; } } @@ -1263,7 +1259,7 @@ namespace BizHawk.Client.EmuHawk ToggleSearchDependentToolBarItems(); _forcePreviewClear = true; UpdateUndoToolBarButtons(); - MessageLabel.Text = restoredCount.ToString() + " address" + (restoredCount != 1 ? "es" : "") + " removed"; + MessageLabel.Text = restoredCount + " address" + (restoredCount != 1 ? "es" : string.Empty) + " removed"; } } @@ -1393,17 +1389,14 @@ namespace BizHawk.Client.EmuHawk { var recentFiles = Settings.RecentSearches; // We don't want to wipe recent files when restoring - Settings = new RamSearchSettings(); - Settings.RecentSearches = recentFiles; + Settings = new RamSearchSettings { RecentSearches = recentFiles }; Size = new Size(_defaultWidth, _defaultHeight); - RamSearchMenu.Items.Remove( RamSearchMenu.Items .OfType() - .First(x => x.Name == "GeneratedColumnsSubMenu") - ); + .First(x => x.Name == "GeneratedColumnsSubMenu")); RamSearchMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback)); diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index ead2910ed4..9c62a13450 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -78,13 +78,10 @@ namespace BizHawk.Client.EmuHawk }; } - public ColumnList Columns { get; set; } + public ColumnList Columns { get; } } - private IEnumerable SelectedIndices - { - get { return WatchListView.SelectedIndices.Cast(); } - } + private IEnumerable SelectedIndices => WatchListView.SelectedIndices.Cast(); private IEnumerable SelectedItems { @@ -225,7 +222,9 @@ namespace BizHawk.Client.EmuHawk } } - public void NewUpdate(ToolFormUpdateType type) { } + public void NewUpdate(ToolFormUpdateType type) + { + } public void UpdateValues() { @@ -705,7 +704,7 @@ namespace BizHawk.Client.EmuHawk PauseMenuItem.Text = _paused ? "Unpause" : "Pause"; } - private MemoryDomain _currentDomain = null; + private MemoryDomain _currentDomain; private MemoryDomain CurrentDomain { @@ -770,7 +769,7 @@ namespace BizHawk.Client.EmuHawk { if (SelectedWatches.Any()) { - RamPoke poke = new RamPoke + var poke = new RamPoke { InitialLocation = this.ChildPointToScreen(WatchListView) }; diff --git a/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs b/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs index 4f421c042d..e456671535 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs @@ -81,7 +81,7 @@ namespace BizHawk.Client.EmuHawk if (_watchList.Count > 1) { NotesBox.Enabled = false; - NotesBox.Text = String.Empty; + NotesBox.Text = string.Empty; AddressBox.Enabled = false; AddressBox.Text = _watchList.Select(a => a.AddressString).Aggregate((addrStr, nextStr) => addrStr + ("," + nextStr)); @@ -132,7 +132,7 @@ namespace BizHawk.Client.EmuHawk Text = "New Watch"; break; case Mode.Edit: - Text = "Edit Watch" + (_watchList.Count > 1 ? "es" : ""); + Text = "Edit Watch" + (_watchList.Count > 1 ? "es" : string.Empty); break; case Mode.Duplicate: Text = "Duplicate Watch"; @@ -179,10 +179,9 @@ namespace BizHawk.Client.EmuHawk break; } - if (DisplayTypeDropDown.Items.Contains(oldType)) - DisplayTypeDropDown.SelectedItem = oldType; - else - DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items[0]; + DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items.Contains(oldType) + ? oldType + : DisplayTypeDropDown.Items[0]; } private void SetBigEndianCheckBox() @@ -310,10 +309,9 @@ namespace BizHawk.Client.EmuHawk _watchList[i].Domain, _watchList.Count == 1 ? AddressBox.ToRawInt() ?? 0 : _watchList[i].Address, size, - _watchList[i].Type, + _watchList[i].Type, _watchList[i].BigEndian, - _watchList[i].Notes - ); + _watchList[i].Notes); } } diff --git a/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs b/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs index 39a8279c1f..925334aa70 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs @@ -1,11 +1,11 @@ using System; using System.Globalization; +using System.Linq; using System.Windows.Forms; using BizHawk.Common.StringExtensions; using BizHawk.Common.NumberExtensions; using BizHawk.Client.Common; -using System.Linq; namespace BizHawk.Client.EmuHawk { @@ -13,14 +13,13 @@ namespace BizHawk.Client.EmuHawk { private WatchSize _size = WatchSize.Byte; private DisplayType _type = DisplayType.Hex; - private bool _nullable = true; public WatchValueBox() { CharacterCasing = CharacterCasing.Upper; } - public bool Nullable { get { return _nullable; } set { _nullable = value; } } + public bool Nullable { get; set; } = true; public WatchSize ByteSize { @@ -42,15 +41,15 @@ namespace BizHawk.Client.EmuHawk switch (value) { case WatchSize.Byte: - isTypeCompatible = ByteWatch.ValidTypes.Where(t => t == _type).Any(); + isTypeCompatible = ByteWatch.ValidTypes.Any(t => t == _type); break; case WatchSize.Word: - isTypeCompatible = WordWatch.ValidTypes.Where(t => t == _type).Any(); + isTypeCompatible = WordWatch.ValidTypes.Any(t => t == _type); break; case WatchSize.DWord: - isTypeCompatible = DWordWatch.ValidTypes.Where(t => t == _type).Any(); + isTypeCompatible = DWordWatch.ValidTypes.Any(t => t == _type); break; } @@ -131,39 +130,21 @@ namespace BizHawk.Client.EmuHawk } } - private double Max12_4 - { - get { return MaxUnsignedInt / 16.0; } - } + private double Max12_4 => MaxUnsignedInt / 16.0; - private double Max20_12 - { - get { return MaxUnsignedInt / 4096.0; } - } + private double Max20_12 => MaxUnsignedInt / 4096.0; - private double Max16_16 - { - get { return MaxUnsignedInt / 65536.0; } - } + private double Max16_16 => MaxUnsignedInt / 65536.0; - private static double _12_4_Unit - { - get { return 1 / 16.0; } - } + private static double _12_4_Unit => 1 / 16.0; - private static double _20_12_Unit - { - get { return 1 / 4096.0; } - } + private static double _20_12_Unit => 1 / 4096.0; - private static double _16_16_Unit - { - get { return 1 / 65536.0; } - } + private static double _16_16_Unit => 1 / 65536.0; public override void ResetText() { - if (_nullable) + if (Nullable) { Text = string.Empty; } @@ -689,7 +670,10 @@ namespace BizHawk.Client.EmuHawk if (Text.IsFloat()) { if (Text == "-" || Text == ".") + { return 0; + } + float val = float.Parse(Text); var bytes = BitConverter.GetBytes(val); return BitConverter.ToInt32(bytes, 0);