Improve compatibility with Dropbox

.. by checking the ride file CRC before recomputing
   either the metrics or the ridefilecache.

.. this means that users that routinely copy or backup
   or use dropbox to keep things in sync won't see any
   unneccessary metric computations.
This commit is contained in:
Mark Liversedge
2014-03-27 16:20:33 +00:00
parent 3247d1ecce
commit 924ef2a8f1
5 changed files with 56 additions and 28 deletions

View File

@@ -76,8 +76,8 @@ RideFileCache::RideFileCache(Context *context, QString fileName, RideFile *passe
QFileInfo cacheFileInfo(cacheFileName);
// is it up-to-date?
if (cacheFileInfo.exists() && rideFileInfo.lastModified() <= cacheFileInfo.lastModified() &&
cacheFileInfo.size() >= (int)sizeof(struct RideFileCacheHeader)) {
if (cacheFileInfo.exists() && cacheFileInfo.size() >= (int)sizeof(struct RideFileCacheHeader)) {
// we have a file, it is more recent than the ride file
// but is it the latest version?
RideFileCacheHeader head;
@@ -89,12 +89,17 @@ RideFileCache::RideFileCache(Context *context, QString fileName, RideFile *passe
inFile.readRawData((char *) &head, sizeof(head));
cacheFile.close();
// is it as recent as we are?
if (head.version == RideFileCacheVersion) {
// its more recent -or- the crc is the same
if (rideFileInfo.lastModified() <= cacheFileInfo.lastModified() ||
head.crc == DBAccess::computeFileCRC(rideFileName)) {
// it is the same ?
if (head.version == RideFileCacheVersion) {
// WE'RE GOOD
if (check == false) readCache(); // if check is false we aren't just checking
return;
// WE'RE GOOD
if (check == false) readCache(); // if check is false we aren't just checking
return;
}
}
}
}
@@ -429,6 +434,9 @@ RideFileCache::refreshCache()
{
static bool writeerror=false;
// set head crc
crc = DBAccess::computeFileCRC(rideFileName);
// update cache!
QFile cacheFile(cacheFileName);
@@ -1261,6 +1269,7 @@ RideFileCache::serialize(QDataStream *out)
// write header
head.version = RideFileCacheVersion;
head.crc = crc;
head.CP = CP;
head.LTHR = LTHR;