1 #include <creaImageIOSystem.h>
2 #include <creaImageIOSynchronizer.h>
3 #include "boost/filesystem.hpp"
5 namespace fs = boost::filesystem;
10 //==============================================================
11 Synchronizer::Synchronizer(TreeHandler * th)
16 //==============================================================
18 //==============================================================
19 Synchronizer::~Synchronizer()
23 //==============================================================
25 //==============================================================
26 std::string Synchronizer::Synchronize(bool update)
28 GimmickMessage(1,"Synchronizing "<<std::endl);
30 std::stringstream mess;
32 mHandler->GetAttribute("Image","","","FullFileName",file);
35 while(fin<file.size()-1)
37 fin=file.find('#',ini);
38 SynchronizeFile(update,file.substr(ini,fin-ini),mess);
43 mess<<"Database up to date"<<std::endl;
45 GimmickMessage(1,mess.str());
48 //==============================================================
50 //==============================================================
51 void Synchronizer::SynchronizeFile(bool update, std::string file, std::stringstream& mess)
57 mHandler->DeleteTuple("Image","FullFileName",file);
58 mess<<file<<" has been removed from the DB"<<std::endl;
62 mess<<file<<" State: Non existant"<<std::endl;
67 AttributesMatch(update,file,mess);
70 //==============================================================
72 //==============================================================
73 bool Synchronizer::FileExists(std::string file)
75 GimmickDebugMessage(4,"Verifying if file "<<file<<" exists"<<std::endl);
77 if ( !fs::exists( file ) )
83 //==============================================================
85 //==============================================================
86 void Synchronizer::AttributesMatch(bool update, std::string file, std::stringstream& mess)
88 std::map< std::string, std::string> attr;
89 mHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
90 mReader.ReadAttributes(file,attr);
91 tree::LevelDescriptor::AttributeDescriptorListType adl= mHandler->GetTree().GetAttributeDescriptorList(mHandler->GetTree().GetNumberOfLevels()-1);
92 tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
93 for (a = adl.begin();a!=adl.end();++a)
95 std::string databaseVal;
96 mHandler->GetAttribute("Image","FullFileName",file,a->GetKey(),databaseVal);
97 std::string fileVal=attr.find(a->GetKey())->second;
98 if ( a->GetFlags()==0 && databaseVal.compare(fileVal)!=0 )
102 mHandler->SetAttribute("Image",a->GetKey(),fileVal,"FullFileName", file);
103 mess<<file<<" has been updated in the DB"<<std::endl;
107 mess<<file<<" State: Attributes differ"<<std::endl;
112 //==============================================================