00001 // This file is part of par2cmdline (a PAR 2.0 compatible file verification and 00002 // repair tool). See https://parchive.sourceforge.net for details of PAR 2.0. 00003 // 00004 // Copyright (c) 2003 Peter Brian Clements 00005 // 00006 // par2cmdline is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 2 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // par2cmdline is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 #ifndef __DESCRIPTIONPACKET_H__ 00021 #define __DESCRIPTIONPACKET_H__ 00022 00023 // The description packet records details about a file (including its name, 00024 // size, and the Hash of both the whole file and the first 16k of the file). 00025 00026 class DescriptionPacket : public CriticalPacket 00027 { 00028 public: 00029 // Construct the packet 00030 DescriptionPacket(void) {}; 00031 ~DescriptionPacket(void) {}; 00032 00033 public: 00034 // Construct the packet and store the filename and size. 00035 bool Create(string _filename, u64 _filesize); 00036 00037 // Store the computed Hash values in the packet. 00038 void Hash16k(const MD5Hash &hash); 00039 void HashFull(const MD5Hash &hash); 00040 00041 // Compute and return the file id hash from information in the packet 00042 void ComputeFileId(void); 00043 const MD5Hash& FileId(void) const; 00044 00045 // Return the size of the file 00046 u64 FileSize(void) const; 00047 00048 public: 00049 // Load a description packet from a specified file 00050 bool Load(DiskFile *diskfile, u64 offset, PACKET_HEADER &header); 00051 00052 // Return the name of the file 00053 string FileName(void) const; 00054 00055 // Get the Hash values from the packet 00056 const MD5Hash& HashFull(void) const; 00057 const MD5Hash& Hash16k(void) const; 00058 }; 00059 00060 // Get the file id from the packet 00061 inline const MD5Hash& DescriptionPacket::FileId(void) const 00062 { 00063 assert(packetdata != 0); 00064 00065 return ((const FILEDESCRIPTIONPACKET*)packetdata)->fileid; 00066 } 00067 00068 // Get the size of the file from the packet 00069 inline u64 DescriptionPacket::FileSize(void) const 00070 { 00071 assert(packetdata != 0); 00072 00073 return ((const FILEDESCRIPTIONPACKET*)packetdata)->length; 00074 } 00075 00076 // Get the name of the file from the packet 00077 // NB whilst the file format does not guarantee that the name will have a NULL 00078 // termination character, par2cmdline always allocates a little extra data 00079 // and fills it with NULLs to allow the filename to be directly read out of 00080 // the packet. 00081 inline string DescriptionPacket::FileName(void) const 00082 { 00083 assert(packetdata != 0); 00084 00085 // return (char*)((const FILEDESCRIPTIONPACKET*)packetdata)->name(); 00086 return (char*)((const FILEDESCRIPTIONPACKET*)packetdata)->name; 00087 } 00088 00089 // Get the full file hash value from the packet 00090 inline const MD5Hash& DescriptionPacket::HashFull(void) const 00091 { 00092 assert(packetdata != 0); 00093 00094 return ((const FILEDESCRIPTIONPACKET*)packetdata)->hashfull; 00095 } 00096 00097 // The the hash of the first 16k of the file from the packet 00098 inline const MD5Hash& DescriptionPacket::Hash16k(void) const 00099 { 00100 assert(packetdata != 0); 00101 00102 return ((const FILEDESCRIPTIONPACKET*)packetdata)->hash16k; 00103 } 00104 00105 #endif // __DESCRIPTIONPACKET_H__