mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 05:45:35 +08:00
refs #494 Get the filename used for serializing a specific cached value, or list of all files used by whole cache.
This commit is contained in:
@@ -46,6 +46,16 @@ namespace BlackCore
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CDataCache::filenameForKey(const QString &key)
|
||||||
|
{
|
||||||
|
return persistentStore() + "/" + CValueCache::filenameForKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CDataCache::enumerateStore() const
|
||||||
|
{
|
||||||
|
return enumerateFiles(persistentStore());
|
||||||
|
}
|
||||||
|
|
||||||
QString lockFileError(const QLockFile &lock)
|
QString lockFileError(const QLockFile &lock)
|
||||||
{
|
{
|
||||||
switch (lock.error())
|
switch (lock.error())
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ namespace BlackCore
|
|||||||
//! The directory where core data are stored.
|
//! The directory where core data are stored.
|
||||||
static const QString &persistentStore();
|
static const QString &persistentStore();
|
||||||
|
|
||||||
|
//! Return the filename where the value with the given key may be stored.
|
||||||
|
static QString filenameForKey(const QString &key);
|
||||||
|
|
||||||
|
//! Return all files where data may be stored.
|
||||||
|
QStringList enumerateStore() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CDataCache();
|
CDataCache();
|
||||||
|
|
||||||
@@ -75,6 +81,9 @@ namespace BlackCore
|
|||||||
|
|
||||||
//! Reset the data to its default value.
|
//! Reset the data to its default value.
|
||||||
void setDefault() { this->set(Trait::defaultValue()); }
|
void setDefault() { this->set(Trait::defaultValue()); }
|
||||||
|
|
||||||
|
//! Return the file that is used for persistence for this value.
|
||||||
|
QString getFilename() const { return CDataCache::filenameForKey(this->getKey()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -39,4 +39,14 @@ namespace BlackCore
|
|||||||
return loadFromFiles(persistentStore());
|
return loadFromFiles(persistentStore());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CSettingsCache::filenameForKey(const QString &key)
|
||||||
|
{
|
||||||
|
return persistentStore() + "/" + CValueCache::filenameForKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CSettingsCache::enumerateStore() const
|
||||||
|
{
|
||||||
|
return enumerateFiles(persistentStore());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ namespace BlackCore
|
|||||||
//! Load core settings from disk.
|
//! Load core settings from disk.
|
||||||
BlackMisc::CStatusMessage loadFromStore();
|
BlackMisc::CStatusMessage loadFromStore();
|
||||||
|
|
||||||
|
//! Return the filename where the value with the given key may be stored.
|
||||||
|
static QString filenameForKey(const QString &key);
|
||||||
|
|
||||||
|
//! Return all files where settings may be stored.
|
||||||
|
QStringList enumerateStore() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSettingsCache();
|
CSettingsCache();
|
||||||
};
|
};
|
||||||
@@ -63,6 +69,9 @@ namespace BlackCore
|
|||||||
|
|
||||||
//! Reset the setting to its default value.
|
//! Reset the setting to its default value.
|
||||||
void setDefault() { this->set(Trait::defaultValue()); }
|
void setDefault() { this->set(Trait::defaultValue()); }
|
||||||
|
|
||||||
|
//! Return the file that is used for persistence for this value.
|
||||||
|
QString getFilename() const { return CSettingsCache::filenameForKey(this->getKey()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -278,6 +278,19 @@ namespace BlackMisc
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CValueCache::filenameForKey(const QString &key)
|
||||||
|
{
|
||||||
|
return key.section('/', 0, 0) + ".json";
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CValueCache::enumerateFiles(const QString &dir) const
|
||||||
|
{
|
||||||
|
auto values = getAllValues();
|
||||||
|
QSet<QString> files;
|
||||||
|
for (auto it = values.begin(); it != values.end(); ++it) { files.insert(dir + "/" + filenameForKey(it.key())); }
|
||||||
|
return files.toList();
|
||||||
|
}
|
||||||
|
|
||||||
void CValueCache::clearAllValues(const QString &keyPrefix)
|
void CValueCache::clearAllValues(const QString &keyPrefix)
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_mutex);
|
QMutexLocker lock(&m_mutex);
|
||||||
@@ -393,6 +406,11 @@ namespace BlackMisc
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString &CValuePage::getKey(const Element &element) const
|
||||||
|
{
|
||||||
|
return element.m_key;
|
||||||
|
}
|
||||||
|
|
||||||
qint64 CValuePage::getTimestamp(const Element &element) const
|
qint64 CValuePage::getTimestamp(const Element &element) const
|
||||||
{
|
{
|
||||||
return element.m_timestamp;
|
return element.m_timestamp;
|
||||||
|
|||||||
@@ -121,6 +121,16 @@ namespace BlackMisc
|
|||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
CStatusMessage loadFromFiles(const QString &directory);
|
CStatusMessage loadFromFiles(const QString &directory);
|
||||||
|
|
||||||
|
//! Return the (relative) filename that may is (or would be) used to save the value with the given key.
|
||||||
|
//! The file may or may not exist (because it might not have been saved yet).
|
||||||
|
//! \threadsafe
|
||||||
|
static QString filenameForKey(const QString &key);
|
||||||
|
|
||||||
|
//! List the Json files which are (or would be) used to save the current values.
|
||||||
|
//! The files may or may not exist (because they might not have been saved yet).
|
||||||
|
//! \threadsafe
|
||||||
|
QStringList enumerateFiles(const QString &directory) const;
|
||||||
|
|
||||||
//! Clear all values from the cache.
|
//! Clear all values from the cache.
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
void clearAllValues(const QString &keyPrefix = {});
|
void clearAllValues(const QString &keyPrefix = {});
|
||||||
@@ -219,6 +229,9 @@ namespace BlackMisc
|
|||||||
//! Write a new value. Must be called from the thread in which the owner lives.
|
//! Write a new value. Must be called from the thread in which the owner lives.
|
||||||
CStatusMessage set(const T &value) { return m_page.setValue(m_element, CVariant::from(value)); }
|
CStatusMessage set(const T &value) { return m_page.setValue(m_element, CVariant::from(value)); }
|
||||||
|
|
||||||
|
//! Get the key string of this value.
|
||||||
|
const QString &getKey() const { return m_page.getKey(m_element); }
|
||||||
|
|
||||||
//! Return the time when this value was updated.
|
//! Return the time when this value was updated.
|
||||||
QDateTime getTimestamp() const { return m_page.getTimestamp(m_element); }
|
QDateTime getTimestamp() const { return m_page.getTimestamp(m_element); }
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ namespace BlackMisc
|
|||||||
//! Write the value corresponding to the element's key and begin synchronizing it to any other pages.
|
//! Write the value corresponding to the element's key and begin synchronizing it to any other pages.
|
||||||
CStatusMessage setValue(Element &element, const CVariant &value);
|
CStatusMessage setValue(Element &element, const CVariant &value);
|
||||||
|
|
||||||
|
//! Get the key string corresponding to the element.
|
||||||
|
const QString &getKey(const Element &element) const;
|
||||||
|
|
||||||
//! Get the timestamp corresponding to the element.
|
//! Get the timestamp corresponding to the element.
|
||||||
qint64 getTimestamp(const Element &element) const;
|
qint64 getTimestamp(const Element &element) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user