From 92ce098218fb122af6dd38e0551a42b916550055 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Fri, 13 Jan 2012 01:20:49 -0500 Subject: [PATCH] Convenience improvements --- About.cs | 1 - EditValue.cs | 3 +- Find.cs | 1 - Form1.Designer.cs | 31 +++++++++++- Form1.cs | 118 +++++++++++++++++++++++++++++++++++++-------- Form1.resx | 6 +-- NBTExplorer.csproj | 10 +--- Program.cs | 1 - 8 files changed, 134 insertions(+), 37 deletions(-) diff --git a/About.cs b/About.cs index cdd45f1..279e5cf 100644 --- a/About.cs +++ b/About.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; -using System.Linq; using System.Text; using System.Windows.Forms; diff --git a/EditValue.cs b/EditValue.cs index fc8fc6c..29fead5 100644 --- a/EditValue.cs +++ b/EditValue.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; -using System.Linq; using System.Text; using System.Windows.Forms; using Substrate.Nbt; @@ -97,7 +96,7 @@ namespace NBTExplorer private bool ValidateNameInput () { string text = textBox1.Text.Trim(); - if (String.IsNullOrWhiteSpace(text)) { + if (String.IsNullOrEmpty(text)) { MessageBox.Show("You must provide a nonempty name."); return false; } diff --git a/Find.cs b/Find.cs index 6420758..0f45d2a 100644 --- a/Find.cs +++ b/Find.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; -using System.Linq; using System.Text; using System.Windows.Forms; diff --git a/Form1.Designer.cs b/Form1.Designer.cs index f647e17..fe0c6ef 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -49,6 +49,7 @@ this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this._buttonOpen = new System.Windows.Forms.ToolStripButton(); + this._buttonOpenFolder = new System.Windows.Forms.ToolStripButton(); this._buttonSave = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this._buttonRename = new System.Windows.Forms.ToolStripButton(); @@ -70,6 +71,7 @@ this._nodeContainerContext = new System.Windows.Forms.ContextMenuStrip(this.components); this.openSubTreeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.openMinecraftSaveFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.toolStripContainer1.ContentPanel.SuspendLayout(); this.toolStripContainer1.TopToolStripPanel.SuspendLayout(); @@ -96,6 +98,7 @@ this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.openToolStripMenuItem, this.openFolderToolStripMenuItem, + this.openMinecraftSaveFolderToolStripMenuItem, this.toolStripSeparator3, this.saveToolStripMenuItem, this.toolStripSeparator4, @@ -165,7 +168,7 @@ this.findToolStripMenuItem.Image = global::NBTExplorer.Properties.Resources.binocular; this.findToolStripMenuItem.Name = "findToolStripMenuItem"; this.findToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F))); - this.findToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.findToolStripMenuItem.Size = new System.Drawing.Size(146, 22); this.findToolStripMenuItem.Text = "Find..."; this.findToolStripMenuItem.Click += new System.EventHandler(this.findToolStripMenuItem_Click); // @@ -174,7 +177,7 @@ this.findNextToolStripMenuItem.Image = global::NBTExplorer.Properties.Resources.binocular__arrow; this.findNextToolStripMenuItem.Name = "findNextToolStripMenuItem"; this.findNextToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F3; - this.findNextToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.findNextToolStripMenuItem.Size = new System.Drawing.Size(146, 22); this.findNextToolStripMenuItem.Text = "Find Next"; this.findNextToolStripMenuItem.Click += new System.EventHandler(this.findNextToolStripMenuItem_Click); // @@ -235,6 +238,7 @@ // // _nodeTree // + this._nodeTree.AllowDrop = true; this._nodeTree.Dock = System.Windows.Forms.DockStyle.Fill; this._nodeTree.ImageIndex = 0; this._nodeTree.ImageList = this.imageList1; @@ -243,6 +247,8 @@ this._nodeTree.SelectedImageIndex = 0; this._nodeTree.Size = new System.Drawing.Size(562, 351); this._nodeTree.TabIndex = 0; + this._nodeTree.DragDrop += new System.Windows.Forms.DragEventHandler(this._nodeTree_DragDrop); + this._nodeTree.DragEnter += new System.Windows.Forms.DragEventHandler(this._nodeTree_DragEnter); // // imageList1 // @@ -268,6 +274,7 @@ this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None; this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this._buttonOpen, + this._buttonOpenFolder, this._buttonSave, this.toolStripSeparator1, this._buttonRename, @@ -302,6 +309,16 @@ this._buttonOpen.Text = "Open NBT Data Source"; this._buttonOpen.Click += new System.EventHandler(this.toolStripButton1_Click); // + // _buttonOpenFolder + // + this._buttonOpenFolder.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this._buttonOpenFolder.Image = global::NBTExplorer.Properties.Resources.folder_open; + this._buttonOpenFolder.ImageTransparentColor = System.Drawing.Color.Magenta; + this._buttonOpenFolder.Name = "_buttonOpenFolder"; + this._buttonOpenFolder.Size = new System.Drawing.Size(23, 22); + this._buttonOpenFolder.Text = "Open Folder"; + this._buttonOpenFolder.Click += new System.EventHandler(this._buttonOpenFolder_Click); + // // _buttonSave // this._buttonSave.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; @@ -489,8 +506,16 @@ this.saveItemToolStripMenuItem.Size = new System.Drawing.Size(179, 22); this.saveItemToolStripMenuItem.Text = "Save Node"; // + // openMinecraftSaveFolderToolStripMenuItem + // + this.openMinecraftSaveFolderToolStripMenuItem.Name = "openMinecraftSaveFolderToolStripMenuItem"; + this.openMinecraftSaveFolderToolStripMenuItem.Size = new System.Drawing.Size(223, 22); + this.openMinecraftSaveFolderToolStripMenuItem.Text = "Open &Minecraft Save Folder"; + this.openMinecraftSaveFolderToolStripMenuItem.Click += new System.EventHandler(this.openMinecraftSaveFolderToolStripMenuItem_Click); + // // Form1 // + this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(562, 400); @@ -561,6 +586,8 @@ private System.Windows.Forms.ToolStripButton _buttonFindNext; private System.Windows.Forms.StatusStrip statusStrip1; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; + private System.Windows.Forms.ToolStripButton _buttonOpenFolder; + private System.Windows.Forms.ToolStripMenuItem openMinecraftSaveFolderToolStripMenuItem; } } diff --git a/Form1.cs b/Form1.cs index e81d31c..aee1cdb 100644 --- a/Form1.cs +++ b/Form1.cs @@ -26,16 +26,13 @@ namespace NBTExplorer _nodeTree.NodeMouseClick += NodeClicked; _nodeTree.NodeMouseDoubleClick += NodeDoubleClicked; - string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - path = Path.Combine(path, ".minecraft"); - path = Path.Combine(path, "saves"); - - if (!Directory.Exists(path)) { - path = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); + string[] args = Environment.GetCommandLineArgs(); + if (args.Length > 1) { + OpenFile(args[1]); + } + else { + OpenMinecraftDir(); } - - LoadDirectory(path); - _nodeTree.Nodes[0].Expand(); } public void LoadNbtStream (TreeNodeCollection parent, Stream stream) @@ -481,6 +478,48 @@ namespace NBTExplorer _buttonAddTagCompound.Enabled = state; } + public void OpenDirectory (string path) + { + _nodeTree.Nodes.Clear(); + + LoadDirectory(path); + + if (_nodeTree.Nodes.Count > 0) { + _nodeTree.Nodes[0].Expand(); + } + } + + public void OpenPaths (string[] paths) + { + _nodeTree.Nodes.Clear(); + + foreach (string path in paths) { + if (Directory.Exists(path)) { + LoadDirectory(path); + } + else if (File.Exists(path)) { + TryLoadFile(_nodeTree.Nodes, path); + } + } + + if (_nodeTree.Nodes.Count > 0) { + _nodeTree.Nodes[0].Expand(); + } + } + + public void OpenMinecraftDir () + { + string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + path = Path.Combine(path, ".minecraft"); + path = Path.Combine(path, "saves"); + + if (!Directory.Exists(path)) { + path = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); + } + + OpenDirectory(path); + } + public void LoadDirectory (string path) { LoadDirectory(path, _nodeTree.Nodes); @@ -559,18 +598,36 @@ namespace NBTExplorer { OpenFileDialog ofd = new OpenFileDialog(); ofd.RestoreDirectory = true; - ofd.Multiselect = false; + ofd.Multiselect = true; if (ofd.ShowDialog() == DialogResult.OK) { - _nodeTree.Nodes.Clear(); - TryLoadFile(_nodeTree.Nodes, ofd.FileName); + OpenPaths(ofd.FileNames); + } + } + + private void OpenFile (string file) + { + _nodeTree.Nodes.Clear(); + TryLoadFile(_nodeTree.Nodes, file); + } + + private string _openFolderPath = null; + private void OpenFolder () + { + FolderBrowserDialog ofd = new FolderBrowserDialog(); + if (_openFolderPath != null) + ofd.SelectedPath = _openFolderPath; + + if (ofd.ShowDialog() == DialogResult.OK) { + _openFolderPath = ofd.SelectedPath; + OpenDirectory(ofd.SelectedPath); } } private void SaveAll () { - if (_nodeTree.Nodes.Count > 0) { - SaveNode(_nodeTree.Nodes[0]); + foreach (TreeNode node in _nodeTree.Nodes) { + SaveNode(node); } } @@ -627,11 +684,7 @@ namespace NBTExplorer private void openFolderToolStripMenuItem_Click (object sender, EventArgs e) { - FolderBrowserDialog ofd = new FolderBrowserDialog(); - if (ofd.ShowDialog() == DialogResult.OK) { - _nodeTree.Nodes.Clear(); - LoadDirectory(ofd.SelectedPath); - } + OpenFolder(); } private void toolStripButton1_Click (object sender, EventArgs e) @@ -1138,6 +1191,33 @@ namespace NBTExplorer else FindNext(); } + + private void _buttonOpenFolder_Click (object sender, EventArgs e) + { + OpenFolder(); + } + + private void DropFile (DragEventArgs e) + { + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + OpenPaths(files); + } + + private void _nodeTree_DragDrop (object sender, DragEventArgs e) + { + DropFile(e); + } + + private void _nodeTree_DragEnter (object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + e.Effect = DragDropEffects.Copy; + } + + private void openMinecraftSaveFolderToolStripMenuItem_Click (object sender, EventArgs e) + { + OpenMinecraftDir(); + } } public class TagKey : IComparable diff --git a/Form1.resx b/Form1.resx index 465e679..80c9a63 100644 --- a/Form1.resx +++ b/Form1.resx @@ -131,7 +131,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADW - LgAAAk1TRnQBSQFMAgEBDgEAAYgBAAGIAQABEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA + LgAAAk1TRnQBSQFMAgEBDgEAAaABAAGgAQABEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA AwABQAMAAQEBAAEYBgABMBIAA/wD+SH4A/kD/AMAA/0D+SH4A/kD/WMAAZYBqQG8AVwBhAGuAVwBhAGu AVwBhAGuAVwBhAGuAVwBhAGuAVwBhAGuAVwBhAGuAVwBhAGuAVwBhAGuAVwBhAGuAVwBhAGuAVwBhAGu AVwBhAGuAZYBqQG8AwACzwHLArkBsAK5AbACuQGwArkBsAK5AbACuQGwArkBsAK5AbACuQGwArkBsAK5 @@ -517,11 +517,11 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAFySURBVDhPY2CgBthfz8CyP4kl40AiczcM19sxnEHGyHIg tSA9cLv3xrErn6rWXPp+T+f/d7s7wHh2hikKhomD1IDUgvTADdiVwOx+c4r3EWQDlpc4/ofhJYV2cINB - akBqQXrgBuyIZ8m9vyz7wbPNDf9heEuj338YXlftARcHyYPUgvTADdgawzz17anlf//fXfUfhu+uKgcy + akBqQXrgBuyIZ8m9vyz7wbPNDf9heEuj338YXlftARcHyYPUgvTADdgawzz11fHlf//fXfUfhu+uKgcy IfjMzDS4OEgepBakB27A5ijmGT8vzf//+cRUON7dEfofhjc3+KLIgdSC9MAN2BDFPPvbudn/PxyZCMcg zavKXcCGLCt2QJEDqQXpgRuwOoJ5/qeT0/6/2d8DxyDNID6MRpYDqQXpgRuwPIx58btD/f9f7monCoPU gvTADVgSwrjsFTDun25tIgqD1IL0wA2YH8C4+smWxv8PN9QShUFqQXrgBkzxZNzxYF31//trq4jCILUg - PTAD5FKNGee1uTAeJQWD9AANkAMZwg/E4kAsRSIG6QHppQwAAARN3Xh69LLBAAAAAElFTkSuQmCC + PTAD5FKNGee1uTAeJQWD9AANkAMZwg/E4kAsRSIG6QHppQwAAOQ03Wz0/VCVAAAAAElFTkSuQmCC diff --git a/NBTExplorer.csproj b/NBTExplorer.csproj index 73a38cc..c1b0390 100644 --- a/NBTExplorer.csproj +++ b/NBTExplorer.csproj @@ -37,17 +37,10 @@ dead_bush.ico - - ..\Substrate\SubstrateCS\bin\Release\Ionic.Zlib.dll - - ..\Substrate\SubstrateCS\bin\Release\Substrate.dll + ..\Substrate\SubstrateCS\bin\Release\NET4\Substrate.dll - - - - @@ -103,6 +96,7 @@ Resources.resx True + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/Program.cs b/Program.cs index 6ffef44..c9908a1 100644 --- a/Program.cs +++ b/Program.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Windows.Forms; namespace NBTExplorer