refs #906, obtain .rev file name from static function instead of member

This commit is contained in:
Klaus Basan
2017-03-15 18:05:06 +01:00
committed by Mathew Sutcliffe
parent 31a01d74c6
commit ecb7877908
2 changed files with 13 additions and 5 deletions

View File

@@ -85,12 +85,12 @@ namespace BlackMisc
connect(&m_watcher, &QFileSystemWatcher::fileChanged, this, &CDataCache::loadFromStoreAsync);
connect(&m_serializer, &CDataCacheSerializer::valuesLoadedFromStore, this, &CDataCache::changeValuesFromRemote, Qt::DirectConnection);
if (! QFile::exists(m_revisionFileName)) { QFile(m_revisionFileName).open(QFile::WriteOnly); }
if (! QFile::exists(revisionFileName())) { QFile(revisionFileName()).open(QFile::WriteOnly); }
m_serializer.loadFromStore({}, false, true); // load pinned values
singleShot(0, this, [this] // only start the serializer if the main thread event loop runs
{
m_serializer.start();
m_watcher.addPath(m_revisionFileName);
m_watcher.addPath(revisionFileName());
loadFromStoreAsync();
});
}
@@ -107,6 +107,12 @@ namespace BlackMisc
return dir;
}
const QString &CDataCache::revisionFileName()
{
static const QString rev = CFileUtils::appendFilePaths(persistentStore(), ".rev");
return rev;
}
QString CDataCache::filenameForKey(const QString &key)
{
return CFileUtils::appendFilePaths(persistentStore(), instance()->CValueCache::filenameForKey(key));
@@ -781,7 +787,7 @@ namespace BlackMisc
QUuid uuid(json.value("uuid").toString());
CSequence<CProcessInfo> apps;
auto status = apps.convertFromJsonNoThrow(json.value("apps").toObject(), this, QStringLiteral("Error in %1 apps object").arg(m_filename));
apps.removeIf([](const CProcessInfo &pi) { return ! pi.exists(); });
apps.removeIf([](const CProcessInfo & pi) { return ! pi.exists(); });
if (apps.isEmpty()) { uuid = CIdentifier().toUuid(); }
m_uuid = uuid;

View File

@@ -255,6 +255,9 @@ namespace BlackMisc
//! The directory where core data are stored.
static const QString &persistentStore();
//! Revision file name
static const QString &revisionFileName();
//! Return the filename where the value with the given key may be stored.
static QString filenameForKey(const QString &key);
@@ -297,9 +300,8 @@ namespace BlackMisc
virtual void connectPage(Private::CValuePage *page) override;
QFileSystemWatcher m_watcher;
const QString m_revisionFileName { CFileUtils::appendFilePaths(persistentStore(), ".rev") };
CDataCacheSerializer m_serializer { this, m_revisionFileName };
CDataCacheSerializer m_serializer { this, revisionFileName() };
CDataCacheRevision m_revision { persistentStore() + "/" };
friend class CDataCacheSerializer; // to access m_revision and protected members of CValueCache
};