mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-22 16:09:18 +01:00
[FSTEntry] Parse name only when needed.
This commit is contained in:
parent
cd58f8b580
commit
6dbd94c9a0
@ -20,6 +20,7 @@ import java.io.File;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import de.mas.wiiu.jnus.entities.content.Content;
|
import de.mas.wiiu.jnus.entities.content.Content;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -37,7 +38,9 @@ public class FSTEntry {
|
|||||||
public static final byte FSTEntry_DIR = (byte) 0x01;
|
public static final byte FSTEntry_DIR = (byte) 0x01;
|
||||||
public static final byte FSTEntry_notInNUS = (byte) 0x80;
|
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 FSTEntry parent;
|
||||||
|
|
||||||
@Getter private final List<FSTEntry> children = new ArrayList<>();
|
@Getter private final List<FSTEntry> children = new ArrayList<>();
|
||||||
@ -56,8 +59,7 @@ public class FSTEntry {
|
|||||||
@Getter private final short contentFSTID;
|
@Getter private final short contentFSTID;
|
||||||
|
|
||||||
protected FSTEntry(FSTEntryParam fstParam) {
|
protected FSTEntry(FSTEntryParam fstParam) {
|
||||||
this.filename = fstParam.getFilename();
|
this.filenameSupplier = fstParam.getFileNameSupplier();
|
||||||
this.path = fstParam.getPath();
|
|
||||||
this.flags = fstParam.getFlags();
|
this.flags = fstParam.getFlags();
|
||||||
this.parent = fstParam.getParent();
|
this.parent = fstParam.getParent();
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
@ -87,6 +89,13 @@ public class FSTEntry {
|
|||||||
return new FSTEntry(param);
|
return new FSTEntry(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFilename() {
|
||||||
|
if (filename == null) {
|
||||||
|
filename = filenameSupplier.get();
|
||||||
|
}
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
public String getFullPath() {
|
public String getFullPath() {
|
||||||
return getPath() + getFilename();
|
return getPath() + getFilename();
|
||||||
}
|
}
|
||||||
@ -163,7 +172,7 @@ public class FSTEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void printRecursive(int space) {
|
public void printRecursive(int space) {
|
||||||
printRecursive(System.out,space);
|
printRecursive(System.out, space);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printRecursive(PrintStream out, int space) {
|
public void printRecursive(PrintStream out, int space) {
|
||||||
@ -191,8 +200,7 @@ public class FSTEntry {
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
protected static class FSTEntryParam {
|
protected static class FSTEntryParam {
|
||||||
private String filename = "";
|
private Supplier<String> fileNameSupplier = () -> "";
|
||||||
|
|
||||||
private FSTEntry parent = null;
|
private FSTEntry parent = null;
|
||||||
|
|
||||||
private short flags;
|
private short flags;
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
package de.mas.wiiu.jnus.entities.fst;
|
package de.mas.wiiu.jnus.entities.fst;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -29,6 +28,7 @@ import lombok.extern.java.Log;
|
|||||||
|
|
||||||
@Log
|
@Log
|
||||||
public final class FSTService {
|
public final class FSTService {
|
||||||
|
|
||||||
private FSTService() {
|
private FSTService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ public final class FSTService {
|
|||||||
int[] LEntry = new int[16];
|
int[] LEntry = new int[16];
|
||||||
int[] Entry = new int[16];
|
int[] Entry = new int[16];
|
||||||
|
|
||||||
HashMap<Integer, FSTEntry> fstEntryToOffsetMap = new HashMap<>();
|
final HashMap<Integer, FSTEntry> fstEntryToOffsetMap = new HashMap<>();
|
||||||
Entry[level] = 0;
|
Entry[level] = 0;
|
||||||
LEntry[level++] = 0;
|
LEntry[level++] = 0;
|
||||||
|
|
||||||
@ -65,8 +65,6 @@ public final class FSTService {
|
|||||||
lastlevel = level;
|
lastlevel = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
String filename = getName(curEntry, namesSection);
|
|
||||||
|
|
||||||
long fileOffset = ByteUtils.getIntFromBytes(curEntry, 0x04);
|
long fileOffset = ByteUtils.getIntFromBytes(curEntry, 0x04);
|
||||||
long fileSize = ByteUtils.getUnsingedIntFromBytes(curEntry, 0x08);
|
long fileSize = ByteUtils.getUnsingedIntFromBytes(curEntry, 0x08);
|
||||||
|
|
||||||
@ -98,7 +96,8 @@ public final class FSTService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
entryParam.setFlags(flags);
|
entryParam.setFlags(flags);
|
||||||
entryParam.setFilename(filename);
|
final int nameOffset = getNameOffset(curEntry);
|
||||||
|
entryParam.setFileNameSupplier(() -> getName(nameOffset, namesSection));
|
||||||
|
|
||||||
if (contentsByIndex != null) {
|
if (contentsByIndex != null) {
|
||||||
Content content = contentsByIndex.get((int) contentIndex);
|
Content content = contentsByIndex.get((int) contentIndex);
|
||||||
@ -134,7 +133,10 @@ public final class FSTService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getName(byte[] data, byte[] namesSection) {
|
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;
|
int j = 0;
|
||||||
|
|
||||||
while ((nameOffset + j) < namesSection.length && namesSection[nameOffset + j] != 0) {
|
while ((nameOffset + j) < namesSection.length && namesSection[nameOffset + j] != 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user