diff --git a/NBTExplorer/Interop.cs b/NBTExplorer/Interop.cs index 2be1bdd..9f0d08f 100644 --- a/NBTExplorer/Interop.cs +++ b/NBTExplorer/Interop.cs @@ -56,9 +56,5 @@ namespace NBTExplorer [DllImport("user32.dll")] public static extern IntPtr SendMessage (IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); - - - - } } diff --git a/NBTExplorer/Properties/AssemblyInfo.cs b/NBTExplorer/Properties/AssemblyInfo.cs index ec1408e..07f2afb 100644 --- a/NBTExplorer/Properties/AssemblyInfo.cs +++ b/NBTExplorer/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.7.0.0")] -[assembly: AssemblyFileVersion("2.7.0.0")] +[assembly: AssemblyVersion("2.7.1.0")] +[assembly: AssemblyFileVersion("2.7.1.0")] diff --git a/NBTExplorer/SearchWorker.cs b/NBTExplorer/SearchWorker.cs index 3e325e5..645fea5 100644 --- a/NBTExplorer/SearchWorker.cs +++ b/NBTExplorer/SearchWorker.cs @@ -1,7 +1,6 @@ -using System; -using System.Collections.Generic; -using NBTExplorer.Model; +using System.Collections.Generic; using System.Diagnostics; +using NBTExplorer.Model; namespace NBTExplorer { diff --git a/NBTExplorer/Windows/SearchStateWin.cs b/NBTExplorer/Windows/SearchStateWin.cs index 02dbd12..65fe339 100644 --- a/NBTExplorer/Windows/SearchStateWin.cs +++ b/NBTExplorer/Windows/SearchStateWin.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using System.Text; -using NBTExplorer.Model; using System.Windows.Forms; +using NBTExplorer.Model; namespace NBTExplorer.Windows { diff --git a/NBTModel/CompoundTagContainer.cs b/NBTModel/Data/CompoundTagContainer.cs similarity index 100% rename from NBTModel/CompoundTagContainer.cs rename to NBTModel/Data/CompoundTagContainer.cs diff --git a/NBTModel/CubicRegionFile.cs b/NBTModel/Data/CubicRegionFile.cs similarity index 100% rename from NBTModel/CubicRegionFile.cs rename to NBTModel/Data/CubicRegionFile.cs diff --git a/NBTModel/DataNodeCollection.cs b/NBTModel/Data/DataNodeCollection.cs similarity index 100% rename from NBTModel/DataNodeCollection.cs rename to NBTModel/Data/DataNodeCollection.cs diff --git a/NBTModel/FileTypeRegistry.cs b/NBTModel/Data/FileTypeRegistry.cs similarity index 100% rename from NBTModel/FileTypeRegistry.cs rename to NBTModel/Data/FileTypeRegistry.cs diff --git a/NBTModel/ListTagContainer.cs b/NBTModel/Data/ListTagContainer.cs similarity index 100% rename from NBTModel/ListTagContainer.cs rename to NBTModel/Data/ListTagContainer.cs diff --git a/NBTModel/CubicRegionDataNode.cs b/NBTModel/Data/Nodes/CubicRegionDataNode.cs similarity index 100% rename from NBTModel/CubicRegionDataNode.cs rename to NBTModel/Data/Nodes/CubicRegionDataNode.cs diff --git a/NBTModel/DataNode.cs b/NBTModel/Data/Nodes/DataNode.cs similarity index 98% rename from NBTModel/DataNode.cs rename to NBTModel/Data/Nodes/DataNode.cs index e0d377b..0d244f4 100644 --- a/NBTModel/DataNode.cs +++ b/NBTModel/Data/Nodes/DataNode.cs @@ -65,6 +65,11 @@ namespace NBTExplorer.Model internal set { _parent = value; } } + public DataNode Root + { + get { return (_parent == null) ? this : _parent.Root; } + } + public DataNodeCollection Nodes { get { return _children; } diff --git a/NBTModel/DirectoryDataNode.cs b/NBTModel/Data/Nodes/DirectoryDataNode.cs similarity index 100% rename from NBTModel/DirectoryDataNode.cs rename to NBTModel/Data/Nodes/DirectoryDataNode.cs diff --git a/NBTModel/NbtFileDataNode.cs b/NBTModel/Data/Nodes/NbtFileDataNode.cs similarity index 100% rename from NBTModel/NbtFileDataNode.cs rename to NBTModel/Data/Nodes/NbtFileDataNode.cs diff --git a/NBTModel/NodeCapabilities.cs b/NBTModel/Data/Nodes/NodeCapabilities.cs similarity index 100% rename from NBTModel/NodeCapabilities.cs rename to NBTModel/Data/Nodes/NodeCapabilities.cs diff --git a/NBTModel/RegionChunkDataNode.cs b/NBTModel/Data/Nodes/RegionChunkDataNode.cs similarity index 100% rename from NBTModel/RegionChunkDataNode.cs rename to NBTModel/Data/Nodes/RegionChunkDataNode.cs diff --git a/NBTModel/RegionFileDataNode.cs b/NBTModel/Data/Nodes/RegionFileDataNode.cs similarity index 100% rename from NBTModel/RegionFileDataNode.cs rename to NBTModel/Data/Nodes/RegionFileDataNode.cs diff --git a/NBTModel/TagByteArrayDataNode.cs b/NBTModel/Data/Nodes/TagByteArrayDataNode.cs similarity index 100% rename from NBTModel/TagByteArrayDataNode.cs rename to NBTModel/Data/Nodes/TagByteArrayDataNode.cs diff --git a/NBTModel/TagByteDataNode.cs b/NBTModel/Data/Nodes/TagByteDataNode.cs similarity index 100% rename from NBTModel/TagByteDataNode.cs rename to NBTModel/Data/Nodes/TagByteDataNode.cs diff --git a/NBTModel/TagCompoundDataNode.cs b/NBTModel/Data/Nodes/TagCompoundDataNode.cs similarity index 100% rename from NBTModel/TagCompoundDataNode.cs rename to NBTModel/Data/Nodes/TagCompoundDataNode.cs diff --git a/NBTModel/TagDataNode.cs b/NBTModel/Data/Nodes/TagDataNode.cs similarity index 100% rename from NBTModel/TagDataNode.cs rename to NBTModel/Data/Nodes/TagDataNode.cs diff --git a/NBTModel/TagDoubleDataNode.cs b/NBTModel/Data/Nodes/TagDoubleDataNode.cs similarity index 100% rename from NBTModel/TagDoubleDataNode.cs rename to NBTModel/Data/Nodes/TagDoubleDataNode.cs diff --git a/NBTModel/TagFloatDataNode.cs b/NBTModel/Data/Nodes/TagFloatDataNode.cs similarity index 100% rename from NBTModel/TagFloatDataNode.cs rename to NBTModel/Data/Nodes/TagFloatDataNode.cs diff --git a/NBTModel/TagIntArrayDataNode.cs b/NBTModel/Data/Nodes/TagIntArrayDataNode.cs similarity index 100% rename from NBTModel/TagIntArrayDataNode.cs rename to NBTModel/Data/Nodes/TagIntArrayDataNode.cs diff --git a/NBTModel/TagIntDataNode.cs b/NBTModel/Data/Nodes/TagIntDataNode.cs similarity index 100% rename from NBTModel/TagIntDataNode.cs rename to NBTModel/Data/Nodes/TagIntDataNode.cs diff --git a/NBTModel/TagListDataNode.cs b/NBTModel/Data/Nodes/TagListDataNode.cs similarity index 100% rename from NBTModel/TagListDataNode.cs rename to NBTModel/Data/Nodes/TagListDataNode.cs diff --git a/NBTModel/TagLongDataNode.cs b/NBTModel/Data/Nodes/TagLongDataNode.cs similarity index 100% rename from NBTModel/TagLongDataNode.cs rename to NBTModel/Data/Nodes/TagLongDataNode.cs diff --git a/NBTModel/TagShortDataNode.cs b/NBTModel/Data/Nodes/TagShortDataNode.cs similarity index 100% rename from NBTModel/TagShortDataNode.cs rename to NBTModel/Data/Nodes/TagShortDataNode.cs diff --git a/NBTModel/TagStringDataNode.cs b/NBTModel/Data/Nodes/TagStringDataNode.cs similarity index 100% rename from NBTModel/TagStringDataNode.cs rename to NBTModel/Data/Nodes/TagStringDataNode.cs diff --git a/NBTModel/TagContainerInterface.cs b/NBTModel/Data/TagContainerInterface.cs similarity index 100% rename from NBTModel/TagContainerInterface.cs rename to NBTModel/Data/TagContainerInterface.cs diff --git a/NBTModel/TagKey.cs b/NBTModel/Data/TagKey.cs similarity index 100% rename from NBTModel/TagKey.cs rename to NBTModel/Data/TagKey.cs diff --git a/NBTModel/NBTModel.csproj b/NBTModel/NBTModel.csproj index f55d59c..6901e4d 100644 --- a/NBTModel/NBTModel.csproj +++ b/NBTModel/NBTModel.csproj @@ -39,37 +39,38 @@ - - - - - - - + + + + + + + - - - + + + + - - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/NBTModel/NbtPath.cs b/NBTModel/NbtPath.cs new file mode 100644 index 0000000..2af4da6 --- /dev/null +++ b/NBTModel/NbtPath.cs @@ -0,0 +1,147 @@ +using System.Collections; +using System.Collections.Generic; +using System.IO; + +namespace NBTExplorer.Model +{ + public class NbtPathEnumerator : IEnumerable + { + private class PathPartDesc + { + public string Name; + public DataNode Node; + } + + private string _pathRoot; + private List _pathParts = new List(); + + public NbtPathEnumerator (string path) + { + _pathRoot = Path.GetPathRoot(path); + _pathParts = new List(path.Substring(_pathRoot.Length).Split('/', '\\')); + + if (string.IsNullOrEmpty(_pathRoot)) + _pathRoot = Directory.GetCurrentDirectory(); + } + + public IEnumerator GetEnumerator () + { + DataNode dataNode = new DirectoryDataNode(_pathRoot); + dataNode.Expand(); + + foreach (DataNode childNode in EnumerateNodes(dataNode, _pathParts)) + yield return childNode; + } + + IEnumerator IEnumerable.GetEnumerator () + { + return GetEnumerator(); + } + + private IEnumerable EnumerateNodes (DataNode containerNode, List nextLevels) + { + containerNode.Expand(); + if (nextLevels.Count == 0) { + yield return containerNode; + yield break; + } + + if (containerNode.Nodes.Count == 0) + yield break; + + string part = nextLevels[0]; + List remainingLevels = nextLevels.GetRange(1, nextLevels.Count - 1); + + if (part == "*") { + foreach (DataNode childNode in containerNode.Nodes) { + foreach (DataNode grandChildNode in EnumerateNodes(childNode, remainingLevels)) + yield return grandChildNode; + } + } + else if (part == "**") { + foreach (DataNode childNode in containerNode.Nodes) { + foreach (DataNode grandChildNode in EnumerateNodes(childNode, remainingLevels)) + yield return grandChildNode; + + foreach (DataNode grandChildNode in EnumerateNodes(childNode, nextLevels)) + yield return grandChildNode; + } + } + else { + foreach (var childNode in containerNode.Nodes) { + if (childNode.NodePathName == part) { + foreach (DataNode grandChildNode in EnumerateNodes(childNode, remainingLevels)) + yield return grandChildNode; + } + } + } + } + } + + public class NbtPath + { + private class PathPart + { + public string Name; + public DataNode Node; + } + + + //private List _pathParts = new List(); + + private List _nodes; + + internal NbtPath (List nodes) + { + _nodes = nodes; + } + + /*public NbtPath (string path) + { + Path = path; + + string[] parts = path.Split('/', '\\'); + foreach (var p in parts) { + _pathParts.Add(new PathPart() { + Name = p, + }); + } + } + + public string Path { get; private set; } + + public DataNode RootNode + { + get { return (_pathParts.Count == 0) ? null : _pathParts[0].Node; } + } + + public DataNode TargetNode + { + get { return (_pathParts.Count == 0) ? null : _pathParts[_pathParts.Count - 1].Node; } + } + + public DataNode Open () + { + DataNode dataNode = new DirectoryDataNode(Directory.GetCurrentDirectory()); + dataNode.Expand(); + + foreach (var part in _pathParts) { + DataNode match = null; + foreach (var child in dataNode.Nodes) { + if (child.NodePathName == part.Name) + match = child; + } + + if (match == null) + return null; + + part.Node = match; + + dataNode = match; + dataNode.Expand(); + } + + return dataNode; + }*/ + } +} diff --git a/NBTUtil/ConsoleRunner.cs b/NBTUtil/ConsoleRunner.cs index 183881a..eb89318 100644 --- a/NBTUtil/ConsoleRunner.cs +++ b/NBTUtil/ConsoleRunner.cs @@ -37,23 +37,30 @@ namespace NBTUtil if (!_commandTable.ContainsKey(_options.Command)) return PrintUsage("Error: No command specified"); - NbtPath path = new NbtPath(_options.Path); - DataNode targetNode = path.Open(); - - if (targetNode == null) - return PrintError("Error: Invalid path"); - ConsoleOperation op = _commandTable[_options.Command]; if (!op.OptionsValid(_options)) return PrintError("Error: Invalid options specified for the given command"); - if (!op.CanProcess(targetNode)) - return PrintError("Error: The given command can't be applied to the given tag"); - if (!op.Process(targetNode, _options)) - return PrintError("Error: Problem encountered applying the given command"); - path.RootNode.Save(); + int successCount = 0; + int failCount = 0; - Console.WriteLine("The operation completed successfully"); + foreach (var targetNode in new NbtPathEnumerator(_options.Path)) { + if (!op.CanProcess(targetNode)) { + Console.WriteLine(targetNode.NodePath + ": ERROR (invalid command)"); + failCount++; + } + if (!op.Process(targetNode, _options)) { + Console.WriteLine(targetNode.NodePath + ": ERROR (apply)"); + failCount++; + } + + targetNode.Root.Save(); + + Console.WriteLine(targetNode.NodePath + ": OK"); + successCount++; + } + + Console.WriteLine("Operation complete. Nodes succeeded: {0} Nodes failed: {1}", successCount, failCount); return true; } @@ -119,63 +126,4 @@ namespace NBTUtil return false; } } - - class NbtPath - { - private class PathPart - { - public string Name; - public DataNode Node; - } - - private List _pathParts = new List(); - - public NbtPath (string path) - { - Path = path; - - string[] parts = path.Split('/', '\\'); - foreach (var p in parts) { - _pathParts.Add(new PathPart() { - Name = p, - }); - } - } - - public string Path { get; private set; } - - public DataNode RootNode - { - get { return (_pathParts.Count == 0) ? null : _pathParts[0].Node; } - } - - public DataNode TargetNode - { - get { return (_pathParts.Count == 0) ? null : _pathParts[_pathParts.Count - 1].Node; } - } - - public DataNode Open () - { - DataNode dataNode = new DirectoryDataNode(Directory.GetCurrentDirectory()); - dataNode.Expand(); - - foreach (var part in _pathParts) { - DataNode match = null; - foreach (var child in dataNode.Nodes) { - if (child.NodePathName == part.Name) - match = child; - } - - if (match == null) - return null; - - part.Node = match; - - dataNode = match; - dataNode.Expand(); - } - - return dataNode; - } - } }