mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Rename "mod metadata" to "mod storage" everywhere
This commit is contained in:
parent
8817af07fb
commit
7c21347a40
22 changed files with 480 additions and 474 deletions
|
@ -376,12 +376,12 @@ bool AuthDatabaseFiles::writeAuthFile()
|
|||
return true;
|
||||
}
|
||||
|
||||
ModMetadataDatabaseFiles::ModMetadataDatabaseFiles(const std::string &savedir):
|
||||
ModStorageDatabaseFiles::ModStorageDatabaseFiles(const std::string &savedir):
|
||||
m_storage_dir(savedir + DIR_DELIM + "mod_storage")
|
||||
{
|
||||
}
|
||||
|
||||
bool ModMetadataDatabaseFiles::getModEntries(const std::string &modname, StringMap *storage)
|
||||
bool ModStorageDatabaseFiles::getModEntries(const std::string &modname, StringMap *storage)
|
||||
{
|
||||
Json::Value *meta = getOrCreateJson(modname);
|
||||
if (!meta)
|
||||
|
@ -396,7 +396,7 @@ bool ModMetadataDatabaseFiles::getModEntries(const std::string &modname, StringM
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ModMetadataDatabaseFiles::getModKeys(const std::string &modname,
|
||||
bool ModStorageDatabaseFiles::getModKeys(const std::string &modname,
|
||||
std::vector<std::string> *storage)
|
||||
{
|
||||
Json::Value *meta = getOrCreateJson(modname);
|
||||
|
@ -411,7 +411,7 @@ bool ModMetadataDatabaseFiles::getModKeys(const std::string &modname,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ModMetadataDatabaseFiles::getModEntry(const std::string &modname,
|
||||
bool ModStorageDatabaseFiles::getModEntry(const std::string &modname,
|
||||
const std::string &key, std::string *value)
|
||||
{
|
||||
Json::Value *meta = getOrCreateJson(modname);
|
||||
|
@ -425,13 +425,13 @@ bool ModMetadataDatabaseFiles::getModEntry(const std::string &modname,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ModMetadataDatabaseFiles::hasModEntry(const std::string &modname, const std::string &key)
|
||||
bool ModStorageDatabaseFiles::hasModEntry(const std::string &modname, const std::string &key)
|
||||
{
|
||||
Json::Value *meta = getOrCreateJson(modname);
|
||||
return meta && meta->isMember(key);
|
||||
}
|
||||
|
||||
bool ModMetadataDatabaseFiles::setModEntry(const std::string &modname,
|
||||
bool ModStorageDatabaseFiles::setModEntry(const std::string &modname,
|
||||
const std::string &key, const std::string &value)
|
||||
{
|
||||
Json::Value *meta = getOrCreateJson(modname);
|
||||
|
@ -444,7 +444,7 @@ bool ModMetadataDatabaseFiles::setModEntry(const std::string &modname,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ModMetadataDatabaseFiles::removeModEntry(const std::string &modname,
|
||||
bool ModStorageDatabaseFiles::removeModEntry(const std::string &modname,
|
||||
const std::string &key)
|
||||
{
|
||||
Json::Value *meta = getOrCreateJson(modname);
|
||||
|
@ -459,7 +459,7 @@ bool ModMetadataDatabaseFiles::removeModEntry(const std::string &modname,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ModMetadataDatabaseFiles::removeModEntries(const std::string &modname)
|
||||
bool ModStorageDatabaseFiles::removeModEntries(const std::string &modname)
|
||||
{
|
||||
Json::Value *meta = getOrCreateJson(modname);
|
||||
if (!meta || meta->empty())
|
||||
|
@ -470,22 +470,22 @@ bool ModMetadataDatabaseFiles::removeModEntries(const std::string &modname)
|
|||
return true;
|
||||
}
|
||||
|
||||
void ModMetadataDatabaseFiles::beginSave()
|
||||
void ModStorageDatabaseFiles::beginSave()
|
||||
{
|
||||
}
|
||||
|
||||
void ModMetadataDatabaseFiles::endSave()
|
||||
void ModStorageDatabaseFiles::endSave()
|
||||
{
|
||||
if (m_modified.empty())
|
||||
return;
|
||||
|
||||
if (!fs::CreateAllDirs(m_storage_dir)) {
|
||||
errorstream << "ModMetadataDatabaseFiles: Unable to save. '"
|
||||
errorstream << "ModStorageDatabaseFiles: Unable to save. '"
|
||||
<< m_storage_dir << "' cannot be created." << std::endl;
|
||||
return;
|
||||
}
|
||||
if (!fs::IsDir(m_storage_dir)) {
|
||||
errorstream << "ModMetadataDatabaseFiles: Unable to save. '"
|
||||
errorstream << "ModStorageDatabaseFiles: Unable to save. '"
|
||||
<< m_storage_dir << "' is not a directory." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
@ -493,10 +493,10 @@ void ModMetadataDatabaseFiles::endSave()
|
|||
for (auto it = m_modified.begin(); it != m_modified.end();) {
|
||||
const std::string &modname = *it;
|
||||
|
||||
const Json::Value &json = m_mod_meta[modname];
|
||||
const Json::Value &json = m_mod_storage[modname];
|
||||
|
||||
if (!fs::safeWriteToFile(m_storage_dir + DIR_DELIM + modname, fastWriteJson(json))) {
|
||||
errorstream << "ModMetadataDatabaseFiles[" << modname
|
||||
errorstream << "ModStorageDatabaseFiles[" << modname
|
||||
<< "]: failed to write file." << std::endl;
|
||||
++it;
|
||||
continue;
|
||||
|
@ -506,24 +506,24 @@ void ModMetadataDatabaseFiles::endSave()
|
|||
}
|
||||
}
|
||||
|
||||
void ModMetadataDatabaseFiles::listMods(std::vector<std::string> *res)
|
||||
void ModStorageDatabaseFiles::listMods(std::vector<std::string> *res)
|
||||
{
|
||||
// List in-memory metadata first.
|
||||
for (const auto &pair : m_mod_meta) {
|
||||
for (const auto &pair : m_mod_storage) {
|
||||
res->push_back(pair.first);
|
||||
}
|
||||
|
||||
// List other metadata present in the filesystem.
|
||||
for (const auto &entry : fs::GetDirListing(m_storage_dir)) {
|
||||
if (!entry.dir && m_mod_meta.count(entry.name) == 0)
|
||||
if (!entry.dir && m_mod_storage.count(entry.name) == 0)
|
||||
res->push_back(entry.name);
|
||||
}
|
||||
}
|
||||
|
||||
Json::Value *ModMetadataDatabaseFiles::getOrCreateJson(const std::string &modname)
|
||||
Json::Value *ModStorageDatabaseFiles::getOrCreateJson(const std::string &modname)
|
||||
{
|
||||
auto found = m_mod_meta.find(modname);
|
||||
if (found != m_mod_meta.end())
|
||||
auto found = m_mod_storage.find(modname);
|
||||
if (found != m_mod_storage.end())
|
||||
return &found->second;
|
||||
|
||||
Json::Value meta(Json::objectValue);
|
||||
|
@ -537,11 +537,11 @@ Json::Value *ModMetadataDatabaseFiles::getOrCreateJson(const std::string &modnam
|
|||
std::string errs;
|
||||
|
||||
if (!Json::parseFromStream(builder, is, &meta, &errs)) {
|
||||
errorstream << "ModMetadataDatabaseFiles[" << modname
|
||||
errorstream << "ModStorageDatabaseFiles[" << modname
|
||||
<< "]: failed to decode data: " << errs << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return &(m_mod_meta[modname] = std::move(meta));
|
||||
return &(m_mod_storage[modname] = std::move(meta));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue