From 9b38f9c8c6029cb3ab13ba11f1d92ee92bca4dce Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 19 Apr 2019 10:56:24 +0200 Subject: [PATCH] The readToFile function of the FSTDataProvider Interface now does return a value value to indicate success --- .../jnus/implementations/FSTDataProviderNUSTitle.java | 4 ++-- .../implementations/FSTDataProviderWUDDataPartition.java | 8 ++++---- .../jnus/implementations/wud/reader/WUDDiscReader.java | 5 +++-- .../wud/reader/WUDDiscReaderCompressed.java | 5 ++--- .../implementations/wud/reader/WUDDiscReaderSplitted.java | 7 +++++-- .../wud/reader/WUDDiscReaderUncompressed.java | 7 +++++-- src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java | 6 +++--- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/de/mas/wiiu/jnus/implementations/FSTDataProviderNUSTitle.java b/src/de/mas/wiiu/jnus/implementations/FSTDataProviderNUSTitle.java index c4625dd..ead8985 100644 --- a/src/de/mas/wiiu/jnus/implementations/FSTDataProviderNUSTitle.java +++ b/src/de/mas/wiiu/jnus/implementations/FSTDataProviderNUSTitle.java @@ -74,7 +74,7 @@ public class FSTDataProviderNUSTitle implements FSTDataProvider, HasNUSTitle { } @Override - public void readFileToStream(OutputStream out, FSTEntry entry, long offset, Optional size) throws IOException { + public boolean readFileToStream(OutputStream out, FSTEntry entry, long offset, Optional size) throws IOException { if (!entry.getContent().isPresent()) { out.close(); throw new IOException("Content for the FSTEntry not found: " + entry); @@ -94,7 +94,7 @@ public class FSTDataProviderNUSTitle implements FSTDataProvider, HasNUSTitle { } } try { - decryptFSTEntryToStream(entry, out, fileOffsetBlock, fileOffset, usedSize); + return decryptFSTEntryToStream(entry, out, fileOffsetBlock, fileOffset, usedSize); } catch (CheckSumWrongException e) { throw new IOException(e); } diff --git a/src/de/mas/wiiu/jnus/implementations/FSTDataProviderWUDDataPartition.java b/src/de/mas/wiiu/jnus/implementations/FSTDataProviderWUDDataPartition.java index 522b6e6..aa63d2d 100644 --- a/src/de/mas/wiiu/jnus/implementations/FSTDataProviderWUDDataPartition.java +++ b/src/de/mas/wiiu/jnus/implementations/FSTDataProviderWUDDataPartition.java @@ -62,14 +62,14 @@ public class FSTDataProviderWUDDataPartition implements FSTDataProvider { } @Override - public void readFileToStream(OutputStream out, FSTEntry entry, long offset, Optional size) throws IOException { + public boolean readFileToStream(OutputStream out, FSTEntry entry, long offset, Optional size) throws IOException { ContentFSTInfo info = partition.getFST().getContentFSTInfos().get((int) entry.getContentFSTID()); long usedSize = size.orElse(entry.getFileSize()); if (titleKey == null) { - discReader.readEncryptedToStream(out, partition.getPartitionOffset() + info.getOffset() + entry.getFileOffset() + offset, usedSize); + return discReader.readEncryptedToStream(out, partition.getPartitionOffset() + info.getOffset() + entry.getFileOffset() + offset, usedSize); } - discReader.readDecryptedToOutputStream(out, partition.getPartitionOffset() + info.getOffset(), entry.getFileOffset() + offset, usedSize, - titleKey, null, false); + return discReader.readDecryptedToOutputStream(out, partition.getPartitionOffset() + info.getOffset(), entry.getFileOffset() + offset, usedSize, titleKey, null, + false); } @Override 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 2fbb6f1..1ee40d9 100644 --- a/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReader.java +++ b/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReader.java @@ -53,7 +53,7 @@ public abstract class WUDDiscReader { return out.toByteArray(); } - public abstract void readEncryptedToStream(OutputStream out, long offset, long size) throws IOException; + public abstract boolean readEncryptedToStream(OutputStream out, long offset, long size) throws IOException; public InputStream readEncryptedToStream(long offset, long size) throws IOException { PipedInputStreamWithException in = new PipedInputStreamWithException(); @@ -92,7 +92,7 @@ public abstract class WUDDiscReader { return decryptedChunk; } - public void readDecryptedToOutputStream(OutputStream outputStream, long clusterOffset, long fileOffset, long size, byte[] key, byte[] IV, + public boolean readDecryptedToOutputStream(OutputStream outputStream, long clusterOffset, long fileOffset, long size, byte[] key, byte[] IV, boolean useFixedIV) throws IOException { byte[] usedIV = null; if (useFixedIV) { @@ -149,6 +149,7 @@ public abstract class WUDDiscReader { } while (totalread < size); outputStream.close(); + return totalread >= size; } /** 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 d64122f..5983a5d 100644 --- a/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderCompressed.java +++ b/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderCompressed.java @@ -23,9 +23,7 @@ import java.util.Arrays; import de.mas.wiiu.jnus.implementations.wud.WUDImage; import de.mas.wiiu.jnus.implementations.wud.WUDImageCompressedInfo; -import lombok.extern.java.Log; -@Log public class WUDDiscReaderCompressed extends WUDDiscReader { public WUDDiscReaderCompressed(WUDImage image) { @@ -36,7 +34,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 - public void readEncryptedToStream(OutputStream out, long offset, long size) throws IOException { + public boolean readEncryptedToStream(OutputStream out, long offset, long size) throws IOException { // make sure there is no out-of-bounds read WUDImageCompressedInfo info = getImage().getCompressedInfo(); @@ -92,5 +90,6 @@ public class WUDDiscReaderCompressed extends WUDDiscReader { synchronized (out) { out.close(); } + return usedSize == 0; } } 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 42aa896..7a34c6f 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 - public void readEncryptedToStream(OutputStream outputStream, long offset, long size) throws IOException { + public boolean readEncryptedToStream(OutputStream outputStream, long offset, long size) throws IOException { RandomAccessFile input = getFileByOffset(offset); int bufferSize = 0x8000; @@ -64,7 +64,9 @@ public class WUDDiscReaderSplitted extends WUDDiscReader { } int read = input.read(buffer, 0, curReadSize); - if (read < 0) break; + if (read < 0) { + break; + } if (totalread + read > size) { read = (int) (size - totalread); } @@ -84,6 +86,7 @@ public class WUDDiscReaderSplitted extends WUDDiscReader { input.close(); outputStream.close(); + return totalread >= size; } private int getFilePartByOffset(long offset) { 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 a8118e9..5e55ecf 100644 --- a/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderUncompressed.java +++ b/src/de/mas/wiiu/jnus/implementations/wud/reader/WUDDiscReaderUncompressed.java @@ -31,7 +31,7 @@ public class WUDDiscReaderUncompressed extends WUDDiscReader { } @Override - public void readEncryptedToStream(OutputStream outputStream, long offset, long size) throws IOException { + public boolean readEncryptedToStream(OutputStream outputStream, long offset, long size) throws IOException { FileInputStream input = new FileInputStream(getImage().getFileHandle()); @@ -42,7 +42,9 @@ public class WUDDiscReaderUncompressed extends WUDDiscReader { long totalread = 0; do { int read = input.read(buffer); - if (read < 0) break; + if (read < 0) { + break; + } if (totalread + read > size) { read = (int) (size - totalread); } @@ -60,6 +62,7 @@ public class WUDDiscReaderUncompressed extends WUDDiscReader { } while (totalread < size); input.close(); outputStream.close(); + return totalread >= size; } @Override diff --git a/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java b/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java index 624a993..b1fb12d 100644 --- a/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java +++ b/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java @@ -57,11 +57,11 @@ public interface FSTDataProvider { return in; } - default public void readFileToStream(OutputStream out, FSTEntry entry, long offset) throws IOException { - readFileToStream(out, entry, offset, Optional.empty()); + default public boolean readFileToStream(OutputStream out, FSTEntry entry, long offset) throws IOException { + return readFileToStream(out, entry, offset, Optional.empty()); } - public void readFileToStream(OutputStream out, FSTEntry entry, long offset, Optional size) throws IOException; + public boolean readFileToStream(OutputStream out, FSTEntry entry, long offset, Optional size) throws IOException;