5#include "io/FileSystem.h"
12#elif defined(__APPLE__)
13# include <mach-o/dyld.h>
14#elif defined(__linux__)
25 wchar_t buf[MAX_PATH];
26 GetModuleFileNameW(NULL, buf, MAX_PATH);
27 return std::filesystem::path(buf).remove_filename();
28#elif defined(__APPLE__)
30 _NSGetExecutablePath(
nullptr, &size);
31 std::string tmp(size,
'\0');
32 _NSGetExecutablePath(tmp.data(), &size);
33 return std::filesystem::weakly_canonical(std::filesystem::path(tmp)).remove_filename();
34#elif defined(__linux__)
35 return std::filesystem::weakly_canonical(std::filesystem::read_symlink(
"/proc/self/exe")).remove_filename();
37 return std::filesystem::current_path();
43#if defined(ASSETS_ROOT)
44 auto path = std::filesystem::path(std::string(ASSETS_ROOT));
45 if (std::filesystem::exists(path)) {
54 std::ifstream file(path, std::ios::binary | std::ios::ate);
55 if (!file.is_open()) {
56 LOG_ERROR(
"Could not open file: %s", path.c_str());
60 auto size = file.tellg();
63 std::vector<char> buffer(size);
65 if (!file.read(buffer.data(), size)) {
66 LOG_ERROR(
"Could not open file: %s", path.c_str());
81 return std::string(buffer.begin(), buffer.end());
constexpr const char * kAssetsDirName
Console logging macros for all engine and game code.
#define LOG_ERROR(fmt,...)
std::filesystem::path GetExecutableFolder() const
Return the directory containing the running executable.
std::vector< char > LoadFile(const std::filesystem::path &path)
Load an arbitrary file into a byte buffer.
std::string LoadAssetFileText(const std::string &relativePath)
Load a text file from the assets directory into a string.
std::vector< char > LoadAssetFile(const std::string &relativePath)
Load a file from the assets directory into a byte buffer.
std::filesystem::path GetAssetsFolder() const
Return the runtime assets directory.