[FSTEntry] Parse name only when needed.

This commit is contained in:
Maschell 2019-02-28 21:01:21 +01:00
parent cd58f8b580
commit 6dbd94c9a0
2 changed files with 22 additions and 12 deletions

View File

@ -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<String> filenameSupplier;
@Getter private final FSTEntry parent;
@Getter private final List<FSTEntry> 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<String> fileNameSupplier = () -> "";
private FSTEntry parent = null;
private short flags;

View File

@ -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<Integer, FSTEntry> fstEntryToOffsetMap = new HashMap<>();
final HashMap<Integer, FSTEntry> 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) {