This commit is contained in:
JosJuice 2024-11-13 01:30:53 -06:00 committed by GitHub
commit 9f1ed3d82d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 49 additions and 57 deletions

View File

@ -12,6 +12,7 @@ import android.view.Surface;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.Keep; import androidx.annotation.Keep;
import androidx.core.util.Pair;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import org.dolphinemu.dolphinemu.activities.EmulationActivity; import org.dolphinemu.dolphinemu.activities.EmulationActivity;
@ -20,7 +21,6 @@ import org.dolphinemu.dolphinemu.utils.CompressCallback;
import org.dolphinemu.dolphinemu.utils.Log; import org.dolphinemu.dolphinemu.utils.Log;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.LinkedHashMap;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
/** /**
@ -411,7 +411,7 @@ public final class NativeLibrary
*/ */
public static native void RefreshWiimotes(); public static native void RefreshWiimotes();
public static native LinkedHashMap<String, String> GetLogTypeNames(); public static native Pair<String, String>[] GetLogTypeNames();
public static native void ReloadLoggerConfig(); public static native void ReloadLoggerConfig();

View File

@ -1972,8 +1972,8 @@ class SettingsFragmentPresenter(
) { SettingsAdapter.clearLog() }) ) { SettingsAdapter.clearLog() })
sl.add(HeaderSetting(context, R.string.log_types, 0)) sl.add(HeaderSetting(context, R.string.log_types, 0))
for ((key, value) in LOG_TYPE_NAMES) { for (logType in LOG_TYPE_NAMES) {
sl.add(LogSwitchSetting(key, value, "")) sl.add(LogSwitchSetting(logType.first, logType.second, ""))
} }
} }
@ -2504,11 +2504,11 @@ class SettingsFragmentPresenter(
fun setAllLogTypes(value: Boolean) { fun setAllLogTypes(value: Boolean) {
val settings = fragmentView.settings val settings = fragmentView.settings
for ((key) in LOG_TYPE_NAMES) { for (logType in LOG_TYPE_NAMES) {
AdHocBooleanSetting( AdHocBooleanSetting(
Settings.FILE_LOGGER, Settings.FILE_LOGGER,
Settings.SECTION_LOGGER_LOGS, Settings.SECTION_LOGGER_LOGS,
key, logType.first,
false false
).setBoolean(settings!!, value) ).setBoolean(settings!!, value)
} }

View File

@ -29,9 +29,8 @@ static jclass s_analytics_class;
static jmethodID s_send_analytics_report; static jmethodID s_send_analytics_report;
static jmethodID s_get_analytics_value; static jmethodID s_get_analytics_value;
static jclass s_linked_hash_map_class; static jclass s_pair_class;
static jmethodID s_linked_hash_map_init; static jmethodID s_pair_constructor;
static jmethodID s_linked_hash_map_put;
static jclass s_hash_map_class; static jclass s_hash_map_class;
static jmethodID s_hash_map_init; static jmethodID s_hash_map_init;
@ -212,19 +211,14 @@ jfieldID GetGameFileCachePointer()
return s_game_file_cache_pointer; return s_game_file_cache_pointer;
} }
jclass GetLinkedHashMapClass() jclass GetPairClass()
{ {
return s_linked_hash_map_class; return s_pair_class;
} }
jmethodID GetLinkedHashMapInit() jmethodID GetPairConstructor()
{ {
return s_linked_hash_map_init; return s_pair_constructor;
}
jmethodID GetLinkedHashMapPut()
{
return s_linked_hash_map_put;
} }
jclass GetHashMapClass() jclass GetHashMapClass()
@ -565,12 +559,11 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
"(Ljava/lang/String;)Ljava/lang/String;"); "(Ljava/lang/String;)Ljava/lang/String;");
env->DeleteLocalRef(analytics_class); env->DeleteLocalRef(analytics_class);
const jclass linked_hash_map_class = env->FindClass("java/util/LinkedHashMap"); const jclass pair_class = env->FindClass("androidx/core/util/Pair");
s_linked_hash_map_class = reinterpret_cast<jclass>(env->NewGlobalRef(linked_hash_map_class)); s_pair_class = reinterpret_cast<jclass>(env->NewGlobalRef(pair_class));
s_linked_hash_map_init = env->GetMethodID(s_linked_hash_map_class, "<init>", "(I)V"); s_pair_constructor =
s_linked_hash_map_put = env->GetMethodID( env->GetMethodID(s_pair_class, "<init>", "(Ljava/lang/Object;Ljava/lang/Object;)V");
s_linked_hash_map_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); env->DeleteLocalRef(pair_class);
env->DeleteLocalRef(linked_hash_map_class);
const jclass hash_map_class = env->FindClass("java/util/HashMap"); const jclass hash_map_class = env->FindClass("java/util/HashMap");
s_hash_map_class = reinterpret_cast<jclass>(env->NewGlobalRef(hash_map_class)); s_hash_map_class = reinterpret_cast<jclass>(env->NewGlobalRef(hash_map_class));
@ -741,7 +734,7 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved)
env->DeleteGlobalRef(s_game_file_class); env->DeleteGlobalRef(s_game_file_class);
env->DeleteGlobalRef(s_game_file_cache_class); env->DeleteGlobalRef(s_game_file_cache_class);
env->DeleteGlobalRef(s_analytics_class); env->DeleteGlobalRef(s_analytics_class);
env->DeleteGlobalRef(s_linked_hash_map_class); env->DeleteGlobalRef(s_pair_class);
env->DeleteGlobalRef(s_hash_map_class); env->DeleteGlobalRef(s_hash_map_class);
env->DeleteGlobalRef(s_compress_cb_class); env->DeleteGlobalRef(s_compress_cb_class);
env->DeleteGlobalRef(s_content_handler_class); env->DeleteGlobalRef(s_content_handler_class);

View File

@ -29,9 +29,8 @@ jmethodID GetGameFileConstructor();
jclass GetGameFileCacheClass(); jclass GetGameFileCacheClass();
jfieldID GetGameFileCachePointer(); jfieldID GetGameFileCachePointer();
jclass GetLinkedHashMapClass(); jclass GetPairClass();
jmethodID GetLinkedHashMapInit(); jmethodID GetPairConstructor();
jmethodID GetLinkedHashMapPut();
jclass GetHashMapClass(); jclass GetHashMapClass();
jmethodID GetHashMapInit(); jmethodID GetHashMapInit();

View File

@ -14,6 +14,7 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include <utility> #include <utility>
#include <vector>
#include "Common/AndroidAnalytics.h" #include "Common/AndroidAnalytics.h"
#include "Common/Assert.h" #include "Common/Assert.h"
@ -677,27 +678,25 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(J
system.GetDVDInterface().ChangeDisc(Core::CPUThreadGuard{system}, path); system.GetDVDInterface().ChangeDisc(Core::CPUThreadGuard{system}, path);
} }
JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetLogTypeNames(JNIEnv* env, JNIEXPORT jobjectArray JNICALL
jclass) Java_org_dolphinemu_dolphinemu_NativeLibrary_GetLogTypeNames(JNIEnv* env, jclass)
{ {
std::map<std::string, std::string> map = Common::Log::LogManager::GetInstance()->GetLogTypes(); using LogManager = Common::Log::LogManager;
auto map_size = static_cast<jsize>(map.size()); return VectorToJObjectArray(
jobject linked_hash_map = env, LogManager::GetInstance()->GetLogTypes(), IDCache::GetPairClass(),
env->NewObject(IDCache::GetLinkedHashMapClass(), IDCache::GetLinkedHashMapInit(), map_size); [](JNIEnv* env_, const LogManager::LogContainer& log_container) {
for (const auto& entry : map) jstring short_name = ToJString(env_, log_container.m_short_name);
{ jstring full_name = ToJString(env_, log_container.m_full_name);
jstring key = ToJString(env, entry.first);
jstring value = ToJString(env, entry.second);
jobject result = jobject pair = env_->NewObject(IDCache::GetPairClass(), IDCache::GetPairConstructor(),
env->CallObjectMethod(linked_hash_map, IDCache::GetLinkedHashMapPut(), key, value); short_name, full_name);
env->DeleteLocalRef(key); env_->DeleteLocalRef(short_name);
env->DeleteLocalRef(value); env_->DeleteLocalRef(full_name);
env->DeleteLocalRef(result);
} return pair;
return linked_hash_map; });
} }
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadLoggerConfig(JNIEnv*, JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadLoggerConfig(JNIEnv*,

View File

@ -252,12 +252,13 @@ bool LogManager::IsEnabled(LogType type, LogLevel level) const
return m_log[type].m_enable && GetLogLevel() >= level; return m_log[type].m_enable && GetLogLevel() >= level;
} }
std::map<std::string, std::string> LogManager::GetLogTypes() std::vector<LogManager::LogContainer> LogManager::GetLogTypes()
{ {
std::map<std::string, std::string> log_types; std::vector<LogContainer> log_types;
log_types.reserve(m_log.size());
for (const auto& container : m_log) for (const auto& container : m_log)
log_types.emplace(container.m_short_name, container.m_full_name); log_types.emplace_back(container);
return log_types; return log_types;
} }

View File

@ -5,8 +5,8 @@
#include <array> #include <array>
#include <cstdarg> #include <cstdarg>
#include <map>
#include <string> #include <string>
#include <vector>
#include "Common/BitSet.h" #include "Common/BitSet.h"
#include "Common/EnumMap.h" #include "Common/EnumMap.h"
@ -34,6 +34,13 @@ public:
class LogManager class LogManager
{ {
public: public:
struct LogContainer
{
const char* m_short_name;
const char* m_full_name;
bool m_enable = false;
};
static LogManager* GetInstance(); static LogManager* GetInstance();
static void Init(); static void Init();
static void Shutdown(); static void Shutdown();
@ -48,7 +55,7 @@ public:
void SetEnable(LogType type, bool enable); void SetEnable(LogType type, bool enable);
bool IsEnabled(LogType type, LogLevel level = LogLevel::LNOTICE) const; bool IsEnabled(LogType type, LogLevel level = LogLevel::LNOTICE) const;
std::map<std::string, std::string> GetLogTypes(); std::vector<LogContainer> GetLogTypes();
const char* GetShortName(LogType type) const; const char* GetShortName(LogType type) const;
const char* GetFullName(LogType type) const; const char* GetFullName(LogType type) const;
@ -60,13 +67,6 @@ public:
void SaveSettings(); void SaveSettings();
private: private:
struct LogContainer
{
const char* m_short_name;
const char* m_full_name;
bool m_enable = false;
};
LogManager(); LogManager();
~LogManager(); ~LogManager();