]> Creatis software - creaImageIO.git/blob - src/creaImageIOTreeHandlerImageAdder.cpp
f51ef14c816a299a222309a2b04eb3d08101d713
[creaImageIO.git] / src / creaImageIOTreeHandlerImageAdder.cpp
1 #include <creaImageIOTreeHandlerImageAdder.h>
2 #include <creaImageIOSystem.h>
3 #include <boost/filesystem.hpp>
4 #include <boost/algorithm/string.hpp>
5 #include <boost/utility.hpp>
6
7
8 namespace fs = boost::filesystem;
9 using boost::filesystem::path;
10 using boost::next;
11 using boost::prior;
12
13
14 using namespace crea;
15 using namespace boost;
16
17 namespace creaImageIO
18 {
19   //====================================================================
20   // Ctor
21   TreeHandlerImageAdder::TreeHandlerImageAdder(TreeHandler* tree)
22     : mTreeHandler(tree)
23   {
24   }
25   // Dtor
26   TreeHandlerImageAdder::~TreeHandlerImageAdder()
27   {
28   }
29   //====================================================================
30
31   //====================================================================
32   void TreeHandlerImageAdder::ConnectProgressObserver(ProgressCallbackType callback)
33   {
34     mProgressSignal.connect(callback);
35   }
36   //====================================================================
37
38   //=====================================================================
39   bool TreeHandlerImageAdder::IsHandledFile( const std::string& filename)
40   {
41     return (mReader.CanRead(filename));
42   }
43   //=====================================================================
44
45   //=====================================================================
46   void TreeHandlerImageAdder::AddFiles( const std::vector<std::string>& filenames)
47   {
48     mProgress.Reset();
49         
50     unsigned int nbf = filenames.size(); 
51     std::vector<std::string>::const_iterator i;
52         mSynchronizer->GetList(mCurrentDB);
53     for (i=filenames.begin();i!=filenames.end();++i)
54       {
55         
56         mProgress.IncNumberScannedFiles();
57         if (IsHandledFile(*i)) 
58           {
59             mProgress.IncNumberHandledFiles();
60                 if(mSynchronizer->isIndexed(*i))
61                 {
62                         mSynchronizer->InsertAddOp((*i),"0","1",mCurrentDB);
63                         std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",(*i),mCurrentDB);
64                         std::stringstream removedOn;
65                         removedOn<<time(0);
66                         mSynchronizer->InsertIgnoreFile(addKey,(*i),"0",removedOn.str(),mCurrentDB);
67                         AddFile(*i);
68                 }
69           }
70         mProgressSignal(mProgress);
71         if (mProgress.GetStop()) break;
72       }
73   }
74   //=====================================================================
75
76   //=====================================================================
77   void TreeHandlerImageAdder::AddDirectory( const std::string& directory,
78                                             bool recurse)
79   {
80     mProgress.Reset();
81         std::stringstream files;
82         
83         std::stringstream rec;
84         rec<<recurse;
85         mSynchronizer->InsertAddOp(directory,rec.str(),"0",mCurrentDB);
86         std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB);
87         mTreeHandler->BeginTransaction();
88         mSynchronizer->GetList(mCurrentDB);
89         AddDirectoryRecursor( directory, recurse, addKey );
90         //DicomImageScanner sc;
91         //AddDirectoryRecursorScanner(directory, recurse, addKey, sc, false );
92         
93         int nFiles=GetProgress().GetNumberAddedFiles();
94         files<<nFiles;
95         mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",files.str(),"ADD_KEY",addKey,mCurrentDB);
96         mTreeHandler->EndTransaction();
97     GimmickDebugMessage(3,mProgress<<std::endl);
98   }
99
100   //=====================================================================
101   void TreeHandlerImageAdder::AddFile( const std::string& filename )
102   {
103     GimmickDebugMessage(4,"Adding '"<<filename<<"'"<<std::endl);
104     std::map< std::string, std::string>  attr;
105     mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
106
107         
108     mReader.ReadAttributes(filename,attr);
109         //// TO DO Create a function to test if the SOP Instance ID (0008,0018) is not already on DB
110         //// test befor if this attr is present on DB if not don't perform the test!!!
111         //bool bSOPIID = false;
112         //std::map<std::string, std::string>::iterator it_att = attr.begin();
113         //for(; it_att != attr.end(); it_att++)
114         //{
115         //      if (it_att->first == "D0008_0018")
116         //      {
117         //              bSOPIID = mTreeHandler->TestSOPIID(it_attr->second);
118         //              break;
119         //      }
120         //}
121         //if(bSOPIID)
122         //      return;
123
124     int lev = mTreeHandler->AddBranch(attr);
125
126     // update the progress according to lev
127     if (lev<mTreeHandler->GetTree().GetNumberOfLevels())
128       mProgress.IncNumberAddedFiles();
129   }
130   //=====================================================================
131
132   void TreeHandlerImageAdder::RemoveFile( tree::Node* node)
133   {
134                 int n=node->GetNumberOfChildren();
135                 if(n>0)
136                 {
137                         RemoveFiles(node->GetChildrenList());
138                 }
139                 else
140                 {
141                   std::string path=node->GetAttribute("FullFileName");
142                   //Gets the add key
143                   std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB);
144                   //Gets the number of files added
145                   int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str());
146                   files=files-1;
147                   std::stringstream out;
148                   out<<files;
149                   //Sets the new number of files
150                   mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey,mCurrentDB);
151                   //Sets the file as removed
152                   mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",addKey,mCurrentDB);
153                 }
154   }
155
156   //=====================================================================
157
158   void TreeHandlerImageAdder::RemoveFiles(const std::vector<tree::Node*>& nodes)
159   {
160           std::vector<tree::Node*>::const_iterator it;
161           for(it=nodes.begin();it!=nodes.end();++it)
162           {
163                 int n=(*it)->GetNumberOfChildren();
164                 if(n>0)
165                 {
166                         RemoveFiles((*it)->GetChildrenList());
167                 }
168                 else
169                 {
170                    std::string path=(*it)->GetAttribute("FullFileName");
171                   //Gets the add key
172                   std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB);
173                   //Gets the number of files added
174                   int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str());
175                   files=files-1;
176                   std::stringstream out;
177                   out<<files;
178                   //Sets the new number of files
179                   mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey,mCurrentDB);
180                   //Sets the file as removed
181                   mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",addKey,mCurrentDB);
182                 }
183         
184           }
185   }
186
187  
188   
189   //=======================================================================
190     //=====================================================================
191 #if defined(USE_GDCM2)
192  
193   void TreeHandlerImageAdder::AddDirectoryRecursorScanner(const std::string &dirpath, 
194                                                    bool recursive,const std::string &addKey, DicomImageScanner i_sc, bool b_loaded)
195   {
196     GimmickDebugMessage(4,"Scanning '"<<dirpath<<"'"<<std::endl);
197     mProgress.IncNumberScannedDirs();
198
199     if ( !fs::exists( dirpath ) ) return;
200         time_t lastModif=fs::last_write_time(dirpath);
201
202                         
203         
204                 std::map< std::string, std::string>  attr;
205                 mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
206                 std::string path = dirpath.c_str();
207                 i_sc.addDirectory(path, attr);
208         
209
210     fs::directory_iterator end_itr; // default construction yields past-the-end
211     for ( fs::directory_iterator itr( dirpath );
212           itr != end_itr;
213           ++itr )
214         {
215         
216                 // If is directory & recurse : do recurse
217         if ( fs::is_directory(itr->status()) )
218           {
219             if (recursive) 
220                 {
221                         AddDirectoryRecursorScanner( itr->string(), recursive, addKey, i_sc, true);
222                 }
223           }
224         else 
225           {
226                 std::string parent_id;
227                 // tTest if directory (and only it) exists or not.
228                 bool valid = mSynchronizer->isIndexed(itr->string());//true;//=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0),mCurrentDB);
229                 if(valid)
230                 {
231
232                         mProgress.IncNumberScannedFiles();
233                         boost::algorithm::replace_all( itr->string(),
234                                     INVALID_FILE_SEPARATOR , 
235                                    VALID_FILE_SEPARATOR);
236                         i_sc.ReadAttributes(itr->string(),attr);
237                         mTreeHandler->GetTopLevelNodeId("FullFileName",itr->string(),parent_id);
238                         mTreeHandler->AddBranch(attr);
239                         mProgress.IncNumberHandledFiles();
240                         std::stringstream removedOn;
241                         removedOn<<time(0);
242                         mSynchronizer->InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str(),mCurrentDB);
243
244                         
245                         mProgressSignal(mProgress);
246                         if (mProgress.GetStop()) 
247                         {
248                         //itr = end_itr;
249                         break;
250                         }
251                 }
252                         
253                 }
254         }
255         }
256 #endif
257  //=====================================================================
258   void TreeHandlerImageAdder::AddDirectoryRecursor(const std::string &dirpath, 
259                                                    bool recursive,
260                                                    const std::string &addKey)
261   {
262     GimmickDebugMessage(4,"Scanning '"<<dirpath<<"'"<<std::endl);
263     mProgress.IncNumberScannedDirs();
264
265     if ( !fs::exists( dirpath ) ) return;
266         time_t lastModif=fs::last_write_time(dirpath);
267
268         
269     fs::directory_iterator end_itr; // default construction yields past-the-end
270     for ( fs::directory_iterator itr( dirpath );
271           itr != end_itr;
272           ++itr )
273         {
274         // If is directory & recurse : do recurse
275         if ( fs::is_directory(itr->status()) )
276           {
277             if (recursive) 
278                 {
279                         AddDirectoryRecursor( itr->string(), recursive, addKey);
280                 }
281           }
282         else 
283           {
284                 std::string parent_id;
285                 // tTest if directory (and only it) exists or not.
286                 bool valid = mSynchronizer->isIndexed(itr->string());//true;//=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0),mCurrentDB);
287                 if(valid)
288                 {
289                         mProgress.IncNumberScannedFiles();
290                         if (IsHandledFile(itr->string()))
291                         {
292                         mProgress.IncNumberHandledFiles();
293                         AddFile( itr->string() );
294                         mTreeHandler->GetTopLevelNodeId("FullFileName",itr->string(),parent_id);
295                         std::stringstream removedOn;
296                         removedOn<<time(0);
297                         mSynchronizer->InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str(),mCurrentDB);
298                         }
299                         
300                         mProgressSignal(mProgress);
301                         if (mProgress.GetStop()) 
302                         {
303                         //itr = end_itr;
304                         break;
305                         }
306                         
307                 }
308           }
309       }
310         
311   }
312   //=======================================================================
313   
314
315   //=======================================================================
316
317   void TreeHandlerImageAdder::CheckSyncDirectory(const std::string &dirpath, 
318                                                                                                 bool recursive, 
319                                                                                                 bool repair,
320                                                                                                 bool checkAttributes,
321                                                                                                 std::vector<std::string> &i_ignorefiles,
322                                                                                                 std::vector<std::string> & attsModified,
323                                                                                                 std::vector<std::string> & newfiles)
324   {
325     if ( !fs::exists( dirpath ) ) return;
326     fs::directory_iterator end_itr; // default construction yields past-the-end
327                           
328     for ( fs::directory_iterator itr( dirpath ); itr != end_itr; ++itr ) 
329         {
330         // If is directory & recurse : do recurse
331         if ( fs::is_directory(itr->status()) )
332         {
333             if (recursive)
334                         {
335                 CheckSyncDirectory( itr->string(), recursive, repair, checkAttributes, i_ignorefiles, attsModified, newfiles);
336                         }
337         }
338         else
339         {
340             if (IsHandledFile(itr->string()))
341             {
342                 bool bfound = false;
343                 for(std::vector<std::string>::iterator it_new = i_ignorefiles.begin(); it_new < i_ignorefiles.end(); ++it_new)
344                 {
345                                         if((*it_new) == itr->string())
346                     {
347                         bfound = true;
348                                                 //Additional checking of attributes
349                                                 if(checkAttributes)
350                                                 {
351                                                         CheckAttributes(repair,(*it_new),attsModified);
352                                                 }
353                         i_ignorefiles.erase(it_new);
354                         break;
355                     }
356                                 }
357                                 if(!bfound && i_ignorefiles.size()>0 )
358                 {
359                     newfiles.push_back( itr->string() );
360                 }
361                         }
362                 }
363          }
364   } 
365
366   //=======================================================================
367   
368   //=======================================================================
369
370   std::string TreeHandlerImageAdder::Synchronize(bool repair, bool checkAttributes)
371   {
372           std::vector<AddList> fileList;
373           std::vector<std::string> ignoreList;
374           std::vector<std::string> newFiles;
375           std::vector<std::string> attsModified;
376           std::stringstream mess;
377           std::vector<AddList>::iterator iter;
378
379           //Gets the list of added files
380           mSynchronizer->GetFileList(fileList,mCurrentDB);
381
382           std::vector<std::string>::iterator i;
383           //Actions to take if the user doesn't want to repair
384           if(!repair)
385           {
386                 //Iterates to see if they are in sync
387                 for(iter=fileList.begin();iter!=fileList.end();++iter)
388                 {
389                         mSynchronizer->GetIgnoredFiles((*iter).key,ignoreList);
390                         bool rec=true;
391                         if((*iter).recursive=="0"){rec=false;}
392                         CheckSyncDirectory((*iter).path,rec,repair,checkAttributes,ignoreList,attsModified,newFiles);
393                 }
394
395                 //Add to message the result of new found files
396                 mess<<"New Files Found: "<<newFiles.size()<<std::endl;
397                 if(newFiles.size()>0)
398                 {
399                         mess<<"Filenames: "<<std::endl;
400                         for(i=newFiles.begin();i!=newFiles.end();++i)
401                         {
402                                 mess<<*i<<std::endl;
403                         }
404                 }
405
406                 //Add to message the result of missing files
407                 mess<<"Missing Files: "<<ignoreList.size()<<std::endl;
408                 if(ignoreList.size()>0)
409                 {
410                         mess<<"Filenames: "<<std::endl;
411                         for(i=ignoreList.begin();i!=ignoreList.end();++i)
412                         {
413                                 mess<<*i<<std::endl;
414                         }
415                 }
416
417                 //In the case that the user wants to check the attributes...
418                 if(checkAttributes)
419                 {
420                         //... add to message the result of files that have been changed.
421                         mess<<"Files with different attributes: "<<attsModified.size()<<std::endl;
422                         if(attsModified.size()>0)
423                         {
424                                 mess<<"Filenames: "<<std::endl;
425                                 for(i=attsModified.begin();i!=attsModified.end();++i)
426                                 {
427                                         mess<<*i<<std::endl;
428                                 }
429                         }
430                 }
431                 
432           }
433
434           //Actions to take if the user wants to repair
435           else
436           {
437                   int nf=0;
438                 //Iterates to see if they are in sync
439                 for(iter=fileList.begin();iter!=fileList.end();++iter)
440                 {
441                         mSynchronizer->GetIgnoredFiles((*iter).key,ignoreList);
442                         bool rec=true;
443                         if((*iter).recursive=="0"){rec=false;}
444                         CheckSyncDirectory((*iter).path,rec,repair,checkAttributes,ignoreList,attsModified,newFiles);
445
446                         //For the new files, add them
447                         for (i=newFiles.begin();i!=newFiles.end();++i)
448                         {
449                         if (IsHandledFile(*i)) 
450                         {
451                                 std::stringstream removedOn;
452                                 removedOn<<time(0);
453                                 mSynchronizer->InsertIgnoreFile((*iter).key,(*i),"0",removedOn.str(),mCurrentDB);
454                                 //Gets the number of files added
455                                 int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",(*iter).key,mCurrentDB)).c_str());
456                                 files=files+1;
457                                 std::stringstream out;
458                                 out<<files;
459                                 //Sets the new number of files
460                                 mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",(*iter).key,mCurrentDB);
461                                 AddFile(*i);
462                         }
463                         }
464                         nf+=newFiles.size();
465                         newFiles.clear();
466
467                 }
468                 //Reports number of added files
469                 mess<<"Files Added: "<<nf<<std::endl;
470                 
471                 //Removes the necessary files and reports the results
472                 if(ignoreList.size()>0)
473                 {
474                         tree::Node* node;
475                         mTreeHandler->LoadChildren(NULL,4);
476                         for(i=ignoreList.begin();i!=ignoreList.end();++i)
477                         {
478                                 FindNode(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",*i,node);
479                                 RemoveFile(node);
480                                 mTreeHandler->Remove(node);
481                         }
482                 }
483                 mess<<"Files Removed: "<<ignoreList.size()<<std::endl;
484                 //In the case that the user wants to check the attributes...
485                 if(checkAttributes)
486                 {
487                         //... add to message the result of files that were modified.
488                         mess<<"Files Modified: "<<attsModified.size()<<std::endl;
489                 }
490           }
491           return mess.str();
492
493   }
494   //=======================================================================
495
496   void TreeHandlerImageAdder::CheckAttributes(bool repair, std::string& file, std::vector<std::string>& attsModified)
497   {
498           std::map< std::string, std::string>  attr;
499           mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
500       mReader.ReadAttributes(file,attr);
501           tree::LevelDescriptor::AttributeDescriptorListType adl= mTreeHandler->GetTree().GetAttributeDescriptorList(mTreeHandler->GetTree().GetNumberOfLevels()-1);    
502           tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
503           for (a = adl.begin();a!=adl.end();++a)
504           {
505            std::string databaseVal;
506            mTreeHandler->GetAttribute("Image","FullFileName",file,a->GetKey(),databaseVal);
507            std::string fileVal=attr.find(a->GetKey())->second;
508            if ( a->GetFlags()==0 && databaseVal == fileVal) 
509             {
510                         if(repair)
511                         {
512                                 mTreeHandler->SetAttribute("Image",a->GetKey(),fileVal,"FullFileName", file);   
513                         }
514                         attsModified.push_back(file);
515             }
516                 
517           }
518           
519   }
520
521   //=======================================================================
522
523
524   void TreeHandlerImageAdder::FindNode(tree::Node* parent, int level, const std::string& searchParam, const std::string& searchVal, tree::Node*& node)
525   {
526           if(level>1)
527           {
528                   std::vector<tree::Node*>::iterator iter;
529                   for(iter=parent->GetChildrenList().begin();iter!=parent->GetChildrenList().end();++iter)
530                   {
531                           FindNode(*iter,level-1,searchParam,searchVal,node);
532                   }
533           }
534           else
535           {
536                   if(parent->GetAttribute(searchParam).compare(searchVal)==0)
537                   {
538                           node=parent;
539                   }
540
541           }
542   }
543   
544   void TreeHandlerImageAdder::SaveAs(const std::vector<std::string>& filenames, std::vector<vtkImageData *> i_images)
545   {
546           std::vector<std::string>::const_iterator it_file = filenames.begin();
547           std::vector<vtkImageData *>::iterator it_image = i_images.begin();
548         /*  mWriter.CanWrite(".jpeg");
549           for(; it_file != filenames.end(); ++it_file, ++it_image)
550                   mWriter.WriteImage(it_file->c_str(), (vtkImageData &)it_image);*/
551   }
552
553   //=======================================================================
554   void TreeHandlerImageAdder::FindNodePartial(tree::Node* parent, int level, const std::string& searchParam, const std::string& searchVal, tree::Node*& node)
555   {
556           if(level>1)
557           {
558                   std::vector<tree::Node*>::iterator iter;
559                   for(iter=parent->GetChildrenList().begin();iter!=parent->GetChildrenList().end() && node==0 ;++iter)
560                   {
561                           FindNodePartial(*iter,level-1,searchParam,searchVal,node);
562                   }
563           }
564           else
565           {
566                   if(parent->GetAttribute(searchParam).find(searchVal)<9000)
567                   {
568                           node=parent;
569                           return;
570                   }
571
572           }
573   }
574   
575   //=======================================================================
576
577   void TreeHandlerImageAdder::CopyFiles(const std::vector<std::string>& filenames, const std::string directory  )
578   {
579           std::vector<std::string>::const_iterator i;
580           if(!boost::filesystem::exists(directory))
581           {
582           boost::filesystem::create_directory(boost::filesystem::path(directory));
583           mSynchronizer->InsertAddOp(directory,"0","0",mCurrentDB);
584           }
585           std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB);
586           size_t last;
587           std::vector<std::string> newNames;
588           for(i=filenames.begin();i!=filenames.end();++i)
589           {
590                   std::string dir=directory.c_str();
591                   if(boost::filesystem::exists(*i) && (*i).find(dir)==std::string::npos)
592                   {
593                   std::string path=*i;
594                   last=(*i).find_last_of('/');
595                   std::string f="\\"+(*i).substr(last+1);
596         
597                   int p=1;
598                   std::stringstream out;
599                   out<<directory<<f;
600                   while(boost::filesystem::exists(out.str()))
601                   {
602                           out.str("");
603                           out<<directory<<f.substr(0,f.size()-4)<<"("<<p<<")"<<f.substr(f.size()-4);
604                           p++;
605                   }
606                   std::string result=out.str();
607                   boost::filesystem::copy_file((*i),result);
608
609                   //To update image database
610                   mTreeHandler->SetAttribute("Image","FullFileName",result,"FullFileName", (*i));
611                   
612                   //To update maintenance database
613                   //1.Add the new path and increase number of children on new operation.
614                   std::stringstream removedOn;
615                   removedOn<<time(0);
616                   //Inserts the file
617                   mSynchronizer->InsertIgnoreFile(addKey, result,"0",removedOn.str(),mCurrentDB);
618                   //Gets the number of files added
619                   int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str());
620                   files=files+1;
621                   std::stringstream fil;
622                   fil<<files;
623                   //Sets the new number of files
624                   mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",fil.str(),"ADD_KEY",addKey,mCurrentDB);
625                   fil.str("");
626
627                   //2.Set the old path as removed and decrease number of children on old operation.
628                   //Gets the old add key
629                   std::string oldAddKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB);
630                   //Sets the file as removed
631                   mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",oldAddKey,mCurrentDB);
632                   //Gets the number of files added
633                   files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",oldAddKey,mCurrentDB)).c_str());
634                   files=files-1;
635                   fil<<files;
636                   //Sets the new number of files
637                   mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",fil.str(),"ADD_KEY",oldAddKey,mCurrentDB);
638                   
639                   }
640
641           }
642   }
643
644   //=======================================================================
645
646   void TreeHandlerImageAdder::DeleteDriveFromMainDB(const std::string& drive)
647   {
648           //Delete from local database and others
649           tree::Node* node=0;
650           mTreeHandler->LoadChildren(NULL,4);
651           FindNodePartial(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",drive,node);
652           while(node!=0)
653           {
654           mTreeHandler->Remove(node);
655           node=0;
656           mTreeHandler->LoadChildren(NULL,4);
657           FindNodePartial(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",drive,node); 
658           }
659   }
660
661    //=======================================================================
662
663   void TreeHandlerImageAdder::DeleteDriveFromOtherDB(const std::string& drive)
664   {
665           //Delete from maintenance
666           mSynchronizer->RemoveEntries("ADD_OPS", "PATH", "LIKE", drive+"%");
667           mSynchronizer->RemoveEntries("IGNORED_FILES", "PATH", "LIKE", drive+"%");
668   }
669
670   //=======================================================================
671   void TreeHandlerImageAdder::EditField(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
672   {
673           node->SetAttribute(key,val);
674           mTreeHandler->SetAttribute(node,key,val);
675   }
676
677   //=======================================================================
678   void TreeHandlerImageAdder::GetAttributes(const std::vector<std::string>& params, 
679           const std::string& filename, 
680           std::vector<std::string>& results)
681   {
682           std::vector<std::string>::const_iterator i;
683           std::string result;
684           for(i=params.begin();i!=params.end();i++)
685           {
686                   mTreeHandler->GetAttribute("Image","FullFileName",filename,*i,result);
687                   results.push_back(result);
688           }
689   }
690
691  
692 }