From a538301891312b756828e220e735110d9484a411 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 22 Jul 2020 15:28:26 +0200 Subject: Android: Hook up global settings to the new config system --- Source/Android/jni/NativeConfig.cpp | 163 ++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 Source/Android/jni/NativeConfig.cpp (limited to 'Source/Android/jni/NativeConfig.cpp') diff --git a/Source/Android/jni/NativeConfig.cpp b/Source/Android/jni/NativeConfig.cpp new file mode 100644 index 0000000000..f499885b7d --- /dev/null +++ b/Source/Android/jni/NativeConfig.cpp @@ -0,0 +1,163 @@ +// Copyright 2020 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include +#include + +#include + +#include "Common/Assert.h" +#include "Common/Config/Config.h" +#include "Core/ConfigLoaders/IsSettingSaveable.h" +#include "jni/AndroidCommon/AndroidCommon.h" + +constexpr jint LAYER_BASE_OR_CURRENT = 0; +constexpr jint LAYER_LOCAL_GAME = 1; + +static Config::Location GetLocation(JNIEnv* env, jstring file, jstring section, jstring key) +{ + const std::string decoded_file = GetJString(env, file); + + Config::System system; + if (decoded_file == "Dolphin") + { + system = Config::System::Main; + } + else if (decoded_file == "GFX") + { + system = Config::System::GFX; + } + else if (decoded_file == "Logger") + { + system = Config::System::Logger; + } + else + { + ASSERT(false); + return {}; + } + + return Config::Location{system, GetJString(env, section), GetJString(env, key)}; +} + +static std::shared_ptr GetLayer(jint layer, const Config::Location& location) +{ + switch (layer) + { + case LAYER_BASE_OR_CURRENT: + if (GetActiveLayerForConfig(location) == Config::LayerType::Base) + return Config::GetLayer(Config::LayerType::Base); + else + return Config::GetLayer(Config::LayerType::CurrentRun); + + case LAYER_LOCAL_GAME: + return Config::GetLayer(Config::LayerType::LocalGame); + + default: + ASSERT(false); + return nullptr; + } +} + +template +static T Get(jint layer, const Config::Location& location, T default_value) +{ + return GetLayer(layer, location)->Get(location).value_or(default_value); +} + +template +static void Set(jint layer, const Config::Location& location, T value) +{ + GetLayer(layer, location)->Set(location, value); + Config::InvokeConfigChangedCallbacks(); +} + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT jboolean JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_isSettingSaveable( + JNIEnv* env, jclass obj, jstring file, jstring section, jstring key) +{ + const Config::Location location = GetLocation(env, file, section, key); + return static_cast(ConfigLoaders::IsSettingSaveable(location)); +} + +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_save( + JNIEnv* env, jclass obj, jint layer) +{ + return GetLayer(layer, {})->Save(); +} + +JNIEXPORT jboolean JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_deleteKey( + JNIEnv* env, jclass obj, jint layer, jstring file, jstring section, jstring key) +{ + const Config::Location location = GetLocation(env, file, section, key); + return static_cast(GetLayer(layer, location)->DeleteKey(location)); +} + +JNIEXPORT jstring JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_getString( + JNIEnv* env, jclass obj, jint layer, jstring file, jstring section, jstring key, + jstring default_value) +{ + const Config::Location location = GetLocation(env, file, section, key); + return ToJString(env, Get(layer, location, GetJString(env, default_value))); +} + +JNIEXPORT jboolean JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_getBoolean( + JNIEnv* env, jclass obj, jint layer, jstring file, jstring section, jstring key, + jboolean default_value) +{ + const Config::Location location = GetLocation(env, file, section, key); + return static_cast(Get(layer, location, static_cast(default_value))); +} + +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_getInt( + JNIEnv* env, jclass obj, jint layer, jstring file, jstring section, jstring key, + jint default_value) +{ + return Get(layer, GetLocation(env, file, section, key), default_value); +} + +JNIEXPORT jfloat JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_getFloat( + JNIEnv* env, jclass obj, jint layer, jstring file, jstring section, jstring key, + jfloat default_value) +{ + return Get(layer, GetLocation(env, file, section, key), default_value); +} + +JNIEXPORT void JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_setString( + JNIEnv* env, jclass obj, jint layer, jstring file, jstring section, jstring key, jstring value) +{ + return Set(layer, GetLocation(env, file, section, key), GetJString(env, value)); +} + +JNIEXPORT void JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_setBoolean( + JNIEnv* env, jclass obj, jint layer, jstring file, jstring section, jstring key, jboolean value) +{ + return Set(layer, GetLocation(env, file, section, key), static_cast(value)); +} + +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_setInt( + JNIEnv* env, jclass obj, jint layer, jstring file, jstring section, jstring key, jint value) +{ + return Set(layer, GetLocation(env, file, section, key), value); +} + +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_setFloat( + JNIEnv* env, jclass obj, jint layer, jstring file, jstring section, jstring key, jfloat value) +{ + return Set(layer, GetLocation(env, file, section, key), value); +} + +#ifdef __cplusplus +} +#endif -- cgit v1.2.3 From e24d50e881128f944fa76f15c7d3fd6f6c43e0d5 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 22 Jul 2020 16:28:08 +0200 Subject: Android: Hook up game settings to the new config system --- Source/Android/jni/NativeConfig.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Source/Android/jni/NativeConfig.cpp') diff --git a/Source/Android/jni/NativeConfig.cpp b/Source/Android/jni/NativeConfig.cpp index f499885b7d..54c927a97e 100644 --- a/Source/Android/jni/NativeConfig.cpp +++ b/Source/Android/jni/NativeConfig.cpp @@ -9,6 +9,7 @@ #include "Common/Assert.h" #include "Common/Config/Config.h" +#include "Core/ConfigLoaders/GameConfigLoader.h" #include "Core/ConfigLoaders/IsSettingSaveable.h" #include "jni/AndroidCommon/AndroidCommon.h" @@ -85,6 +86,26 @@ Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_isSettingSav return static_cast(ConfigLoaders::IsSettingSaveable(location)); } +JNIEXPORT void JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_loadGameInis(JNIEnv* env, + jclass obj, + jstring jGameId, + jint jRevision) +{ + const std::string game_id = GetJString(env, jGameId); + const u16 revision = static_cast(jRevision); + Config::AddLayer(ConfigLoaders::GenerateGlobalGameConfigLoader(game_id, revision)); + Config::AddLayer(ConfigLoaders::GenerateLocalGameConfigLoader(game_id, revision)); +} + +JNIEXPORT void JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_unloadGameInis(JNIEnv* env, + jclass obj) +{ + Config::RemoveLayer(Config::LayerType::GlobalGame); + Config::RemoveLayer(Config::LayerType::LocalGame); +} + JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_save( JNIEnv* env, jclass obj, jint layer) { -- cgit v1.2.3 From 736505f020a8e1b637a7a84a294b30bde558ebde Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 22 Jul 2020 17:51:02 +0200 Subject: Android: Show overridden game settings in bold --- Source/Android/jni/NativeConfig.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Source/Android/jni/NativeConfig.cpp') diff --git a/Source/Android/jni/NativeConfig.cpp b/Source/Android/jni/NativeConfig.cpp index 54c927a97e..3a3a5289c3 100644 --- a/Source/Android/jni/NativeConfig.cpp +++ b/Source/Android/jni/NativeConfig.cpp @@ -112,6 +112,15 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_Na return GetLayer(layer, {})->Save(); } +JNIEXPORT jboolean JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_isOverridden( + JNIEnv* env, jclass obj, jstring file, jstring section, jstring key) +{ + const Config::Location location = GetLocation(env, file, section, key); + const bool result = Config::GetActiveLayerForConfig(location) != Config::LayerType::Base; + return static_cast(result); +} + JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_deleteKey( JNIEnv* env, jclass obj, jint layer, jstring file, jstring section, jstring key) -- cgit v1.2.3