From 2adce1795211fd0a42c3b4e03ab35a90bb01bccf Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 26 Nov 2023 14:05:29 -0500 Subject: Stop relying on correctly set working directory --- src/global.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/global.cpp (limited to 'src/global.cpp') diff --git a/src/global.cpp b/src/global.cpp new file mode 100644 index 0000000..3ee4f58 --- /dev/null +++ b/src/global.cpp @@ -0,0 +1,24 @@ +#include "global.h" + +#include + +#include +#include +#include + +const std::filesystem::path& GetExecutableDirectory() { + static const std::filesystem::path* executable_directory = []() { + int length = wai_getExecutablePath(NULL, 0, NULL); + std::string buf(length, 0); + wai_getExecutablePath(buf.data(), length, NULL); + + std::filesystem::path exec_path(buf); + return new std::filesystem::path(exec_path.parent_path()); + }(); + + return *executable_directory; +} + +std::string GetAbsolutePath(std::string_view path) { + return (GetExecutableDirectory() / path).string(); +} -- cgit 1.4.1