#include <creaImageIOGimmick.h>
#include <creaImageIOSystem.h>
-
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
//==============================================================
Gimmick::~Gimmick()
{
-
+ mSettings->writeSettingsFile();
+ delete mSettings;
+ delete mSynchronizer;
}
//==============================================================
mCurrentDirectory = GetHomeDirectory();
mSynchronizer= new Synchronizer(GetUserSettingsDirectory());
+ mSettings = new Settings(mCurrentDirectory);
+
+
std::string dbpath = GetLocalDatabasePath();
// Create or open local database
mLocalDatabase = createDB(i_nameDB, mCurrentDirectory + "\\.gimmick\\localdatabase_Descriptor.txt", dbpath);
// Add it to the TreeHandlerMap
mTreeHandlerMap[i_nameDB] = mLocalDatabase;
+ //Add additional DB from user Settings
+ addDBSettings();
+
// Creates files and directories database
mTimestampDatabase = new TimestampDatabaseHandler(GetTimestampDatabasePath());
// Create or open local database
// @param i_location : DB location //
// return : - //
///////////////////////////////////////////////////////////////////////
- void Gimmick::addDB(std::string &i_name, std::string &i_location)
+ void Gimmick::addDB(const std::string &i_name,
+ const std::string &i_location)
{
if(mTreeHandlerMap.find(i_name) == mTreeHandlerMap.end())
{
mTreeHandlerMap[i_name] = new SQLiteTreeHandler(i_location);
mTreeHandlerMap[i_name]->Open(true);
+ mSettings->addDB(i_location);
}
}
// @param i_locDB : location of DB //
// return : the SQLiteTreeHandler object on DB //
/////////////////////////////////////////////////////////////////////////
- SQLiteTreeHandler *Gimmick::createDB(std::string &i_name, std::string &i_locDesc, std::string &i_locDB)
+ SQLiteTreeHandler *Gimmick::createDB(const std::string &i_name,
+ const std::string &i_locDesc,
+ const std::string &i_locDB)
{
SQLiteTreeHandler *sqlTreeH = new SQLiteTreeHandler(i_locDB);
// Create or open local database
//========================================================================
void Gimmick::RemoveFile(const std::string& d,
- const tree::Node* & node)
+ tree::Node* node)
{
mImageAdder.SetSynchronizer(mSynchronizer);
mTimestampDatabase->RemoveNode("PATH",node);
GetTreeHandler(d)->GetTree().Print();
}
//========================================================================
+ /////////////////////////////////////////////////////////////////////////
+ // add DB from Settings file //
+ // @param : - //
+ // return : - //
+ /////////////////////////////////////////////////////////////////////////
+ void Gimmick::addDBSettings()
+ {
+
+ std::string pathSettings = mSettings->getValue(SETTINGS_DBPATH);
+
+ // split to find all paths
+ std::vector<std::string> paths;
+ std::string separator = ";";
+ std::string::size_type last_pos = pathSettings.find_first_not_of(separator);
+ //find first separator
+ std::string::size_type pos = pathSettings.find_first_of(separator, last_pos);
+ while(std::string::npos != pos || std::string::npos != last_pos)
+ {
+ paths.push_back(pathSettings.substr(last_pos, pos - last_pos));
+ last_pos = pathSettings.find_first_not_of(separator, pos);
+ pos = pathSettings.find_first_of(separator, last_pos);
+ }
+ std::vector<std::string>::iterator it_path = paths.begin();
+ for(; it_path != paths.end(); ++it_path)
+ {
+ pos = it_path->find_last_of("\\");
+ last_pos = it_path->find_last_of(".");
+ std::string name = it_path->substr(pos +1, last_pos -pos-1 );
+ addDB(name, it_path->c_str());
+ }
+ }
+
}