workaround multithreaded base directory issues

This commit is contained in:
qimiko 2024-01-08 23:11:27 -07:00
parent aecd7cc186
commit 6b1164d4a6
No known key found for this signature in database
GPG key ID: D2D404DD810FE0E3

View file

@ -56,10 +56,17 @@ namespace {
} }
} }
// jni breaks over multithreading, so the value is stored to avoid more jni calls
std::string s_savedBaseDir = "";
ghc::filesystem::path getBaseDir() { ghc::filesystem::path getBaseDir() {
JniMethodInfo t;
std::string path = "/storage/emulated/0/Android/data/com.geode.launcher/files"; std::string path = "/storage/emulated/0/Android/data/com.geode.launcher/files";
if (!s_savedBaseDir.empty()) {
return ghc::filesystem::path(s_savedBaseDir);
}
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/geode/launcher/utils/GeodeUtils", "getBaseDirectory", "()Ljava/lang/String;")) { if (JniHelper::getStaticMethodInfo(t, "com/geode/launcher/utils/GeodeUtils", "getBaseDirectory", "()Ljava/lang/String;")) {
jstring str = reinterpret_cast<jstring>(t.env->CallStaticObjectMethod(t.classID, t.methodID)); jstring str = reinterpret_cast<jstring>(t.env->CallStaticObjectMethod(t.classID, t.methodID));
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
@ -69,6 +76,7 @@ namespace {
clearJNIException(); clearJNIException();
} }
s_savedBaseDir = path;
return ghc::filesystem::path(path); return ghc::filesystem::path(path);
} }
} }