From 57611173b479073dddf474b8f96b1264645de952 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 6 Apr 2019 16:57:12 +0200 Subject: [PATCH] Optimize the NUSDataProviderWUDGI implementation --- .../implementations/NUSDataProviderWUDGI.java | 8 +++++-- .../wud/parser/WUDGIPartitionTitle.java | 22 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/de/mas/wiiu/jnus/implementations/NUSDataProviderWUDGI.java b/src/de/mas/wiiu/jnus/implementations/NUSDataProviderWUDGI.java index 66c8718..be5a226 100644 --- a/src/de/mas/wiiu/jnus/implementations/NUSDataProviderWUDGI.java +++ b/src/de/mas/wiiu/jnus/implementations/NUSDataProviderWUDGI.java @@ -45,11 +45,15 @@ public class NUSDataProviderWUDGI extends NUSDataProvider { @Override public InputStream getInputStreamFromContent(Content content, long fileOffsetBlock) throws IOException { - InputStream in = getGiPartitionTitle().getFileAsStream(content.getFilename(), getDiscReader(), titleKey); - in.skip(fileOffsetBlock); + InputStream in = getGiPartitionTitle().getFileAsStream(content.getFilename(), getDiscReader(), fileOffsetBlock, titleKey); return in; } + @Override + public byte[] getChunkFromContent(Content content, long offset, int size) throws IOException { + return getGiPartitionTitle().getFileAsByte(content.getFilename(), getDiscReader(), offset, size, titleKey); + } + @Override public byte[] getContentH3Hash(Content content) throws IOException { return getGiPartitionTitle().getFileAsByte(String.format("%08X.h3", content.getID()), getDiscReader(), titleKey); diff --git a/src/de/mas/wiiu/jnus/implementations/wud/parser/WUDGIPartitionTitle.java b/src/de/mas/wiiu/jnus/implementations/wud/parser/WUDGIPartitionTitle.java index f7c3bb7..c05d0d5 100644 --- a/src/de/mas/wiiu/jnus/implementations/wud/parser/WUDGIPartitionTitle.java +++ b/src/de/mas/wiiu/jnus/implementations/wud/parser/WUDGIPartitionTitle.java @@ -25,15 +25,29 @@ public class WUDGIPartitionTitle { public byte[] getFileAsByte(String filename, WUDDiscReader discReader, byte[] titleKey) throws IOException { FSTEntry entry = getEntryByFilename(rootEntry, filename); - return StreamUtils.getBytesFromStream(getFileAsStream(filename, discReader, titleKey), (int) entry.getFileSize()); + return StreamUtils.getBytesFromStream(getFileAsStream(filename, discReader, 0, titleKey), (int) entry.getFileSize()); } - public InputStream getFileAsStream(String filename, WUDDiscReader discReader, byte[] titleKey) throws IOException { + public InputStream getFileAsStream(String filename, WUDDiscReader discReader, long offsetInFile, byte[] titleKey) throws IOException { FSTEntry entry = getEntryByFilename(rootEntry, filename); ContentFSTInfo info = fst.getContentFSTInfos().get((int) entry.getContentFSTID()); - return discReader.readDecryptedToInputStream(getAbsoluteReadOffset() + (long) info.getOffset(), entry.getFileOffset(), (int) entry.getFileSize(), - titleKey, null, false); + return getFileAsStream(info.getOffset(), entry.getFileOffset() + offsetInFile, (int) entry.getFileSize(), discReader, titleKey); + } + + public InputStream getFileAsStream(long contentOffset, long fileoffset, long size, WUDDiscReader discReader, byte[] titleKey) throws IOException { + return discReader.readDecryptedToInputStream(getAbsoluteReadOffset() + contentOffset, fileoffset, (int) size, titleKey, null, false); + } + + public byte[] getFileAsData(long contentOffset, long fileoffset, long size, WUDDiscReader discReader, byte[] titleKey) throws IOException { + return discReader.readDecryptedToByteArray(getAbsoluteReadOffset() + contentOffset, fileoffset, (int) size, titleKey, null, false); + } + + public byte[] getFileAsByte(String filename, WUDDiscReader discReader, long offsetInFile, int size, byte[] titleKey) throws IOException { + FSTEntry entry = getEntryByFilename(rootEntry, filename); + ContentFSTInfo info = fst.getContentFSTInfos().get((int) entry.getContentFSTID()); + + return getFileAsData(info.getOffset(), entry.getFileOffset() + offsetInFile, size, discReader, titleKey); } private long getAbsoluteReadOffset() {