public static FileVerificationPacket Create(PacketHeader header, byte[] bytes, int index) { FileVerificationPacket tmpPacket = new FileVerificationPacket(); tmpPacket.header = header; int offset = 0; Buffer.BlockCopy(bytes, index + offset, tmpPacket.fileid, 0, tmpPacket.fileid.Length * sizeof(byte)); offset += tmpPacket.fileid.Length * sizeof(byte); int nbEntries = ((int)header.length - header.GetSize() - (16 * sizeof(byte))) / FileVerificationEntry.GetSize(); tmpPacket.entries = new List <FileVerificationEntry>(); tmpPacket.blockcount = (ulong)((header.length - (ulong)tmpPacket.GetSize()) / (ulong)FileVerificationEntry.GetSize()); for (int i = 0; i < nbEntries; i++) { FileVerificationEntry entry = new FileVerificationEntry(); Buffer.BlockCopy(bytes, index + offset, entry.hash, 0, entry.hash.Length * sizeof(byte)); offset += entry.hash.Length * sizeof(byte); entry.crc = BitConverter.ToUInt32(bytes, index + offset); offset += sizeof(UInt32); tmpPacket.entries.Add(entry); } return(tmpPacket); }
// Create a packet large enough for the specified number of blocks internal static FileVerificationPacket Create(ulong _blockcount) { // Allocate a packet large enough to hold the required number of verification entries. FileVerificationPacket tmpPacket = new FileVerificationPacket(); tmpPacket.blockcount = _blockcount; // Record everything we know in the packet. tmpPacket.header = new PacketHeader(); tmpPacket.header.magic = Par2FileReader.packet_magic; tmpPacket.header.hash = new byte[16]; tmpPacket.header.setid = new byte[16]; tmpPacket.header.type = Par2FileReader.fileverificationpacket_type; tmpPacket.fileid = new byte[16]; tmpPacket.entries = new List <FileVerificationEntry>((int)_blockcount); tmpPacket.header.length = (ulong)tmpPacket.GetSize() + (_blockcount * (ulong)FileVerificationEntry.GetSize()); return(tmpPacket); }
public int GetSize() { return(header.GetSize() + 16 * sizeof(byte) + (entries.Count * FileVerificationEntry.GetSize())); }