Skip to content

Commit

Permalink
feat: app_dir impl for posix
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Feb 20, 2024
1 parent e6fc395 commit 986850b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
32 changes: 31 additions & 1 deletion source/MaaUtils/AppRuntime/AppRuntime_Posix.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
#ifndef _WIN32

#include "Utils/AppRuntime.h"

#include <dlfcn.h>

#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
1 change: 0 additions & 1 deletion source/MaaUtils/AppRuntime/AppRuntime_Win.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifdef _WIN32

#include "Utils/AppRuntime.h"

#include "Utils/Platform.h"
Expand Down

0 comments on commit 986850b

Please sign in to comment.