mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Merge pull request #7076 from JosJuice/android-gamelist-uicommon
Use UICommon's game list code on Android
This commit is contained in:
@ -14,8 +14,7 @@
|
||||
|
||||
#include "Core/HW/WiimoteReal/IOAndroid.h"
|
||||
|
||||
// Global java_vm class
|
||||
extern JavaVM* g_java_vm;
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
|
||||
namespace WiimoteReal
|
||||
{
|
||||
@ -31,10 +30,11 @@ void WiimoteScannerAndroid::FindWiimotes(std::vector<Wiimote*>& found_wiimotes,
|
||||
NOTICE_LOG(WIIMOTE, "Finding Wiimotes");
|
||||
|
||||
JNIEnv* env;
|
||||
int get_env_status = g_java_vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
|
||||
int get_env_status =
|
||||
IDCache::GetJavaVM()->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
|
||||
|
||||
if (get_env_status == JNI_EDETACHED)
|
||||
g_java_vm->AttachCurrentThread(&env, nullptr);
|
||||
IDCache::GetJavaVM()->AttachCurrentThread(&env, nullptr);
|
||||
|
||||
jmethodID openadapter_func = env->GetStaticMethodID(s_adapter_class, "OpenAdapter", "()Z");
|
||||
jmethodID queryadapter_func = env->GetStaticMethodID(s_adapter_class, "QueryAdapter", "()Z");
|
||||
@ -47,7 +47,7 @@ void WiimoteScannerAndroid::FindWiimotes(std::vector<Wiimote*>& found_wiimotes,
|
||||
}
|
||||
|
||||
if (get_env_status == JNI_EDETACHED)
|
||||
g_java_vm->DetachCurrentThread();
|
||||
IDCache::GetJavaVM()->DetachCurrentThread();
|
||||
}
|
||||
|
||||
WiimoteAndroid::WiimoteAndroid(int index) : Wiimote(), m_mayflash_index(index)
|
||||
@ -62,7 +62,7 @@ WiimoteAndroid::~WiimoteAndroid()
|
||||
// Connect to a Wiimote with a known address.
|
||||
bool WiimoteAndroid::ConnectInternal()
|
||||
{
|
||||
g_java_vm->AttachCurrentThread(&m_env, nullptr);
|
||||
IDCache::GetJavaVM()->AttachCurrentThread(&m_env, nullptr);
|
||||
|
||||
jfieldID payload_field = m_env->GetStaticFieldID(s_adapter_class, "wiimote_payload", "[[B");
|
||||
jobjectArray payload_object =
|
||||
@ -81,7 +81,7 @@ bool WiimoteAndroid::ConnectInternal()
|
||||
|
||||
void WiimoteAndroid::DisconnectInternal()
|
||||
{
|
||||
g_java_vm->DetachCurrentThread();
|
||||
IDCache::GetJavaVM()->DetachCurrentThread();
|
||||
}
|
||||
|
||||
bool WiimoteAndroid::IsConnected() const
|
||||
@ -117,7 +117,7 @@ int WiimoteAndroid::IOWrite(u8 const* buf, size_t len)
|
||||
void InitAdapterClass()
|
||||
{
|
||||
JNIEnv* env;
|
||||
g_java_vm->AttachCurrentThread(&env, nullptr);
|
||||
IDCache::GetJavaVM()->AttachCurrentThread(&env, nullptr);
|
||||
|
||||
jclass adapter_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Java_WiimoteAdapter");
|
||||
s_adapter_class = reinterpret_cast<jclass>(env->NewGlobalRef(adapter_class));
|
||||
|
@ -20,8 +20,7 @@
|
||||
#include "InputCommon/GCAdapter.h"
|
||||
#include "InputCommon/GCPadStatus.h"
|
||||
|
||||
// Global java_vm class
|
||||
extern JavaVM* g_java_vm;
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
|
||||
namespace GCAdapter
|
||||
{
|
||||
@ -67,7 +66,7 @@ static void ScanThreadFunc()
|
||||
NOTICE_LOG(SERIALINTERFACE, "GC Adapter scanning thread started");
|
||||
|
||||
JNIEnv* env;
|
||||
g_java_vm->AttachCurrentThread(&env, NULL);
|
||||
IDCache::GetJavaVM()->AttachCurrentThread(&env, NULL);
|
||||
|
||||
jmethodID queryadapter_func = env->GetStaticMethodID(s_adapter_class, "QueryAdapter", "()Z");
|
||||
|
||||
@ -78,7 +77,7 @@ static void ScanThreadFunc()
|
||||
Setup();
|
||||
Common::SleepCurrentThread(1000);
|
||||
}
|
||||
g_java_vm->DetachCurrentThread();
|
||||
IDCache::GetJavaVM()->DetachCurrentThread();
|
||||
|
||||
NOTICE_LOG(SERIALINTERFACE, "GC Adapter scanning thread stopped");
|
||||
}
|
||||
@ -89,7 +88,7 @@ static void Write()
|
||||
NOTICE_LOG(SERIALINTERFACE, "GC Adapter write thread started");
|
||||
|
||||
JNIEnv* env;
|
||||
g_java_vm->AttachCurrentThread(&env, NULL);
|
||||
IDCache::GetJavaVM()->AttachCurrentThread(&env, NULL);
|
||||
jmethodID output_func = env->GetStaticMethodID(s_adapter_class, "Output", "([B)I");
|
||||
|
||||
while (s_write_adapter_thread_running.IsSet())
|
||||
@ -119,7 +118,7 @@ static void Write()
|
||||
Common::YieldCPU();
|
||||
}
|
||||
|
||||
g_java_vm->DetachCurrentThread();
|
||||
IDCache::GetJavaVM()->DetachCurrentThread();
|
||||
|
||||
NOTICE_LOG(SERIALINTERFACE, "GC Adapter write thread stopped");
|
||||
}
|
||||
@ -131,7 +130,7 @@ static void Read()
|
||||
|
||||
bool first_read = true;
|
||||
JNIEnv* env;
|
||||
g_java_vm->AttachCurrentThread(&env, NULL);
|
||||
IDCache::GetJavaVM()->AttachCurrentThread(&env, NULL);
|
||||
|
||||
jfieldID payload_field = env->GetStaticFieldID(s_adapter_class, "controller_payload", "[B");
|
||||
jobject payload_object = env->GetStaticObjectField(s_adapter_class, payload_field);
|
||||
@ -185,7 +184,7 @@ static void Read()
|
||||
s_fd = 0;
|
||||
s_detected = false;
|
||||
|
||||
g_java_vm->DetachCurrentThread();
|
||||
IDCache::GetJavaVM()->DetachCurrentThread();
|
||||
|
||||
NOTICE_LOG(SERIALINTERFACE, "GC Adapter read thread stopped");
|
||||
}
|
||||
@ -204,7 +203,7 @@ void Init()
|
||||
}
|
||||
|
||||
JNIEnv* env;
|
||||
g_java_vm->AttachCurrentThread(&env, NULL);
|
||||
IDCache::GetJavaVM()->AttachCurrentThread(&env, NULL);
|
||||
|
||||
jclass adapter_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Java_GCAdapter");
|
||||
s_adapter_class = reinterpret_cast<jclass>(env->NewGlobalRef(adapter_class));
|
||||
|
@ -78,8 +78,15 @@ const std::string& GameFile::Lookup(DiscIO::Language language,
|
||||
const std::string&
|
||||
GameFile::LookupUsingConfigLanguage(const std::map<DiscIO::Language, std::string>& strings) const
|
||||
{
|
||||
#ifdef ANDROID
|
||||
// TODO: Make the Android app load the config at app start instead of emulation start
|
||||
// so that we can access the user's preference here
|
||||
const DiscIO::Language language = DiscIO::Language::English;
|
||||
#else
|
||||
const bool wii = DiscIO::IsWii(m_platform);
|
||||
return Lookup(SConfig::GetInstance().GetCurrentLanguage(wii), strings);
|
||||
const DiscIO::Language language = SConfig::GetInstance().GetCurrentLanguage(wii);
|
||||
#endif
|
||||
return Lookup(language, strings);
|
||||
}
|
||||
|
||||
GameFile::GameFile(const std::string& path)
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/ChunkFile.h"
|
||||
@ -38,12 +39,25 @@ std::vector<std::string> FindAllGamePaths(const std::vector<std::string>& direct
|
||||
return Common::DoFileSearch(directories_to_scan, search_extensions, recursive_scan);
|
||||
}
|
||||
|
||||
GameFileCache::GameFileCache() : m_path(File::GetUserPath(D_CACHE_IDX) + "gamelist.cache")
|
||||
{
|
||||
}
|
||||
|
||||
GameFileCache::GameFileCache(std::string path) : m_path(std::move(path))
|
||||
{
|
||||
}
|
||||
|
||||
void GameFileCache::ForEach(std::function<void(const std::shared_ptr<const GameFile>&)> f) const
|
||||
{
|
||||
for (const std::shared_ptr<const GameFile>& item : m_cached_files)
|
||||
f(item);
|
||||
}
|
||||
|
||||
size_t GameFileCache::GetSize() const
|
||||
{
|
||||
return m_cached_files.size();
|
||||
}
|
||||
|
||||
void GameFileCache::Clear()
|
||||
{
|
||||
m_cached_files.clear();
|
||||
@ -179,9 +193,8 @@ bool GameFileCache::Save()
|
||||
|
||||
bool GameFileCache::SyncCacheFile(bool save)
|
||||
{
|
||||
std::string filename(File::GetUserPath(D_CACHE_IDX) + "gamelist.cache");
|
||||
const char* open_mode = save ? "wb" : "rb";
|
||||
File::IOFile f(filename, open_mode);
|
||||
File::IOFile f(m_path, open_mode);
|
||||
if (!f)
|
||||
return false;
|
||||
bool success = false;
|
||||
@ -217,7 +230,7 @@ bool GameFileCache::SyncCacheFile(bool save)
|
||||
{
|
||||
// If some file operation failed, try to delete the probably-corrupted cache
|
||||
f.Close();
|
||||
File::Delete(filename);
|
||||
File::Delete(m_path);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
@ -6,9 +6,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -26,8 +24,12 @@ std::vector<std::string> FindAllGamePaths(const std::vector<std::string>& direct
|
||||
class GameFileCache
|
||||
{
|
||||
public:
|
||||
GameFileCache(); // Uses the default path
|
||||
explicit GameFileCache(std::string path);
|
||||
|
||||
void ForEach(std::function<void(const std::shared_ptr<const GameFile>&)> f) const;
|
||||
|
||||
size_t GetSize() const;
|
||||
void Clear();
|
||||
|
||||
// Returns nullptr if the file is invalid.
|
||||
@ -49,6 +51,7 @@ private:
|
||||
bool SyncCacheFile(bool save);
|
||||
void DoState(PointerWrap* p, u64 size = 0);
|
||||
|
||||
std::string m_path;
|
||||
std::vector<std::shared_ptr<GameFile>> m_cached_files;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user