mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-29 03:14:18 +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
|
@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()) {
|
if (!entry.getContent().isPresent()) {
|
||||||
out.close();
|
out.close();
|
||||||
throw new IOException("Content for the FSTEntry not found: " + entry);
|
throw new IOException("Content for the FSTEntry not found: " + entry);
|
||||||
@ -94,7 +94,7 @@ public class FSTDataProviderNUSTitle implements FSTDataProvider, HasNUSTitle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
decryptFSTEntryToStream(entry, out, fileOffsetBlock, fileOffset, usedSize);
|
return decryptFSTEntryToStream(entry, out, fileOffsetBlock, fileOffset, usedSize);
|
||||||
} catch (CheckSumWrongException e) {
|
} catch (CheckSumWrongException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
|
@ -62,14 +62,14 @@ public class FSTDataProviderWUDDataPartition implements FSTDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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());
|
ContentFSTInfo info = partition.getFST().getContentFSTInfos().get((int) entry.getContentFSTID());
|
||||||
long usedSize = size.orElse(entry.getFileSize());
|
long usedSize = size.orElse(entry.getFileSize());
|
||||||
if (titleKey == null) {
|
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,
|
return discReader.readDecryptedToOutputStream(out, partition.getPartitionOffset() + info.getOffset(), entry.getFileOffset() + offset, usedSize, titleKey, null,
|
||||||
titleKey, null, false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,7 +53,7 @@ public abstract class WUDDiscReader {
|
|||||||
return out.toByteArray();
|
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 {
|
public InputStream readEncryptedToStream(long offset, long size) throws IOException {
|
||||||
PipedInputStreamWithException in = new PipedInputStreamWithException();
|
PipedInputStreamWithException in = new PipedInputStreamWithException();
|
||||||
@ -92,7 +92,7 @@ public abstract class WUDDiscReader {
|
|||||||
return decryptedChunk;
|
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 {
|
boolean useFixedIV) throws IOException {
|
||||||
byte[] usedIV = null;
|
byte[] usedIV = null;
|
||||||
if (useFixedIV) {
|
if (useFixedIV) {
|
||||||
@ -149,6 +149,7 @@ public abstract class WUDDiscReader {
|
|||||||
} while (totalread < size);
|
} while (totalread < size);
|
||||||
|
|
||||||
outputStream.close();
|
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.WUDImage;
|
||||||
import de.mas.wiiu.jnus.implementations.wud.WUDImageCompressedInfo;
|
import de.mas.wiiu.jnus.implementations.wud.WUDImageCompressedInfo;
|
||||||
import lombok.extern.java.Log;
|
|
||||||
|
|
||||||
@Log
|
|
||||||
public class WUDDiscReaderCompressed extends WUDDiscReader {
|
public class WUDDiscReaderCompressed extends WUDDiscReader {
|
||||||
|
|
||||||
public WUDDiscReaderCompressed(WUDImage image) {
|
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/
|
* 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
|
@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
|
// make sure there is no out-of-bounds read
|
||||||
WUDImageCompressedInfo info = getImage().getCompressedInfo();
|
WUDImageCompressedInfo info = getImage().getCompressedInfo();
|
||||||
|
|
||||||
@ -92,5 +90,6 @@ public class WUDDiscReaderCompressed extends WUDDiscReader {
|
|||||||
synchronized (out) {
|
synchronized (out) {
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
return usedSize == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public class WUDDiscReaderSplitted extends WUDDiscReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
RandomAccessFile input = getFileByOffset(offset);
|
||||||
|
|
||||||
int bufferSize = 0x8000;
|
int bufferSize = 0x8000;
|
||||||
@ -64,7 +64,9 @@ public class WUDDiscReaderSplitted extends WUDDiscReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int read = input.read(buffer, 0, curReadSize);
|
int read = input.read(buffer, 0, curReadSize);
|
||||||
if (read < 0) break;
|
if (read < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (totalread + read > size) {
|
if (totalread + read > size) {
|
||||||
read = (int) (size - totalread);
|
read = (int) (size - totalread);
|
||||||
}
|
}
|
||||||
@ -84,6 +86,7 @@ public class WUDDiscReaderSplitted extends WUDDiscReader {
|
|||||||
|
|
||||||
input.close();
|
input.close();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
|
return totalread >= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getFilePartByOffset(long offset) {
|
private int getFilePartByOffset(long offset) {
|
||||||
|
@ -31,7 +31,7 @@ public class WUDDiscReaderUncompressed extends WUDDiscReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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());
|
FileInputStream input = new FileInputStream(getImage().getFileHandle());
|
||||||
|
|
||||||
@ -42,7 +42,9 @@ public class WUDDiscReaderUncompressed extends WUDDiscReader {
|
|||||||
long totalread = 0;
|
long totalread = 0;
|
||||||
do {
|
do {
|
||||||
int read = input.read(buffer);
|
int read = input.read(buffer);
|
||||||
if (read < 0) break;
|
if (read < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (totalread + read > size) {
|
if (totalread + read > size) {
|
||||||
read = (int) (size - totalread);
|
read = (int) (size - totalread);
|
||||||
}
|
}
|
||||||
@ -60,6 +62,7 @@ public class WUDDiscReaderUncompressed extends WUDDiscReader {
|
|||||||
} while (totalread < size);
|
} while (totalread < size);
|
||||||
input.close();
|
input.close();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
|
return totalread >= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,11 +57,11 @@ public interface FSTDataProvider {
|
|||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
default public void readFileToStream(OutputStream out, FSTEntry entry, long offset) throws IOException {
|
default public boolean readFileToStream(OutputStream out, FSTEntry entry, long offset) throws IOException {
|
||||||
readFileToStream(out, entry, offset, Optional.empty());
|
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