00001
00009 #include "cli.h"
00010
00011 namespace bpo = boost::program_options;
00012
00013 Dedupe::CLI::Cli::Cli( int ac, char* av[],
00014 Dedupe::Core::Kernel &RunningKernel,
00015 std::ostream &Message )
00016 :Kernel( RunningKernel ),
00017 MessageOut( Message ),
00018 OpDesc( "Program Options" ),
00019 VarMap( ),
00020 Recursive( false ),
00021 SupressUpdate( false ),
00022 AddValues( ),
00023 DelValues( ),
00024 DupByHash(),
00025 DupByFilename(),
00026 DupByFilesize(),
00027 DupByFiledate(),
00028 Outputfile( "" ),
00029 Inputfile( "")
00030 {
00031
00032 bpo::options_description General( "General Options");
00033 General.add_options()
00034 ( "help,h", "Show the help text")
00035 ( "version,V", "Show program version")
00036 ( "verbose,v", "Enable verbose mode(NOT IMPLEMENTED)")
00037 ( "no-dbs-update,s",
00038 "Disable automatic update of database on programcall");
00039
00040
00041
00042 bpo::options_description Operating( "Operation Options");
00043 Operating.add_options()
00044
00045 ( "track,t",
00046 bpo::value<Dedupe::FilePaths>( &AddValues ),
00047 "Add a file to the tracked files")
00048
00049 ( "list,l", "List all files that are stored in the database" )
00050
00051 ( "untrack,d",
00052 bpo::value<Dedupe::FilePaths>( &DelValues ),
00053 "Delete a file from the tracked files")
00054
00055 ( "find-hash-duplicates,H",
00056 bpo::value<Dedupe::FilePaths>( &DupByHash )->multitoken()->zero_tokens(),
00057 "Find duplicates by hash and start userinterface. If you give a path,\
00058 duplicates are searched directly in the directories without database")
00059
00060 ( "find-filename-duplicates,F",
00061 bpo::value<Dedupe::FilePaths>( &DupByFilename )->multitoken()->zero_tokens(),
00062 "Find duplicates by filename and start userinterface. If you give a path,\
00063 duplicates are searched directly in the directories without database")
00064
00065 ( "find-filesize-duplicates,S",
00066 bpo::value<Dedupe::FilePaths>( &DupByFilesize )->multitoken()->zero_tokens(),
00067 "Find duplicates by filesize and start userinterface. If you give a path,\
00068 duplicates are searched directly in the directories without database")
00069
00070 ( "find-filedate-duplicates,D",
00071 bpo::value<Dedupe::FilePaths>( &DupByFiledate)->multitoken()->zero_tokens(),
00072 "Find duplicates by filedate and start userinterface. If you give a path,\
00073 duplicates are searched directly in the directories without database")
00074
00075
00076 ( "output-file,o",
00077 bpo::value<Dedupe::FilePath>( &Outputfile ),
00078 "Set Outputfile" )
00079
00080 ("process-duplicates,p", bpo::value<Dedupe::FilePath>(&Inputfile ),
00081 "Give File with decided Duplicates back to process them ")
00082
00083 ( "update-database,u", "Update the database manually")
00084
00085 ( "recursive,r", "Enable recursive");
00086
00087
00088
00089 bpo::positional_options_description PosDesc;
00090 PosDesc.add( "track", -1 );
00091
00092
00093 OpDesc.add( General ) .add( Operating );
00094
00095
00096 bpo::store(boost::program_options::command_line_parser( ac, av )
00097 .options( OpDesc )
00098 .positional( PosDesc )
00099 .run() , VarMap );
00100 }
00101
00102 void Dedupe::CLI::Cli::Run()
00103 {
00104 bpo::notify(VarMap);
00105
00106 if( VarMap.count ( "recursive" ) ) Recursive = true;
00107 if( VarMap.count( "help" ) ) MessageOut << OpDesc << std::endl;
00108 if( VarMap.count ( "version" ) ) MessageOut << "ALPHA 4" << std::endl;
00109 if( VarMap.count ( "no-dbs-update")) SupressUpdate = true;
00110
00111 if( VarMap.count ("track" ) )
00112 {
00113
00114
00115 if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
00116 Kernel.TrackFiles( AddValues, Recursive );
00117 }
00118
00119 if( VarMap.count ( "list" ) )
00120 {
00121 if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
00122 Kernel.ListDatabase();
00123 }
00124
00125 if( VarMap.count ( "untrack" ) )
00126 {
00127 if( !SupressUpdate) Kernel.AutoUpdateDatabase();
00128 Kernel.UntrackFiles( DelValues, Recursive );
00129 }
00130
00131 if( VarMap.count ( "find-hash-duplicates") )
00132 {
00133 Dedupe::CLI::UI Userinterface( MessageOut );
00134
00135
00136 if( DupByHash.size() > 0 )
00137 {
00138 Userinterface.SetTitle( "Founded Duplicats by Hash(Extern)" );
00139 Userinterface.WriteDuplicatesToFile(
00140 Kernel.FindHashDuplicatesExtern( DupByHash, Recursive ),
00141 Outputfile );
00142 }
00143
00144 else
00145 {
00146 if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
00147 Userinterface.SetTitle( "Founded Duplicats by Hash(Intern)" );
00148 Userinterface.WriteDuplicatesToFile(
00149 Kernel.FindHashDuplicates(), Outputfile );
00150 }
00151 }
00152
00153 if( VarMap.count( "find-filename-duplicates" ))
00154 {
00155 Dedupe::CLI::UI Userinterface( MessageOut );
00156
00157
00158 if( DupByFilename.size() > 0 )
00159 {
00160 Userinterface.SetTitle( "Founded Duplicats by Filename(Extern)" );
00161 Userinterface.WriteDuplicatesToFile(
00162 Kernel.FindFilenameDuplicatesExtern( DupByFilename, Recursive ),
00163 Outputfile );
00164 }
00165
00166 else
00167 {
00168 if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
00169 Userinterface.SetTitle( "Founded Duplicats by Filename(Intern)" );
00170 Userinterface.WriteDuplicatesToFile(
00171 Kernel.FindFilenameDuplicates(), Outputfile );
00172 }
00173 }
00174
00175 if( VarMap.count( "find-filesize-duplicates" ))
00176 {
00177 Dedupe::CLI::UI Userinterface( MessageOut );
00178
00179
00180 if( DupByFilesize.size() > 0 )
00181 {
00182 Userinterface.SetTitle( "Founded Duplicats by Filesize(Extern)" );
00183 Userinterface.WriteDuplicatesToFile(
00184 Kernel.FindFilesizeDuplicatesExtern( DupByFilesize, Recursive ),
00185 Outputfile );
00186 }
00187
00188 else
00189 {
00190 if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
00191 Userinterface.SetTitle( "Founded Duplicats by Filesize(Intern)" );
00192 Userinterface.WriteDuplicatesToFile(
00193 Kernel.FindFilesizeDuplicates(), Outputfile );
00194 }
00195 }
00196
00197 if( VarMap.count( "find-filedate-duplicates" ))
00198 {
00199 Dedupe::CLI::UI Userinterface( MessageOut );
00200
00201
00202 if( DupByFiledate.size() > 0 )
00203 {
00204 Userinterface.SetTitle( "Founded Duplicats by Filedate(Extern)" );
00205 Userinterface.WriteDuplicatesToFile(
00206 Kernel.FindFiledateDuplicatesExtern( DupByFiledate, Recursive ),
00207 Outputfile );
00208 }
00209
00210 else
00211 {
00212 if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
00213 Userinterface.SetTitle( "Founded Duplicats by Filedate(Intern)" );
00214 Userinterface.WriteDuplicatesToFile(
00215 Kernel.FindFiledateDuplicates(), Outputfile );
00216 }
00217 }
00218
00219 if( VarMap.count( "process-duplicates"))
00220 {
00221 Dedupe::CLI::UI Userinterface( MessageOut );
00222 Userinterface.ReadDecidedDuplicatesFromFile( Inputfile );
00223 }
00224
00225 if( VarMap.count( "update-database") ) Kernel.AutoUpdateDatabase();
00226 }