diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-11-26 14:05:29 -0500 |
|---|---|---|
| committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-11-26 14:05:29 -0500 |
| commit | 2adce1795211fd0a42c3b4e03ab35a90bb01bccf (patch) | |
| tree | 7fda2f874f0653e4c74edaaf1547fe9802b2005a /src/global.cpp | |
| parent | 7fc0e0f50ae961efbe0cac1032b03a42d41d87d5 (diff) | |
| download | lingo-ap-tracker-2adce1795211fd0a42c3b4e03ab35a90bb01bccf.tar.gz lingo-ap-tracker-2adce1795211fd0a42c3b4e03ab35a90bb01bccf.tar.bz2 lingo-ap-tracker-2adce1795211fd0a42c3b4e03ab35a90bb01bccf.zip | |
Stop relying on correctly set working directory
Diffstat (limited to 'src/global.cpp')
| -rw-r--r-- | src/global.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
| 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 @@ | |||
| 1 | #include "global.h" | ||
| 2 | |||
| 3 | #include <whereami.h> | ||
| 4 | |||
| 5 | #include <filesystem> | ||
| 6 | #include <string> | ||
| 7 | #include <string_view> | ||
| 8 | |||
| 9 | const std::filesystem::path& GetExecutableDirectory() { | ||
| 10 | static const std::filesystem::path* executable_directory = []() { | ||
| 11 | int length = wai_getExecutablePath(NULL, 0, NULL); | ||
| 12 | std::string buf(length, 0); | ||
| 13 | wai_getExecutablePath(buf.data(), length, NULL); | ||
| 14 | |||
| 15 | std::filesystem::path exec_path(buf); | ||
| 16 | return new std::filesystem::path(exec_path.parent_path()); | ||
| 17 | }(); | ||
| 18 | |||
| 19 | return *executable_directory; | ||
| 20 | } | ||
| 21 | |||
| 22 | std::string GetAbsolutePath(std::string_view path) { | ||
| 23 | return (GetExecutableDirectory() / path).string(); | ||
| 24 | } | ||
