add file.read_combined_list(...)

This commit is contained in:
MihailRis
2024-09-30 01:55:42 +03:00
parent f20a0dfae0
commit e590d06bb0
5 changed files with 63 additions and 8 deletions
+28
View File
@@ -10,6 +10,9 @@
#include <utility>
#include "WorldFiles.hpp"
#include "debug/Logger.hpp"
static debug::Logger logger("engine-paths");
/// @brief ENUM for accessing folder and file names
@@ -258,6 +261,31 @@ std::vector<std::filesystem::path> ResPaths::listdir(
return entries;
}
dv::value ResPaths::readCombinedList(const std::string& filename) {
dv::value list = dv::list();
for (const auto& root : roots) {
auto path = root.path / fs::u8path(filename);
if (!fs::exists(path)) {
continue;
}
try {
auto value = files::read_object(path);
if (!value.isList()) {
logger.warning() << "reading combined list " << root.name << ":"
<< filename << " is not a list (skipped)";
continue;
}
for (const auto& elem : value) {
list.add(elem);
}
} catch (const std::runtime_error& err) {
logger.warning() << "reading combined list " << root.name << ":"
<< filename << ": " << err.what();
}
}
return list;
}
const std::filesystem::path& ResPaths::getMainRoot() const {
return mainRoot;
}