par2creatorsourcefile.h

Go to the documentation of this file.
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 // Modifications for concurrent processing, Unicode support, and hierarchial
00021 // directory support are Copyright (c) 2007-2008 Vincent Tan.
00022 // Search for "#if WANT_CONCURRENT" for concurrent code.
00023 // Concurrent processing utilises Intel Thread Building Blocks 2.0,
00024 // Copyright (c) 2007 Intel Corp.
00025 
00026 #ifndef __PAR2CREATORSOURCEFILE_H__
00027 #define __PAR2CREATORSOURCEFILE_H__
00028 
00029 class DescriptionPacket;
00030 class VerificationPacket;
00031 class DiskFile;
00032 
00033 // The Par2CreatorSourceFile contains the file verification and file description
00034 // packet for one source file.
00035 
00036 class Par2CreatorSourceFile
00037 {
00038 private:
00039   // Don't permit copying or assignment
00040   Par2CreatorSourceFile(const Par2CreatorSourceFile &other);
00041   Par2CreatorSourceFile& operator=(const Par2CreatorSourceFile &other);
00042 
00043 public:
00044   Par2CreatorSourceFile(void);
00045   ~Par2CreatorSourceFile(void);
00046 
00047   // Open the source file and compute the Hashes and CRCs.
00048   bool Open(CommandLine::NoiseLevel noiselevel, const CommandLine::ExtraFile &extrafile, u64 blocksize, bool deferhashcomputation
00049 #if WANT_CONCURRENT_PAR2_FILE_OPENING
00050             , tbb::mutex& cout_mutex, tbb::tick_count& last_cout
00051 #endif
00052                );
00053   void Close(void);
00054 
00055   // Recover the file description and file verification packets
00056   // in the critical packet list.
00057   void RecordCriticalPackets(list &criticalpackets);
00058 
00059   // Get the file id
00060   const MD5Hash& FileId(void) const;
00061 
00062   // Sort source files based on the file id hash
00063   static bool CompareLess(const Par2CreatorSourceFile* const &left, const Par2CreatorSourceFile* const &right);
00064 
00065   // Allocate the appropriate number of source blocks to the source file
00066   void InitialiseSourceBlocks(vector::iterator &sourceblock, u64 blocksize);
00067 
00068   // Update the file hash and the block crc and hashes
00069   void UpdateHashes(u32 blocknumber, const void *buffer, size_t length);
00070 
00071   // Finish computation of the file hash
00072   void FinishHashes(void);
00073 
00074   // How many blocks does this source file use
00075   u32 BlockCount(void) const {return blockcount;}
00076 
00077 protected:
00078   DescriptionPacket  *descriptionpacket;  // The file description packet.
00079   VerificationPacket *verificationpacket; // The file verification packet.
00080   DiskFile           *diskfile;           // The source file
00081 
00082   u64    filesize;      // The size of the source file.
00083   string diskfilename;  // The filename of the source file on disk.
00084   string parfilename;   // The filename that will be recorded in the file description packet.
00085 
00086   u32    blockcount;    // How many blocks the file will be divided into.
00087 
00088   MD5Context *contextfull; // MD5 context used to calculate the hash of the whole file
00089 };
00090 
00091 #endif // __PAR2CREATORSOURCEFILE_H__

Generated on Sun Oct 12 01:45:30 2008 for NNTPGrab by  1.5.4