private static List <ModuleDataBlock> GetBlockList(ModuleEntryStruct data, ModuleStruct module) { var blocks = new List <ModuleDataBlock>(data.BlockCount); if (data.TotalCompressedSize == 0) { return(blocks); } if ((data.Flags & ModuleEntryFlags.HasBlocks) != 0) { for (var i = 0; i < data.BlockCount; i++) { var block = module.DataBlocks[data.FirstBlockIndex + i]; blocks.Add(new ModuleDataBlock(block)); } } else { // If an entry has 0 blocks, then make one var blockStruct = new ModuleDataBlockStruct { Checksum = data.AssetChecksum, CompressedOffset = 0, CompressedSize = data.TotalCompressedSize, Compression = (data.Flags & ModuleEntryFlags.Compressed) != 0 ? 1 : 0, UncompressedOffset = 0, UncompressedSize = data.TotalUncompressedSize, }; blocks.Add(new ModuleDataBlock(blockStruct)); } return(blocks); }
internal ModuleDataBlock(ModuleDataBlockStruct data) { Checksum = data.Checksum; CompressedOffset = data.CompressedOffset; CompressedSize = data.CompressedSize; UncompressedOffset = data.UncompressedOffset; UncompressedSize = data.UncompressedSize; IsCompressed = data.Compression != 0; }
public void TestReadingDummyCompressedBlock() { var block = new ModuleDataBlockStruct(); using (var serializer = new BinarySerializer(new BinaryReader(new MemoryStream(DummyBlockBytes)))) { block.Serialize(serializer); Assert.AreEqual(DummyBlockBytes.Length, serializer.BaseStream.Position); } Assert.AreEqual(1U, block.Checksum); Assert.AreEqual(2U, block.CompressedOffset); Assert.AreEqual(3U, block.CompressedSize); Assert.AreEqual(4U, block.UncompressedOffset); Assert.AreEqual(5U, block.UncompressedSize); Assert.AreEqual(6, block.Compression); }
public void TestWritingDummyCompressedBlock() { var block = new ModuleDataBlockStruct { Checksum = 1, CompressedOffset = 2, CompressedSize = 3, UncompressedOffset = 4, UncompressedSize = 5, Compression = 6, }; byte[] writtenBytes; using (var stream = new MemoryStream()) { using (var serializer = new BinarySerializer(new BinaryWriter(stream))) { block.Serialize(serializer); writtenBytes = new byte[stream.Length]; Buffer.BlockCopy(stream.GetBuffer(), 0, writtenBytes, 0, writtenBytes.Length); } } CollectionAssert.AreEqual(DummyBlockBytes, writtenBytes); }