content-pack resources support
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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_
|
||||
Reference in New Issue
Block a user