int MfStatusCache::GetFormatVersion() const { return BuildVersion(1, 1); }
bool MfStatusCache::DoLoad(const wxTextFile& file, int version) { bool isFmtOk = true; CacheFileFormat fmt; if ( version == BuildVersion(1, 1) ) { fmt = CacheFile_1_1; } else if ( version == BuildVersion(1, 0) ) { fmt = CacheFile_1_0; } else { fmt = CacheFile_Max; } // read the data wxString str, name; str.Alloc(1024); // avoid extra memory allocations name.Alloc(1024); MailFolderStatus status; size_t count = file.GetLineCount(); for ( size_t n = 1; n < count; n++ ) { str = file[n]; // first get the end of the full folder name knowing that we should // skip all "::" as they could have only resulted from quoting a ':' // in the folder name and so the loop below looks for the first ':' // not followed by another ':' const wxChar *p = wxStrchr(str, CACHE_DELIMITER_CH); while ( p && p[1] == CACHE_DELIMITER_CH ) { p = wxStrchr(p + 2, CACHE_DELIMITER_CH); } if ( !p ) { wxLogError(_("Missing '%c' at line %d."), CACHE_DELIMITER_CH, n + 1); isFmtOk = false; break; } name = wxString(str.c_str(), p); // now unquote ':' which were doubled by Save() name.Replace(CACHE_DELIMITER CACHE_DELIMITER, CACHE_DELIMITER); // get the rest status.Init(); switch ( fmt ) { case CacheFile_1_0: isFmtOk = wxSscanf(p + 1, _T("%lu") CACHE_DELIMITER _T("%lu") CACHE_DELIMITER _T("%lu"), &status.total, &status.unread, &status.flagged) == 3; break; default: FAIL_MSG( _T("unknown cache file format") ); // fall through nevertheless case CacheFile_1_1: isFmtOk = wxSscanf(p + 1, _T("%lu") CACHE_DELIMITER _T("%lu") CACHE_DELIMITER _T("%lu") CACHE_DELIMITER _T("%lu"), &status.total, &status.newmsgs, &status.unread, &status.flagged) == 4; } if ( !isFmtOk ) { wxLogError(_("Missing field(s) at line %d."), n + 1); break; } // ignore the folders which were deleted during the last program run MFolder *folder = MFolder::Get(name); if ( folder ) { folder->DecRef(); // do add the entry to the cache size_t entry = m_folderNames.Add(name); m_folderData.Insert(new MailFolderStatus(status), entry); } else { wxLogDebug(_T("Removing deleted folder '%s' from status cache."), name.c_str()); } } if ( !isFmtOk ) { wxLogWarning(_("Your mail folder status cache file (%s) was corrupted."), file.GetName()); return false; } return true; }
QString VersionInfo::VersionString() { return QString("%1.%2.%3").arg(MajorVersion()).arg(MinorVersion()).arg(BuildVersion()); }