mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-05 07:45:11 +01:00
Fix and optimize the getFileEntryDir and getFSTEntryByFullPath functions
This commit is contained in:
parent
847ed71ae1
commit
e8985f0c12
@ -23,11 +23,12 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import de.mas.wiiu.jnus.entities.TMD;
|
||||
import de.mas.wiiu.jnus.entities.Ticket;
|
||||
import de.mas.wiiu.jnus.entities.content.Content;
|
||||
@ -92,14 +93,15 @@ public class NUSTitle {
|
||||
fullPath = File.separator + fullPath;
|
||||
}
|
||||
|
||||
String[] dirs = fullPath.split(Pattern.quote(File.separator));
|
||||
if (dirs.length <= 1) {
|
||||
return Optional.of(FST.getRoot());
|
||||
String dirPath = FilenameUtils.getFullPathNoEndSeparator(fullPath);
|
||||
Optional<FSTEntry> pathOpt = Optional.of(FST.getRoot());
|
||||
if (!dirPath.equals(File.separator)) {
|
||||
pathOpt = getFileEntryDir(dirPath);
|
||||
}
|
||||
String dirPath = fullPath.substring(0, fullPath.length() - dirs[dirs.length - 1].length() - 1);
|
||||
|
||||
String path = fullPath;
|
||||
return getFileEntryDir(dirPath).flatMap(e -> getAllFSTEntryChildrenAsStream(e).filter(en -> path.equals(en.getFullPath())).findAny());
|
||||
|
||||
return pathOpt.flatMap(e -> e.getChildren().stream().filter(c -> c.getFullPath().equals(path)).findAny());
|
||||
}
|
||||
|
||||
public List<FSTEntry> getFSTEntriesByRegEx(String regEx) {
|
||||
@ -139,14 +141,22 @@ public class NUSTitle {
|
||||
}
|
||||
|
||||
public Optional<FSTEntry> getFileEntryDir(String string, FSTEntry curEntry) {
|
||||
if (!string.endsWith(File.separator)) {
|
||||
string += File.separator;
|
||||
}
|
||||
for (val curChild : curEntry.getDirChildren()) {
|
||||
if (string.startsWith(curChild.getFullPath())) {
|
||||
if (string.equals(curChild.getFullPath())) {
|
||||
String compareTo = curChild.getFullPath();
|
||||
if (!compareTo.endsWith(File.separator)) {
|
||||
compareTo += File.separator;
|
||||
}
|
||||
if (string.startsWith(compareTo)) {
|
||||
if (string.equals(compareTo)) {
|
||||
return Optional.of(curChild);
|
||||
}
|
||||
return getFileEntryDir(string, curChild);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user