1#include "components/PathUtils.hpp"
2#include "components/ErrorUtils.hpp"
6#elif defined(__APPLE__)
7#include <mach-o/dyld.h>
15static std::string gAssetRootOverride =
"";
16static std::string gUserDataDir =
"";
19 gAssetRootOverride = projectPath;
23 if (!std::filesystem::exists(userDataDir)) {
24 std::filesystem::create_directories(userDataDir);
26 gUserDataDir = userDataDir;
30 return gAssetRootOverride;
38 std::filesystem::path exePath;
41 wchar_t wPath[MAX_PATH];
42 DWORD len = GetModuleFileNameW(NULL, wPath, MAX_PATH);
43 if (len == 0 || len == MAX_PATH) {
46 int utf8Size = WideCharToMultiByte(CP_UTF8, 0, wPath, -1,
nullptr, 0,
nullptr,
nullptr);
50 std::string utf8Path(utf8Size,
'\0');
51 WideCharToMultiByte(CP_UTF8, 0, wPath, -1, utf8Path.data(), utf8Size,
nullptr,
nullptr);
52 exePath = std::filesystem::path(utf8Path);
53#elif defined(__APPLE__)
54 char pathBuf[MAXPATHLEN];
55 uint32_t size =
sizeof(pathBuf);
56 if (_NSGetExecutablePath(pathBuf, &size) != 0) {
59 exePath = std::filesystem::canonical(pathBuf);
62 ssize_t len = ::readlink(
"/proc/self/exe", pathBuf,
sizeof(pathBuf) - 1);
67 exePath = std::filesystem::path(pathBuf);
70 return exePath.parent_path();
75 const std::string& overridePath = gAssetRootOverride;
76 if (!overridePath.empty()) {
77 if(relativePath.contains(overridePath)){
80 return (std::filesystem::path(overridePath) / relativePath).string();
85 return (exeDir / relativePath).string();
92 return (std::filesystem::path(gUserDataDir) / relativePath).string();
96 std::filesystem::path logDir;
99 if (!std::filesystem::exists(logDir)) {
100 std::filesystem::create_directories(logDir);
104 return std::filesystem::current_path();
std::string VEX_EXPORT GetAssetDir()
Gets the current asset directory override.
std::filesystem::path VEX_EXPORT GetExecutableDir()
Retrieves the directory containing the current executable.
void VEX_EXPORT SetAssetRoot(const std::string &projectPath)
Overrides the default asset root directory.
std::filesystem::path VEX_EXPORT GetLogDir()
Gets the directory where logs and crash dumps are stored.
void VEX_EXPORT throw_error(const std::string &msg)
Throws an error or terminates the application.
std::string VEX_EXPORT GetAssetPath(const std::string &relativePath)
Resolves the absolute path of an asset based on the current build configuration.
std::string VEX_EXPORT GetUserDataDir()
Gets the current user data directory.
void VEX_EXPORT SetUserDataDir(const std::string &userDataDir)
Sets the current user data directory.
std::string VEX_EXPORT GetUserDataPath(const std::string &relativePath)
Resolves the absolute path of a user data file based on the current user data directory.