X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src2%2FcreaImageIOGimmick.cpp;h=09a6fd00685fdd34328f9ef18ae91fd960039354;hb=75778b43c0c928b88c6dc93f2c8b2c1ac6af59e5;hp=b30fbc18ba9a4fa5d9704fae24640b158b75cb1b;hpb=852af4a5c6e97a6fc349126cf3370e27f89fe067;p=creaImageIO.git diff --git a/src2/creaImageIOGimmick.cpp b/src2/creaImageIOGimmick.cpp index b30fbc1..09a6fd0 100644 --- a/src2/creaImageIOGimmick.cpp +++ b/src2/creaImageIOGimmick.cpp @@ -3,90 +3,77 @@ #include #include #include +//#include "io.h" +#ifndef PATH_MAX // If not defined yet : do it +# define PATH_MAX 2048 +#endif namespace creaImageIO { - - //============================================================== Gimmick::Gimmick() : mImageAdder(0) { RegisterGimmickMessageTypes(); + mSettings=0; + mSynchronizer=0; } //============================================================== - //============================================================== Gimmick::~Gimmick() { + if(mSettings!=0) + { mSettings->writeSettingsFile(); delete mSettings; + } + if(mSynchronizer!=0) + { delete mSynchronizer; + } } //============================================================== + //============================================================== + void Gimmick::Initialize(const std::string& path) + { + Initialize(); + } //============================================================== void Gimmick::Initialize() { - std::string i_nameDB = "Local database"; + std::string i_nameDB = "Local database"; // Create the UserSettings dir if does not exist CreateUserSettingsDirectory(); // Sets the current directory to the home dir mCurrentDirectory = GetHomeDirectory(); - mSynchronizer= new Synchronizer(GetUserSettingsDirectory()); + mSynchronizer= new Synchronizer(GetUserSettingsDirectory()+"Shared/gimmick/"); - mSettings = new Settings(mCurrentDirectory); + mSettings = new Settings(mCurrentDirectory); - - std::string dbpath = GetLocalDatabasePath(); + std::string dbpath = GetLocalDatabasePath(); // Create or open local database - mLocalDatabase = createDB(i_nameDB, mCurrentDirectory + "\\.gimmick\\localdatabase_Descriptor.txt", dbpath); + std::string dpath= mCurrentDirectory + "/.gimmick/Shared/gimmick/localdatabase_Descriptor.dscp"; + boost::algorithm::replace_all( dpath, + INVALID_FILE_SEPARATOR , + VALID_FILE_SEPARATOR); + mLocalDatabase = createDB(i_nameDB, dpath, 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 - if (! boost::filesystem::exists( GetTimestampDatabasePath() ) ) - { - std::string mess = "Timestamp database '"; - mess += GetTimestampDatabasePath(); - mess += "' does not exist : creating it"; - GimmickMessage(1,mess<Create() ) - { - GimmickError("ERROR CREATING '"<Open() ) - { - GimmickError("ERROR OPENING '"<GetTree().GetDescriptor().createDescriptorfromFile(i_locDesc); if ( ! sqlTreeH->Create(true) ) - { - GimmickError("ERROR CREATING '"<SetAttribute(0,"Name",i_name); } @@ -131,15 +117,14 @@ namespace creaImageIO { /// Open and test it GimmickMessage(1,"Opening local database '" <Open(true) ) + if ( !sqlTreeH->Open(true) ) { GimmickError("ERROR OPENING '"<second; } - delete mTimestampDatabase; } //============================================================== @@ -193,13 +177,14 @@ namespace creaImageIO } //================================================================ + //================================================================ const std::string& Gimmick::GetLocalDatabasePath() { if (mLocalDatabasePath.size()==0) { mLocalDatabasePath = GetUserSettingsDirectory(); - mLocalDatabasePath += "local_database.sqlite3"; + mLocalDatabasePath += "Shared/gimmick/local_database.sqlite3"; boost::algorithm::replace_all( mLocalDatabasePath, INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR); @@ -207,21 +192,6 @@ namespace creaImageIO return mLocalDatabasePath; } - //================================================================ - - //================================================================ - const std::string& Gimmick::GetTimestampDatabasePath() - { - if (mTimestampDatabasePath.size()==0) - { - mTimestampDatabasePath = GetUserSettingsDirectory(); - mTimestampDatabasePath += "timestamp_database.sqlite3"; - boost::algorithm::replace_all( mTimestampDatabasePath, - INVALID_FILE_SEPARATOR , - VALID_FILE_SEPARATOR); - } - return mTimestampDatabasePath; - } //======================================================================== //======================================================================== @@ -237,6 +207,43 @@ namespace creaImageIO GimmickError("ERROR CREATING '"<second; } - //======================================================================== - ///Returns the timestamp database handler - TimestampDatabaseHandler* Gimmick::GetTimestampDatabase() const - { - return mTimestampDatabase; - } - - //======================================================================== /// Add the files to the tree handler void Gimmick::AddFiles(const std::string& d, @@ -285,10 +284,10 @@ namespace creaImageIO { GimmickMessage(2,"Adding files to '"<RemoveNode("PATH",node); mImageAdder.RemoveFile(node); } //======================================================================== //======================================================================== - std::string Gimmick::Synchronize(bool repair, bool checkAttributes) + void Gimmick::CopyFiles(const std::vector& filenames, const std::string& d ) + { + TreeHandler * handler=GetTreeHandler(d); + mImageAdder.SetCurrentDatabase(d); + mImageAdder.SetTreeHandler(handler); + mImageAdder.SetSynchronizer(mSynchronizer); + mImageAdder.CopyFiles(filenames, mSettings->getValue(SETTINGS_COPY_PATH)); + } + + //======================================================================== + + std::string Gimmick::Synchronize(const std::string& d, bool repair, bool checkAttributes) { - TreeHandler * handler=GetTreeHandler("Local database"); + TreeHandler * handler=GetTreeHandler(d); + mImageAdder.SetCurrentDatabase(d); mImageAdder.SetTreeHandler(handler); - mImageAdder.SetTimestampHandler(mTimestampDatabase); mImageAdder.SetSynchronizer(mSynchronizer); return mImageAdder.Synchronize(repair, checkAttributes); } @@ -338,11 +348,64 @@ namespace creaImageIO GetTreeHandler(d)->GetTree().Print(); } //======================================================================== - ///////////////////////////////////////////////////////////////////////// - // add DB from Settings file // - // @param : - // - // return : - // - ///////////////////////////////////////////////////////////////////////// + + void Gimmick::GetSetting(const std::string& name, std::string& value) + { + value = mSettings->getValue(name); + } + //======================================================================== + + //======================================================================== + + void Gimmick::GetAttributes(const std::string& d, + const std::string& filename, + const std::vector& params, + std::vector& results) + { + TreeHandler * handler=GetTreeHandler(d); + mImageAdder.SetCurrentDatabase(d); + mImageAdder.SetTreeHandler(handler); + mImageAdder.SetSynchronizer(mSynchronizer); + mImageAdder.GetAttributes(params, filename, results); + } + //======================================================================== + + //======================================================================== + + void Gimmick::UpdateSetting(const std::string& name, const std::string& value) + { + mSettings->updateSetting(name,value); + mSettings->writeSettingsFile(); + } + //======================================================================== + + void Gimmick::DeleteDrive(const std::string& drive) + { + for( TreeHandlerMapType::const_iterator it = mTreeHandlerMap.begin(); + it!= mTreeHandlerMap.end(); ++it) + { + mImageAdder.SetTreeHandler(it->second); + mImageAdder.DeleteDriveFromMainDB(drive); + } + mImageAdder.SetSynchronizer(mSynchronizer); + mImageAdder.DeleteDriveFromOtherDB(drive); + } + + //======================================================================== + void Gimmick::EditField(tree::Node* node, const std::string& d, const std::string& name, const std::string& key, const std::string& val) + { + TreeHandler * handler=GetTreeHandler(d); + mImageAdder.SetCurrentDatabase(d); + mImageAdder.SetTreeHandler(handler); + mImageAdder.EditField(node,name,key,val); + } + //======================================================================== + + //////////////////////////////////////////////////////////////////////// + // add DB from Settings file // + // @param : - // + // return : - // + //////////////////////////////////////////////////////////////////////// void Gimmick::addDBSettings() { @@ -369,7 +432,5 @@ namespace creaImageIO std::string name = it_path->substr(pos +1, last_pos -pos-1 ); addDB(name, it_path->c_str()); } - - } - + } }