00001 00002 #ifndef ORG_PROGGEN_DEDUPE_KERNELINTERFACE 00003 #define ORG_PROGGEN_DEDUPE_KERNELINTERFACE 00004 00005 #include <fileinfo.h> 00006 #include <hash.h> 00007 #include <dataholding.h> 00008 #include <boost/function.hpp> 00009 #include <boost/bind.hpp> 00010 00011 00012 namespace Dedupe 00013 { 00014 namespace Core 00015 { 00016 00021 class HandleDuplicates 00022 { 00023 protected: 00024 int value; 00025 Dedupe::FilePath LinkToFile; 00026 00027 public: 00028 00029 HandleDuplicates( const int Handle ): value ( Handle ) {} 00030 00031 const int operator()(void ) const {return value;} 00032 00037 inline HandleDuplicates operator= ( const int given ) 00038 { 00039 value = given; 00040 return *this; 00041 } 00042 00043 inline bool operator==( const int rhs ) 00044 { 00045 return (this->value == rhs); 00046 } 00047 00052 inline bool SetLinkPath( Dedupe::FilePath Path ) 00053 { 00054 if( value != 4 ) return false; 00055 00056 LinkToFile = Path; 00057 return true; 00058 } 00059 00060 inline Dedupe::FilePath GetLinkPath() 00061 { 00062 return LinkToFile; 00063 } 00064 00065 static int const Empty = 0; 00066 static int const Keep = 1; 00067 static int const MarkAsKeep = 2; 00068 static int const Delete = 3; 00069 static int const LinkTo = 4; 00070 static int const Error = 5; 00071 }; 00072 00076 typedef std::vector<Dedupe::FileInfo> DuplicateGroup; 00077 00082 typedef std::vector<DuplicateGroup> Duplicates; 00083 00089 typedef std::pair<Dedupe::FilePath, HandleDuplicates> DuplicateHandle; 00090 00095 typedef std::vector<DuplicateHandle> FilesToProcess; 00096 00097 class Kernel 00098 { 00099 public: 00100 00101 Kernel( Dedupe::FilePath DatabaseLocation, size_t Threads, std::ostream &Messages ); 00102 00107 void TrackFiles( Dedupe::FilePaths const &Paths , bool recursiv ); 00108 00113 void ListDatabase(); 00114 00119 Dedupe::FileStream GetDatabase(); 00120 00125 void UntrackFiles( Dedupe::FilePaths const &Paths, bool recursiv ); 00126 00133 Duplicates FindHashDuplicates(); 00134 00141 Duplicates FindHashDuplicatesExtern( Dedupe::FilePaths, 00142 bool recursiv ); 00143 00150 Duplicates FindFilenameDuplicates(); 00151 00158 Duplicates FindFilenameDuplicatesExtern( Dedupe::FilePaths, 00159 bool recursiv ); 00166 Duplicates FindFilesizeDuplicates(); 00167 00174 Duplicates FindFilesizeDuplicatesExtern( Dedupe::FilePaths, 00175 bool recursiv ); 00176 00183 Duplicates FindFiledateDuplicates(); 00184 00191 Duplicates FindFiledateDuplicatesExtern( Dedupe::FilePaths, 00192 bool recursiv ); 00193 00199 void ProcessDuplicates( FilesToProcess Dups ); 00200 00205 void AutoUpdateDatabase(); 00206 00213 void QuitKernel( bool &AmIDead ); 00214 00215 private: 00216 00217 void AddFile( Dedupe::FileInfo &Info ); 00218 00219 void FileAndDirectoryHandlerToFunction( Dedupe::FilePaths const &Paths, 00220 bool recursiv, 00221 boost::function<void ( Dedupe::FileInfo& )>Function ); 00222 00223 Dedupe::FileStream FileAndDirectoryHandler( Dedupe::FilePaths const &Paths, 00224 bool recursiv); 00225 00226 void Threadcontroller( std::function<void(Dedupe::FileInfo&)> Func, Dedupe::FileStream &stream ); 00227 00228 Duplicates FindDuplicates( Dedupe::FileStream Files, 00229 std::function<bool(Dedupe::FileInfo, Dedupe::FileInfo)>SortFunc, 00230 std::function<bool(Dedupe::FileInfo, Dedupe::FileInfo)> EqualFunc); 00231 00232 Duplicates FindExternDuplicates( Dedupe::FilePaths Paths, 00233 bool recursiv, 00234 std::function<bool(Dedupe::FileInfo, Dedupe::FileInfo)>SortFunc, 00235 std::function<bool(Dedupe::FileInfo, Dedupe::FileInfo)> EqualFunc); 00236 00237 Dedupe::Dataholding::Dataholding Database; 00238 size_t Threadcount; 00239 Dedupe::FileSearch::SearchFiles Searcher; 00240 Dedupe::Hash::Hash64 Hasher; 00241 00242 std::ostream &MessageOut; 00243 00244 }; 00245 00246 } 00247 } 00248 00249 #endif