Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Resources.cpp
1#include <Core/Resources/Resources.hpp>
2#include <Core/Utils/StdOptional.hpp>
3#include <cpplocate/cpplocate.h>
4#include <filesystem>
5#include <stack>
6#include <string>
7#include <utility>
8
9namespace Ra {
10namespace Core {
11namespace Resources {
12
13using namespace Ra::Core::Utils;
14namespace fs = ::std::filesystem;
15
16// see https://www.doxygen.nl/manual/commands.html#cmdcond
19fs::path searchPath( const std::string& pattern, const std::string& system, void* libSymbol ) {
20 std::string p = cpplocate::locatePath( pattern, system, libSymbol );
21 return fs::path( p ).lexically_normal();
22}
23
25fs::path clean( const fs::path& path ) {
26 auto status = fs::status( path );
27 if ( status.type() == fs::file_type::not_found ) return "";
28 if ( status.type() == fs::file_type::directory ) return fs::canonical( path ) / "";
29 return fs::canonical( path );
30}
32
33optional<std::string> getRadiumResourcesPath() {
34 auto p =
35 searchPath( "Resources/Radium/", "", reinterpret_cast<void*>( getRadiumResourcesPath ) );
36 p = clean( p / "Resources/Radium" );
37
38 if ( p.empty() ) return {};
39 return p.string();
40}
41
42optional<std::string> getRadiumPluginsPath() {
43 auto p = searchPath( "Plugins/lib", "", reinterpret_cast<void*>( getRadiumPluginsPath ) );
44 p = clean( p / "Plugins" / "lib" );
45
46 if ( p.empty() ) return {};
47 return p.string();
48}
49
51optional<std::string> getBasePath() {
52 return clean( cpplocate::getModulePath() ).string();
53}
54
55optional<std::string> getResourcesPath( void* symbol, const std::string& pattern ) {
56 auto p = searchPath( pattern, "", symbol );
57 p = clean( p / pattern );
58 if ( p.empty() ) return {};
59 return p.string();
60}
61
63namespace DataPath {
64static std::stack<std::string> s_dataPaths;
65}
67
69 if ( DataPath::s_dataPaths.empty() ) { return fs::current_path().string(); }
70 return DataPath::s_dataPaths.top();
71}
72
74 if ( DataPath::s_dataPaths.empty() ) { return fs::current_path().string(); }
75 auto p = DataPath::s_dataPaths.top();
76 DataPath::s_dataPaths.pop();
77 return p;
78}
79
80void pushDataPath( std::string datapath ) {
81 DataPath::s_dataPaths.emplace( std::move( datapath ) );
82 fs::create_directories( DataPath::s_dataPaths.top() );
83}
84
85} // namespace Resources
86} // namespace Core
87} // namespace Ra
T move(T... args)
std::string getDataPath()
Get the current data path.
Definition Resources.cpp:68
std::string popDataPath()
Pop the current data path.
Definition Resources.cpp:73
optional< std::string > getRadiumPluginsPath()
Get the path of Radium embedded plugins.
Definition Resources.cpp:42
optional< std::string > getBasePath()
this one is always found, use optional for consistency ?
Definition Resources.cpp:51
void pushDataPath(std::string datapath)
Push a new data path.
Definition Resources.cpp:80
optional< std::string > getResourcesPath(void *symbol, const std::string &pattern)
Search for general resource path.
Definition Resources.cpp:55
optional< std::string > getRadiumResourcesPath()
Get the path of Radium internal resources.
Definition Resources.cpp:33
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4