mirror of
https://github.com/izzy2lost/WeeU.git
synced 2026-07-06 00:19:59 -07:00
Cleanup android code
This commit is contained in:
@@ -2,9 +2,6 @@
|
||||
#include "Cafe/HW/Latte/LatteAddrLib/LatteAddrLib.h"
|
||||
#include "Cafe/OS/libs/gx2/GX2_Surface.h"
|
||||
#include <bit>
|
||||
#if __ANDROID__
|
||||
#include <boost/core/bit.hpp>
|
||||
#endif
|
||||
/*
|
||||
Info:
|
||||
|
||||
@@ -75,11 +72,7 @@ namespace LatteAddrLib
|
||||
|
||||
uint32 NextPow2(uint32 dim)
|
||||
{
|
||||
#if __ANDROID__
|
||||
return boost::core::bit_ceil(dim);
|
||||
#else
|
||||
return std::bit_ceil<uint32>(dim);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32 GetBitsPerPixel(E_HWSURFFMT format, uint32* pElemMode, uint32* pExpandX, uint32* pExpandY)
|
||||
|
||||
@@ -10,48 +10,19 @@ class AndroidFilesystemCallbacks : public FilesystemAndroid::FilesystemCallbacks
|
||||
jmethodID m_isFileMid;
|
||||
jmethodID m_existsMid;
|
||||
JNIUtils::Scopedjclass m_fileUtilClass;
|
||||
std::function<void(JNIEnv*)> m_function = nullptr;
|
||||
std::mutex m_functionMutex;
|
||||
std::condition_variable m_functionCV;
|
||||
std::thread m_thread;
|
||||
std::mutex m_threadMutex;
|
||||
std::condition_variable m_threadCV;
|
||||
std::atomic_bool m_continue = true;
|
||||
|
||||
bool callBooleanFunction(const std::filesystem::path& uri, jmethodID methodId)
|
||||
{
|
||||
std::lock_guard lock(m_functionMutex);
|
||||
bool functionFinished = false;
|
||||
bool result = false;
|
||||
m_function = [&, this](JNIEnv* env) {
|
||||
std::thread([&, this]() {
|
||||
JNIUtils::ScopedJNIENV env;
|
||||
jstring uriString = env->NewStringUTF(uri.c_str());
|
||||
result = env->CallStaticBooleanMethod(*m_fileUtilClass, methodId, uriString);
|
||||
env->DeleteLocalRef(uriString);
|
||||
functionFinished = true;
|
||||
};
|
||||
m_threadCV.notify_one();
|
||||
{
|
||||
std::unique_lock threadLock(m_threadMutex);
|
||||
m_functionCV.wait(threadLock, [&]() -> bool { return functionFinished; });
|
||||
}
|
||||
}).join();
|
||||
return result;
|
||||
}
|
||||
|
||||
void runFilesystemCallbacks()
|
||||
{
|
||||
JNIUtils::ScopedJNIENV env;
|
||||
while (m_continue)
|
||||
{
|
||||
std::unique_lock threadLock(m_threadMutex);
|
||||
m_threadCV.wait(threadLock, [&] { return m_function || !m_continue; });
|
||||
if (!m_continue)
|
||||
return;
|
||||
m_function(*env);
|
||||
m_function = nullptr;
|
||||
m_functionCV.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
AndroidFilesystemCallbacks()
|
||||
{
|
||||
@@ -62,41 +33,25 @@ class AndroidFilesystemCallbacks : public FilesystemAndroid::FilesystemCallbacks
|
||||
m_isDirectoryMid = env->GetStaticMethodID(*m_fileUtilClass, "isDirectory", "(Ljava/lang/String;)Z");
|
||||
m_isFileMid = env->GetStaticMethodID(*m_fileUtilClass, "isFile", "(Ljava/lang/String;)Z");
|
||||
m_existsMid = env->GetStaticMethodID(*m_fileUtilClass, "exists", "(Ljava/lang/String;)Z");
|
||||
m_thread = std::thread(&AndroidFilesystemCallbacks::runFilesystemCallbacks, this);
|
||||
}
|
||||
|
||||
~AndroidFilesystemCallbacks()
|
||||
{
|
||||
m_continue = false;
|
||||
m_threadCV.notify_one();
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
int openContentUri(const std::filesystem::path& uri) override
|
||||
{
|
||||
std::lock_guard lock(m_functionMutex);
|
||||
bool functionFinished = false;
|
||||
int fd = -1;
|
||||
m_function = [&, this](JNIEnv* env) {
|
||||
std::thread([&, this]() {
|
||||
JNIUtils::ScopedJNIENV env;
|
||||
jstring uriString = env->NewStringUTF(uri.c_str());
|
||||
fd = env->CallStaticIntMethod(*m_fileUtilClass, m_openContentUriMid, uriString);
|
||||
env->DeleteLocalRef(uriString);
|
||||
functionFinished = true;
|
||||
};
|
||||
m_threadCV.notify_one();
|
||||
{
|
||||
std::unique_lock threadLock(m_threadMutex);
|
||||
m_functionCV.wait(threadLock, [&]() { return functionFinished; });
|
||||
}
|
||||
}).join();
|
||||
return fd;
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> listFiles(const std::filesystem::path& uri) override
|
||||
{
|
||||
std::lock_guard lock(m_functionMutex);
|
||||
bool functionFinished = false;
|
||||
std::vector<std::filesystem::path> paths;
|
||||
m_function = [&, this](JNIEnv* env) {
|
||||
std::thread([&, this]() {
|
||||
JNIUtils::ScopedJNIENV env;
|
||||
jstring uriString = env->NewStringUTF(uri.c_str());
|
||||
jobjectArray pathsObjArray = static_cast<jobjectArray>(env->CallStaticObjectMethod(*m_fileUtilClass, m_listFilesMid, uriString));
|
||||
env->DeleteLocalRef(uriString);
|
||||
@@ -105,17 +60,11 @@ class AndroidFilesystemCallbacks : public FilesystemAndroid::FilesystemCallbacks
|
||||
for (jsize i = 0; i < arrayLength; i++)
|
||||
{
|
||||
jstring pathStr = static_cast<jstring>(env->GetObjectArrayElement(pathsObjArray, i));
|
||||
paths.push_back(JNIUtils::JStringToString(env, pathStr));
|
||||
paths.push_back(JNIUtils::JStringToString(*env, pathStr));
|
||||
env->DeleteLocalRef(pathStr);
|
||||
}
|
||||
env->DeleteLocalRef(pathsObjArray);
|
||||
functionFinished = true;
|
||||
};
|
||||
m_threadCV.notify_one();
|
||||
{
|
||||
std::unique_lock threadLock(m_threadMutex);
|
||||
m_functionCV.wait(threadLock, [&]() { return functionFinished; });
|
||||
}
|
||||
}).join();
|
||||
return paths;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,12 +24,8 @@ private:
|
||||
}
|
||||
static fs::path GetPath(const fs::path& path, std::string_view p)
|
||||
{
|
||||
#if __ANDROID__
|
||||
return path / fs::path(p);
|
||||
#else
|
||||
std::basic_string_view<char8_t> s((const char8_t*)p.data(), p.size());
|
||||
return path / fs::path(s);
|
||||
#endif // __ANDROID__
|
||||
}
|
||||
static fs::path GetPath(const fs::path& path)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user