mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-16 21:19:19 +01:00
Add a FSTDataProvider implementation using a WUDDataPartition.
This commit is contained in:
parent
8e4faa58dc
commit
4d703d631a
@ -0,0 +1,58 @@
|
|||||||
|
package de.mas.wiiu.jnus.implementations;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import de.mas.wiiu.jnus.entities.content.ContentFSTInfo;
|
||||||
|
import de.mas.wiiu.jnus.entities.fst.FSTEntry;
|
||||||
|
import de.mas.wiiu.jnus.implementations.wud.parser.WUDDataPartition;
|
||||||
|
import de.mas.wiiu.jnus.implementations.wud.reader.WUDDiscReader;
|
||||||
|
import de.mas.wiiu.jnus.interfaces.FSTDataProvider;
|
||||||
|
|
||||||
|
public class FSTDataProviderWUDDataPartition implements FSTDataProvider {
|
||||||
|
private final WUDDataPartition partition;
|
||||||
|
private final WUDDiscReader discReader;
|
||||||
|
private final byte[] titleKey;
|
||||||
|
|
||||||
|
public FSTDataProviderWUDDataPartition(WUDDataPartition partition, WUDDiscReader discReader, byte[] titleKey) {
|
||||||
|
this.partition = partition;
|
||||||
|
this.discReader = discReader;
|
||||||
|
this.titleKey = titleKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return partition.getPartitionName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FSTEntry getRoot() {
|
||||||
|
return partition.getFST().getRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] readFile(FSTEntry entry, long offset, long size) throws IOException {
|
||||||
|
ContentFSTInfo info = partition.getFST().getContentFSTInfos().get((int) entry.getContentFSTID());
|
||||||
|
return getChunkOfData(info.getOffset(), entry.getFileOffset() + offset, size, discReader, titleKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream readFileAsStream(FSTEntry entry, long offset, Optional<Long> size) throws IOException {
|
||||||
|
ContentFSTInfo info = partition.getFST().getContentFSTInfos().get((int) entry.getContentFSTID());
|
||||||
|
long fileSize = size.orElse(entry.getFileSize());
|
||||||
|
if (titleKey == null) {
|
||||||
|
return discReader.readEncryptedToInputStream(partition.getAbsolutePartitionOffset() + info.getOffset() + entry.getFileOffset() + offset, fileSize);
|
||||||
|
}
|
||||||
|
return discReader.readDecryptedToInputStream(partition.getAbsolutePartitionOffset() + info.getOffset(), entry.getFileOffset() + offset, fileSize,
|
||||||
|
titleKey, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getChunkOfData(long contentOffset, long fileoffset, long size, WUDDiscReader discReader, byte[] titleKey) throws IOException {
|
||||||
|
if (titleKey == null) {
|
||||||
|
return discReader.readEncryptedToByteArray(partition.getAbsolutePartitionOffset() + contentOffset, fileoffset, (int) size);
|
||||||
|
}
|
||||||
|
return discReader.readDecryptedToByteArray(partition.getAbsolutePartitionOffset() + contentOffset, fileoffset, (int) size, titleKey, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user