mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-25 09:26:55 +01:00
The readToFile function of the FSTDataProvider Interface now does return a value value to indicate success
This commit is contained in:
parent
194b3084ae
commit
9b38f9c8c6
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user