RunicVTT Open Source Virtual Tabletop for TTRPG using P2P
Loading...
Searching...
No Matches
PathManager Class Reference

#include <PathManager.h>

Collaboration diagram for PathManager:

Static Public Member Functions

static fs::path getRootDirectory ()
 
static fs::path getMapsPath ()
 
static fs::path getMarkersPath ()
 
static fs::path getNotesPath ()
 
static fs::path getGameTablesPath ()
 
static fs::path getBoardsPath (std::string gametable_name)
 
static fs::path getConfigPath ()
 
static fs::path getExternalPath ()
 
static fs::path getNodeExePath ()
 
static fs::path getLocalTunnelClientPath ()
 
static fs::path getLocalTunnelControllerPath ()
 
static fs::path getUpnpcExePath ()
 
static fs::path getExecutableDirectory ()
 
static fs::path getExecutableRoot ()
 
static fs::path getResPath ()
 
static fs::path getCertsPath ()
 
static fs::path getShaderPath ()
 
static void ensureDirectories ()
 
static bool hasDirSep (const std::string &s)
 
static bool isUNC (const std::string &s)
 
static bool isDriveAbsolute (const std::string &s)
 
static bool isDriveRelative (const std::string &s)
 
static bool isAbsolutePath (const std::string &s)
 
static bool isPathLike (const std::string &s)
 
static bool isFilenameOnly (const std::string &s)
 

Static Private Member Functions

static fs::path getDocumentsFolder ()
 
static void createIfNotExists (const fs::path &path)
 

Static Private Attributes

static fs::path executableDir = fs::current_path()
 
static fs::path baseDocumentsPath = PathManager::getDocumentsFolder() / "RunicVTT"
 

Detailed Description

Definition at line 14 of file PathManager.h.

Member Function Documentation

◆ createIfNotExists()

static void PathManager::createIfNotExists ( const fs::path & path)
inlinestaticprivate

Definition at line 41 of file PathManager.h.

42 {
43 if (!fs::exists(path))
44 {
45 fs::create_directories(path);
46 std::cout << "[PathManager] Created folder: " << path << std::endl;
47 }
48 }
Here is the caller graph for this function:

◆ ensureDirectories()

static void PathManager::ensureDirectories ( )
inlinestatic

Definition at line 140 of file PathManager.h.

141 {
148 }
static fs::path getMarkersPath()
Definition PathManager.h:66
static fs::path getRootDirectory()
Definition PathManager.h:55
static fs::path getConfigPath()
Definition PathManager.h:86
static fs::path getGameTablesPath()
Definition PathManager.h:76
static void createIfNotExists(const fs::path &path)
Definition PathManager.h:41
static fs::path getMapsPath()
Definition PathManager.h:61
static fs::path getNotesPath()
Definition PathManager.h:71
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBoardsPath()

static fs::path PathManager::getBoardsPath ( std::string gametable_name)
inlinestatic

Definition at line 81 of file PathManager.h.

82 {
83 return getGameTablesPath() / gametable_name / "Boards";
84 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCertsPath()

static fs::path PathManager::getCertsPath ( )
inlinestatic

Definition at line 129 of file PathManager.h.

130 {
131 return getResPath() / "certs";
132 }
static fs::path getResPath()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getConfigPath()

static fs::path PathManager::getConfigPath ( )
inlinestatic

Definition at line 86 of file PathManager.h.

87 {
88 return getExecutableRoot() / "Config";
89 }
static fs::path getExecutableRoot()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDocumentsFolder()

static fs::path PathManager::getDocumentsFolder ( )
inlinestaticprivate

Definition at line 17 of file PathManager.h.

18 {
19#ifdef _WIN32
20 //PWSTR path_w = nullptr;
21 //HRESULT result = SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &path_w);
22 //if (SUCCEEDED(result)) {
23 // std::wstring wpath(path_w);
24 // CoTaskMemFree(path_w); // free COM-allocated string
25 // return std::filesystem::path(wpath);
26 //} else {
27 // throw std::runtime_error("Failed to get Documents folder");
28 //}
29 //
30 const char* userProfile = std::getenv("USERPROFILE");
31 return fs::path(userProfile ? userProfile : "C:\\Users\\Default") / "Documents";
32#elif __APPLE__
33 const char* home = std::getenv("HOME");
34 return fs::path(home ? home : "/Users/Default") / "Documents";
35#else // Linux
36 const char* home = std::getenv("HOME");
37 return fs::path(home ? home : "/home/default") / "Documents";
38#endif
39 }

◆ getExecutableDirectory()

static fs::path PathManager::getExecutableDirectory ( )
inlinestatic

Definition at line 114 of file PathManager.h.

115 {
116 return executableDir;
117 }
static fs::path executableDir
Definition PathManager.h:50

◆ getExecutableRoot()

static fs::path PathManager::getExecutableRoot ( )
inlinestatic

Definition at line 119 of file PathManager.h.

120 {
121 return (executableDir.filename() == "bin") ? executableDir.parent_path() : executableDir;
122 }
Here is the caller graph for this function:

◆ getExternalPath()

static fs::path PathManager::getExternalPath ( )
inlinestatic

Definition at line 93 of file PathManager.h.

94 {
95 return getExecutableRoot() / "external";
96 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGameTablesPath()

static fs::path PathManager::getGameTablesPath ( )
inlinestatic

Definition at line 76 of file PathManager.h.

77 {
78 return getExecutableRoot() / "GameTables";
79 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLocalTunnelClientPath()

static fs::path PathManager::getLocalTunnelClientPath ( )
inlinestatic

Definition at line 101 of file PathManager.h.

102 {
103 return getExternalPath() / "localtunnel" / "node_modules" / "localtunnel" / "bin" / "client";
104 }
static fs::path getExternalPath()
Definition PathManager.h:93
Here is the call graph for this function:

◆ getLocalTunnelControllerPath()

static fs::path PathManager::getLocalTunnelControllerPath ( )
inlinestatic

Definition at line 106 of file PathManager.h.

107 {
108 return getExternalPath() / "lt-controller.cjs";
109 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMapsPath()

static fs::path PathManager::getMapsPath ( )
inlinestatic

Definition at line 61 of file PathManager.h.

62 {
63 return getExecutableRoot() / "Maps";
64 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMarkersPath()

static fs::path PathManager::getMarkersPath ( )
inlinestatic

Definition at line 66 of file PathManager.h.

67 {
68 return getExecutableRoot() / "Markers";
69 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNodeExePath()

static fs::path PathManager::getNodeExePath ( )
inlinestatic

Definition at line 97 of file PathManager.h.

98 {
99 return getExternalPath() / "node" / "node.exe";
100 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNotesPath()

static fs::path PathManager::getNotesPath ( )
inlinestatic

Definition at line 71 of file PathManager.h.

72 {
73 return getExecutableRoot() / "Notes";
74 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getResPath()

static fs::path PathManager::getResPath ( )
inlinestatic

Definition at line 124 of file PathManager.h.

125 {
126 return getExecutableRoot() / "res";
127 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRootDirectory()

static fs::path PathManager::getRootDirectory ( )
inlinestatic

Definition at line 55 of file PathManager.h.

56 {
57 return getExecutableRoot();
58 //return baseDocumentsPath;
59 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getShaderPath()

static fs::path PathManager::getShaderPath ( )
inlinestatic

Definition at line 134 of file PathManager.h.

135 {
136 return getResPath() / "shaders";
137 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUpnpcExePath()

static fs::path PathManager::getUpnpcExePath ( )
inlinestatic

Definition at line 110 of file PathManager.h.

111 {
112 return executableDir / "upnpc-static.exe";
113 }
Here is the caller graph for this function:

◆ hasDirSep()

static bool PathManager::hasDirSep ( const std::string & s)
inlinestatic

Definition at line 151 of file PathManager.h.

152 {
153 return s.find('\\') != std::string::npos || s.find('/') != std::string::npos;
154 }
Here is the caller graph for this function:

◆ isAbsolutePath()

static bool PathManager::isAbsolutePath ( const std::string & s)
inlinestatic

Definition at line 174 of file PathManager.h.

175 {
176 // std::filesystem covers POSIX abspaths; supplement for Windows special cases
177 std::filesystem::path p(s);
178 if (p.is_absolute())
179 return true; // works for POSIX and many Windows cases
180 if (isUNC(s) || isDriveAbsolute(s))
181 return true;
182 return false;
183 }
static bool isUNC(const std::string &s)
static bool isDriveAbsolute(const std::string &s)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDriveAbsolute()

static bool PathManager::isDriveAbsolute ( const std::string & s)
inlinestatic

Definition at line 162 of file PathManager.h.

163 {
164 // C:\foo or C:/foo
165 return s.size() > 2 && std::isalpha(static_cast<unsigned char>(s[0])) && s[1] == ':' && (s[2] == '\\' || s[2] == '/');
166 }
Here is the caller graph for this function:

◆ isDriveRelative()

static bool PathManager::isDriveRelative ( const std::string & s)
inlinestatic

Definition at line 168 of file PathManager.h.

169 {
170 // C:foo (relative to current dir on drive C)
171 return s.size() > 1 && std::isalpha(static_cast<unsigned char>(s[0])) && s[1] == ':' && (s.size() == 2 || (s[2] != '\\' && s[2] != '/'));
172 }
Here is the caller graph for this function:

◆ isFilenameOnly()

static bool PathManager::isFilenameOnly ( const std::string & s)
inlinestatic

Definition at line 197 of file PathManager.h.

198 {
199 // No separators, no drive/UNC prefixes => just a filename, like "goblin.png"
200 return !isPathLike(s);
201 }
static bool isPathLike(const std::string &s)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPathLike()

static bool PathManager::isPathLike ( const std::string & s)
inlinestatic

Definition at line 185 of file PathManager.h.

186 {
187 // Treat anything with directory separators OR absolute/UNC/drive-relative prefixes as a path
188 if (isAbsolutePath(s))
189 return true;
190 if (isDriveRelative(s))
191 return true; // still a path, just not absolute
192 if (hasDirSep(s))
193 return true; // e.g. "markers/goblin.png"
194 return false;
195 }
static bool hasDirSep(const std::string &s)
static bool isAbsolutePath(const std::string &s)
static bool isDriveRelative(const std::string &s)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isUNC()

static bool PathManager::isUNC ( const std::string & s)
inlinestatic

Definition at line 156 of file PathManager.h.

157 {
158 // \\server\share or //server/share
159 return (s.rfind("\\\\", 0) == 0) || (s.rfind("//", 0) == 0);
160 }
Here is the caller graph for this function:

Member Data Documentation

◆ baseDocumentsPath

fs::path PathManager::baseDocumentsPath = PathManager::getDocumentsFolder() / "RunicVTT"
inlinestaticprivate

Definition at line 51 of file PathManager.h.

◆ executableDir

fs::path PathManager::executableDir = fs::current_path()
inlinestaticprivate

Definition at line 50 of file PathManager.h.


The documentation for this class was generated from the following file: