1 // This file is part of par2cmdline (a PAR 2.0 compatible file verification and
2 // repair tool). See http://parchive.sourceforge.net for details of PAR 2.0.
3 //
4 // Copyright (c) 2003 Peter Brian Clements
5 //
6 // par2cmdline is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // par2cmdline is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19
20 #ifndef __VERIFICATIONPACKET_H__
21 #define __VERIFICATIONPACKET_H__
22
23 // The file verification packet stores details that allow individual blocks
24 // of valid data within a damaged file to be identified.
25
26 class VerificationPacket : public CriticalPacket
27 {
28 public:
29 // Construct the packet
VerificationPacket(void)30 VerificationPacket(void) {};
~VerificationPacket(void)31 ~VerificationPacket(void) {};
32
33 // Create a packet large enough for the specified number of blocks
34 bool Create(u32 blockcount);
35
36 // Set the fileid (computed from the file description packet).
37 void FileId(const MD5Hash &fileid);
38
39 // Set the block hash and block crc for a specific data block.
40 void SetBlockHashAndCRC(u32 blocknumber, const MD5Hash &hash, u32 crc);
41
42 // Load a verification packet from a specified file
43 bool Load(DiskFile *diskfile, u64 offset, PACKET_HEADER &header);
44
45 // Get the FileId
46 const MD5Hash& FileId(void) const;
47
48 // Get the block count
49 u32 BlockCount(void) const;
50
51 // Get a specific verification entry
52 const FILEVERIFICATIONENTRY* VerificationEntry(u32 blocknumber) const;
53
54 protected:
55 u32 blockcount;
56 };
57
FileId(void)58 inline const MD5Hash& VerificationPacket::FileId(void) const
59 {
60 assert(packetdata != 0);
61
62 return ((FILEVERIFICATIONPACKET*)packetdata)->fileid;
63 }
64
BlockCount(void)65 inline u32 VerificationPacket::BlockCount(void) const
66 {
67 assert(packetdata != 0);
68
69 return blockcount;
70 }
71
VerificationEntry(u32 blocknumber)72 inline const FILEVERIFICATIONENTRY* VerificationPacket::VerificationEntry(u32 blocknumber) const
73 {
74 assert(packetdata != 0);
75
76 // return &((FILEVERIFICATIONPACKET*)packetdata)->entries()[blocknumber];
77 return &((FILEVERIFICATIONPACKET*)packetdata)->entries[blocknumber];
78 }
79
80
81 #endif // __VERIFICATIONPACKET_H__
82