19 std::vector<wchar_t> buffer(MAX_PATH);
20 HMODULE hModule = GetModuleHandle(NULL);
23 DWORD size = GetModuleFileNameW(hModule, buffer.data(), buffer.size());
26 while (size == buffer.size() && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
27 buffer.resize(buffer.size() * 2);
28 size = GetModuleFileNameW(hModule, buffer.data(), buffer.size());
32 throw std::runtime_error(
"Failed to get executable path.");
35 std::wstring exe_path(buffer.begin(), buffer.begin() + size);
38 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
39 return converter.to_bytes(exe_path);
41 char result[PATH_MAX];
42 ssize_t count = readlink(
"/proc/self/exe", result, PATH_MAX);
45 throw std::runtime_error(
"Failed to get executable path.");
48 std::string exe_path(result, count);
58 std::vector<wchar_t> buffer(MAX_PATH);
59 HMODULE hModule = GetModuleHandle(NULL);
62 DWORD size = GetModuleFileNameW(hModule, buffer.data(), buffer.size());
65 while (size == buffer.size() && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
66 buffer.resize(buffer.size() * 2);
67 size = GetModuleFileNameW(hModule, buffer.data(), buffer.size());
71 throw std::runtime_error(
"Failed to get executable path.");
74 std::wstring exe_path(buffer.begin(), buffer.begin() + size);
77 size_t pos = exe_path.find_last_of(L
"\\/");
78 if (pos != std::wstring::npos) {
79 exe_path = exe_path.substr(0, pos);
83 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
84 return converter.to_bytes(exe_path);
86 char result[PATH_MAX];
87 ssize_t count = readlink(
"/proc/self/exe", result, PATH_MAX);
90 throw std::runtime_error(
"Failed to get executable path.");
93 std::string exe_path(result, count);
96 size_t pos = exe_path.find_last_of(
"\\/");
97 if (pos != std::string::npos) {
98 exe_path = exe_path.substr(0, pos);
117 inline std::string
make_relative(
const std::string& file_path,
const std::string& base_path) {
118 if (base_path.empty())
return file_path;
119 std::filesystem::path fileP = std::filesystem::u8path(file_path);
120 std::filesystem::path baseP = std::filesystem::u8path(base_path);
122 std::filesystem::path relativeP = std::filesystem::relative(fileP, baseP, ec);
123 return ec ? file_path : relativeP.u8string();