}
//==============================================================
+ //==============================================================
+ void Gimmick::Initialize(const std::string& path)
+ {
+ mDescriptorPath=path;
+ Initialize();
+ }
//==============================================================
void Gimmick::Initialize()
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);
std::string dbpath = GetLocalDatabasePath();
// Create or open local database
- std::string dpath= mCurrentDirectory + "/.gimmick/localdatabase_Descriptor.txt";
+ std::string dpath= mCurrentDirectory + "/.gimmick/Shared/gimmick/localdatabase_Descriptor.txt";
boost::algorithm::replace_all( dpath,
INVALID_FILE_SEPARATOR ,
VALID_FILE_SEPARATOR);
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);
if (mTimestampDatabasePath.size()==0)
{
mTimestampDatabasePath = GetUserSettingsDirectory();
- mTimestampDatabasePath += "timestamp_database.sqlite3";
+ mTimestampDatabasePath += "Shared/gimmick/timestamp_database.sqlite3";
boost::algorithm::replace_all( mTimestampDatabasePath,
INVALID_FILE_SEPARATOR ,
VALID_FILE_SEPARATOR);
boost::algorithm::replace_all( setDir,
INVALID_FILE_SEPARATOR ,
VALID_FILE_SEPARATOR);
+ setDir+="Shared/";
+ boost::filesystem::create_directory( setDir );
+ setDir+="gimmick/";
+ boost::filesystem::create_directory( setDir );
setDir+="localdatabase_Descriptor.txt";
- //if(!boost::filesystem::is_regular_file(setDir)) //JPRX
+
if(!boost::filesystem::is_regular(setDir))
{
char name[PATH_MAX];
//EED int err = GetBinaryDirectory(name, PATH_MAX);
crea::System::GetAppPath(name,PATH_MAX);
+ std::cout<<name<<std::endl;
std::string path=name;
path=path.substr(0,path.size()-1);
path=path.substr(0,path.find_last_of("/"));
- path+="/data/localdatabase_Descriptor.txt";
+ //Creating directories
+ path+="/bin/Shared/gimmick/localdatabase_Descriptor.txt";
+ std::cout<<"From: "<<path<<std::endl;
+ std::cout<<"To: "<<setDir<<std::endl;
boost::algorithm::replace_all( path,
INVALID_FILE_SEPARATOR ,
VALID_FILE_SEPARATOR);
{
using namespace std;
//================================================================================================================
+ ///Represents the list of currently added files
class AddList
{
public :
+ ///Key to be added into the database
std::string key;
+ ///Path of the directory
std::string path;
+ /// Defines if the operation was recursive or not
std::string recursive;
+ ///Number of added files
std::string nbFiles;
+ ///Ctor
AddList(CppSQLite3Query& res):
key(res.getStringField(0)),
path(res.getStringField(1)),
//================================================================================================================
//================================================================================================================
+ ///Represents the list of currently removed files
class RemoveList
{
public :
+ ///Key to be added into the database
std::string key;
+ ///Path of the remove file
std::string path;
+ ///Defines if the file was removed or not
std::string remove;
+ ///Time of the last change of the file
std::string time;
-
+ ///Ctor
RemoveList(CppSQLite3Query& res):
key(res.getStringField(1)),
path(res.getStringField(2)),
//================================================================================================================
//================================================================================================================
+ ///In charge of the synchronization of the database and the disk state.
class Synchronizer
{
public:
+ ///Ctor
Synchronizer(const std::string& path);
+ ///Dtor
virtual ~Synchronizer();
+ ///Initializes the database
void Initialize();
+ ///Inserts an add operation to the database
void InsertAddOp(const std::string& path,
const std::string& recursive,
const std::string& nChildren,
const std::string& refdb);
+ ///Inserts a file to be ignored
void InsertIgnoreFile(const std::string& addKey,
const std::string& path,
const std::string& remove,
const std::string& time,
const std::string& refdb);
+ ///Removes an entry that matches the given parameter
void RemoveEntry(const std::string i_table, const std::string i_key);
+ ///Removes several entries
void RemoveEntries(const std::string i_table,
const std::string i_attribute,
const std::string i_operand,
const std::string i_key);
+ ///Gets the list of AddFiles
void GetFileList(std::vector<AddList>& files , const std::string& refdb);
+ ///Gets the list of ignored files
void GetIgnoredFiles(const std::string& key, std::vector<std::string> &ignoreList);
+ ///Gets the attribute that matches the parameters
std::string GetAttribute(const std::string& attribute,
const std::string& table,
const std::string& searchParam,
const std::string& searchValue,
const std::string& refdb);
+ ///Sets an attribute to an entry that matches the given parameters
void SetAttribute(const std::string& attribute,
const std::string& table,
const std::string& value,
const std::string& searchParam,
const std::string& searchValue,
const std::string& refdb);
+ ///The current AddList
std::vector<AddList> mAddList;
+ ///The current RemoveList
std::vector<RemoveList> mIgnoreList;
private :
/// The DB
CppSQLite3DB* mDB;
+ ///Path of the current database
std::string pathDB;
+ ///Creates a new database
void CreateDB();
+ ///Updates the AddList
void UpdateAddList(const std::string& refdb);
+ ///Cleans the list in case operations are no longer useful (0 added files)
void CleanList(const std::string& refdb);
+ ///Cleans the name (changes slashes and backslashes according to the system)
void CleanName(std::string& str) const;
-
+ ///Gets the ignore list
std::vector<std::string> GetIgnoreList(const std::string &i_key);
};