Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Idented code properly for common/etag.cpp
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Fri, 11 Mar 2016 14:25:10 +0000 (14:25 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Fri, 11 Mar 2016 14:25:10 +0000 (14:25 +0000)
source/common/etag.cpp

index e22a40a..6e24d01 100644 (file)
 
 ETagDB::~ETagDB(){
     
-    // Write out the database to file.
+       // Write out the database to file.
     
-    ProcessLock->try_lock();
+       ProcessLock->try_lock();
     
-    if (NeedsWrite == TRUE){
+       if (NeedsWrite == TRUE){
         
-        WriteETagDB();
+               WriteETagDB();
         
-    }
+       }
     
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
 }
 
 void ETagDB::SetupDB(wxString AccountDirInc){
     
-    AccountDir = AccountDirInc;
-    LoadETagDB();
+       // Setup the ETag Database.
+       
+       AccountDir = AccountDirInc;
+       LoadETagDB();
     
 }
 
 void ETagDB::AddETag(wxString Filename, wxString ETag, wxString ETagOriginal){
     
-    // Lock or wait if it is already locked.
+       // Lock or wait if it is already locked.
     
-    ProcessLock->lock();
+       ProcessLock->lock();
     
-    // Process the ETag addition.
+       // Process the ETag addition.
     
-    FilenameETag.insert(std::make_pair(Filename, ETag));
-    FilenameETagOriginal.insert(std::make_pair(Filename, ETagOriginal));
+       FilenameETag.insert(std::make_pair(Filename, ETag));
+       FilenameETagOriginal.insert(std::make_pair(Filename, ETagOriginal));
     
-    NeedsWrite = TRUE;
+       NeedsWrite = TRUE;
     
-    // Unlock.
+       // Unlock.
     
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
 }
 
 void ETagDB::RemoveETag(wxString Filename){
     
-    // Lock or wait if it is already locked.
+       // Remove the ETag.
+       
+       // Lock or wait if it is already locked.
     
-    ProcessLock->lock();
+       ProcessLock->lock();
     
-    // Remove the ETag.
+       // Remove the ETag.
     
-    Filename.Trim();
+       Filename.Trim();
     
-    FilenameETag.erase(Filename);
-    FilenameETagOriginal.erase(Filename);
-    
-    NeedsWrite = TRUE;
+       FilenameETag.erase(Filename);
+       FilenameETagOriginal.erase(Filename);
+
+       NeedsWrite = TRUE;
     
-    // Unlock.
+       // Unlock.
     
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
 }
 
 void ETagDB::UpdateETag(wxString Filename, wxString ETag){
     
-    // Lock or wait if it is already locked.
+       // Update the ETag.
+       
+       // Lock or wait if it is already locked.
     
-    ProcessLock->lock();
+       ProcessLock->lock();
     
-    // Update the ETag.
+       // Update the ETag.
     
-    FilenameETag.erase(Filename);
-    FilenameETag.insert(std::make_pair(Filename, ETag));
+       FilenameETag.erase(Filename);
+       FilenameETag.insert(std::make_pair(Filename, ETag));
     
-    NeedsWrite = TRUE;
+       NeedsWrite = TRUE;
     
-    // Unlock.
+       // Unlock.
     
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
 }
 
 void ETagDB::UpdateETag(wxString Filename, wxString ETag, wxString ETagOriginal){
     
-    // Lock or wait if it is already locked.
+       // Update the ETag with the tags given.
+       
+       // Lock or wait if it is already locked.
     
-    ProcessLock->lock();
+       ProcessLock->lock();
     
-    // Update the ETag.
+       // Update the ETag.
     
-    FilenameETag.erase(Filename);
-    FilenameETagOriginal.erase(Filename);
-    FilenameETag.insert(std::make_pair(Filename, ETag));
-    FilenameETagOriginal.insert(std::make_pair(Filename, ETagOriginal));
+       FilenameETag.erase(Filename);
+       FilenameETagOriginal.erase(Filename);
+       FilenameETag.insert(std::make_pair(Filename, ETag));
+       FilenameETagOriginal.insert(std::make_pair(Filename, ETagOriginal));
     
-    std::map<wxString,wxString>::iterator IterWxS;
-    IterWxS = FilenameETagOriginal.find(Filename);
-    NeedsWrite = TRUE;
-    
-    // Unlock.
+       std::map<wxString,wxString>::iterator IterWxS;
+       IterWxS = FilenameETagOriginal.find(Filename);
+       NeedsWrite = TRUE;
+
+       // Unlock.
     
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
 }
 
 bool ETagDB::ETagExists(wxString Filename){
 
-    // Lock or wait if it is already locked.
+       // Check if the ETag exists.
+       
+       // Lock or wait if it is already locked.
     
-    ProcessLock->lock();
+       ProcessLock->lock();
     
-    bool FileResult = FALSE;
+       bool FileResult = FALSE;
     
-    if (FilenameETag.find(Filename) != FilenameETag.end()){
+       if (FilenameETag.find(Filename) != FilenameETag.end()){
         
-       FileResult = TRUE;
+               FileResult = TRUE;
            
-    } else {
+       } else {
     
-       FileResult = FALSE;
+               FileResult = FALSE;
     
-    }
+       }
     
-    // Unlock.
+       // Unlock.
 
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
-    return FileResult;
+       return FileResult;
 
 }
 
 std::map<wxString,wxString>* ETagDB::GetFilenamePointer(){
     
-    return &FilenameETag;
+       // Get the Filename Pointer.
+       
+       return &FilenameETag;
     
 }
 
 wxString ETagDB::GetETag(wxString Filename){
+
+       // Get the ETag.
+       
+       // Lock or wait if it is already locked.
+
+       wxString ETagOut;
+       std::map<wxString,wxString>::iterator IterwxS;
     
-    // Lock or wait if it is already locked.
-    
-    wxString ETagOut;
-    std::map<wxString,wxString>::iterator IterwxS;
-    
-    ProcessLock->lock();
+       ProcessLock->lock();
     
-    // Get the ETag.
+       // Get the ETag.
     
-    //IterwxS = FilenameETag.find(Filename);
+       //IterwxS = FilenameETag.find(Filename);
     
-    if (FilenameETag.find(Filename) != FilenameETag.end()){
+       if (FilenameETag.find(Filename) != FilenameETag.end()){
         
-        IterwxS = FilenameETag.find(Filename);
+               IterwxS = FilenameETag.find(Filename);
         
-        ETagOut = IterwxS->second;
+               ETagOut = IterwxS->second;
         
-    }
+       }
     
-    // Unlock.
+       // Unlock.
     
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
-    return ETagOut;
+       return ETagOut;
     
 }
 
 wxString ETagDB::GetETagOriginal(wxString Filename){
     
-    // Lock or wait if it is already locked.
+       // Get the original ETag.
+       
+       // Lock or wait if it is already locked.
     
-    wxString ETagOrigOut;
-    std::map<wxString,wxString>::iterator IterwxS;
+       wxString ETagOrigOut;
+       std::map<wxString,wxString>::iterator IterwxS;
     
-    ProcessLock->lock();
+       ProcessLock->lock();
     
-    // Get the ETag.
+       // Get the ETag.
     
-    //IterwxS = FilenameETag.find(Filename);
+       //IterwxS = FilenameETag.find(Filename);
     
-    if (FilenameETagOriginal.find(Filename) != FilenameETagOriginal.end()){
+       if (FilenameETagOriginal.find(Filename) != FilenameETagOriginal.end()){
         
-        IterwxS = FilenameETagOriginal.find(Filename);
+               IterwxS = FilenameETagOriginal.find(Filename);
         
-        ETagOrigOut = IterwxS->second;
+               ETagOrigOut = IterwxS->second;
         
-    }
+       }
     
-    // Unlock.
+       // Unlock.
     
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
-    return ETagOrigOut;
+       return ETagOrigOut;
     
 }
 
 bool ETagDB::WriteETagDB(){
     
-    // Lock or wait if it is already locked.
+       // Write the ETag database.
+       
+       // Lock or wait if it is already locked.
     
-    ProcessLock->lock();
-    
-    // Write the ETag database.
-    
-    wxString AccountETagDB;
-    std::map<wxString,wxString>::iterator IterwxS;
-    int LineSeek = 0;
+       ProcessLock->lock();
     
+       // Write the ETag database.
     
+       wxString AccountETagDB;
+       std::map<wxString,wxString>::iterator IterwxS;
+       int LineSeek = 0;
     
 #if defined(__HAIKU__)
     
-    //preffilename = wxT("noo");
+       //preffilename = wxT("noo");
     
 #elif defined(__WIN32__)
     
-    AccountETagDB.Clear();
-    AccountETagDB = GetAccountDir(AccountDir, FALSE);
-    AccountETagDB.Append(wxT("\\etag.db"));
+       AccountETagDB.Clear();
+       AccountETagDB = GetAccountDir(AccountDir, FALSE);
+       AccountETagDB.Append(wxT("\\etag.db"));
     
 #else
     
-    // This entry applies to OSX as well.
-    
-    AccountETagDB.Clear();
-    AccountETagDB = GetAccountDir(AccountDir, FALSE);
-    AccountETagDB.Append(wxT("/etag.db"));
+       // This entry applies to OSX as well.
     
+       AccountETagDB.Clear();
+       AccountETagDB = GetAccountDir(AccountDir, FALSE);
+       AccountETagDB.Append(wxT("/etag.db"));
+       
 #endif
     
-    wxTextFile ETagDBFile;
-    wxString SettingLine;
+       wxTextFile ETagDBFile;
+       wxString SettingLine;
     
-    if (wxFileExists(AccountETagDB) == FALSE){
+       if (wxFileExists(AccountETagDB) == FALSE){
+        
+               if (ETagDBFile.Create(AccountETagDB) == FALSE){
+                       ////ProcessLock.unlock();
+                       return FALSE;
+               
+               }
         
-        if (ETagDBFile.Create(AccountETagDB) == FALSE){
-            ////ProcessLock.unlock();
-            return FALSE;
-        }
+       } else {
         
-    } else {
+               if (ETagDBFile.Open(AccountETagDB) == FALSE){
+                       ////ProcessLock.unlock();
+                       return FALSE;
         
-        if (ETagDBFile.Open(AccountETagDB) == FALSE){
-            ////ProcessLock.unlock();
-            return FALSE;
-        }
+               }
         
-    }
+       }
     
-    ETagDBFile.Clear();
+       ETagDBFile.Clear();
     
-    for (std::map<wxString,wxString>::iterator iter = FilenameETag.begin();
-         iter != FilenameETag.end(); ++iter){
+       for (std::map<wxString,wxString>::iterator iter = FilenameETag.begin();
+               iter != FilenameETag.end(); ++iter){
         
-        // Get Original ETag as well.
+               // Get Original ETag as well.
         
-        IterwxS = FilenameETagOriginal.find(iter->first);
+               IterwxS = FilenameETagOriginal.find(iter->first);
         
-        if (iter->first.IsEmpty()){
-            continue;
-        }
+               if (iter->first.IsEmpty()){
+                       continue;
+               }
         
-        SettingLine = iter->first + wxT("|") + iter->second + wxT("|") + IterwxS->second;
+               SettingLine = iter->first + wxT("|") + iter->second + wxT("|") + IterwxS->second;
         
-        ETagDBFile.InsertLine(SettingLine, LineSeek);
+               ETagDBFile.InsertLine(SettingLine, LineSeek);
         
-        LineSeek++;
+               LineSeek++;
         
-    }
+       }
     
-    ETagDBFile.Write();
+       ETagDBFile.Write();
     
-    NeedsWrite = FALSE;
+       NeedsWrite = FALSE;
     
-    // Unlock.
+       // Unlock.
     
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
-    return TRUE;
+       return TRUE;
     
 }
 
 bool ETagDB::LoadETagDB(){
     
-    // Lock or wait if it is already locked.
+       // Load the ETag database.
+       
+       // Lock or wait if it is already locked.
     
-    ProcessLock->lock();
+       ProcessLock->lock();
     
-    // Load the ETag database.
+       // Load the ETag database.
     
-    wxString AccountETagDB;
-    wxString AccountDirPath;
+       wxString AccountETagDB;
+       wxString AccountDirPath;
     
 #if defined(__HAIKU__)
     
-    //preffilename = wxT("noo");
+       //preffilename = wxT("noo");
     
 #elif defined(__WIN32__)
     
-    AccountDirPath = GetAccountDir(AccountDir, FALSE);
+       AccountDirPath = GetAccountDir(AccountDir, FALSE);
     
-    AccountETagDB = AccountDirPath;
-    AccountETagDB.Append(wxT("\\etag.db"));
+       AccountETagDB = AccountDirPath;
+       AccountETagDB.Append(wxT("\\etag.db"));
     
 #else
     
-    AccountDirPath = GetAccountDir(AccountDir, FALSE);
+       AccountDirPath = GetAccountDir(AccountDir, FALSE);
     
-    AccountETagDB = AccountDirPath;
-    AccountETagDB.Append(wxT("/etag.db"));
+       AccountETagDB = AccountDirPath;
+       AccountETagDB.Append(wxT("/etag.db"));
     
 #endif
     
-    wxTextFile ETagDBFile;
+       wxTextFile ETagDBFile;
     
-    if (wxFileExists(AccountETagDB) == FALSE){
+       if (wxFileExists(AccountETagDB) == FALSE){
         
-        if (ETagDBFile.Create(AccountETagDB) == FALSE){
-            ////ProcessLock.unlock();
-            //ProcessLock->unlock();
-            return FALSE;
-        }
+               if (ETagDBFile.Create(AccountETagDB) == FALSE){
+                       ////ProcessLock.unlock();
+                       //ProcessLock->unlock();
+                       
+                       return FALSE;
+                       
+               }
         
-    } else {
+       } else {
         
-        if (ETagDBFile.Open(AccountETagDB, wxConvUTF8) == FALSE){
-            ////ProcessLock.unlock();
-            //ProcessLock->unlock();
-            return FALSE;
-        }
+               if (ETagDBFile.Open(AccountETagDB, wxConvUTF8) == FALSE){
+               
+                       ////ProcessLock.unlock();
+                       //ProcessLock->unlock();
+                       return FALSE;
+               
+               }
         
-    }
+       }
     
-    wxString wxSFilename;
-    wxString wxSValue;
-    wxString ETagContactFilename;
+       wxString wxSFilename;
+       wxString wxSValue;
+       wxString ETagContactFilename;
     
-    for (wxStringTokenizer ETagDBLine(ETagDBFile.GetFirstLine(), wxT("|"));
-         !ETagDBFile.Eof(); ETagDBLine.SetString(ETagDBFile.GetNextLine(), wxT("|"), wxTOKEN_DEFAULT) )
-    {
+       for (wxStringTokenizer ETagDBLine(ETagDBFile.GetFirstLine(), wxT("|"));
+               !ETagDBFile.Eof(); ETagDBLine.SetString(ETagDBFile.GetNextLine(), wxT("|"), wxTOKEN_DEFAULT) )
+       {
         
-        // Split the file into three.
+               // Split the file into three.
         
-        wxSFilename = ETagDBLine.GetNextToken();
+               wxSFilename = ETagDBLine.GetNextToken();
         
-        // Get the ETag.
+               // Get the ETag.
         
-        wxSValue = ETagDBLine.GetNextToken();
-        FilenameETag.insert(std::make_pair(wxSFilename, wxSValue));
+               wxSValue = ETagDBLine.GetNextToken();
+               FilenameETag.insert(std::make_pair(wxSFilename, wxSValue));
         
-        // Get the original ETag.
+               // Get the original ETag.
         
-        wxSValue = ETagDBLine.GetNextToken();
-        wxSValue.Trim();
-        FilenameETagOriginal.insert(std::make_pair(wxSFilename, wxSValue));
+               wxSValue = ETagDBLine.GetNextToken();
+               wxSValue.Trim();
+               FilenameETagOriginal.insert(std::make_pair(wxSFilename, wxSValue));
         
-    }
+       }
     
-    // Unlock.
+       // Unlock.
     
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
-    return TRUE;
+       return TRUE;
     
 }
 
 void ETagDB::DeleteETagDB(){
     
-    // Lock or wait if it is already locked.
+       // Delete the ETag database.
+       
+       // Lock or wait if it is already locked.
     
-    ProcessLock->lock();
+       ProcessLock->lock();
     
-    wxString AccountETagDB;
+       wxString AccountETagDB;
     
-    // Delete the ETagDB.
+       // Delete the ETagDB.
     
 #if defined(__HAIKU__)
     
-    //preffilename = wxT("noo");
+       //preffilename = wxT("noo");
     
 #elif defined(__WIN32__)
     
-    AccountETagDB.Clear();
-    AccountETagDB = GetAccountDir(AccountDir, FALSE);
-    AccountETagDB.Append(wxT("\\etag.db"));
+       AccountETagDB.Clear();
+       AccountETagDB = GetAccountDir(AccountDir, FALSE);
+       AccountETagDB.Append(wxT("\\etag.db"));
     
-    wxRemoveFile(AccountETagDB);
+       wxRemoveFile(AccountETagDB);
     
 #else
     
-    AccountETagDB.Clear();
-    AccountETagDB = GetAccountDir(AccountDir, FALSE);
-    AccountETagDB.Append(wxT("/etag.db"));
+       AccountETagDB.Clear();
+       AccountETagDB = GetAccountDir(AccountDir, FALSE);
+       AccountETagDB.Append(wxT("/etag.db"));
     
-    wxRemoveFile(AccountETagDB);
+       wxRemoveFile(AccountETagDB);
     
 #endif
     
-    // Unlock.
+       // Unlock.
     
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
 }
 
 bool ETagDB::CheckETagExists(wxString Filename){
     
-    if (FilenameETag.find(Filename) == FilenameETag.end()){
+       if (FilenameETag.find(Filename) == FilenameETag.end()){
         
-        return FALSE;
+               return FALSE;
         
-    } else {
+       } else {
         
-        return TRUE;
+               return TRUE;
         
-    }  
+       }       
     
 }
 
 std::map<wxString,ETagData> ETagDB::GetETagData(){
     
-    // Lock the database.
+       // Get the ETag data.
+       
+       // Lock the database.
     
-    ProcessLock->lock();
+       ProcessLock->lock();
     
-    // Go through each of the ETags and process them accordingly.
+       // Go through each of the ETags and process them accordingly.
     
-    std::map<wxString,ETagData> DataSet;
+       std::map<wxString,ETagData> DataSet;
     
-    for (std::map<wxString,wxString>::iterator iter = FilenameETag.begin(); 
-         iter != FilenameETag.end(); ++iter){
+       for (std::map<wxString,wxString>::iterator iter = FilenameETag.begin(); 
+               iter != FilenameETag.end(); ++iter){
         
-        std::map<wxString,wxString>::iterator origiter = FilenameETagOriginal.find(iter->first);
+               std::map<wxString,wxString>::iterator origiter = FilenameETagOriginal.find(iter->first);
         
-        ETagData etd;
+               ETagData etd;
+               
+               etd.ETagValue = iter->second;
+               etd.ETagOrigValue = origiter->second;
         
-        etd.ETagValue = iter->second;
-        etd.ETagOrigValue = origiter->second;
+               DataSet.insert(std::make_pair(iter->first, etd));
         
-        DataSet.insert(std::make_pair(iter->first, etd));
-        
-    }
+       }
     
-    // Unlock the database.
+       // Unlock the database.
     
-    ProcessLock->unlock();
+       ProcessLock->unlock();
     
-    return DataSet;
+       return DataSet;
     
 }
 
 bool ETagDB::GetWriteStatus(){
     
-    return NeedsWrite;
-    
+       // Check if the ETag database needs to be
+       // written to a file.
+       
+       return NeedsWrite;
+
 }
\ No newline at end of file
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy