#include #include #include #include namespace creaImageIO { //============================================================== Gimmick::Gimmick() : mImageAdder(0) { RegisterGimmickMessageTypes(); } //============================================================== //============================================================== Gimmick::~Gimmick() { } //============================================================== //============================================================== void Gimmick::Initialize() { 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=0; 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; // 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); } else { /// Open and test it GimmickMessage(1,"Opening local database '" <Open(true) ) { GimmickError("ERROR OPENING '"<second; } delete mTimestampDatabase; } //============================================================== //================================================================ // file separator #if defined(_WIN32) #define VALID_FILE_SEPARATOR "\\" #define INVALID_FILE_SEPARATOR "/" #else #define INVALID_FILE_SEPARATOR "\\" #define VALID_FILE_SEPARATOR "/" #endif //================================================================ //================================================================ const std::string& Gimmick::GetHomeDirectory() { if (mHomeDirectory.size()==0) { #if defined(__GNUC__) mHomeDirectory = getenv("HOME"); #elif defined(_WIN32) mHomeDirectory = getenv("USERPROFILE"); #endif } return mHomeDirectory; } //================================================================ const std::string& Gimmick::GetUserSettingsDirectory() { if (mUserSettingsDirectory.size()==0) { mUserSettingsDirectory = GetHomeDirectory(); mUserSettingsDirectory += "/.gimmick/"; boost::algorithm::replace_all( mUserSettingsDirectory, INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR); } return mUserSettingsDirectory; } //================================================================ //================================================================ const std::string& Gimmick::GetLocalDatabasePath() { if (mLocalDatabasePath.size()==0) { mLocalDatabasePath = GetUserSettingsDirectory(); mLocalDatabasePath += "local_database.sqlite3"; boost::algorithm::replace_all( mLocalDatabasePath, INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR); } 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; } //======================================================================== //======================================================================== void Gimmick::CreateUserSettingsDirectory() { if (! boost::filesystem::is_directory( GetUserSettingsDirectory() ) ) { GimmickMessage(1,"Directory '"<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, const std::vector& filenames) { GimmickMessage(2,"Adding files to '"<SetTreeHandler(handler); } mSynchronizer->Synchronize(update); } //======================================================================== /// void Gimmick::Print(const std::string& d) { GetTreeHandler(d)->GetTree().Print(); } //======================================================================== }