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 __MAINPACKET_H__ 00021 #define __MAINPACKET_H__ 00022 00023 // The main packet ties all other critical packets together. 00024 // It specifies the block size to use for both verification of 00025 // files and for the Reed Solomon computation. 00026 // It also specifies how many of the source files are repairable 00027 // and in what order they should be processed. 00028 00029 class MainPacket : public CriticalPacket 00030 { 00031 public: 00032 // Construct the packet 00033 MainPacket(void) {}; 00034 ~MainPacket(void) {}; 00035 00036 public: 00037 // Construct the main packet from the source file list and block size. 00038 // "sourcefiles" will be sorted base on their FileId value. 00039 bool Create(vector&sourcefiles, 00040 u64 _blocksize); 00041 00042 // Load a main packet from a specified file 00043 bool Load(DiskFile *diskfile, u64 offset, PACKET_HEADER &header); 00044 00045 public: 00046 // Get the set id. 00047 const MD5Hash& SetId(void) const; 00048 00049 // Get the block size. 00050 u64 BlockSize(void) const; 00051 00052 // Get the file counts. 00053 u32 RecoverableFileCount(void) const; 00054 u32 TotalFileCount(void) const; 00055 00056 // Get the fileid of one file 00057 const MD5Hash& FileId(u32 filenumber) const; 00058 00059 protected: 00060 u64 blocksize; 00061 u32 totalfilecount; 00062 u32 recoverablefilecount; 00063 }; 00064 00065 // Get the data block size 00066 inline u64 MainPacket::BlockSize(void) const 00067 { 00068 assert(packetdata != 0); 00069 00070 return blocksize; 00071 } 00072 00073 // Get the number of recoverable files 00074 inline u32 MainPacket::RecoverableFileCount(void) const 00075 { 00076 assert(packetdata != 0); 00077 00078 return recoverablefilecount; 00079 } 00080 00081 // Get the total number of files 00082 inline u32 MainPacket::TotalFileCount(void) const 00083 { 00084 assert(packetdata != 0); 00085 00086 return totalfilecount; 00087 } 00088 00089 // Get the file id hash of one of the files 00090 inline const MD5Hash& MainPacket::FileId(u32 filenumber) const 00091 { 00092 assert(packetdata != 0); 00093 assert(filenumbertotalfilecount); 00094 00095 // return ((const MAINPACKET*)packetdata)->fileid()[filenumber]; 00096 return ((const MAINPACKET*)packetdata)->fileid[filenumber]; 00097 } 00098 00099 inline const MD5Hash& MainPacket::SetId(void) const 00100 { 00101 return ((const MAINPACKET*)packetdata)->header.setid; 00102 } 00103 00104 00105 #endif // __MAINPACKET_H__