commandline.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 __COMMANDLINE_H__
00027 #define __COMMANDLINE_H__
00028 
00029 // The CommandLine object is responsible for understanding the format
00030 // of the command line parameters are parsing the command line to
00031 // extract details as to what the user wants to do.
00032 
00033 class CommandLine
00034 {
00035   static CommandLine* sInstance;
00036 
00037 public:
00038   static CommandLine* get(void);
00039   static string FileOrPathForCout(const string& path);
00040 
00041 
00042   CommandLine(void);
00043   ~CommandLine(void);
00044 
00045   // Parse the supplied command line arguments. 
00046   bool Parse(int argc, TCHAR *argv[]);
00047 
00048   // Display details of the correct format for command line parameters.
00049   static void usage(void);
00050 
00051   // What operation will we be carrying out
00052   typedef enum
00053   {
00054     opNone = 0,
00055     opCreate,        // Create new PAR2 recovery volumes
00056     opVerify,        // Verify but don't repair damaged data files
00057     opRepair         // Verify and if possible repair damaged data files
00058   } Operation;
00059 
00060   typedef enum
00061   {
00062     verUnknown = 0,
00063     verPar1,         // Processing PAR 1.0 files
00064     verPar2          // Processing PAR 2.0 files
00065   } Version;
00066 
00067   typedef enum
00068   {
00069     scUnknown = 0,
00070     scVariable,      // Each PAR2 file will have 2x as many blocks as previous
00071     scLimited,       // Limit PAR2 file size
00072     scUniform        // All PAR2 files the same size
00073   } Scheme;
00074 
00075   typedef enum
00076   {
00077     nlUnknown = 0,
00078     nlSilent,       // Absolutely no output (other than errors)
00079     nlQuiet,        // Bare minimum of output
00080     nlNormal,       // Normal level of output
00081     nlNoisy,        // Lots of output
00082     nlDebug         // Extra debugging information
00083   } NoiseLevel;
00084 
00085   // Any extra files listed on the command line
00086   class ExtraFile
00087   {
00088   public:
00089     ExtraFile(void);
00090     ExtraFile(const ExtraFile&);
00091     ExtraFile& operator=(const ExtraFile&);
00092 
00093     ExtraFile(const string &name, u64 size);
00094 
00095     string FileName(void) const {return filename;}
00096     u64 FileSize(void) const {return filesize;}
00097 
00098   protected:
00099     string filename;
00100     u64    filesize;
00101   };
00102 
00103 public:
00104   // Accessor functions for the command line parameters
00105 
00106   CommandLine::Operation GetOperation(void) const {return operation;}
00107   CommandLine::Version   GetVersion(void) const {return version;}
00108   u64                    GetBlockSize(void) const {return blocksize;}
00109   u32                    GetBlockCount(void) const {return blockcount;}
00110   u32                    GetRedundancy(void) const {return redundancy;}
00111   u32                    GetFirstRecoveryBlock(void) const {return firstblock;}
00112   u32                    GetRecoveryFileCount(void) const {return recoveryfilecount;}
00113   u32                    GetRecoveryBlockCount(void) const {return recoveryblockcount;}
00114   CommandLine::Scheme    GetRecoveryFileScheme(void) const {return recoveryfilescheme;}
00115   size_t                 GetMemoryLimit(void) const {return memorylimit;}
00116   u64                    GetLargestSourceSize(void) const {return largestsourcesize;}
00117   u64                    GetTotalSourceSize(void) const {return totalsourcesize;}
00118   CommandLine::NoiseLevel GetNoiseLevel(void) const {return noiselevel;}
00119 
00120   // 2007/10/21 for hierarchial support:
00121   const string&          GetBaseDirectory(void) const {return base_directory;}
00122 
00123 #if WANT_CONCURRENT
00124   unsigned               GetConcurrentProcessingLevel(void) const { return concurrent_processing_level; }
00125 #endif
00126 
00127   string                              GetParFilename(void) const {return parfilename;}
00128   const list& GetExtraFiles(void) const {return extrafiles;}
00129 
00130 protected:
00131   Operation operation;         // The operation to be carried out.
00132   Version version;             // What version files will be processed.
00133 
00134   NoiseLevel noiselevel;       // How much display output should there be.
00135 
00136   u32 blockcount;              // How many blocks the source files should 
00137                                // be virtually split into.
00138 
00139   u64 blocksize;               // What virtual block size to use.
00140 
00141   u32 firstblock;              // What the exponent value for the first
00142                                // recovery block will be.
00143 
00144   Scheme recoveryfilescheme;   // How the the size of the recovery files should
00145                                // be calculated.
00146 
00147   u32 recoveryfilecount;       // How many recovery files should be created.
00148 
00149   u32 recoveryblockcount;      // How many recovery blocks should be created.
00150   bool recoveryblockcountset;  // Set if the recoveryblockcount as been specified
00151 
00152   u32 redundancy;              // What percentage of recovery data should
00153                                // be created.
00154   bool redundancyset;          // Set if the redundancy has been specified
00155 
00156   string parfilename;          // The name of the PAR2 file to create, or
00157                                // the name of the first PAR2 file to read
00158                                // when verifying or repairing.
00159 
00160   list extrafiles;  // The list of other files specified on the
00161                                // command line. When creating, this will be
00162                                // the source files, and when verifying or
00163                                // repairing, this will be additional PAR2
00164                                // files or data files to be examined.
00165 
00166   u64 totalsourcesize;         // Total size of the source files.
00167 
00168   u64 largestsourcesize;       // Size of the largest source file.
00169 
00170   size_t memorylimit;          // How much memory is permitted to be used
00171                                // for the output buffer when creating
00172                                // or repairing.
00173 
00174   // 2007/10/21 - added this to support hierarchial repair (eg, to protect a
00175   // hierarchy of folders of jpg files)
00176 
00177   // if non-empty then this is the base directory for paths stored in par2
00178   // files to support hierarchial repair
00179   string base_directory;
00180 
00181 #if WANT_CONCURRENT
00182   // although it is possible to specify how many threads that TBB should
00183   // use, that functionality is not implemented (and the TBB documentation
00184   // recommends not using it in production code), so this is merely a bool:
00185   unsigned concurrent_processing_level; // whether to process serially or concurrently
00186 #endif
00187 };
00188 
00189 typedef list::const_iterator ExtraFileIterator;
00190 
00191 #endif // __COMMANDLINE_H__

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