Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions NBTModel/Data/Nodes/AbstractFileDataNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.IO;

namespace NBTExplorer.Model
{
/// <summary>
/// Common functionality for a few nodes that represent files.
/// </summary>
public class AbstractFileDataNode : DataNode
{
protected string _path;

protected AbstractFileDataNode(string path)
{
_path = path;
}

/// <summary>
/// Not only the name of the node but also (in some cases, but not all) the value (or part of the value) that is displayed to the user.
/// Return the full path if this node is the root, otherwise return only the file/folder name
/// </summary>
public override string NodeName
{
get => Parent == null ? _path : Path.GetFileName(_path);
}

/// <summary>
/// Just return NodeName, since that is where the display name is build.
/// Side note: I believe NodeName and NodeDisplay should be separated, this would then allow to replace NodePathName with NodeName, but that
/// would require changing a lot of unfamiliar (to me) code.
/// </summary>
public override string NodeDisplay
{
get => NodeName;
}

/// <summary>
/// The actual name of the node in a path. Return only the name of the file or folder, not the whole path.
/// </summary>
public override string NodePathName
{
get => Path.GetFileName(_path);
}
}
}
21 changes: 4 additions & 17 deletions NBTModel/Data/Nodes/CubicRegionDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@

namespace NBTExplorer.Model
{
public class CubicRegionDataNode : DataNode
{
private string _path;
public class CubicRegionDataNode : AbstractFileDataNode
{
private CubicRegionFile _region;

private static Regex _namePattern = new Regex(@"^r2(\.-?\d+){3}\.(mcr|mca)$");

private CubicRegionDataNode (string path)
{
_path = path;
}
private CubicRegionDataNode (string path) : base(path)
{}

public static CubicRegionDataNode TryCreateFrom (string path)
{
Expand Down Expand Up @@ -47,16 +44,6 @@ public override bool IsContainerType
get { return true; }
}

public override string NodePathName
{
get { return Path.GetFileName(_path); }
}

public override string NodeDisplay
{
get { return Path.GetFileName(_path); }
}

protected override void ExpandCore ()
{
try {
Expand Down
15 changes: 3 additions & 12 deletions NBTModel/Data/Nodes/DirectoryDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

namespace NBTExplorer.Model
{
public class DirectoryDataNode : DataNode
public class DirectoryDataNode : AbstractFileDataNode
{
private string _path;

public DirectoryDataNode (string path)
{
_path = path;
}
public DirectoryDataNode (string path) : base(path)
{}

protected override NodeCapabilities Capabilities
{
Expand Down Expand Up @@ -40,11 +36,6 @@ public override string NodePathName
}
}

public override string NodeDisplay
{
get { return Path.GetFileName(_path); }
}

public override bool HasUnexpandedChildren
{
get { return !IsExpanded; }
Expand Down
16 changes: 2 additions & 14 deletions NBTModel/Data/Nodes/NbtFileDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@

namespace NBTExplorer.Model
{
public class NbtFileDataNode : DataNode, IMetaTagContainer
public class NbtFileDataNode : AbstractFileDataNode, IMetaTagContainer
{
private NbtTree _tree;
private string _path;
private CompressionType _compressionType;

private CompoundTagContainer _container;

private static Regex _namePattern = new Regex(@"\.(dat|nbt|schematic|dat_mcr|dat_old|bpt|rc)$");

private NbtFileDataNode (string path, CompressionType compressionType)
private NbtFileDataNode (string path, CompressionType compressionType) : base(path)
{
_path = path;
_compressionType = compressionType;
_container = new CompoundTagContainer(new TagNodeCompound());
}
Expand Down Expand Up @@ -66,16 +64,6 @@ protected override NodeCapabilities Capabilities
}
}

public override string NodeName
{
get { return Path.GetFileName(_path); }
}

public override string NodePathName
{
get { return Path.GetFileName(_path); }
}

public override string NodeDisplay
{
get
Expand Down
19 changes: 3 additions & 16 deletions NBTModel/Data/Nodes/RegionFileDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@

namespace NBTExplorer.Model
{
public class RegionFileDataNode : DataNode
public class RegionFileDataNode : AbstractFileDataNode
{
private string _path;
private RegionFile _region;
private List<RegionKey> _deleteQueue = new List<RegionKey>();

private static Regex _namePattern = new Regex(@"^r\.(-?\d+)\.(-?\d+)\.(mcr|mca)$");

private RegionFileDataNode (string path)
{
_path = path;
}
private RegionFileDataNode (string path) : base(path)
{}

public static RegionFileDataNode TryCreateFrom (string path)
{
Expand Down Expand Up @@ -64,16 +61,6 @@ public override bool IsContainerType
get { return true; }
}

public override string NodePathName
{
get { return Path.GetFileName(_path); }
}

public override string NodeDisplay
{
get { return Path.GetFileName(_path); }
}

protected override void ExpandCore ()
{
try {
Expand Down
1 change: 1 addition & 0 deletions NBTModel/NBTModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Data\CompoundTagContainer.cs" />
<Compile Include="Data\Nodes\AbstractFileDataNode.cs" />
<Compile Include="Data\Nodes\CubicRegionDataNode.cs" />
<Compile Include="Data\CubicRegionFile.cs" />
<Compile Include="Data\Nodes\DataNode.cs" />
Expand Down