30 #include <boost/filesystem.hpp>
31 #include <boost/algorithm/string.hpp>
32 #include <boost/utility.hpp>
35 namespace fs = boost::filesystem;
36 using boost::filesystem::path;
42 using namespace boost;
48 TreeHandlerImageAdder::TreeHandlerImageAdder(
TreeHandler* tree)
78 std::vector<std::string>::const_iterator i;
80 for (i=filenames.begin();i!=filenames.end();++i)
91 std::stringstream removedOn;
108 std::stringstream files;
110 std::stringstream rec;
131 std::map< std::string, std::string> attr;
154 if (lev<mTreeHandler->GetTree().GetNumberOfLevels())
176 std::vector<tree::Node*>::const_iterator it;
177 for(it=nodes.begin();it!=nodes.end();++it)
179 int n=(*it)->GetNumberOfChildren();
201 std::stringstream out;
212 #if defined(USE_GDCM2)
214 void TreeHandlerImageAdder::AddDirectoryRecursorScanner(
const std::string &dirpath,
220 if ( !fs::exists( dirpath ) )
return;
221 time_t lastModif=fs::last_write_time(dirpath);
225 std::map< std::string, std::string> attr;
227 std::string path = dirpath.c_str();
231 fs::directory_iterator end_itr;
232 for ( fs::directory_iterator itr( dirpath );
238 if ( fs::is_directory(itr->status()) )
242 AddDirectoryRecursorScanner( itr->path().string(), recursive, addKey, i_sc,
true);
247 std::string parent_id;
252 std::string path(itr->path().string());
259 std::stringstream removedOn;
279 const std::string &addKey)
284 if ( !fs::exists( dirpath ) )
return;
287 time_t lastModif=fs::last_write_time(dirpath);
289 fs::directory_iterator end_itr;
290 for ( fs::directory_iterator itr( dirpath );
295 if ( fs::is_directory(itr->status()) )
304 std::string parent_id;
313 AddFile( itr->path().string() );
315 std::stringstream removedOn;
340 bool checkAttributes,
341 std::vector<std::string> &i_ignorefiles,
342 std::vector<std::string> & attsModified,
343 std::vector<std::string> & newfiles)
345 if ( !fs::exists( dirpath ) )
return;
346 fs::directory_iterator end_itr;
348 for ( fs::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
351 if ( fs::is_directory(itr->status()) )
355 CheckSyncDirectory( itr->path().string(), recursive, repair, checkAttributes, i_ignorefiles, attsModified, newfiles);
363 for(std::vector<std::string>::iterator it_new = i_ignorefiles.begin(); it_new < i_ignorefiles.end(); ++it_new)
365 if((*it_new) == itr->path().string())
373 i_ignorefiles.erase(it_new);
377 if(!bfound && i_ignorefiles.size()>0 )
379 newfiles.push_back( itr->path().string() );
392 std::vector<AddList> fileList;
393 std::vector<std::string> ignoreList;
394 std::vector<std::string> newFiles;
395 std::vector<std::string> attsModified;
396 std::stringstream mess;
397 std::vector<AddList>::iterator iter;
402 std::vector<std::string>::iterator i;
407 for(iter=fileList.begin();iter!=fileList.end();++iter)
411 if((*iter).recursive==
"0"){rec=
false;}
412 CheckSyncDirectory((*iter).path,rec,repair,checkAttributes,ignoreList,attsModified,newFiles);
416 mess<<
"New Files Found: "<<newFiles.size()<<std::endl;
417 if(newFiles.size()>0)
419 mess<<
"Filenames: "<<std::endl;
420 for(i=newFiles.begin();i!=newFiles.end();++i)
427 mess<<
"Missing Files: "<<ignoreList.size()<<std::endl;
428 if(ignoreList.size()>0)
430 mess<<
"Filenames: "<<std::endl;
431 for(i=ignoreList.begin();i!=ignoreList.end();++i)
441 mess<<
"Files with different attributes: "<<attsModified.size()<<std::endl;
442 if(attsModified.size()>0)
444 mess<<
"Filenames: "<<std::endl;
445 for(i=attsModified.begin();i!=attsModified.end();++i)
459 for(iter=fileList.begin();iter!=fileList.end();++iter)
463 if((*iter).recursive==
"0"){rec=
false;}
464 CheckSyncDirectory((*iter).path,rec,repair,checkAttributes,ignoreList,attsModified,newFiles);
467 for (i=newFiles.begin();i!=newFiles.end();++i)
471 std::stringstream removedOn;
477 std::stringstream out;
484 nf+=(int)newFiles.size();
489 mess<<
"Files Added: "<<nf<<std::endl;
492 if(ignoreList.size()>0)
496 for(i=ignoreList.begin();i!=ignoreList.end();++i)
503 mess<<
"Files Removed: "<<ignoreList.size()<<std::endl;
508 mess<<
"Files Modified: "<<attsModified.size()<<std::endl;
518 std::map< std::string, std::string> attr;
522 tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
523 for (a = adl.begin();a!=adl.end();++a)
525 std::string databaseVal;
527 std::string fileVal=attr.find(a->GetKey())->second;
528 if ( a->GetFlags()==0 && databaseVal == fileVal)
534 attsModified.push_back(file);
548 std::vector<tree::Node*>::iterator iter;
551 FindNode(*iter,level-1,searchParam,searchVal,node);
556 if(parent->
GetAttribute(searchParam).compare(searchVal)==0)
566 std::vector<std::string>::const_iterator it_file = filenames.begin();
567 std::vector<vtkImageData *>::iterator it_image = i_images.begin();
578 std::vector<tree::Node*>::iterator iter;
586 if(parent->
GetAttribute(searchParam).find(searchVal)<9000)
599 std::vector<std::string>::const_iterator i;
600 if(!boost::filesystem::exists(directory))
602 boost::filesystem::create_directory(boost::filesystem::path(directory));
607 std::vector<std::string> newNames;
608 for(i=filenames.begin();i!=filenames.end();++i)
610 std::string dir=directory.c_str();
611 if(boost::filesystem::exists(*i) && (*i).find(dir)==std::string::npos)
614 last=(*i).find_last_of(
'/');
615 std::string f=
"\\"+(*i).substr(last+1);
618 std::stringstream out;
620 while(boost::filesystem::exists(out.str()))
623 out<<directory<<f.substr(0,f.size()-4)<<
"("<<p<<
")"<<f.substr(f.size()-4);
626 std::string result=out.str();
627 boost::filesystem::copy_file((*i),result);
634 std::stringstream removedOn;
641 std::stringstream fil;
699 const std::string& filename,
700 std::vector<std::string>& results)
702 std::vector<std::string>::const_iterator i;
704 for(i=params.begin();i!=params.end();i++)
707 results.push_back(result);