content-pack resources support

This commit is contained in:
MihailRis
2023-12-14 02:30:39 +03:00
parent c6d2266026
commit 396ee31bcc
43 changed files with 170 additions and 90 deletions
+36
View File
@@ -8,6 +8,7 @@
namespace fs = std::filesystem;
using std::string;
using std::vector;
using fs::path;
path EnginePaths::getUserfiles() const {
@@ -56,3 +57,38 @@ void EnginePaths::setUserfiles(path folder) {
void EnginePaths::setResources(path folder) {
this->resources = folder;
}
ResPaths::ResPaths(path mainRoot, vector<path> roots)
: mainRoot(mainRoot), roots(roots) {
}
path ResPaths::find(const string& filename) const {
for (auto& root : roots) {
path file = root / path(filename);
if (fs::exists(file)) {
return file;
}
}
return mainRoot / path(filename);
}
vector<path> ResPaths::listdir(const string& folderName) const {
vector<path> entries;
for (auto& root : roots) {
path folder = root / path(folderName);
if (!fs::is_directory(folder))
continue;
for (const auto& entry : fs::directory_iterator(folder)) {
entries.push_back(entry.path());
}
}
{
path folder = mainRoot / path(folderName);
if (!fs::is_directory(folder))
return entries;
for (const auto& entry : fs::directory_iterator(folder)) {
entries.push_back(entry.path());
}
}
return entries;
}