From 89d5927acd85365461a1e53f9ee68adb77103eab Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 11 Apr 2019 13:14:50 +0200 Subject: [PATCH] Add a readFileToStream function to the FSTDataProvider interface while allows your to read a file to a outputstream --- .../jnus/implementations/FSTDataProviderNUSTitle.java | 9 +++++++++ .../FSTDataProviderWUDDataPartition.java | 11 +++++++++++ .../implementations/wud/reader/WUDDiscReader.java | 2 +- .../wud/reader/WUDDiscReaderCompressed.java | 2 +- .../wud/reader/WUDDiscReaderSplitted.java | 2 +- .../wud/reader/WUDDiscReaderUncompressed.java | 2 +- src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java | 3 +++ 7 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/de/mas/wiiu/jnus/implementations/FSTDataProviderNUSTitle.java b/src/de/mas/wiiu/jnus/implementations/FSTDataProviderNUSTitle.java index f42ad12..58db709 100644 --- a/src/de/mas/wiiu/jnus/implementations/FSTDataProviderNUSTitle.java +++ b/src/de/mas/wiiu/jnus/implementations/FSTDataProviderNUSTitle.java @@ -91,6 +91,15 @@ public class FSTDataProviderNUSTitle implements FSTDataProvider, HasNUSTitle { return in; } + @Override + public void readFileToStream(OutputStream outputStream, FSTEntry entry) throws IOException { + try { + readFileToOutputStream(outputStream, entry, 0, entry.getFileSize()); + } catch (CheckSumWrongException e) { + throw new IOException(e); + } + } + public boolean readFileToOutputStream(OutputStream out, FSTEntry entry, long offset, long size) throws IOException, CheckSumWrongException { long fileOffset = entry.getFileOffset() + offset; long fileOffsetBlock = fileOffset; diff --git a/src/de/mas/wiiu/jnus/implementations/FSTDataProviderWUDDataPartition.java b/src/de/mas/wiiu/jnus/implementations/FSTDataProviderWUDDataPartition.java index 7d3fb9e..34d13bf 100644 --- a/src/de/mas/wiiu/jnus/implementations/FSTDataProviderWUDDataPartition.java +++ b/src/de/mas/wiiu/jnus/implementations/FSTDataProviderWUDDataPartition.java @@ -18,6 +18,7 @@ package de.mas.wiiu.jnus.implementations; ****************************************************************************/ import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.util.Optional; import de.mas.wiiu.jnus.entities.content.ContentFSTInfo; @@ -53,6 +54,16 @@ public class FSTDataProviderWUDDataPartition implements FSTDataProvider { return getChunkOfData(info.getOffset(), entry.getFileOffset() + offset, size, discReader, titleKey); } + @Override + public void readFileToStream(OutputStream out, FSTEntry entry) throws IOException { + ContentFSTInfo info = partition.getFST().getContentFSTInfos().get((int) entry.getContentFSTID()); + if (titleKey == null) { + discReader.readEncryptedToOutputStream(out, partition.getAbsolutePartitionOffset() + info.getOffset() + entry.getFileOffset(), entry.getFileSize()); + } + discReader.readDecryptedToOutputStream(out, partition.getAbsolutePartitionOffset() + info.getOffset(), entry.getFileOffset(), entry.getFileSize(), + titleKey, null, false); + } + @Override public InputStream readFileAsStream(FSTEntry entry, long offset, Optional size) throws IOException { ContentFSTInfo info = partition.getFST().getContentFSTInfos().get((int) entry.getContentFSTID()); diff --git a/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReader.java b/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReader.java index 6c7d5f9..53d79c9 100644 --- a/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReader.java +++ b/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReader.java @@ -83,7 +83,7 @@ public abstract class WUDDiscReader { return out.toByteArray(); } - protected abstract void readEncryptedToOutputStream(OutputStream out, long offset, long size) throws IOException; + public abstract void readEncryptedToOutputStream(OutputStream out, long offset, long size) throws IOException; /** * diff --git a/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderCompressed.java b/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderCompressed.java index 02e681b..2e985b7 100644 --- a/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderCompressed.java +++ b/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderCompressed.java @@ -36,7 +36,7 @@ public class WUDDiscReaderCompressed extends WUDDiscReader { * Expects the .wux format by Exzap. You can more infos about it here. https://gbatemp.net/threads/wii-u-image-wud-compression-tool.397901/ */ @Override - protected void readEncryptedToOutputStream(OutputStream out, long offset, long size) throws IOException { + public void readEncryptedToOutputStream(OutputStream out, long offset, long size) throws IOException { // make sure there is no out-of-bounds read WUDImageCompressedInfo info = getImage().getCompressedInfo(); diff --git a/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderSplitted.java b/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderSplitted.java index d865caf..6c8156f 100644 --- a/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderSplitted.java +++ b/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderSplitted.java @@ -37,7 +37,7 @@ public class WUDDiscReaderSplitted extends WUDDiscReader { } @Override - protected void readEncryptedToOutputStream(OutputStream outputStream, long offset, long size) throws IOException { + public void readEncryptedToOutputStream(OutputStream outputStream, long offset, long size) throws IOException { RandomAccessFile input = getFileByOffset(offset); int bufferSize = 0x8000; diff --git a/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderUncompressed.java b/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderUncompressed.java index 5665d00..4c3e876 100644 --- a/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderUncompressed.java +++ b/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderUncompressed.java @@ -30,7 +30,7 @@ public class WUDDiscReaderUncompressed extends WUDDiscReader { } @Override - protected void readEncryptedToOutputStream(OutputStream outputStream, long offset, long size) throws IOException { + public void readEncryptedToOutputStream(OutputStream outputStream, long offset, long size) throws IOException { FileInputStream input = new FileInputStream(getImage().getFileHandle()); diff --git a/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java b/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java index dad26a5..eed5f05 100644 --- a/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java +++ b/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java @@ -18,6 +18,7 @@ package de.mas.wiiu.jnus.interfaces; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.util.Optional; import de.mas.wiiu.jnus.entities.fst.FSTEntry; @@ -35,4 +36,6 @@ public interface FSTDataProvider { public InputStream readFileAsStream(FSTEntry entry, long offset, Optional size) throws IOException; + public void readFileToStream(OutputStream out, FSTEntry entry) throws IOException; + }