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;
}
+12
View File
@@ -2,6 +2,7 @@
#define FILES_ENGINE_PATHS_H_
#include <string>
#include <vector>
#include <filesystem>
class EnginePaths {
@@ -19,4 +20,15 @@ public:
void setResources(std::filesystem::path folder);
};
class ResPaths {
std::filesystem::path mainRoot;
std::vector<std::filesystem::path> roots;
public:
ResPaths(std::filesystem::path mainRoot,
std::vector<std::filesystem::path> roots);
std::filesystem::path find(const std::string& filename) const;
std::vector<std::filesystem::path> listdir(const std::string& folder) const;
};
#endif // FILES_ENGINE_PATHS_H_