Files
XCEngine/new_editor/app/Support/ExecutablePath.h

32 lines
792 B
C
Raw Normal View History

#pragma once
#include <filesystem>
#include <vector>
#include <windows.h>
namespace XCEngine::UI::Editor::Support {
inline std::filesystem::path GetExecutableDirectory() {
std::vector<wchar_t> buffer(MAX_PATH);
while (true) {
const DWORD copied = ::GetModuleFileNameW(
nullptr,
buffer.data(),
static_cast<DWORD>(buffer.size()));
if (copied == 0u) {
return std::filesystem::current_path().lexically_normal();
}
if (copied < buffer.size() - 1u) {
return std::filesystem::path(std::wstring(buffer.data(), copied))
.parent_path()
.lexically_normal();
}
buffer.resize(buffer.size() * 2u);
}
}
} // namespace XCEngine::UI::Editor::Support