mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-25 17:36:55 +01:00
Optimize getFSTEntryByFullPath
This commit is contained in:
parent
9bc418357e
commit
9acd11bd11
@ -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);
|
||||
}
|
||||
|
@ -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