internal static RecoveryPacket Create(DiskFile diskFile, ulong offset, ulong blocksize, uint exponent, byte[] setid) { RecoveryPacket tmpPacket = new RecoveryPacket(); // Fill in the details the we know tmpPacket.header = new PacketHeader(); tmpPacket.header.magic = Par2FileReader.packet_magic; tmpPacket.header.hash = new byte[16]; // Compute later tmpPacket.header.setid = setid; tmpPacket.header.type = Par2FileReader.recoveryblockpacket_type; tmpPacket.diskfile = diskFile; tmpPacket.offset = (int)offset; tmpPacket.exponent = exponent; //tmpPacket.length = 0; // tmpPacket.header.length = (ulong)(tmpPacket.header.GetSize() + sizeof(UInt32) + (int)blocksize); tmpPacket.length = (int)tmpPacket.header.length; // Start computation of the packet hash tmpPacket.packetcontext = MD5.Create(); using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { // PacketHeader section bw.Write(tmpPacket.header.setid); bw.Write(tmpPacket.header.type); //Packet section bw.Write(tmpPacket.exponent); byte[] buffer = ms.ToArray(); tmpPacket.packetcontext.TransformBlock(buffer, 0, buffer.Length, null, 0); } } // Set the data block to immediatly follow the header on disk tmpPacket.datablock = new DataBlock(); tmpPacket.datablock.SetLocation(tmpPacket.diskfile, (ulong)(tmpPacket.offset + tmpPacket.GetSize())); tmpPacket.datablock.SetLength(blocksize); return tmpPacket; }
internal static RecoveryPacket Create(DiskFile diskFile, ulong offset, ulong blocksize, uint exponent, byte[] setid) { RecoveryPacket tmpPacket = new RecoveryPacket(); // Fill in the details the we know tmpPacket.header = new PacketHeader(); tmpPacket.header.magic = Par2FileReader.packet_magic; tmpPacket.header.hash = new byte[16]; // Compute later tmpPacket.header.setid = setid; tmpPacket.header.type = Par2FileReader.recoveryblockpacket_type; tmpPacket.diskfile = diskFile; tmpPacket.offset = (int)offset; tmpPacket.exponent = exponent; //tmpPacket.length = 0; // tmpPacket.header.length = (ulong)(tmpPacket.header.GetSize() + sizeof(UInt32) + (int)blocksize); tmpPacket.length = (int)tmpPacket.header.length; // Start computation of the packet hash tmpPacket.packetcontext = MD5.Create(); using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { // PacketHeader section bw.Write(tmpPacket.header.setid); bw.Write(tmpPacket.header.type); //Packet section bw.Write(tmpPacket.exponent); byte[] buffer = ms.ToArray(); tmpPacket.packetcontext.TransformBlock(buffer, 0, buffer.Length, null, 0); } } // Set the data block to immediatly follow the header on disk tmpPacket.datablock = new DataBlock(); tmpPacket.datablock.SetLocation(tmpPacket.diskfile, (ulong)(tmpPacket.offset + tmpPacket.GetSize())); tmpPacket.datablock.SetLength(blocksize); return(tmpPacket); }