2012-06-24 03:45:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2012-06-24 03:45:56 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class HexFind : Form
|
|
|
|
|
{
|
|
|
|
|
public HexFind()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-02-24 03:18:43 +00:00
|
|
|
|
ChangeCasing();
|
2012-06-24 03:45:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-31 01:16:41 +00:00
|
|
|
|
public Point InitialLocation { get; set; }
|
2012-06-24 03:45:56 +00:00
|
|
|
|
|
2015-01-31 01:16:41 +00:00
|
|
|
|
public string InitialValue
|
2012-06-24 03:45:56 +00:00
|
|
|
|
{
|
2015-01-31 01:16:41 +00:00
|
|
|
|
get { return FindBox.Text; }
|
|
|
|
|
set { FindBox.Text = value ?? string.Empty; }
|
2012-06-24 03:45:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HexFind_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-01-31 01:16:41 +00:00
|
|
|
|
if (InitialLocation.X > 0 && InitialLocation.Y > 0)
|
2012-09-03 01:17:03 +00:00
|
|
|
|
{
|
2015-01-31 01:16:41 +00:00
|
|
|
|
Location = InitialLocation;
|
2012-09-03 01:17:03 +00:00
|
|
|
|
}
|
2015-01-31 01:25:08 +00:00
|
|
|
|
|
|
|
|
|
FindBox.Focus();
|
|
|
|
|
FindBox.Select();
|
2012-09-03 01:17:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetFindBoxChars()
|
|
|
|
|
{
|
2014-02-24 02:50:56 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(FindBox.Text))
|
2012-09-03 01:17:03 +00:00
|
|
|
|
{
|
2014-02-24 02:50:56 +00:00
|
|
|
|
return string.Empty;
|
2012-09-03 01:17:03 +00:00
|
|
|
|
}
|
2014-02-24 02:50:56 +00:00
|
|
|
|
|
|
|
|
|
if (HexRadio.Checked)
|
2012-09-03 01:17:03 +00:00
|
|
|
|
{
|
|
|
|
|
return FindBox.Text;
|
|
|
|
|
}
|
2014-02-24 02:50:56 +00:00
|
|
|
|
|
2014-03-23 23:47:20 +00:00
|
|
|
|
|
|
|
|
|
var bytes = GlobalWin.Tools.HexEditor.ConvertTextToBytes(FindBox.Text);
|
|
|
|
|
|
2014-02-24 02:50:56 +00:00
|
|
|
|
var bytestring = new StringBuilder();
|
2014-03-23 23:47:20 +00:00
|
|
|
|
foreach (var b in bytes)
|
2012-09-03 01:17:03 +00:00
|
|
|
|
{
|
2014-02-24 02:50:56 +00:00
|
|
|
|
bytestring.Append(string.Format("{0:X2}", b));
|
2012-09-03 01:17:03 +00:00
|
|
|
|
}
|
2014-02-24 02:50:56 +00:00
|
|
|
|
|
|
|
|
|
return bytestring.ToString();
|
2012-06-24 03:45:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Find_Prev_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.Tools.HexEditor.FindPrev(GetFindBoxChars(), false);
|
2012-06-24 03:45:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Find_Next_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.Tools.HexEditor.FindNext(GetFindBoxChars(), false);
|
2012-09-03 01:17:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ChangeCasing()
|
|
|
|
|
{
|
2014-02-24 03:18:43 +00:00
|
|
|
|
var text = FindBox.Text;
|
|
|
|
|
var location = FindBox.Location;
|
|
|
|
|
var size = FindBox.Size;
|
|
|
|
|
|
|
|
|
|
Controls.Remove(FindBox);
|
2015-01-31 01:23:03 +00:00
|
|
|
|
|
2015-04-01 13:59:40 +00:00
|
|
|
|
if (HexRadio.Checked)
|
2014-02-24 03:18:43 +00:00
|
|
|
|
{
|
2015-04-01 13:59:40 +00:00
|
|
|
|
|
|
|
|
|
FindBox = new HexTextBox
|
|
|
|
|
{
|
|
|
|
|
CharacterCasing = CharacterCasing.Upper,
|
|
|
|
|
Nullable = HexRadio.Checked,
|
|
|
|
|
Text = text,
|
|
|
|
|
Size = size,
|
|
|
|
|
Location = location
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FindBox = new TextBox
|
|
|
|
|
{
|
|
|
|
|
Text = text,
|
|
|
|
|
Size = size,
|
|
|
|
|
Location = location
|
|
|
|
|
};
|
|
|
|
|
}
|
2014-02-24 03:18:43 +00:00
|
|
|
|
|
|
|
|
|
Controls.Add(FindBox);
|
2012-09-03 01:17:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HexRadio_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ChangeCasing();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TextRadio_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ChangeCasing();
|
2012-06-24 03:45:56 +00:00
|
|
|
|
}
|
2012-09-23 23:20:30 +00:00
|
|
|
|
|
|
|
|
|
private void FindBox_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyData == Keys.Enter)
|
|
|
|
|
{
|
2016-02-16 01:13:12 +00:00
|
|
|
|
Find_Next_Click(null, null);
|
|
|
|
|
e.Handled = true;
|
2012-09-23 23:20:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-22 01:14:49 +00:00
|
|
|
|
|
|
|
|
|
private void HexFind_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Escape)
|
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2016-02-16 01:13:12 +00:00
|
|
|
|
else if (e.KeyData == Keys.Enter)
|
|
|
|
|
{
|
|
|
|
|
Find_Next_Click(null, null);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2015-01-22 01:14:49 +00:00
|
|
|
|
}
|
2012-06-24 03:45:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|