Optimize getFSTEntryByFullPath

This commit is contained in:
Maschell 2019-03-01 15:56:15 +01:00
parent 9bc418357e
commit 9acd11bd11
2 changed files with 12 additions and 17 deletions

View File

@ -315,11 +315,7 @@ public final class DecryptionService {
// Decrypt FSTEntry to OutputStream // Decrypt FSTEntry to OutputStream
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
public void decryptFSTEntryTo(String entryFullPath, OutputStream outputStream) throws IOException, CheckSumWrongException { public void decryptFSTEntryTo(String entryFullPath, OutputStream outputStream) throws IOException, CheckSumWrongException {
FSTEntry entry = getNUSTitle().getFSTEntryByFullPath(entryFullPath); FSTEntry entry = getNUSTitle().getFSTEntryByFullPath(entryFullPath).orElseThrow(() -> new FileNotFoundException("File not found: " + entryFullPath));
if (entry == null) {
log.info("File not found");
throw new FileNotFoundException("File not found");
}
decryptFSTEntryToStream(entry, outputStream); decryptFSTEntryToStream(entry, outputStream);
} }
@ -342,11 +338,7 @@ public final class DecryptionService {
public void decryptFSTEntryTo(boolean fullPath, String entryFullPath, String outputFolder, boolean skipExistingFiles) public void decryptFSTEntryTo(boolean fullPath, String entryFullPath, String outputFolder, boolean skipExistingFiles)
throws IOException, CheckSumWrongException { throws IOException, CheckSumWrongException {
FSTEntry entry = getNUSTitle().getFSTEntryByFullPath(entryFullPath); FSTEntry entry = getNUSTitle().getFSTEntryByFullPath(entryFullPath).orElseThrow(() -> new FileNotFoundException("File not found: " + entryFullPath));
if (entry == null) {
log.info("File not found");
CompletableFuture.completedFuture(null);
}
decryptFSTEntryTo(fullPath, entry, outputFolder, skipExistingFiles); decryptFSTEntryTo(fullPath, entry, outputFolder, skipExistingFiles);
} }

View File

@ -86,17 +86,20 @@ public class NUSTitle {
}); });
} }
public FSTEntry getFSTEntryByFullPath(String givenFullPath) { public Optional<FSTEntry> getFSTEntryByFullPath(String givenFullPath) {
String fullPath = givenFullPath.replace("/", File.separator); String fullPath = givenFullPath.replace("/", File.separator);
if (!fullPath.startsWith(File.separator)) { if (!fullPath.startsWith(File.separator)) {
fullPath = File.separator + fullPath; fullPath = File.separator + fullPath;
} }
for (FSTEntry f : getAllFSTEntriesFlat()) {
if (f.getFullPath().equals(fullPath)) { String[] dirs = fullPath.split(Pattern.quote(File.separator));
return f; if (dirs.length <= 1) {
return Optional.of(FST.getRoot());
} }
} String dirPath = fullPath.substring(0, fullPath.length() - dirs[dirs.length - 1].length() - 1);
return null;
String path = fullPath;
return getFileEntryDir(dirPath).flatMap(e -> getAllFSTEntryChildrenAsStream(e).filter(en -> path.equals(en.getFullPath())).findAny());
} }
public List<FSTEntry> getFSTEntriesByRegEx(String regEx) { public List<FSTEntry> getFSTEntriesByRegEx(String regEx) {