mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-02 04:37:54 +08:00
Uses environment variable to tell the program where to find resource files. Sharder sources are still search for in the current workind directory.
50 lines
1.0 KiB
C++
50 lines
1.0 KiB
C++
#ifndef FILESYSTEM_H
|
|
#define FILESYSTEM_H
|
|
|
|
#include <string>
|
|
|
|
class FileSystem
|
|
{
|
|
private:
|
|
typedef std::string (*Builder) (const std::string& path);
|
|
|
|
public:
|
|
static std::string getPath(const std::string& path)
|
|
{
|
|
static std::string(*pathBuilder)(std::string const &) = getPathBuilder();
|
|
return (*pathBuilder)(path);
|
|
}
|
|
|
|
private:
|
|
static std::string const & getRoot()
|
|
{
|
|
static char const * givenRoot {getenv("LOGL_ROOT_PATH")};
|
|
static std::string root {givenRoot != nullptr ? givenRoot : ""};
|
|
return root;
|
|
}
|
|
|
|
//static std::string(*foo (std::string const &)) getPathBuilder()
|
|
static Builder getPathBuilder()
|
|
{
|
|
if (getRoot() != "")
|
|
return &FileSystem::getPathRelativeRoot;
|
|
else
|
|
return &FileSystem::getPathRelativeBinary;
|
|
}
|
|
|
|
static std::string getPathRelativeRoot(const std::string& path)
|
|
{
|
|
return getRoot() + std::string("/") + path;
|
|
}
|
|
|
|
static std::string getPathRelativeBinary(const std::string& path)
|
|
{
|
|
return "../../../" + path;
|
|
}
|
|
|
|
|
|
};
|
|
|
|
// FILESYSTEM_H
|
|
#endif
|