X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=inline;f=src2%2FcreaImageIOTreeHandlerImageAdder.cpp;h=a6b073764818e4508cbad6240554ba7f47dadbce;hb=b029354f54449e058d14c671e7155e65b4086de6;hp=22c727b87d83ae02b21b47dbff5e85d6646baa66;hpb=be812877eb9dfa9b921df4f6d88df98af73328c3;p=creaImageIO.git diff --git a/src2/creaImageIOTreeHandlerImageAdder.cpp b/src2/creaImageIOTreeHandlerImageAdder.cpp index 22c727b..a6b0737 100644 --- a/src2/creaImageIOTreeHandlerImageAdder.cpp +++ b/src2/creaImageIOTreeHandlerImageAdder.cpp @@ -50,16 +50,16 @@ namespace creaImageIO std::vector::const_iterator i; for (i=filenames.begin();i!=filenames.end();++i) { - mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0)); + mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0),mCurrentDB); mProgress.IncNumberScannedFiles(); if (IsHandledFile(*i)) { mProgress.IncNumberHandledFiles(); - mSynchronizer->InsertAddOp((*i),"0","1"); - std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",(*i)); + mSynchronizer->InsertAddOp((*i),"0","1",mCurrentDB); + std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",(*i),mCurrentDB); std::stringstream removedOn; removedOn<InsertIgnoreFile(addKey,(*i),"0",removedOn.str()); + mSynchronizer->InsertIgnoreFile(addKey,(*i),"0",removedOn.str(),mCurrentDB); AddFile(*i); } mProgressSignal(mProgress); @@ -77,13 +77,15 @@ namespace creaImageIO std::stringstream rec; rec<InsertAddOp(directory,rec.str(),"0"); - std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory); + mSynchronizer->InsertAddOp(directory,rec.str(),"0",mCurrentDB); + std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB); + mTreeHandler->BeginTransaction(); AddDirectoryRecursor( directory, recurse, addKey ); int nFiles=GetProgress().GetNumberAddedFiles(); files<SetAttribute("FILES_ADDED","ADD_OPS",files.str(),"ADD_KEY",addKey); + mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",files.str(),"ADD_KEY",addKey,mCurrentDB); + mTreeHandler->EndTransaction(); GimmickDebugMessage(3,mProgress<GetAttribute("FullFileName"); //Gets the add key - std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path); + std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB); //Gets the number of files added - int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey)).c_str()); + int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str()); files=files-1; std::stringstream out; out<SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey); + mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey,mCurrentDB); //Sets the file as removed - mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH",path); + mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",addKey,mCurrentDB); } } @@ -144,16 +146,16 @@ namespace creaImageIO { std::string path=(*it)->GetAttribute("FullFileName"); //Gets the add key - std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path); + std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB); //Gets the number of files added - int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey)).c_str()); + int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str()); files=files-1; std::stringstream out; out<SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey); + mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey,mCurrentDB); //Sets the file as removed - mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH",path); + mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",addKey,mCurrentDB); } } @@ -186,7 +188,7 @@ namespace creaImageIO else { std::string parent_id; - bool valid=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0)); + bool valid=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0),mCurrentDB); if(valid) { mProgress.IncNumberScannedFiles(); @@ -198,14 +200,16 @@ namespace creaImageIO mTimestampHandler->SetAttribute("TopLevelNodeId",parent_id,"PATH",itr->string()); std::stringstream removedOn; removedOn<InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str()); + mSynchronizer->InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str(),mCurrentDB); } + mProgressSignal(mProgress); if (mProgress.GetStop()) { //itr = end_itr; break; } + } mTimestampHandler->SetAttribute("TopLevelNodeId",parent_id,"PATH",dirpath); } @@ -279,7 +283,7 @@ namespace creaImageIO std::vector::iterator iter; //Gets the list of added files - mSynchronizer->GetFileList(fileList); + mSynchronizer->GetFileList(fileList,mCurrentDB); std::vector::iterator i; //Actions to take if the user doesn't want to repair @@ -348,19 +352,19 @@ namespace creaImageIO //For the new files, add them for (i=newFiles.begin();i!=newFiles.end();++i) { - mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0)); + mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0),mCurrentDB); if (IsHandledFile(*i)) { std::stringstream removedOn; removedOn<InsertIgnoreFile((*iter).key,(*i),"0",removedOn.str()); + mSynchronizer->InsertIgnoreFile((*iter).key,(*i),"0",removedOn.str(),mCurrentDB); //Gets the number of files added - int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",(*iter).key)).c_str()); + int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",(*iter).key,mCurrentDB)).c_str()); files=files+1; std::stringstream out; out<SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",(*iter).key); + mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",(*iter).key,mCurrentDB); AddFile(*i); } } @@ -445,7 +449,142 @@ namespace creaImageIO } //======================================================================= + void TreeHandlerImageAdder::FindNodePartial(tree::Node* parent, int level, const std::string& searchParam, const std::string& searchVal, tree::Node*& node) + { + if(level>1) + { + std::vector::iterator iter; + for(iter=parent->GetChildrenList().begin();iter!=parent->GetChildrenList().end() && node==0 ;++iter) + { + FindNodePartial(*iter,level-1,searchParam,searchVal,node); + } + } + else + { + if(parent->GetAttribute(searchParam).find(searchVal)<9000) + { + node=parent; + return; + } + } + } + + //======================================================================= + + void TreeHandlerImageAdder::CopyFiles(const std::vector& filenames, const std::string directory ) + { + std::vector::const_iterator i; + if(!boost::filesystem::exists(directory)) + { + boost::filesystem::create_directory(boost::filesystem::path(directory)); + mTimestampHandler->AddDirectory("",directory,fs::last_write_time(directory)+10, time(0),mCurrentDB); + mSynchronizer->InsertAddOp(directory,"0","0",mCurrentDB); + } + std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB); + std::string parent_id=mTimestampHandler->IsIndexed(directory,mCurrentDB); + size_t last; + std::vector newNames; + for(i=filenames.begin();i!=filenames.end();++i) + { + std::string dir=directory.c_str(); + mTimestampHandler->CleanPath(dir); + if(boost::filesystem::exists(*i) && (*i).find(dir)==std::string::npos) + { + std::string path=*i; + last=(*i).find_last_of('/'); + std::string f="\\"+(*i).substr(last+1); + + int p=1; + std::stringstream out; + out<CleanPath(result); + boost::filesystem::copy_file((*i),result); + + //To update image database + mTreeHandler->SetAttribute("Image","FullFileName",result,"FullFileName", (*i)); + + //To update timestamp database + mTimestampHandler->SetAttribute("PATH",result,"PATH",(*i)); + mTimestampHandler->SetAttribute("PARENT_ID",parent_id,"PATH",result); + std::stringstream t; + t<SetAttribute("LastModified",t.str(),"PATH",result); + + //To update maintenance database + //1.Add the new path and increase number of children on new operation. + std::stringstream removedOn; + removedOn<InsertIgnoreFile(addKey, result,"0",removedOn.str(),mCurrentDB); + //Gets the number of files added + int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str()); + files=files+1; + std::stringstream fil; + fil<SetAttribute("FILES_ADDED","ADD_OPS",fil.str(),"ADD_KEY",addKey,mCurrentDB); + fil.str(""); + + //2.Set the old path as removed and decrease number of children on old operation. + //Gets the old add key + std::string oldAddKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB); + //Sets the file as removed + mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",oldAddKey,mCurrentDB); + //Gets the number of files added + files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",oldAddKey,mCurrentDB)).c_str()); + files=files-1; + fil<SetAttribute("FILES_ADDED","ADD_OPS",fil.str(),"ADD_KEY",oldAddKey,mCurrentDB); + + } + + } + } + + //======================================================================= + + void TreeHandlerImageAdder::DeleteDriveFromMainDB(const std::string& drive) + { + //Delete from local database and others + tree::Node* node=0; + mTreeHandler->LoadChildren(NULL,4); + FindNodePartial(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",drive,node); + while(node!=0) + { + mTreeHandler->Remove(node); + node=0; + mTreeHandler->LoadChildren(NULL,4); + FindNodePartial(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",drive,node); + } + } + + //======================================================================= + + void TreeHandlerImageAdder::DeleteDriveFromOtherDB(const std::string& drive) + { + //Delete from timestamp + mTimestampHandler->RemoveEntries("FILES", "PATH", "LIKE", drive+"%"); + + //Delete from maintenance + mSynchronizer->RemoveEntries("ADD_OPS", "PATH", "LIKE", drive+"%"); + mSynchronizer->RemoveEntries("IGNORED_FILES", "PATH", "LIKE", drive+"%"); + } + + //======================================================================= + void TreeHandlerImageAdder::EditField(tree::Node* node, const std::string& name, const std::string& key, const std::string& val) + { + node->SetAttribute(key,val); + mTreeHandler->SetAttribute(node,key,val); + } }