blob: 94bbba579dff1a9ee5e4d3628226c6cc3dafae3b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include "path_utils.hpp"
#include <iostream>
#include <optional>
#include <filesystem>
#ifdef _WIN32
# include <windows.h>
# include <tchar.h>
#endif
std::optional<std::filesystem::path> engine::path_utils::exe_path() noexcept {
#if defined(_WIN32)
TCHAR filename[MAX_PATH];
if (!GetModuleFileName(NULL, filename, MAX_PATH))
return {};
return std::filesystem::path(filename);
#elif defined(linux)
return std::filesystem::canonical("/proc/self/exe");
#else
# error "operating system not supported"
#endif
}
engine::path_utils::Paths::Paths() noexcept {
const auto exe_path_opt = engine::path_utils::exe_path();
if (!exe_path_opt) {
std::cerr << "cannot find path of executable" << std::endl;
exit(1);
}
const auto files_root = (*exe_path_opt).parent_path();
m_assets_objs = files_root / std::filesystem::relative(PKGDATADIR "/assets/objs", BINDIR);
m_assets_textures = files_root / std::filesystem::relative(PKGDATADIR "/assets/textures", BINDIR);
m_spvshaders = files_root / std::filesystem::relative(SPVSHADERSDIR, BINDIR);
}
|