commit ca6a44e536fed9f185d475c031993234d61e4d33
parent 6242063465e48c5955af6b4166180f3edae2ed16
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sat, 2 Nov 2024 19:19:42 +0100
do not store name of cache/json as member as we might want to change the root directory at runtime
Diffstat:
2 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/source/jucePluginLib/patchdb/db.cpp b/source/jucePluginLib/patchdb/db.cpp
@@ -16,12 +16,13 @@
namespace pluginLib::patchDB
{
+ constexpr const char* g_fileNameCache = "patchmanagerdb.cache";
+ constexpr const char* g_filenameJson = "patchmanagerdb.json";
+
static constexpr bool g_cacheEnabled = true;
DB::DB(juce::File _dir)
: m_settingsDir(std::move(_dir))
- , m_jsonFileName(m_settingsDir.getChildFile("patchmanagerdb.json"))
- , m_cacheFileName(m_settingsDir.getChildFile("patchmanagerdb.cache"))
, m_loader("PatchLoader", false, dsp56k::ThreadPriority::Lowest)
{
}
@@ -1294,7 +1295,7 @@ namespace pluginLib::patchDB
{
bool success = true;
- const auto json = juce::JSON::parse(m_jsonFileName);
+ const auto json = juce::JSON::parse(getJsonFile());
const auto* datasources = json["datasources"].getArray();
if(datasources)
@@ -1474,11 +1475,15 @@ namespace pluginLib::patchDB
bool DB::saveJson()
{
m_cacheDirty = true;
- m_cacheFileName.deleteFile();
- if (!m_jsonFileName.hasWriteAccess())
+ const auto cacheFile = getCacheFile();
+ const auto jsonFile = getJsonFile();
+
+ cacheFile.deleteFile();
+
+ if (!jsonFile.hasWriteAccess())
{
- pushError("No write access to file:\n" + m_jsonFileName.getFullPathName().toStdString());
+ pushError("No write access to file:\n" + jsonFile.getFullPathName().toStdString());
return false;
}
@@ -1583,7 +1588,7 @@ namespace pluginLib::patchDB
json->setProperty("patches", patchMods);
}
- return saveJson(m_jsonFileName, json);
+ return saveJson(jsonFile, json);
}
juce::File DB::getJsonFile(const DataSource& _ds) const
@@ -1739,11 +1744,13 @@ namespace pluginLib::patchDB
{
m_cacheDirty = true;
- if(!m_cacheFileName.existsAsFile())
+ const auto cacheFile = getCacheFile();
+
+ if(!cacheFile.existsAsFile())
return false;
std::vector<uint8_t> data;
- if(!synthLib::readFile(data, m_cacheFileName.getFullPathName().toStdString()))
+ if(!synthLib::readFile(data, cacheFile.getFullPathName().toStdString()))
return false;
try
@@ -1945,7 +1952,9 @@ namespace pluginLib::patchDB
void DB::saveCache()
{
- if(!m_cacheFileName.hasWriteAccess())
+ const auto cacheFile = getCacheFile();
+
+ if(!cacheFile.hasWriteAccess())
return;
baseLib::BinaryStream outStream;
@@ -2059,8 +2068,18 @@ namespace pluginLib::patchDB
std::vector<uint8_t> buffer;
outStream.toVector(buffer);
- m_cacheFileName.replaceWithData(buffer.data(), buffer.size());
+ cacheFile.replaceWithData(buffer.data(), buffer.size());
m_cacheDirty = false;
}
+
+ juce::File DB::getCacheFile() const
+ {
+ return m_settingsDir.getChildFile(g_fileNameCache);
+ }
+
+ juce::File DB::getJsonFile() const
+ {
+ return m_settingsDir.getChildFile(g_filenameJson);
+ }
}
diff --git a/source/jucePluginLib/patchdb/db.h b/source/jucePluginLib/patchdb/db.h
@@ -152,11 +152,11 @@ namespace pluginLib::patchDB
bool loadCache();
void saveCache();
+ juce::File getCacheFile() const;
+ juce::File getJsonFile() const;
// IO
juce::File m_settingsDir;
- juce::File m_jsonFileName;
- juce::File m_cacheFileName;
// loader
JobQueue m_loader;