diff --git a/Model/TagByteArrayDataNode.cs b/Model/TagByteArrayDataNode.cs
index 0ed183b..d55995c 100644
--- a/Model/TagByteArrayDataNode.cs
+++ b/Model/TagByteArrayDataNode.cs
@@ -16,7 +16,11 @@ namespace NBTExplorer.Model
public override bool CanEditNode
{
- get { return !IsMono(); }
+#if WINDOWS
+ get { return true; }
+#else
+ get { return false; }
+#endif
}
public override bool EditNode ()
@@ -28,10 +32,5 @@ namespace NBTExplorer.Model
{
get { return NodeDisplayPrefix + Tag.Data.Length + " bytes"; }
}
-
- private bool IsMono ()
- {
- return Type.GetType("Mono.Runtime") != null;
- }
}
}
diff --git a/Model/TagIntArrayDataNode.cs b/Model/TagIntArrayDataNode.cs
index a11bb98..bb07359 100644
--- a/Model/TagIntArrayDataNode.cs
+++ b/Model/TagIntArrayDataNode.cs
@@ -16,7 +16,11 @@ namespace NBTExplorer.Model
public override bool CanEditNode
{
- get { return !IsMono(); }
+#if WINDOWS
+ get { return true; }
+#else
+ get { return false; }
+#endif
}
public override bool EditNode ()
@@ -28,10 +32,5 @@ namespace NBTExplorer.Model
{
get { return NodeDisplayPrefix + Tag.Data.Length + " integers"; }
}
-
- private bool IsMono ()
- {
- return Type.GetType("Mono.Runtime") != null;
- }
}
}
diff --git a/NBTExplorer.csproj b/NBTExplorer.csproj
index 101a8a8..8239c3d 100644
--- a/NBTExplorer.csproj
+++ b/NBTExplorer.csproj
@@ -38,7 +38,7 @@
True
bin\Debug\
- DEBUG;TRACE
+ TRACE;DEBUG;WINDOWS
full
AnyCPU
bin\Debug\NBTExplorer.exe.CodeAnalysisLog.xml
@@ -55,7 +55,7 @@
bin\Release\
- TRACE
+ TRACE;WINDOWS
True
pdbonly
AnyCPU
diff --git a/Windows/EditHex.Designer.cs b/Windows/EditHex.Designer.cs
index 5b51d7e..51c525d 100644
--- a/Windows/EditHex.Designer.cs
+++ b/Windows/EditHex.Designer.cs
@@ -28,64 +28,23 @@
private void InitializeComponent ()
{
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
- //this._curPositionLabel = new System.Windows.Forms.ToolStripStatusLabel();
- //this._curElementLabel = new System.Windows.Forms.ToolStripStatusLabel();
- //this._space = new System.Windows.Forms.ToolStripStatusLabel();
- //this._insertStateLabel = new System.Windows.Forms.ToolStripStatusLabel();
this._buttonCancel = new System.Windows.Forms.Button();
this._buttonOK = new System.Windows.Forms.Button();
- //this.hexBox1 = new Be.Windows.Forms.HexBox();
this._buttonImport = new System.Windows.Forms.Button();
this._buttonExport = new System.Windows.Forms.Button();
this.viewTabs = new System.Windows.Forms.TabControl();
- //this.textView = new System.Windows.Forms.TabPage();
- //this.textBox1 = new System.Windows.Forms.TextBox();
- //this.hexView = new System.Windows.Forms.TabPage();
this.statusStrip1.SuspendLayout();
this.viewTabs.SuspendLayout();
- //this.textView.SuspendLayout();
- //this.hexView.SuspendLayout();
this.SuspendLayout();
//
// statusStrip1
//
- /*this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this._curPositionLabel,
- this._curElementLabel,
- this._space,
- this._insertStateLabel});*/
this.statusStrip1.Location = new System.Drawing.Point(0, 333);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(532, 22);
this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "statusStrip1";
//
- // _curPositionLabel
- //
- /*this._curPositionLabel.AutoSize = false;
- this._curPositionLabel.Name = "_curPositionLabel";
- this._curPositionLabel.Size = new System.Drawing.Size(100, 17);
- this._curPositionLabel.Text = "0000";
- //
- // _curElementLabel
- //
- this._curElementLabel.Name = "_curElementLabel";
- this._curElementLabel.Size = new System.Drawing.Size(59, 17);
- this._curElementLabel.Text = "Element 0";
- this._curElementLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // _space
- //
- this._space.Name = "_space";
- this._space.Size = new System.Drawing.Size(300, 17);
- this._space.Spring = true;
- //
- // _insertStateLabel
- //
- this._insertStateLabel.Name = "_insertStateLabel";
- this._insertStateLabel.Size = new System.Drawing.Size(58, 17);
- this._insertStateLabel.Text = "Overwrite";*/
- //
// _buttonCancel
//
this._buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@@ -108,22 +67,6 @@
this._buttonOK.UseVisualStyleBackColor = true;
this._buttonOK.Click += new System.EventHandler(this._buttonOK_Click);
//
- // hexBox1
- //
- /*this.hexBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.hexBox1.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.hexBox1.LineInfoForeColor = System.Drawing.Color.Empty;
- this.hexBox1.LineInfoVisible = true;
- this.hexBox1.Location = new System.Drawing.Point(0, 0);
- this.hexBox1.Name = "hexBox1";
- this.hexBox1.ReadOnly = true;
- this.hexBox1.ShadowSelectionColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(60)))), ((int)(((byte)(188)))), ((int)(((byte)(255)))));
- this.hexBox1.Size = new System.Drawing.Size(500, 263);
- this.hexBox1.TabIndex = 0;
- this.hexBox1.VScrollBarVisible = true;*/
- //
// _buttonImport
//
this._buttonImport.Location = new System.Drawing.Point(12, 307);
@@ -146,49 +89,12 @@
//
// viewTabs
//
- //this.viewTabs.Controls.Add(this.textView);
- //this.viewTabs.Controls.Add(this.hexView);
this.viewTabs.Location = new System.Drawing.Point(12, 12);
this.viewTabs.Name = "viewTabs";
this.viewTabs.SelectedIndex = 0;
this.viewTabs.Size = new System.Drawing.Size(508, 289);
this.viewTabs.TabIndex = 16;
//
- // textView
- //
- /*this.textView.Controls.Add(this.textBox1);
- this.textView.Location = new System.Drawing.Point(4, 22);
- this.textView.Name = "textView";
- this.textView.Padding = new System.Windows.Forms.Padding(3);
- this.textView.Size = new System.Drawing.Size(500, 263);
- this.textView.TabIndex = 1;
- this.textView.Text = "Text View";
- this.textView.UseVisualStyleBackColor = true;*/
- //
- // textBox1
- //
- /*this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.textBox1.Location = new System.Drawing.Point(0, 0);
- this.textBox1.Margin = new System.Windows.Forms.Padding(0);
- this.textBox1.Multiline = true;
- this.textBox1.Name = "textBox1";
- this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
- this.textBox1.Size = new System.Drawing.Size(500, 263);
- this.textBox1.TabIndex = 0;*/
- //
- // hexView
- //
- /*this.hexView.Controls.Add(this.hexBox1);
- this.hexView.Location = new System.Drawing.Point(4, 22);
- this.hexView.Name = "hexView";
- this.hexView.Padding = new System.Windows.Forms.Padding(3);
- this.hexView.Size = new System.Drawing.Size(500, 263);
- this.hexView.TabIndex = 0;
- this.hexView.Text = "Hex View";
- this.hexView.UseVisualStyleBackColor = true;*/
- //
// HexEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -208,9 +114,6 @@
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.viewTabs.ResumeLayout(false);
- //this.textView.ResumeLayout(false);
- //this.textView.PerformLayout();
- //this.hexView.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@@ -218,19 +121,11 @@
#endregion
- //private Be.Windows.Forms.HexBox hexBox1;
private System.Windows.Forms.StatusStrip statusStrip1;
- //private System.Windows.Forms.ToolStripStatusLabel _curPositionLabel;
private System.Windows.Forms.Button _buttonCancel;
private System.Windows.Forms.Button _buttonOK;
- //private System.Windows.Forms.ToolStripStatusLabel _curElementLabel;
- //private System.Windows.Forms.ToolStripStatusLabel _space;
- //private System.Windows.Forms.ToolStripStatusLabel _insertStateLabel;
private System.Windows.Forms.Button _buttonImport;
private System.Windows.Forms.Button _buttonExport;
private System.Windows.Forms.TabControl viewTabs;
- //private System.Windows.Forms.TabPage textView;
- //private System.Windows.Forms.TextBox textBox1;
- //private System.Windows.Forms.TabPage hexView;
}
}
\ No newline at end of file
diff --git a/Windows/EditHex.cs b/Windows/EditHex.cs
index 981939a..7b3ce88 100644
--- a/Windows/EditHex.cs
+++ b/Windows/EditHex.cs
@@ -47,6 +47,8 @@ namespace NBTExplorer.Windows
private ToolStripStatusLabel _elementLabel;
private ToolStripStatusLabel _spaceLabel;
+ private Dictionary _elemIndex = new Dictionary();
+
public TextView (StatusStrip statusBar, int bytesPerElem)
: base(statusBar, bytesPerElem)
{ }
@@ -62,6 +64,7 @@ namespace NBTExplorer.Windows
ScrollBars = ScrollBars.Vertical,
Size = new Size(500, 263),
TabIndex = 0,
+ MaxLength = 0,
};
_tabPage = new TabPage() {
@@ -75,7 +78,10 @@ namespace NBTExplorer.Windows
_tabPage.Controls.Add(_textBox);
- _textBox.TextChanged += (s, e) => { OnModified(); };
+ _textBox.TextChanged += (s, e) => { OnModified(); RebuildElementIndex(); };
+ _textBox.PreviewKeyDown += (s, e) => { e.IsInputKey = true; };
+ _textBox.KeyUp += (s, e) => { UpdateElementLabel(); };
+ _textBox.MouseClick += (s, e) => { UpdateElementLabel(); };
InitializeStatusBar();
}
@@ -114,6 +120,39 @@ namespace NBTExplorer.Windows
public override void SetRawData (byte[] data)
{
_textBox.Text = HexEditor.RawToText(data, BytesPerElem);
+ RebuildElementIndex();
+ }
+
+ private void RebuildElementIndex ()
+ {
+ _elemIndex.Clear();
+
+ int element = 0;
+ String text = _textBox.Text;
+ bool lcw = true;
+
+ for (int i = 0; i < text.Length; i++) {
+ bool w = IsWhiteSpace(text[i]);
+ if (lcw && !w)
+ _elemIndex[i] = element++;
+ lcw = w;
+ }
+ }
+
+ private bool IsWhiteSpace (char c)
+ {
+ return c == ' ' || c == '\n' || c == '\r' || c == '\t';
+ }
+
+ private void UpdateElementLabel ()
+ {
+ int index = _textBox.SelectionStart;
+ int element = 0;
+
+ while (index >= 0 && !_elemIndex.TryGetValue(index, out element))
+ index--;
+
+ _elementLabel.Text = "Element " + element;
}
}
@@ -254,7 +293,6 @@ namespace NBTExplorer.Windows
private int _bytesPerElem;
private byte[] _data;
private bool _modified;
- //DynamicByteProvider _byteProvider;
private Dictionary _views = new Dictionary();
@@ -262,44 +300,44 @@ namespace NBTExplorer.Windows
{
InitializeComponent();
- TextView textView = new TextView(statusStrip1, bytesPerElem);
+ EditView textView = new TextView(statusStrip1, bytesPerElem);
textView.Initialize();
+ textView.SetRawData(data);
+ textView.Modified += (s, e) => { _modified = true; };
+
_views.Add(textView.TabPage, textView);
viewTabs.TabPages.Add(textView.TabPage);
+ EditView hexView = null;
+
if (!IsMono()) {
- HexView hexView = new HexView(statusStrip1, bytesPerElem);
+ hexView = new HexView(statusStrip1, bytesPerElem);
hexView.Initialize();
+ hexView.SetRawData(data);
+ hexView.Modified += (s, e) => { _modified = true; };
+
_views.Add(hexView.TabPage, hexView);
viewTabs.TabPages.Add(hexView.TabPage);
}
+ if (bytesPerElem > 1 || IsMono()) {
+ textView.Activate();
+ viewTabs.SelectedTab = textView.TabPage;
+ }
+ else {
+ hexView.Activate();
+ viewTabs.SelectedTab = hexView.TabPage;
+ }
+
viewTabs.Deselected += (o, e) => { _previousPage = e.TabPage; };
viewTabs.Selecting += HandleTabChanged;
- //textBox1.TextChanged += (o, e) => { _modified = true; };
this.Text = "Editing: " + tagName;
_bytesPerElem = bytesPerElem;
- //_curPositionLabel.Text = "0x0000";
- //_curElementLabel.Text = "Element 0";
_data = new byte[data.Length];
Array.Copy(data, _data, data.Length);
-
- //_byteProvider = new DynamicByteProvider(_data);
- //_byteProvider.Changed += (o, e) => { _modified = true; };
-
- //hexBox1.ByteProvider = _byteProvider;
-
- //hexBox1.HorizontalByteCountChanged += HexBox_HorizontalByteCountChanged;
- //hexBox1.CurrentLineChanged += HexBox_CurrentLineChanged;
- //hexBox1.CurrentPositionInLineChanged += HexBox_CurrentPositionInLineChanged;
- //hexBox1.InsertActiveChanged += HexBox_InsertActiveChanged;
-
- //hexBox1.ReadOnly = false;
-
- //textBox1.Text = RawToText(data);
}
private bool IsMono ()
@@ -332,64 +370,8 @@ namespace NBTExplorer.Windows
newView.SetRawData(data);
newView.Activate();
-
- /*if (e.TabPage == textView) {
- if (_previousPage == textView)
- return;
-
- byte[] data = DataFromHexBox();
- textBox1.Text = RawToText(data);
-
- _insertStateLabel.Text = "Insert";
- }
- else if (e.TabPage == hexView) {
- if (_previousPage == hexView)
- return;
-
- byte[] data = TextToRaw(textBox1.Text);
- _byteProvider = new DynamicByteProvider(data);
- _byteProvider.Changed += (o, e2) => { _modified = true; };
-
- hexBox1.ByteProvider = _byteProvider;
-
- if (hexBox1.InsertActive)
- _insertStateLabel.Text = "Insert";
- else
- _insertStateLabel.Text = "Overwrite";
- }*/
}
- /*private void HexBox_HorizontalByteCountChanged (object sender, EventArgs e)
- {
- UpdatePosition();
- }
-
- private void HexBox_CurrentLineChanged (object sender, EventArgs e)
- {
- UpdatePosition();
- }
-
- private void HexBox_CurrentPositionInLineChanged (object sender, EventArgs e)
- {
- UpdatePosition();
- }
-
- private void HexBox_InsertActiveChanged (object sender, EventArgs e)
- {
- if (hexBox1.InsertActive)
- _insertStateLabel.Text = "Insert";
- else
- _insertStateLabel.Text = "Overwrite";
- }
-
- private void UpdatePosition ()
- {
- long pos = (hexBox1.CurrentLine - 1) * hexBox1.HorizontalByteCount + hexBox1.CurrentPositionInLine - 1;
-
- _curPositionLabel.Text = "0x" + pos.ToString("X4");
- _curElementLabel.Text = "Element " + pos / _bytesPerElem;
- }*/
-
private void Apply ()
{
EditView view = _views[viewTabs.SelectedTab];
@@ -399,37 +381,6 @@ namespace NBTExplorer.Windows
Close();
}
- /*private void ApplyHex ()
- {
- if (_data.Length != _byteProvider.Length)
- _data = new byte[_byteProvider.Length];
-
- for (int i = 0; i < _data.Length; i++) {
- _data[i] = _byteProvider.Bytes[i];
- }
-
- DialogResult = DialogResult.OK;
- Close();
- }
-
- private void ApplyText ()
- {
- _data = TextToRaw(textBox1.Text);
-
- DialogResult = DialogResult.OK;
- Close();
- }*/
-
- /*private byte[] DataFromHexBox ()
- {
- byte[] data = new byte[_byteProvider.Length];
- for (int i = 0; i < data.Length; i++) {
- data[i] = _byteProvider.Bytes[i];
- }
-
- return data;
- }*/
-
private String RawToText (byte[] data)
{
return RawToText(data, _bytesPerElem);
@@ -446,11 +397,6 @@ namespace NBTExplorer.Windows
}
}
- //private String RawToText (byte[] data, int elementsPerLine)
- //{
- // return RawToText(data, _bytesPerElem, elementsPerLine);
- //}
-
private static String RawToText (byte[] data, int bytesPerElem, int elementsPerLine)
{
StringBuilder builder = new StringBuilder();
@@ -542,10 +488,9 @@ namespace NBTExplorer.Windows
_data = new byte[fstr.Length];
fstr.Read(_data, 0, (int)fstr.Length);
- _byteProvider = new DynamicByteProvider(_data);
- _byteProvider.Changed += (o, e) => { _modified = true; };
+ EditView view = _views[viewTabs.SelectedTab];
+ view.SetRawData(_data);
- hexBox1.ByteProvider = _byteProvider;
_modified = true;
}
}
@@ -564,10 +509,9 @@ namespace NBTExplorer.Windows
string text = System.Text.Encoding.UTF8.GetString(raw, 0, raw.Length);
_data = TextToRaw(text);
- _byteProvider = new DynamicByteProvider(_data);
- _byteProvider.Changed += (o, e) => { _modified = true; };
+ EditView view = _views[viewTabs.SelectedTab];
+ view.SetRawData(_data);
- hexBox1.ByteProvider = _byteProvider;
_modified = true;
}
}
@@ -580,7 +524,9 @@ namespace NBTExplorer.Windows
{
try {
using (FileStream fstr = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.None)) {
- byte[] data = _byteProvider.Bytes.ToArray();
+ EditView view = _views[viewTabs.SelectedTab];
+ byte[] data = view.GetRawData();
+
fstr.Write(data, 0, data.Length);
}
}
@@ -593,7 +539,9 @@ namespace NBTExplorer.Windows
{
try {
using (FileStream fstr = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.None)) {
- string text = RawToText(_byteProvider.Bytes.ToArray());
+ EditView view = _views[viewTabs.SelectedTab];
+ string text = RawToText(view.GetRawData());
+
byte[] data = System.Text.Encoding.UTF8.GetBytes(text);
fstr.Write(data, 0, data.Length);
}
diff --git a/Windows/FindReplace.Designer.cs b/Windows/FindReplace.Designer.cs
index 3557096..54000a6 100644
--- a/Windows/FindReplace.Designer.cs
+++ b/Windows/FindReplace.Designer.cs
@@ -631,4 +631,4 @@
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ToolStrip _explorerStrip;
}
-}
\ No newline at end of file
+}
diff --git a/Windows/FindReplace.resx b/Windows/FindReplace.resx
index deae6d5..6c284b5 100644
--- a/Windows/FindReplace.resx
+++ b/Windows/FindReplace.resx
@@ -745,4 +745,4 @@
345, 17
-
\ No newline at end of file
+
diff --git a/Windows/MainForm.cs b/Windows/MainForm.cs
index 8969055..d1eb4d8 100644
--- a/Windows/MainForm.cs
+++ b/Windows/MainForm.cs
@@ -348,6 +348,8 @@ namespace NBTExplorer.Windows
if (_searchForm.ShowDialog(this) == DialogResult.Cancel) {
worker.Cancel();
_searchState = null;
+
+ UpdateUI();
}
t.Join();
@@ -375,6 +377,9 @@ namespace NBTExplorer.Windows
_searchForm = null;
}
+ _searchState = null;
+ UpdateUI();
+
MessageBox.Show("End of results");
}