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 // Copyright (c) 2011 Andreas Moog 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 __LIBPAR2_H__ 21 #define __LIBPAR2_H__ 22 23 #include <sigc++/sigc++.h> 24 #include "par2cmdline.h" 25 26 class LibPar2 27 { 28 public: 29 LibPar2(CommandLine* commandline); 30 ~LibPar2(void); 31 32 Result PreProcess(); 33 Result Process(bool dorepair); 34 sigc::signal<void, std::string> sig_filename; 35 sigc::signal<void, double> sig_progress; 36 sigc::signal<void, ParHeaders*> sig_headers; 37 sigc::signal<void, std::string, int, int> sig_done; 38 39 protected: 40 void signal_filename(std::string str); 41 void signal_progress(double value); 42 void signal_headers(ParHeaders* headers); 43 void signal_done(std::string filename, int blocks_available, 44 int blocks_total); 45 46 protected: 47 CommandLine* commandLine; 48 Par1Repairer* par1Repairer; 49 Par2Repairer* par2Repairer; 50 51 // Steps in verifying and repairing files: 52 53 /* // Load packets from the specified file */ 54 /* bool LoadPacketsFromFile(string filename); */ 55 /* // Finish loading a recovery packet */ 56 /* bool LoadRecoveryPacket(DiskFile *diskfile, u64 offset, PACKET_HEADER &header); */ 57 /* // Finish loading a file description packet */ 58 /* bool LoadDescriptionPacket(DiskFile *diskfile, u64 offset, PACKET_HEADER &header); */ 59 /* // Finish loading a file verification packet */ 60 /* bool LoadVerificationPacket(DiskFile *diskfile, u64 offset, PACKET_HEADER &header); */ 61 /* // Finish loading the main packet */ 62 /* bool LoadMainPacket(DiskFile *diskfile, u64 offset, PACKET_HEADER &header); */ 63 /* // Finish loading the creator packet */ 64 /* bool LoadCreatorPacket(DiskFile *diskfile, u64 offset, PACKET_HEADER &header); */ 65 66 /* // Load packets from other PAR2 files with names based on the original PAR2 file */ 67 /* bool LoadPacketsFromOtherFiles(string filename); */ 68 69 /* // Load packets from any other PAR2 files whose names are given on the command line */ 70 /* bool LoadPacketsFromExtraFiles(const list<CommandLine::ExtraFile> &extrafiles); */ 71 72 /* // Check that the packets are consistent and discard any that are not */ 73 /* bool CheckPacketConsistency(void); */ 74 75 /* // Use the information in the main packet to get the source files */ 76 /* // into the correct order and determine their filenames */ 77 /* bool CreateSourceFileList(void); */ 78 79 /* // Determine the total number of DataBlocks for the recoverable source files */ 80 /* // The allocate the DataBlocks and assign them to each source file */ 81 /* bool AllocateSourceBlocks(void); */ 82 83 /* // Create a verification hash table for all files for which we have not */ 84 /* // found a complete version of the file and for which we have */ 85 /* // a verification packet */ 86 /* bool PrepareVerificationHashTable(void); */ 87 88 /* // Compute the table for the sliding CRC computation */ 89 /* bool ComputeWindowTable(void); */ 90 91 /* // Attempt to verify all of the source files */ 92 /* bool VerifySourceFiles(void); */ 93 94 /* // Scan any extra files specified on the command line */ 95 /* bool VerifyExtraFiles(const list<CommandLine::ExtraFile> &extrafiles); */ 96 97 /* // Attempt to match the data in the DiskFile with the source file */ 98 /* bool VerifyDataFile(DiskFile *diskfile, Par2RepairerSourceFile *sourcefile); */ 99 100 /* // Perform a sliding window scan of the DiskFile looking for blocks of data that */ 101 /* // might belong to any of the source files (for which a verification packet was */ 102 /* // available). If a block of data might be from more than one source file, prefer */ 103 /* // the one specified by the "sourcefile" parameter. If the first data block */ 104 /* // found is for a different source file then "sourcefile" is changed accordingly. */ 105 /* bool ScanDataFile(DiskFile *diskfile, // [in] The file being scanned */ 106 /* Par2RepairerSourceFile* &sourcefile, // [in/out] The source file matched */ 107 /* MatchType &matchtype, // [out] The type of match */ 108 /* MD5Hash &hashfull, // [out] The full hash of the file */ 109 /* MD5Hash &hash16k, // [out] The hash of the first 16k */ 110 /* u32 &count); // [out] The number of blocks found */ 111 112 /* // Find out how much data we have found */ 113 /* void UpdateVerificationResults(void); */ 114 115 /* // Check the verification results and report the results */ 116 /* bool CheckVerificationResults(void); */ 117 118 /* // Rename any damaged or missnamed target files. */ 119 /* bool RenameTargetFiles(void); */ 120 121 /* // Work out which files are being repaired, create them, and allocate */ 122 /* // target DataBlocks to them, and remember them for later verification. */ 123 /* bool CreateTargetFiles(void); */ 124 125 /* // Work out which data blocks are available, which need to be copied */ 126 /* // directly to the output, and which need to be recreated, and compute */ 127 /* // the appropriate Reed Solomon matrix. */ 128 /* bool ComputeRSmatrix(void); */ 129 130 /* // Allocate memory buffers for reading and writing data to disk. */ 131 /* bool AllocateBuffers(size_t memorylimit); */ 132 133 /* // Read source data, process it through the RS matrix and write it to disk. */ 134 /* bool ProcessData(u64 blockoffset, size_t blocklength); */ 135 136 /* // Verify that all of the reconstructed target files are now correct */ 137 /* bool VerifyTargetFiles(void); */ 138 139 /* // Delete all of the partly reconstructed files */ 140 /* bool DeleteIncompleteTargetFiles(void); */ 141 142 /* protected: */ 143 /* CommandLine::NoiseLevel noiselevel; // OnScreen display */ 144 145 /* string searchpath; // Where to find files on disk */ 146 147 /* bool firstpacket; // Whether or not a valid packet has been found. */ 148 /* MD5Hash setid; // The SetId extracted from the first packet. */ 149 150 /* map<u32, RecoveryPacket*> recoverypacketmap; // One recovery packet for each exponent value. */ 151 /* MainPacket *mainpacket; // One copy of the main packet. */ 152 /* CreatorPacket *creatorpacket; // One copy of the creator packet. */ 153 154 /* DiskFileMap diskFileMap; */ 155 156 /* map<MD5Hash,Par2RepairerSourceFile*> sourcefilemap;// Map from FileId to SourceFile */ 157 /* vector<Par2RepairerSourceFile*> sourcefiles; // The source files */ 158 /* vector<Par2RepairerSourceFile*> verifylist; // Those source files that are being repaired */ 159 160 /* u64 blocksize; // The block size. */ 161 /* u64 chunksize; // How much of a block can be processed. */ 162 /* u32 sourceblockcount; // The total number of blocks */ 163 /* u32 availableblockcount; // How many undamaged blocks have been found */ 164 /* u32 missingblockcount; // How many blocks are missing */ 165 166 /* bool blocksallocated; // Whether or not the DataBlocks have been allocated */ 167 /* vector<DataBlock> sourceblocks; // The DataBlocks that will be read from disk */ 168 /* vector<DataBlock> targetblocks; // The DataBlocks that will be written to disk */ 169 170 /* u32 windowtable[256]; // Table for sliding CRCs */ 171 /* u32 windowmask; // Maks for sliding CRCs */ 172 173 /* bool blockverifiable; // Whether and files can be verified at the block level */ 174 /* VerificationHashTable verificationhashtable; // Hash table for block verification */ 175 /* list<Par2RepairerSourceFile*> unverifiablesourcefiles; // Files that are not block verifiable */ 176 177 /* u32 completefilecount; // How many files are fully verified */ 178 /* u32 renamedfilecount; // How many files are verified but have the wrong name */ 179 /* u32 damagedfilecount; // How many files exist but are damaged */ 180 /* u32 missingfilecount; // How many files are completely missing */ 181 182 /* vector<DataBlock*> inputblocks; // Which DataBlocks will be read from disk */ 183 /* vector<DataBlock*> copyblocks; // Which DataBlocks will copied back to disk */ 184 /* vector<DataBlock*> outputblocks; // Which DataBlocks have to calculated using RS */ 185 186 /* ReedSolomon<Galois16> rs; // The Reed Solomon matrix. */ 187 188 /* void *inputbuffer; // Buffer for reading DataBlocks (chunksize) */ 189 /* void *outputbuffer; // Buffer for writing DataBlocks (chunksize * missingblockcount) */ 190 191 /* u64 progress; // How much data has been processed. */ 192 /* u64 totaldata; // Total amount of data to be processed. */ 193 /* }; */ 194 }; 195 196 197 #endif // __LIBPAR2_H__ 198