diff --git a/src/de/mas/wiiu/jnus/DecryptionService.java b/src/de/mas/wiiu/jnus/DecryptionService.java index 271b174..52acd3b 100644 --- a/src/de/mas/wiiu/jnus/DecryptionService.java +++ b/src/de/mas/wiiu/jnus/DecryptionService.java @@ -211,7 +211,7 @@ public final class DecryptionService { if (content.isHashed()) { NUSDataProvider dataProvider = getNUSTitle().getDataProvider(); byte[] h3 = dataProvider.getContentH3Hash(content); - + nusdecryption.decryptFileStreamHashed(inputStream, outputStream, size, offset, (short) contentIndex, h3); } else { nusdecryption.decryptFileStream(inputStream, outputStream, size, (short) contentIndex, content.getSHA2Hash(), encryptedFileSize); @@ -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); } diff --git a/src/de/mas/wiiu/jnus/NUSTitle.java b/src/de/mas/wiiu/jnus/NUSTitle.java index 1d13925..799676a 100644 --- a/src/de/mas/wiiu/jnus/NUSTitle.java +++ b/src/de/mas/wiiu/jnus/NUSTitle.java @@ -86,17 +86,20 @@ public class NUSTitle { }); } - public FSTEntry getFSTEntryByFullPath(String givenFullPath) { + public Optional 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 getFSTEntriesByRegEx(String regEx) {