mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-25 17:36:55 +01:00
[FSTEntry] Build path from parents instead of caching it.
This commit is contained in:
parent
6d98a8b92c
commit
015e3fff18
@ -16,6 +16,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
package de.mas.wiiu.jnus.entities.fst;
|
package de.mas.wiiu.jnus.entities.fst;
|
||||||
|
|
||||||
|
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;
|
||||||
@ -37,7 +38,6 @@ public class FSTEntry {
|
|||||||
public static final byte FSTEntry_notInNUS = (byte) 0x80;
|
public static final byte FSTEntry_notInNUS = (byte) 0x80;
|
||||||
|
|
||||||
@Getter private final String filename;
|
@Getter private final String filename;
|
||||||
@Getter private final String path;
|
|
||||||
@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<>();
|
||||||
@ -91,6 +91,17 @@ public class FSTEntry {
|
|||||||
return getPath() + getFilename();
|
return getPath() + getFilename();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private StringBuilder getPathInternal() {
|
||||||
|
if (parent != null) {
|
||||||
|
return parent.getPathInternal().append(parent.getFilename()).append(File.separator);
|
||||||
|
}
|
||||||
|
return new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return getPathInternal().toString();
|
||||||
|
}
|
||||||
|
|
||||||
public int getEntryCount() {
|
public int getEntryCount() {
|
||||||
int count = 1;
|
int count = 1;
|
||||||
for (FSTEntry entry : getChildren()) {
|
for (FSTEntry entry : getChildren()) {
|
||||||
@ -174,14 +185,13 @@ public class FSTEntry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "FSTEntry [filename=" + filename + ", path=" + path + ", flags=" + flags + ", filesize=" + fileSize + ", fileoffset=" + fileOffset + ", content="
|
return "FSTEntry [filename=" + getFilename() + ", path=" + getPath() + ", flags=" + flags + ", filesize=" + fileSize + ", fileoffset=" + fileOffset
|
||||||
+ content + ", isDir=" + isDir + ", isRoot=" + isRoot + ", notInPackage=" + isNotInPackage + "]";
|
+ ", content=" + content + ", isDir=" + isDir + ", isRoot=" + isRoot + ", notInPackage=" + isNotInPackage + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
protected static class FSTEntryParam {
|
protected static class FSTEntryParam {
|
||||||
private String filename = "";
|
private String filename = "";
|
||||||
private String path = "";
|
|
||||||
|
|
||||||
private FSTEntry parent = null;
|
private FSTEntry parent = null;
|
||||||
|
|
||||||
|
@ -39,10 +39,6 @@ public final class FSTService {
|
|||||||
int level = 0;
|
int level = 0;
|
||||||
int[] LEntry = new int[16];
|
int[] LEntry = new int[16];
|
||||||
int[] Entry = new int[16];
|
int[] Entry = new int[16];
|
||||||
String[] pathStrings = new String[16];
|
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
pathStrings[i] = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<Integer, FSTEntry> fstEntryToOffsetMap = new HashMap<>();
|
HashMap<Integer, FSTEntry> fstEntryToOffsetMap = new HashMap<>();
|
||||||
Entry[level] = 0;
|
Entry[level] = 0;
|
||||||
@ -51,9 +47,7 @@ public final class FSTService {
|
|||||||
fstEntryToOffsetMap.put(0, rootEntry);
|
fstEntryToOffsetMap.put(0, rootEntry);
|
||||||
|
|
||||||
int lastlevel = level;
|
int lastlevel = level;
|
||||||
String path = File.separator;
|
|
||||||
|
|
||||||
FSTEntry last = null;
|
|
||||||
for (int i = 1; i < totalEntries; i++) {
|
for (int i = 1; i < totalEntries; i++) {
|
||||||
|
|
||||||
int entryOffset = i;
|
int entryOffset = i;
|
||||||
@ -68,7 +62,6 @@ public final class FSTService {
|
|||||||
FSTEntryParam entryParam = new FSTEntry.FSTEntryParam();
|
FSTEntryParam entryParam = new FSTEntry.FSTEntryParam();
|
||||||
|
|
||||||
if (lastlevel != level) {
|
if (lastlevel != level) {
|
||||||
path = pathStrings[level] + getFullPath(level - 1, level, fstSection, namesSection, Entry);
|
|
||||||
lastlevel = level;
|
lastlevel = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +85,6 @@ public final class FSTService {
|
|||||||
parent = fstEntryToOffsetMap.get(parentOffset);
|
parent = fstEntryToOffsetMap.get(parentOffset);
|
||||||
Entry[level] = i;
|
Entry[level] = i;
|
||||||
LEntry[level++] = nextOffset;
|
LEntry[level++] = nextOffset;
|
||||||
pathStrings[level] = path;
|
|
||||||
|
|
||||||
if (level > 15) {
|
if (level > 15) {
|
||||||
log.warning("level > 15");
|
log.warning("level > 15");
|
||||||
@ -107,7 +99,6 @@ public final class FSTService {
|
|||||||
|
|
||||||
entryParam.setFlags(flags);
|
entryParam.setFlags(flags);
|
||||||
entryParam.setFilename(filename);
|
entryParam.setFilename(filename);
|
||||||
entryParam.setPath(path);
|
|
||||||
|
|
||||||
if (contentsByIndex != null) {
|
if (contentsByIndex != null) {
|
||||||
Content content = contentsByIndex.get((int) contentIndex);
|
Content content = contentsByIndex.get((int) contentIndex);
|
||||||
@ -129,7 +120,6 @@ public final class FSTService {
|
|||||||
entryParam.setParent(parent);
|
entryParam.setParent(parent);
|
||||||
|
|
||||||
FSTEntry entry = new FSTEntry(entryParam);
|
FSTEntry entry = new FSTEntry(entryParam);
|
||||||
last = entry;
|
|
||||||
fstEntryToOffsetMap.put(entryOffset, entry);
|
fstEntryToOffsetMap.put(entryOffset, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,15 +144,4 @@ public final class FSTService {
|
|||||||
return (new String(Arrays.copyOfRange(namesSection, nameOffset, nameOffset + j)));
|
return (new String(Arrays.copyOfRange(namesSection, nameOffset, nameOffset + j)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFullPath(int startlevel, int endlevel, byte[] fstSection, byte[] namesSection, int[] Entry) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = startlevel; i < endlevel; i++) {
|
|
||||||
int entryOffset = Entry[i] * 0x10;
|
|
||||||
byte[] entryData = Arrays.copyOfRange(fstSection, entryOffset, entryOffset + 10);
|
|
||||||
String entryName = getName(entryData, namesSection);
|
|
||||||
|
|
||||||
sb.append(entryName).append(File.separator);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user