From a836dd31e27a7ec220376f4d4b05c9a9d40fc57e Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Tue, 29 Jul 2025 21:36:18 +0200 Subject: [PATCH] fix exec path --- src/GraphicalUI/main.cpp | 2 -- src/Utils/AssetManager.cpp | 25 ++++++++++++++++++++----- src/Utils/AssetManager.h | 5 ----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/GraphicalUI/main.cpp b/src/GraphicalUI/main.cpp index 62eea41..9a3c417 100644 --- a/src/GraphicalUI/main.cpp +++ b/src/GraphicalUI/main.cpp @@ -15,8 +15,6 @@ int main(int arc, char** args) { bool everythingIsOK = true; - AssetManager::setExePath(args[0]); - // CHECK PIECES FILES PiecesFiles pf; diff --git a/src/Utils/AssetManager.cpp b/src/Utils/AssetManager.cpp index f42da11..3baf127 100644 --- a/src/Utils/AssetManager.cpp +++ b/src/Utils/AssetManager.cpp @@ -1,18 +1,33 @@ #include "AssetManager.h" +#ifdef _WIN32 +#include //GetModuleFileNameW +#else +#include +#include //readlink +#endif + namespace fs = std::filesystem; -static fs::path EXE_DIRECTORY; - -void AssetManager::setExePath(const std::string& arg0) { - EXE_DIRECTORY = fs::path(arg0).parent_path(); +static fs::path getExeDirectory(){ + #ifdef _WIN32 + wchar_t path[MAX_PATH] = { 0 }; + GetModuleFileNameW(NULL, path, MAX_PATH); + return 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 } + + static fs::path getEnv(const std::string& var) { char* env = std::getenv(var.c_str()); return env ? env : #ifdef JMINOS_IGNORE_WORKDIR - EXE_DIRECTORY.parent_path(); + getExeDirectory().parent_path().parent_path(); #else ""; #endif diff --git a/src/Utils/AssetManager.h b/src/Utils/AssetManager.h index 8e8bdfc..ab36e94 100644 --- a/src/Utils/AssetManager.h +++ b/src/Utils/AssetManager.h @@ -15,9 +15,4 @@ class AssetManager { * @brief Used to save things */ static std::filesystem::path getConfigPath(const std::string& resource); - - /** - * @brief Set the current path of the executable - */ - static void setExePath(const std::string& arg0); }; \ No newline at end of file