diff --git a/source/MaaUtils/AppRuntime/AppRuntime_Posix.cpp b/source/MaaUtils/AppRuntime/AppRuntime_Posix.cpp index aee7ff57c..4ca889e7f 100644 --- a/source/MaaUtils/AppRuntime/AppRuntime_Posix.cpp +++ b/source/MaaUtils/AppRuntime/AppRuntime_Posix.cpp @@ -1,5 +1,35 @@ #ifndef _WIN32 - #include "Utils/AppRuntime.h" +#include + +#include "Utils/Platform.h" + +MAA_NS_BEGIN + +void init_app_dir(); + +static std::filesystem::path s_app_dir_cache; + +const std::filesystem::path& app_dir() +{ + if (s_app_dir_cache.empty()) { + init_app_dir(); + } + + return s_app_dir_cache; +} + +void init_app_dir() +{ + Dl_info dl_info{}; + if (dladdr((void*)init_app_dir, &dl_info) == 0) { + return; + } + + s_app_dir_cache = MAA_NS::path(dl_info.dli_fname).parent_path(); +} + +MAA_NS_END + #endif diff --git a/source/MaaUtils/AppRuntime/AppRuntime_Win.cpp b/source/MaaUtils/AppRuntime/AppRuntime_Win.cpp index b917f53d3..9cfd8fa17 100644 --- a/source/MaaUtils/AppRuntime/AppRuntime_Win.cpp +++ b/source/MaaUtils/AppRuntime/AppRuntime_Win.cpp @@ -1,5 +1,4 @@ #ifdef _WIN32 - #include "Utils/AppRuntime.h" #include "Utils/Platform.h"