32 lines
792 B
C
32 lines
792 B
C
|
|
#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
|