From c432c03f7964843d71cfeafd7314ccb409d667e5 Mon Sep 17 00:00:00 2001 From: Fabio Picchi Date: Wed, 3 May 2023 12:36:19 -0300 Subject: [PATCH] Fix exe path logic --- Converter/src/main.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Converter/src/main.cpp b/Converter/src/main.cpp index 9d14d495..fa0c9752 100644 --- a/Converter/src/main.cpp +++ b/Converter/src/main.cpp @@ -1,7 +1,13 @@ - - #include #include +#include + +#ifdef WINDOWS + #include +#else + #include + #include +#endif #include "unsuck/unsuck.hpp" #include "chunker_countsort_laszip.h" @@ -494,6 +500,17 @@ void generatePage(string exePath, string pagedir, string pagename) { #include "HierarchyBuilder.h" +std::string getExePath() { +#ifdef WINDOWS + char result[ MAX_PATH ]; + return std::string(result, GetModuleFileName(NULL, result, MAX_PATH)); +#else + char result[ PATH_MAX ]; + ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); + return std::string(result, (count > 0) ? count : 0); +#endif +} + int main(int argc, char** argv) { @@ -512,7 +529,8 @@ int main(int argc, char** argv) { double tStart = now(); - auto exePath = fs::canonical(fs::absolute(argv[0])).parent_path().string(); + auto exePath = getExePath(); + cout << "#exe path: " << exePath << endl; launchMemoryChecker(2 * 1024, 0.1); auto cpuData = getCpuData(); @@ -566,4 +584,4 @@ int main(int argc, char** argv) { return 0; -} \ No newline at end of file +}