ResPaths.findRaw

This commit is contained in:
MihailRis
2024-04-19 14:22:14 +03:00
parent bedcc438f4
commit 0e69db13be
4 changed files with 29 additions and 26 deletions
+18 -3
View File
@@ -4,6 +4,7 @@
#include <sstream>
#include <filesystem>
#include "../util/stringutil.h"
#include "../typedefs.h"
#include "WorldFiles.h"
@@ -152,14 +153,14 @@ fs::path EnginePaths::resolve(std::string path) {
throw files_access_error("unknown entry point '"+prefix+"'");
}
ResPaths::ResPaths(fs::path mainRoot, std::vector<fs::path> roots)
ResPaths::ResPaths(fs::path mainRoot, std::vector<std::pair<std::string, fs::path>> roots)
: mainRoot(mainRoot), roots(roots) {
}
fs::path ResPaths::find(const std::string& filename) const {
for (int i = roots.size()-1; i >= 0; i--) {
auto& root = roots[i];
fs::path file = root / fs::u8path(filename);
fs::path file = root.second / fs::u8path(filename);
if (fs::exists(file)) {
return file;
}
@@ -167,11 +168,25 @@ fs::path ResPaths::find(const std::string& filename) const {
return mainRoot / fs::u8path(filename);
}
std::string ResPaths::findRaw(const std::string& filename) const {
for (int i = roots.size()-1; i >= 0; i--) {
auto& root = roots[i];
if (fs::exists(root.second / fs::path(filename))) {
return root.first+":"+filename;
}
}
auto resDir = mainRoot;
if (fs::exists(resDir / fs::path(filename))) {
return "core:"+filename;
}
throw std::runtime_error("could not to find file "+util::quote(filename));
}
std::vector<fs::path> ResPaths::listdir(const std::string& folderName) const {
std::vector<fs::path> entries;
for (int i = roots.size()-1; i >= 0; i--) {
auto& root = roots[i];
fs::path folder = root / fs::u8path(folderName);
fs::path folder = root.second / fs::u8path(folderName);
if (!fs::is_directory(folder))
continue;
for (const auto& entry : fs::directory_iterator(folder)) {