blob: 50c70cdff0f0be8fdbd8bae992fb10038f66f8d8 (
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
35
36
37
38
39
|
#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() 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_opt = engine::path_utils::exe();
if (!exe_opt) {
std::cerr << "cannot find path of executable" << std::endl;
exit(1);
}
m_exe = *exe_opt;
const auto files_root = m_exe.parent_path();
const auto bin = std::filesystem::weakly_canonical(BINDIR);
const std::filesystem::path pkgdata { PKGDATADIR };
const auto assets = pkgdata / "assets";
m_assets_objs = std::filesystem::canonical(files_root / std::filesystem::weakly_canonical(assets / "objs") .lexically_relative(bin));
m_assets_textures = std::filesystem::canonical(files_root / std::filesystem::weakly_canonical(assets / "textures").lexically_relative(bin));
m_spvshaders = std::filesystem::canonical(files_root / std::filesystem::weakly_canonical(SPVSHADERSDIR) .lexically_relative(bin));
}
|