diff --git a/src/de/mas/wiiu/jnus/entities/fst/FSTEntry.java b/src/de/mas/wiiu/jnus/entities/fst/FSTEntry.java index 9e60e21..b81fa40 100644 --- a/src/de/mas/wiiu/jnus/entities/fst/FSTEntry.java +++ b/src/de/mas/wiiu/jnus/entities/fst/FSTEntry.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.PrintStream; import java.util.ArrayList; import java.util.List; +import java.util.function.Supplier; import de.mas.wiiu.jnus.entities.content.Content; import lombok.Data; @@ -37,7 +38,9 @@ public class FSTEntry { public static final byte FSTEntry_DIR = (byte) 0x01; public static final byte FSTEntry_notInNUS = (byte) 0x80; - @Getter private final String filename; + private String filename = null; + private final Supplier filenameSupplier; + @Getter private final FSTEntry parent; @Getter private final List children = new ArrayList<>(); @@ -56,8 +59,7 @@ public class FSTEntry { @Getter private final short contentFSTID; protected FSTEntry(FSTEntryParam fstParam) { - this.filename = fstParam.getFilename(); - this.path = fstParam.getPath(); + this.filenameSupplier = fstParam.getFileNameSupplier(); this.flags = fstParam.getFlags(); this.parent = fstParam.getParent(); if (parent != null) { @@ -87,6 +89,13 @@ public class FSTEntry { return new FSTEntry(param); } + public String getFilename() { + if (filename == null) { + filename = filenameSupplier.get(); + } + return filename; + } + public String getFullPath() { return getPath() + getFilename(); } @@ -163,7 +172,7 @@ public class FSTEntry { } public void printRecursive(int space) { - printRecursive(System.out,space); + printRecursive(System.out, space); } public void printRecursive(PrintStream out, int space) { @@ -191,8 +200,7 @@ public class FSTEntry { @Data protected static class FSTEntryParam { - private String filename = ""; - + private Supplier fileNameSupplier = () -> ""; private FSTEntry parent = null; private short flags; diff --git a/src/de/mas/wiiu/jnus/entities/fst/FSTService.java b/src/de/mas/wiiu/jnus/entities/fst/FSTService.java index 9b157cc..692a54c 100644 --- a/src/de/mas/wiiu/jnus/entities/fst/FSTService.java +++ b/src/de/mas/wiiu/jnus/entities/fst/FSTService.java @@ -16,7 +16,6 @@ ****************************************************************************/ package de.mas.wiiu.jnus.entities.fst; -import java.io.File; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -29,6 +28,7 @@ import lombok.extern.java.Log; @Log public final class FSTService { + private FSTService() { } @@ -40,7 +40,7 @@ public final class FSTService { int[] LEntry = new int[16]; int[] Entry = new int[16]; - HashMap fstEntryToOffsetMap = new HashMap<>(); + final HashMap fstEntryToOffsetMap = new HashMap<>(); Entry[level] = 0; LEntry[level++] = 0; @@ -65,8 +65,6 @@ public final class FSTService { lastlevel = level; } - String filename = getName(curEntry, namesSection); - long fileOffset = ByteUtils.getIntFromBytes(curEntry, 0x04); long fileSize = ByteUtils.getUnsingedIntFromBytes(curEntry, 0x08); @@ -98,7 +96,8 @@ public final class FSTService { } entryParam.setFlags(flags); - entryParam.setFilename(filename); + final int nameOffset = getNameOffset(curEntry); + entryParam.setFileNameSupplier(() -> getName(nameOffset, namesSection)); if (contentsByIndex != null) { Content content = contentsByIndex.get((int) contentIndex); @@ -134,7 +133,10 @@ public final class FSTService { } public static String getName(byte[] data, byte[] namesSection) { - int nameOffset = getNameOffset(data); + return getName(getNameOffset(data), namesSection); + } + + public static String getName(int nameOffset, byte[] namesSection) { int j = 0; while ((nameOffset + j) < namesSection.length && namesSection[nameOffset + j] != 0) {