From 98643b05999e47f8e4918c6f98daaeb9054be397 Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Thu, 24 Feb 2011 13:46:49 +0000 Subject: [PATCH] Ram Poke - better input validation on text boxes --- BizHawk.MultiClient/tools/RamPoke.Designer.cs | 2 + BizHawk.MultiClient/tools/RamPoke.cs | 41 +++++++++++++++++++ BizHawk.MultiClient/tools/RamSearch.cs | 1 - 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/BizHawk.MultiClient/tools/RamPoke.Designer.cs b/BizHawk.MultiClient/tools/RamPoke.Designer.cs index fcec531c0f..7b6d300df9 100644 --- a/BizHawk.MultiClient/tools/RamPoke.Designer.cs +++ b/BizHawk.MultiClient/tools/RamPoke.Designer.cs @@ -71,6 +71,7 @@ this.AddressBox.TabIndex = 2; this.AddressBox.Text = "0000"; this.AddressBox.Leave += new System.EventHandler(this.AddressBox_Leave); + this.AddressBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.AddressBox_KeyPress); // // DataTypeGroupBox // @@ -241,6 +242,7 @@ this.ValueBox.TabIndex = 11; this.ValueBox.Text = "0000"; this.ValueBox.Leave += new System.EventHandler(this.ValueBox_Leave); + this.ValueBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.ValueBox_KeyPress); // // RamPoke // diff --git a/BizHawk.MultiClient/tools/RamPoke.cs b/BizHawk.MultiClient/tools/RamPoke.cs index d1a2af0fe5..40f92fb19e 100644 --- a/BizHawk.MultiClient/tools/RamPoke.cs +++ b/BizHawk.MultiClient/tools/RamPoke.cs @@ -195,5 +195,46 @@ namespace BizHawk.MultiClient t.Show("Must be a valid unsigned decimal value", ValueBox, 5000); } } + + private asigned GetDataType() + { + if (SignedRadio.Checked) + return asigned.UNSIGNED; + if (UnsignedRadio.Checked) + return asigned.SIGNED; + if (HexRadio.Checked) + return asigned.HEX; + + return asigned.UNSIGNED; //Just in case + } + + private void AddressBox_KeyPress(object sender, KeyPressEventArgs e) + { + if (e.KeyChar == '\b') return; + + if (!InputValidate.IsValidHexNumber(e.KeyChar)) + e.Handled = true; + } + + private void ValueBox_KeyPress(object sender, KeyPressEventArgs e) + { + if (e.KeyChar == '\b') return; + + switch (GetDataType()) + { + case asigned.UNSIGNED: + if (!InputValidate.IsValidUnsignedNumber(e.KeyChar)) + e.Handled = true; + break; + case asigned.SIGNED: + if (!InputValidate.IsValidSignedNumber(e.KeyChar)) + e.Handled = true; + break; + case asigned.HEX: + if (!InputValidate.IsValidHexNumber(e.KeyChar)) + e.Handled = true; + break; + } + } } } diff --git a/BizHawk.MultiClient/tools/RamSearch.cs b/BizHawk.MultiClient/tools/RamSearch.cs index 77706b06e6..1cef36fa4f 100644 --- a/BizHawk.MultiClient/tools/RamSearch.cs +++ b/BizHawk.MultiClient/tools/RamSearch.cs @@ -1550,7 +1550,6 @@ namespace BizHawk.MultiClient e.Handled = true; break; } - } private void SpecificAddressBox_KeyPress(object sender, KeyPressEventArgs e)