use of org.pepsoft.worldpainter.mapexplorer.Node in project WorldPainter by Captain-Chaos.
the class MapTreeModel method getPath.
public TreePath getPath(File dir) {
LinkedList<File> components = new LinkedList<>();
while (dir != null) {
components.add(0, dir);
dir = dir.getParentFile();
}
// Components now contains the path's components in the correct order
Object[] path = new Object[components.size() + 1];
path[0] = rootNode;
Node node = rootNode;
int index = 1;
for (File component : components) {
String componentName = FileSystemNode.getName(component);
for (Node childNode : node.getChildren()) {
if (childNode.getName().equals(componentName)) {
path[index++] = childNode;
node = childNode;
break;
}
}
}
return new TreePath(path);
}
use of org.pepsoft.worldpainter.mapexplorer.Node in project WorldPainter by Captain-Chaos.
the class NBTFileNode method loadChildren.
@Override
protected Node[] loadChildren() {
try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
in.mark(2);
Tag tag;
if ((in.read() == 0x1f) && (in.read() == 0x8b)) {
// Gzip signature
in.reset();
tag = new NBTInputStream(new GZIPInputStream(in)).readTag();
} else {
tag = new NBTInputStream(in).readTag();
}
return new Node[] { new TagNode(tag) };
} catch (IOException e) {
throw new RuntimeException("I/O error while reading level.dat file", e);
}
}
use of org.pepsoft.worldpainter.mapexplorer.Node in project WorldPainter by Captain-Chaos.
the class DirectoryNode method loadChildren.
@Override
protected Node[] loadChildren() {
File[] contents = file.listFiles(showFiles ? null : File::isDirectory);
if (contents != null) {
Node[] children = new Node[contents.length];
for (int i = 0; i < contents.length; i++) {
if (contents[i].isDirectory()) {
for (MapRecognizer mapRecognizer : MAP_RECOGNIZERS) {
if (mapRecognizer.isMap(contents[i])) {
children[i] = mapRecognizer.getMapNode(contents[i]);
break;
}
}
if (children[i] == null) {
children[i] = new DirectoryNode(contents[i], showFiles);
}
} else {
children[i] = new FileSystemNode(contents[i]);
}
}
Arrays.sort(children, (node1, node2) -> COLLATOR.compare(node1.getName(), node2.getName()));
return children;
} else {
return new Node[0];
}
}
use of org.pepsoft.worldpainter.mapexplorer.Node in project WorldPainter by Captain-Chaos.
the class MinecraftDirectoryNode method loadChildren.
@Override
protected Node[] loadChildren() {
File[] contents = file.listFiles();
// Can't happen since this node is only created for existing directories
@SuppressWarnings("ConstantConditions") List<Node> children = new ArrayList<>(contents.length);
for (File file : contents) {
if (file.isDirectory()) {
children.add(new MinecraftDirectoryNode(file));
} else if (file.isFile()) {
String name = file.getName();
if (regionFilenamePatternVersion1.matcher(name).matches() || regionFilenamePatternVersion2.matcher(name).matches()) {
children.add(new RegionFileNode(file));
} else {
String lowercaseName = name.toLowerCase();
if (lowercaseName.endsWith(".nbt") || lowercaseName.endsWith(".dat") || lowercaseName.endsWith(".dat_old")) {
children.add(new NBTFileNode(file));
} else if (isGzip(file)) {
// Gamble that any gzipped file is an NBT file
children.add(new NBTFileNode(file));
}
}
}
}
children.sort((node1, node2) -> COLLATOR.compare(node1.getName(), node2.getName()));
return children.toArray(new Node[children.size()]);
}
use of org.pepsoft.worldpainter.mapexplorer.Node in project WorldPainter by Captain-Chaos.
the class RegionFileNode method loadChildren.
@Override
protected Node[] loadChildren() {
try {
List<Node> chunks = new ArrayList<>();
RegionFile regionFile = new RegionFile(file);
for (int chunkX = 0; chunkX < 32; chunkX++) {
for (int chunkZ = 0; chunkZ < 32; chunkZ++) {
if (regionFile.containsChunk(chunkX, chunkZ)) {
chunks.add(new ChunkNode(regionFile, chunkX, chunkZ));
}
}
}
return chunks.toArray(new Node[chunks.size()]);
} catch (IOException e) {
throw new RuntimeException("I/O error while reading region file", e);
}
}
Aggregations