From 51c67aa1e4ddb69879c1bd0e1739104cfc770109 Mon Sep 17 00:00:00 2001 From: Deve Date: Fri, 28 Sep 2018 23:15:16 +0200 Subject: [PATCH] Add a fallback lib path for server creation --- src/io/assets_android.cpp | 23 +++++++++++++++++++++++ src/io/assets_android.hpp | 1 + src/utils/separate_process.cpp | 22 ++++++++++++++++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/io/assets_android.cpp b/src/io/assets_android.cpp index ad3603aec..ea8ef814c 100644 --- a/src/io/assets_android.cpp +++ b/src/io/assets_android.cpp @@ -631,3 +631,26 @@ std::string AssetsAndroid::getDataPath() return ""; } + +//----------------------------------------------------------------------------- +/** Get a path for internal lib directory + * \return Path for internal lib directory or empty string when failed + */ +std::string AssetsAndroid::getLibPath() +{ +#ifdef ANDROID + AndroidApplicationInfo application_info = + CIrrDeviceAndroid::getApplicationInfo(global_android_app->activity); + + std::string lib_path = application_info.native_lib_dir; + + if (access(lib_path.c_str(), R_OK) != 0) + { + lib_path = ""; + } + + return lib_path; +#endif + + return ""; +} \ No newline at end of file diff --git a/src/io/assets_android.hpp b/src/io/assets_android.hpp index a9f03f619..72b107538 100644 --- a/src/io/assets_android.hpp +++ b/src/io/assets_android.hpp @@ -43,6 +43,7 @@ public: void init(); static std::string getDataPath(); + static std::string getLibPath(); }; diff --git a/src/utils/separate_process.cpp b/src/utils/separate_process.cpp index b14a19c36..19ec9b924 100644 --- a/src/utils/separate_process.cpp +++ b/src/utils/separate_process.cpp @@ -283,9 +283,27 @@ bool SeparateProcess::createChildProcess(const std::string& exe, } std::string data_path = AssetsAndroid::getDataPath(); - std::string main_path = data_path + "/lib/libmain.so"; + std::string main_path; - if (data_path.empty() || access(main_path.c_str(), R_OK) != 0) + if (!data_path.empty()) + { + main_path = data_path + "/lib/libmain.so"; + } + + if (main_path.empty() || access(main_path.c_str(), R_OK) != 0) + { + std::string lib_path = AssetsAndroid::getLibPath(); + + if (!lib_path.empty()) + { + main_path = lib_path + "/libmain.so"; + } + + Log::info("SeparateProcess", "Trying to use fallback lib path: %s", + main_path.c_str()); + } + + if (main_path.empty() || access(main_path.c_str(), R_OK) != 0) { Log::error("SeparateProcess", "Error: Cannot read libmain.so"); return false;