Bug fixes; improvements; add preliminary support for field definitions
This commit is contained in:
parent
88ff8e03f0
commit
de8268fa4e
@ -27,6 +27,7 @@ using UniversalWidgetToolkit;
|
||||
using UniversalWidgetToolkit.Controls;
|
||||
using UniversalWidgetToolkit.Controls.HexEditor;
|
||||
using UniversalWidgetToolkit.Dialogs;
|
||||
using UniversalWidgetToolkit.Drawing;
|
||||
using UniversalWidgetToolkit.Layouts;
|
||||
|
||||
namespace UniversalEditor.Editors.Binary
|
||||
@ -127,7 +128,7 @@ namespace UniversalEditor.Editors.Binary
|
||||
input = input.Substring(2);
|
||||
ns |= System.Globalization.NumberStyles.HexNumber;
|
||||
}
|
||||
byte b = Byte.Parse(input);
|
||||
byte b = Byte.Parse(input, ns);
|
||||
return new byte[] { b };
|
||||
}, 1),
|
||||
new CONVERSION_DATA(typeof(short), "Signed 16-bit", delegate(byte[] input)
|
||||
@ -150,7 +151,7 @@ namespace UniversalEditor.Editors.Binary
|
||||
input = input.Substring(2);
|
||||
ns |= System.Globalization.NumberStyles.HexNumber;
|
||||
}
|
||||
short b = Int16.Parse(input);
|
||||
short b = Int16.Parse(input, ns);
|
||||
return BitConverter.GetBytes(b);
|
||||
}, 2),
|
||||
new CONVERSION_DATA(typeof(ushort), "Unsigned 16-bit", delegate(byte[] input)
|
||||
@ -197,7 +198,7 @@ namespace UniversalEditor.Editors.Binary
|
||||
input = input.Substring(2);
|
||||
ns |= System.Globalization.NumberStyles.HexNumber;
|
||||
}
|
||||
int b = Int32.Parse(input);
|
||||
int b = Int32.Parse(input, ns);
|
||||
return BitConverter.GetBytes(b);
|
||||
}, 4),
|
||||
new CONVERSION_DATA(typeof(uint), "Unsigned 32-bit", delegate(byte[] input)
|
||||
@ -221,7 +222,7 @@ namespace UniversalEditor.Editors.Binary
|
||||
ns |= System.Globalization.NumberStyles.HexNumber;
|
||||
}
|
||||
|
||||
uint b = UInt32.Parse(input, 0);
|
||||
uint b = UInt32.Parse(input, ns);
|
||||
return BitConverter.GetBytes(b);
|
||||
}, 4),
|
||||
new CONVERSION_DATA(typeof(float), "Float 32-bit", delegate(byte[] input)
|
||||
@ -245,7 +246,7 @@ namespace UniversalEditor.Editors.Binary
|
||||
ns |= System.Globalization.NumberStyles.HexNumber;
|
||||
}
|
||||
|
||||
float b = Single.Parse(input);
|
||||
float b = Single.Parse(input, ns);
|
||||
return BitConverter.GetBytes(b);
|
||||
}, 4),
|
||||
new CONVERSION_DATA(typeof(double), "Float 64-bit", delegate(byte[] input)
|
||||
@ -268,7 +269,7 @@ namespace UniversalEditor.Editors.Binary
|
||||
input = input.Substring(2);
|
||||
ns |= System.Globalization.NumberStyles.HexNumber;
|
||||
}
|
||||
double b = Double.Parse(input);
|
||||
double b = Double.Parse(input, ns);
|
||||
return BitConverter.GetBytes(b);
|
||||
}, 8),
|
||||
// Third column
|
||||
@ -401,21 +402,22 @@ namespace UniversalEditor.Editors.Binary
|
||||
tabPageFields.Text = "Field Definitions";
|
||||
|
||||
this.tbFieldDefinitions = new Toolbar();
|
||||
this.tbFieldDefinitions.Items.Add(new ToolbarItemButton("tsbFieldDefinitionAdd", StockType.Add));
|
||||
this.tbFieldDefinitions.Items.Add(new ToolbarItemButton("tsbFieldDefinitionEdit", StockType.Edit));
|
||||
this.tbFieldDefinitions.Items.Add(new ToolbarItemButton("tsbFieldDefinitionRemove", StockType.Remove));
|
||||
this.tbFieldDefinitions.Items.Add(new ToolbarItemButton("tsbFieldDefinitionAdd", StockType.Add, tsbFieldDefinitionAdd_Click));
|
||||
this.tbFieldDefinitions.Items.Add(new ToolbarItemButton("tsbFieldDefinitionEdit", StockType.Edit, tsbFieldDefinitionEdit_Click));
|
||||
this.tbFieldDefinitions.Items.Add(new ToolbarItemButton("tsbFieldDefinitionRemove", StockType.Remove, tsbFieldDefinitionRemove_Click));
|
||||
this.tbFieldDefinitions.Items.Add(new ToolbarItemSeparator());
|
||||
this.tbFieldDefinitions.Items.Add(new ToolbarItemButton("tsbFieldDefinitionLoadFromDefinition", "Open Definition File"));
|
||||
this.tbFieldDefinitions.Items.Add(new ToolbarItemButton("tsbFieldDefinitionLoadFromDefinition", "Open Definition File", tsbFieldDefinitionLoad_Click));
|
||||
tabPageFields.Controls.Add(this.tbFieldDefinitions, new BoxLayout.Constraints(false, true));
|
||||
|
||||
this.tmFieldDefinitions = new DefaultTreeModel(new Type[] { typeof(string), typeof(string), typeof(string), typeof(string) });
|
||||
this.tmFieldDefinitions = new DefaultTreeModel(new Type[] { typeof(string), typeof(string), typeof(string), typeof(string), typeof(string) });
|
||||
|
||||
this.lvFieldDefinitions = new ListView();
|
||||
this.lvFieldDefinitions.Model = tmFieldDefinitions;
|
||||
this.lvFieldDefinitions.Columns.Add(new ListViewColumnText(tmFieldDefinitions.Columns[0], "Name"));
|
||||
this.lvFieldDefinitions.Columns.Add(new ListViewColumnText(tmFieldDefinitions.Columns[1], "Offset"));
|
||||
this.lvFieldDefinitions.Columns.Add(new ListViewColumnText(tmFieldDefinitions.Columns[2], "Size"));
|
||||
this.lvFieldDefinitions.Columns.Add(new ListViewColumnText(tmFieldDefinitions.Columns[2], "Data Type [Size]"));
|
||||
this.lvFieldDefinitions.Columns.Add(new ListViewColumnText(tmFieldDefinitions.Columns[3], "Color"));
|
||||
this.lvFieldDefinitions.Columns.Add(new ListViewColumnText(tmFieldDefinitions.Columns[4], "Value"));
|
||||
tabPageFields.Controls.Add(this.lvFieldDefinitions, new BoxLayout.Constraints(true, true));
|
||||
this.tabs.TabPages.Add(tabPageFields);
|
||||
|
||||
@ -423,6 +425,44 @@ namespace UniversalEditor.Editors.Binary
|
||||
this.Controls.Add(tabs, new BoxLayout.Constraints(false, false, 0, BoxLayout.PackType.End));
|
||||
}
|
||||
|
||||
private void tsbFieldDefinitionAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
FieldDefinitionPropertiesDialog dlg = new FieldDefinitionPropertiesDialog();
|
||||
dlg.FieldDefinition.Offset = hexedit.SelectionStart;
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
tmFieldDefinitions.Rows.Add(new TreeModelRow(new TreeModelRowColumn[]
|
||||
{
|
||||
new TreeModelRowColumn(tmFieldDefinitions.Columns[0], dlg.FieldDefinition.Name),
|
||||
new TreeModelRowColumn(tmFieldDefinitions.Columns[1], dlg.FieldDefinition.Offset),
|
||||
new TreeModelRowColumn(tmFieldDefinitions.Columns[2], dlg.FieldDefinition.Length)
|
||||
// new TreeModelRowColumn(tmFieldDefinitions.Columns[0], dlg.cmdColor.Text)
|
||||
}));
|
||||
|
||||
hexedit.HighlightAreas.Add(new HexEditorHighlightArea(dlg.FieldDefinition.Name, dlg.FieldDefinition.Name, dlg.FieldDefinition.Offset, dlg.FieldDefinition.Length, (dlg.cmdColor.BackgroundBrush as SolidBrush).Color));
|
||||
}
|
||||
}
|
||||
private void tsbFieldDefinitionEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (lvFieldDefinitions.SelectedRows.Count != 1)
|
||||
return;
|
||||
|
||||
FieldDefinition def = lvFieldDefinitions.SelectedRows[0].GetExtraData<FieldDefinition>("def");
|
||||
if (def != null)
|
||||
{
|
||||
FieldDefinitionPropertiesDialog dlg = new FieldDefinitionPropertiesDialog();
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
private void tsbFieldDefinitionRemove_Click(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
private void tsbFieldDefinitionLoad_Click(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
void Txt_KeyDown(object sender, UniversalWidgetToolkit.Input.Keyboard.KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == UniversalWidgetToolkit.Input.Keyboard.KeyboardKey.Enter)
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
//
|
||||
// FieldDefinition.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019 Mike Becker
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using MBS.Framework.Drawing;
|
||||
|
||||
namespace UniversalEditor.Editors.Binary
|
||||
{
|
||||
public class FieldDefinition
|
||||
{
|
||||
public string Name;
|
||||
public int Offset;
|
||||
public int Length;
|
||||
public Color Color;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,116 @@
|
||||
//
|
||||
// FieldDefinitionPropertiesDialog.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019 Mike Becker
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using MBS.Framework.Drawing;
|
||||
using UniversalWidgetToolkit;
|
||||
using UniversalWidgetToolkit.Controls;
|
||||
using UniversalWidgetToolkit.Dialogs;
|
||||
using UniversalWidgetToolkit.Drawing;
|
||||
using UniversalWidgetToolkit.Layouts;
|
||||
|
||||
namespace UniversalEditor.Editors.Binary
|
||||
{
|
||||
public class FieldDefinitionPropertiesDialog : Dialog
|
||||
{
|
||||
private Label lblName;
|
||||
internal TextBox txtName;
|
||||
private Label lblOffset;
|
||||
internal TextBox txtOffset;
|
||||
private Label lblLength;
|
||||
internal TextBox txtLength;
|
||||
private Label lblColor;
|
||||
internal Button cmdColor;
|
||||
|
||||
public FieldDefinition FieldDefinition = new FieldDefinition();
|
||||
|
||||
protected override void OnShown(EventArgs e)
|
||||
{
|
||||
base.OnShown(e);
|
||||
|
||||
cmdColor.BackgroundBrush = new SolidBrush(Colors.LightSalmon);
|
||||
txtOffset.Text = FieldDefinition.Offset.ToString();
|
||||
}
|
||||
|
||||
public FieldDefinitionPropertiesDialog()
|
||||
{
|
||||
this.Text = "Field Definition Properties";
|
||||
|
||||
this.Layout = new GridLayout();
|
||||
|
||||
this.lblName = new Label();
|
||||
this.lblName.Text = "_Name";
|
||||
this.Controls.Add(this.lblName, new GridLayout.Constraints(0, 0));
|
||||
|
||||
this.txtName = new TextBox();
|
||||
this.Controls.Add(this.txtName, new GridLayout.Constraints(0, 1));
|
||||
|
||||
this.lblOffset = new Label();
|
||||
this.lblOffset.Text = "_Offset";
|
||||
this.Controls.Add(this.lblOffset, new GridLayout.Constraints(1, 0));
|
||||
|
||||
this.txtOffset = new TextBox();
|
||||
this.Controls.Add(this.txtOffset, new GridLayout.Constraints(1, 1));
|
||||
|
||||
this.lblLength = new Label();
|
||||
this.lblLength.Text = "_Length";
|
||||
this.Controls.Add(this.lblLength, new GridLayout.Constraints(2, 0));
|
||||
|
||||
this.txtLength = new TextBox();
|
||||
this.Controls.Add(this.txtLength, new GridLayout.Constraints(2, 1));
|
||||
|
||||
this.lblColor = new Label();
|
||||
this.lblColor.Text = "_Color";
|
||||
this.Controls.Add(this.lblColor, new GridLayout.Constraints(3, 0));
|
||||
|
||||
this.cmdColor = new Button();
|
||||
this.Controls.Add(this.cmdColor, new GridLayout.Constraints(3, 1));
|
||||
|
||||
this.Buttons.Add(new Button(ButtonStockType.OK));
|
||||
this.Buttons[this.Buttons.Count - 1].Click += cmdOK_Click;
|
||||
this.Buttons[this.Buttons.Count - 1].ResponseValue = (int)DialogResult.OK;
|
||||
|
||||
this.Buttons.Add(new Button(ButtonStockType.Cancel));
|
||||
this.Buttons[this.Buttons.Count - 1].ResponseValue = (int)DialogResult.Cancel;
|
||||
}
|
||||
|
||||
void cmdOK_Click(object sender, EventArgs e)
|
||||
{
|
||||
FieldDefinition.Name = txtName.Text;
|
||||
|
||||
int offset = 0, length = 0;
|
||||
if (!Int32.TryParse(txtOffset.Text, out offset))
|
||||
{
|
||||
MessageDialog.ShowDialog("offset must be a 32-bit integer");
|
||||
this.DialogResult = DialogResult.None;
|
||||
return;
|
||||
}
|
||||
if (!Int32.TryParse(txtLength.Text, out length))
|
||||
{
|
||||
MessageDialog.ShowDialog("length must be a 32-bit integer");
|
||||
this.DialogResult = DialogResult.None;
|
||||
return;
|
||||
}
|
||||
FieldDefinition.Offset = offset;
|
||||
FieldDefinition.Length = length;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -119,6 +119,8 @@
|
||||
<Compile Include="Editors\FileSystem\FileSystemSelection.cs" />
|
||||
<Compile Include="Editors\Text\TextEditor.cs" />
|
||||
<Compile Include="Editors\Binary\BinaryEditor.cs" />
|
||||
<Compile Include="Editors\Binary\FieldDefinitionPropertiesDialog.cs" />
|
||||
<Compile Include="Editors\Binary\FieldDefinition.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user