use of info.ata4.util.io.DataBlock in project disunity by ata4.
the class SerializedFileWriter method writeHeader.
private void writeHeader(DataWriter out) throws IOException {
DataBlock headerBlock = serialized.headerBlock();
headerBlock.markBegin(out);
out.writeStruct(serialized.header());
headerBlock.markEnd(out);
L.log(Level.FINER, "headerBlock: {0}", headerBlock);
}
use of info.ata4.util.io.DataBlock in project disunity by ata4.
the class SerializedFileTest method offsetsAndSizesValid.
@Test
public void offsetsAndSizesValid() throws IOException {
SerializedFileHeader header = asset.header();
long fileSize = Files.size(readFile);
assertEquals("Header file size and actual file size must be equal", header.fileSize(), fileSize);
assertTrue("Data offset must be within file", header.dataOffset() < header.fileSize());
// allowing a difference of 3 bytes because of padding
assertEquals("Metadata sizes in data block and header must match", header.metadataSize(), asset.metadataBlock().length(), 3);
// check blocks
List<DataBlock> blocks = asset.dataBlocks();
blocks.forEach(block1 -> blocks.forEach(block2 -> {
if (block1 != block2) {
assertFalse("Blocks are overlapping: " + block1 + " / " + block2, block1.isIntersecting(block2));
}
}));
}
use of info.ata4.util.io.DataBlock in project disunity by ata4.
the class AssetBlocks method tableModel.
@Override
protected TableModel tableModel(SerializedFile serialized) {
Map<String, DataBlock> blocks = new LinkedHashMap<>();
blocks.put("Header", serialized.headerBlock());
blocks.put("Type Tree", serialized.metadata().typeTreeBlock());
blocks.put("Object Info", serialized.metadata().objectInfoBlock());
blocks.put("External Refs", serialized.metadata().externalsBlock());
blocks.put("Object Data", serialized.objectDataBlock());
TableBuilder table = new TableBuilder();
table.row("Name", "Offset", "Size");
blocks.entrySet().stream().sorted((e1, e2) -> Long.compare(e1.getValue().offset(), e2.getValue().offset())).forEach(e -> {
DataBlock block = e.getValue();
table.row(e.getKey(), block.offset(), block.length());
});
TableModel model = new TableModel("Blocks", table.get());
TextTableFormat format = model.format();
format.columnFormatter(1, Formatters::hex);
return model;
}
use of info.ata4.util.io.DataBlock in project disunity by ata4.
the class AssetUnpack method runSerializedFile.
@Override
protected void runSerializedFile(Path file, SerializedFile asset) {
try {
Path outputDir = PathUtils.removeExtension(file);
if (Files.isRegularFile(outputDir)) {
outputDir = PathUtils.append(outputDir, "_");
}
if (Files.notExists(outputDir)) {
Files.createDirectory(outputDir);
}
try (FileChannel fc = FileChannel.open(file)) {
DataBlock headerBlock = asset.headerBlock();
Path headerFile = outputDir.resolve("header.block");
copyBlock(headerBlock, headerFile, fc);
if (level > 0) {
DataBlock typeTreeBlock = asset.metadata().typeTreeBlock();
Path typeTreeFile = outputDir.resolve("type_tree.block");
copyBlock(typeTreeBlock, typeTreeFile, fc);
DataBlock objectInfoBlock = asset.metadata().objectInfoBlock();
Path objectInfoFile = outputDir.resolve("object_info.block");
copyBlock(objectInfoBlock, objectInfoFile, fc);
DataBlock objectIDBlock = asset.metadata().objectIDBlock();
if (objectIDBlock.length() > 0) {
Path objectIDFile = outputDir.resolve("object_ids.block");
copyBlock(objectIDBlock, objectIDFile, fc);
}
DataBlock fileIdentBlock = asset.metadata().externalsBlock();
Path fileIdentFile = outputDir.resolve("linked_files.block");
copyBlock(fileIdentBlock, fileIdentFile, fc);
} else {
DataBlock metadataBlock = asset.metadataBlock();
Path metadataFile = outputDir.resolve("metadata.block");
copyBlock(metadataBlock, metadataFile, fc);
}
if (level < 2) {
DataBlock objectDataBlock = asset.objectDataBlock();
Path objectDataFile = outputDir.resolve("object_data.block");
copyBlock(objectDataBlock, objectDataFile, fc);
}
}
if (level > 1) {
Path objectDataDir = outputDir.resolve("object_data");
if (Files.notExists(objectDataDir)) {
Files.createDirectory(objectDataDir);
}
for (SerializedObjectData od : asset.objectData()) {
String objectDataName = String.format("%010d", od.id());
Path objectDataFile = objectDataDir.resolve(objectDataName + ".block");
ByteBuffer objectDataBuffer = od.buffer();
objectDataBuffer.rewind();
ByteBufferUtils.save(objectDataFile, objectDataBuffer);
}
}
} catch (IOException ex) {
L.log(Level.WARNING, "Can't unpack asset file " + file, ex);
}
}
Aggregations