The readToFile function of the FSTDataProvider Interface now does return a value value to indicate success

This commit is contained in:
Maschell 2019-04-19 10:56:24 +02:00
parent 194b3084ae
commit 9b38f9c8c6
7 changed files with 24 additions and 18 deletions

View File

@ -74,7 +74,7 @@ public class FSTDataProviderNUSTitle implements FSTDataProvider, HasNUSTitle {
}
@Override
public void readFileToStream(OutputStream out, FSTEntry entry, long offset, Optional<Long> size) throws IOException {
public boolean readFileToStream(OutputStream out, FSTEntry entry, long offset, Optional<Long> 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);
}

View File

@ -62,14 +62,14 @@ public class FSTDataProviderWUDDataPartition implements FSTDataProvider {
}
@Override
public void readFileToStream(OutputStream out, FSTEntry entry, long offset, Optional<Long> size) throws IOException {
public boolean readFileToStream(OutputStream out, FSTEntry entry, long offset, Optional<Long> 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

View File

@ -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;
}
/**

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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

View File

@ -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<Long> size) throws IOException;
public boolean readFileToStream(OutputStream out, FSTEntry entry, long offset, Optional<Long> size) throws IOException;