mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-22 16:09:18 +01:00
Optimize getFSTEntryByFullPath
This commit is contained in:
parent
9bc418357e
commit
9acd11bd11
@ -315,11 +315,7 @@ public final class DecryptionService {
|
||||
// Decrypt FSTEntry to OutputStream
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
public void decryptFSTEntryTo(String entryFullPath, OutputStream outputStream) throws IOException, CheckSumWrongException {
|
||||
FSTEntry entry = getNUSTitle().getFSTEntryByFullPath(entryFullPath);
|
||||
if (entry == null) {
|
||||
log.info("File not found");
|
||||
throw new FileNotFoundException("File not found");
|
||||
}
|
||||
FSTEntry entry = getNUSTitle().getFSTEntryByFullPath(entryFullPath).orElseThrow(() -> new FileNotFoundException("File not found: " + entryFullPath));
|
||||
|
||||
decryptFSTEntryToStream(entry, outputStream);
|
||||
}
|
||||
@ -342,11 +338,7 @@ public final class DecryptionService {
|
||||
public void decryptFSTEntryTo(boolean fullPath, String entryFullPath, String outputFolder, boolean skipExistingFiles)
|
||||
throws IOException, CheckSumWrongException {
|
||||
|
||||
FSTEntry entry = getNUSTitle().getFSTEntryByFullPath(entryFullPath);
|
||||
if (entry == null) {
|
||||
log.info("File not found");
|
||||
CompletableFuture.completedFuture(null);
|
||||
}
|
||||
FSTEntry entry = getNUSTitle().getFSTEntryByFullPath(entryFullPath).orElseThrow(() -> new FileNotFoundException("File not found: " + entryFullPath));
|
||||
|
||||
decryptFSTEntryTo(fullPath, entry, outputFolder, skipExistingFiles);
|
||||
}
|
||||
|
@ -86,17 +86,20 @@ public class NUSTitle {
|
||||
});
|
||||
}
|
||||
|
||||
public FSTEntry getFSTEntryByFullPath(String givenFullPath) {
|
||||
public Optional<FSTEntry> getFSTEntryByFullPath(String givenFullPath) {
|
||||
String fullPath = givenFullPath.replace("/", File.separator);
|
||||
if (!fullPath.startsWith(File.separator)) {
|
||||
fullPath = File.separator + fullPath;
|
||||
}
|
||||
for (FSTEntry f : getAllFSTEntriesFlat()) {
|
||||
if (f.getFullPath().equals(fullPath)) {
|
||||
return f;
|
||||
|
||||
String[] dirs = fullPath.split(Pattern.quote(File.separator));
|
||||
if (dirs.length <= 1) {
|
||||
return Optional.of(FST.getRoot());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
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());
|
||||
}
|
||||
|
||||
public List<FSTEntry> getFSTEntriesByRegEx(String regEx) {
|
||||
|
Loading…
Reference in New Issue
Block a user