2020-07-22 15:28:26 +02:00
|
|
|
// Copyright 2020 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-07-22 15:28:26 +02:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
|
|
#include "Common/Assert.h"
|
|
|
|
#include "Common/Config/Config.h"
|
2020-07-22 16:28:08 +02:00
|
|
|
#include "Core/ConfigLoaders/GameConfigLoader.h"
|
2020-07-22 15:28:26 +02:00
|
|
|
#include "Core/ConfigLoaders/IsSettingSaveable.h"
|
|
|
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
2023-06-11 13:00:52 +02:00
|
|
|
#include "jni/Host.h"
|
2020-07-22 15:28:26 +02:00
|
|
|
|
|
|
|
constexpr jint LAYER_BASE_OR_CURRENT = 0;
|
2020-12-24 13:34:52 +01:00
|
|
|
constexpr jint LAYER_BASE = 1;
|
|
|
|
constexpr jint LAYER_LOCAL_GAME = 2;
|
|
|
|
constexpr jint LAYER_ACTIVE = 3;
|
2022-09-24 13:03:45 +02:00
|
|
|
constexpr jint LAYER_CURRENT = 4;
|
2020-07-22 15:28:26 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2020-09-16 11:49:02 +02:00
|
|
|
else if (decoded_file == "SYSCONF")
|
|
|
|
{
|
|
|
|
system = Config::System::SYSCONF;
|
|
|
|
}
|
2020-07-22 15:28:26 +02:00
|
|
|
else if (decoded_file == "GFX")
|
|
|
|
{
|
|
|
|
system = Config::System::GFX;
|
|
|
|
}
|
|
|
|
else if (decoded_file == "Logger")
|
|
|
|
{
|
|
|
|
system = Config::System::Logger;
|
|
|
|
}
|
2022-02-18 21:58:05 +01:00
|
|
|
else if (decoded_file == "WiimoteNew")
|
|
|
|
{
|
|
|
|
system = Config::System::WiiPad;
|
|
|
|
}
|
2023-03-11 17:14:01 +01:00
|
|
|
else if (decoded_file == "GameSettingsOnly")
|
|
|
|
{
|
|
|
|
system = Config::System::GameSettingsOnly;
|
|
|
|
}
|
2020-07-22 15:28:26 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSERT(false);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return Config::Location{system, GetJString(env, section), GetJString(env, key)};
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::shared_ptr<Config::Layer> GetLayer(jint layer, const Config::Location& location)
|
|
|
|
{
|
2020-10-13 16:17:26 +02:00
|
|
|
Config::LayerType layer_type;
|
|
|
|
|
2020-07-22 15:28:26 +02:00
|
|
|
switch (layer)
|
|
|
|
{
|
|
|
|
case LAYER_BASE_OR_CURRENT:
|
|
|
|
if (GetActiveLayerForConfig(location) == Config::LayerType::Base)
|
2020-10-13 16:17:26 +02:00
|
|
|
layer_type = Config::LayerType::Base;
|
2020-07-22 15:28:26 +02:00
|
|
|
else
|
2020-10-13 16:17:26 +02:00
|
|
|
layer_type = Config::LayerType::CurrentRun;
|
|
|
|
break;
|
2020-07-22 15:28:26 +02:00
|
|
|
|
2020-12-24 13:34:52 +01:00
|
|
|
case LAYER_BASE:
|
|
|
|
layer_type = Config::LayerType::Base;
|
|
|
|
break;
|
|
|
|
|
2020-07-22 15:28:26 +02:00
|
|
|
case LAYER_LOCAL_GAME:
|
2020-10-13 16:17:26 +02:00
|
|
|
layer_type = Config::LayerType::LocalGame;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_ACTIVE:
|
|
|
|
layer_type = Config::GetActiveLayerForConfig(location);
|
|
|
|
break;
|
2020-07-22 15:28:26 +02:00
|
|
|
|
2022-09-24 13:03:45 +02:00
|
|
|
case LAYER_CURRENT:
|
|
|
|
layer_type = Config::LayerType::CurrentRun;
|
|
|
|
break;
|
|
|
|
|
2020-07-22 15:28:26 +02:00
|
|
|
default:
|
|
|
|
ASSERT(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-10-13 16:17:26 +02:00
|
|
|
|
|
|
|
return Config::GetLayer(layer_type);
|
2020-07-22 15:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static T Get(jint layer, const Config::Location& location, T default_value)
|
|
|
|
{
|
|
|
|
return GetLayer(layer, location)->Get<T>(location).value_or(default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static void Set(jint layer, const Config::Location& location, T value)
|
|
|
|
{
|
|
|
|
GetLayer(layer, location)->Set(location, value);
|
2020-12-05 18:24:41 +01:00
|
|
|
Config::OnConfigChanged();
|
2020-07-22 15:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_isSettingSaveable(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv* env, jclass, jstring file, jstring section, jstring key)
|
2020-07-22 15:28:26 +02:00
|
|
|
{
|
|
|
|
const Config::Location location = GetLocation(env, file, section, key);
|
|
|
|
return static_cast<jboolean>(ConfigLoaders::IsSettingSaveable(location));
|
|
|
|
}
|
|
|
|
|
2020-07-22 16:28:08 +02:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_loadGameInis(JNIEnv* env,
|
2020-11-07 11:57:43 +01:00
|
|
|
jclass,
|
2020-07-22 16:28:08 +02:00
|
|
|
jstring jGameId,
|
|
|
|
jint jRevision)
|
|
|
|
{
|
2023-06-11 13:00:52 +02:00
|
|
|
HostThreadLock guard;
|
2020-07-22 16:28:08 +02:00
|
|
|
const std::string game_id = GetJString(env, jGameId);
|
|
|
|
const u16 revision = static_cast<u16>(jRevision);
|
|
|
|
Config::AddLayer(ConfigLoaders::GenerateGlobalGameConfigLoader(game_id, revision));
|
|
|
|
Config::AddLayer(ConfigLoaders::GenerateLocalGameConfigLoader(game_id, revision));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
2020-11-07 11:57:43 +01:00
|
|
|
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_unloadGameInis(JNIEnv*, jclass)
|
2020-07-22 16:28:08 +02:00
|
|
|
{
|
2023-06-11 13:00:52 +02:00
|
|
|
HostThreadLock guard;
|
2020-07-22 16:28:08 +02:00
|
|
|
Config::RemoveLayer(Config::LayerType::GlobalGame);
|
|
|
|
Config::RemoveLayer(Config::LayerType::LocalGame);
|
|
|
|
}
|
|
|
|
|
2020-07-22 15:28:26 +02:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_save(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv*, jclass, jint layer)
|
2020-07-22 15:28:26 +02:00
|
|
|
{
|
2023-06-11 13:00:52 +02:00
|
|
|
HostThreadLock guard;
|
2023-03-11 17:48:42 +01:00
|
|
|
return GetLayer(layer, {})->Save();
|
|
|
|
}
|
2021-01-18 15:23:36 +01:00
|
|
|
|
2023-03-11 17:48:42 +01:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_deleteAllKeys(JNIEnv*, jclass,
|
|
|
|
jint layer)
|
|
|
|
{
|
2023-06-11 13:00:52 +02:00
|
|
|
HostThreadLock guard;
|
2023-03-11 17:48:42 +01:00
|
|
|
return GetLayer(layer, {})->DeleteAllKeys();
|
2020-07-22 15:28:26 +02:00
|
|
|
}
|
|
|
|
|
2020-07-22 17:51:02 +02:00
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_isOverridden(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv* env, jclass, jstring file, jstring section, jstring key)
|
2020-07-22 17:51:02 +02:00
|
|
|
{
|
|
|
|
const Config::Location location = GetLocation(env, file, section, key);
|
|
|
|
const bool result = Config::GetActiveLayerForConfig(location) != Config::LayerType::Base;
|
|
|
|
return static_cast<jboolean>(result);
|
|
|
|
}
|
|
|
|
|
2020-07-22 15:28:26 +02:00
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_deleteKey(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key)
|
2020-07-22 15:28:26 +02:00
|
|
|
{
|
2023-06-11 13:00:52 +02:00
|
|
|
HostThreadLock guard;
|
2020-07-22 15:28:26 +02:00
|
|
|
const Config::Location location = GetLocation(env, file, section, key);
|
2022-01-29 15:48:34 +01:00
|
|
|
const bool had_value = GetLayer(layer, location)->DeleteKey(location);
|
|
|
|
if (had_value)
|
|
|
|
Config::OnConfigChanged();
|
|
|
|
return static_cast<jboolean>(had_value);
|
2020-07-22 15:28:26 +02:00
|
|
|
}
|
|
|
|
|
2023-03-11 17:48:42 +01:00
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_exists(JNIEnv* env, jclass,
|
|
|
|
jint layer, jstring file,
|
|
|
|
jstring section,
|
|
|
|
jstring key)
|
|
|
|
{
|
|
|
|
const Config::Location location = GetLocation(env, file, section, key);
|
|
|
|
return static_cast<jboolean>(GetLayer(layer, location)->Exists(location));
|
|
|
|
}
|
|
|
|
|
2020-07-22 15:28:26 +02:00
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_getString(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key,
|
2020-07-22 15:28:26 +02:00
|
|
|
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(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key,
|
2020-07-22 15:28:26 +02:00
|
|
|
jboolean default_value)
|
|
|
|
{
|
|
|
|
const Config::Location location = GetLocation(env, file, section, key);
|
|
|
|
return static_cast<jboolean>(Get(layer, location, static_cast<bool>(default_value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_getInt(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key, jint default_value)
|
2020-07-22 15:28:26 +02:00
|
|
|
{
|
|
|
|
return Get(layer, GetLocation(env, file, section, key), default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jfloat JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_getFloat(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key,
|
2020-07-22 15:28:26 +02:00
|
|
|
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(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key, jstring value)
|
2020-07-22 15:28:26 +02:00
|
|
|
{
|
2023-06-11 13:00:52 +02:00
|
|
|
HostThreadLock guard;
|
2020-07-22 15:28:26 +02:00
|
|
|
return Set(layer, GetLocation(env, file, section, key), GetJString(env, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_setBoolean(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key, jboolean value)
|
2020-07-22 15:28:26 +02:00
|
|
|
{
|
2023-06-11 13:00:52 +02:00
|
|
|
HostThreadLock guard;
|
2020-07-22 15:28:26 +02:00
|
|
|
return Set(layer, GetLocation(env, file, section, key), static_cast<bool>(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_setInt(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key, jint value)
|
2020-07-22 15:28:26 +02:00
|
|
|
{
|
2023-06-11 13:00:52 +02:00
|
|
|
HostThreadLock guard;
|
2020-07-22 15:28:26 +02:00
|
|
|
return Set(layer, GetLocation(env, file, section, key), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_setFloat(
|
2020-11-07 11:57:43 +01:00
|
|
|
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key, jfloat value)
|
2020-07-22 15:28:26 +02:00
|
|
|
{
|
2023-06-11 13:00:52 +02:00
|
|
|
HostThreadLock guard;
|
2020-07-22 15:28:26 +02:00
|
|
|
return Set(layer, GetLocation(env, file, section, key), value);
|
|
|
|
}
|
|
|
|
}
|