-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
NativeConfig.cpp
248 lines (214 loc) · 8.07 KB
/
NativeConfig.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// Copyright 2020 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <memory>
#include <string>
#include <jni.h>
#include "Common/Assert.h"
#include "Common/Config/Config.h"
#include "Core/ConfigLoaders/GameConfigLoader.h"
#include "Core/ConfigLoaders/IsSettingSaveable.h"
#include "jni/AndroidCommon/AndroidCommon.h"
#include "jni/Host.h"
constexpr jint LAYER_BASE_OR_CURRENT = 0;
constexpr jint LAYER_BASE = 1;
constexpr jint LAYER_LOCAL_GAME = 2;
constexpr jint LAYER_ACTIVE = 3;
constexpr jint LAYER_CURRENT = 4;
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 == "SYSCONF")
{
system = Config::System::SYSCONF;
}
else if (decoded_file == "GFX")
{
system = Config::System::GFX;
}
else if (decoded_file == "Logger")
{
system = Config::System::Logger;
}
else if (decoded_file == "WiimoteNew")
{
system = Config::System::WiiPad;
}
else if (decoded_file == "GameSettingsOnly")
{
system = Config::System::GameSettingsOnly;
}
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)
{
Config::LayerType layer_type;
switch (layer)
{
case LAYER_BASE_OR_CURRENT:
if (GetActiveLayerForConfig(location) == Config::LayerType::Base)
layer_type = Config::LayerType::Base;
else
layer_type = Config::LayerType::CurrentRun;
break;
case LAYER_BASE:
layer_type = Config::LayerType::Base;
break;
case LAYER_LOCAL_GAME:
layer_type = Config::LayerType::LocalGame;
break;
case LAYER_ACTIVE:
layer_type = Config::GetActiveLayerForConfig(location);
break;
case LAYER_CURRENT:
layer_type = Config::LayerType::CurrentRun;
break;
default:
ASSERT(false);
return nullptr;
}
return Config::GetLayer(layer_type);
}
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);
Config::OnConfigChanged();
}
extern "C" {
JNIEXPORT jboolean JNICALL
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_isSettingSaveable(
JNIEnv* env, jclass, jstring file, jstring section, jstring key)
{
const Config::Location location = GetLocation(env, file, section, key);
return static_cast<jboolean>(ConfigLoaders::IsSettingSaveable(location));
}
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_loadGameInis(JNIEnv* env,
jclass,
jstring jGameId,
jint jRevision)
{
HostThreadLock guard;
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
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_unloadGameInis(JNIEnv*, jclass)
{
HostThreadLock guard;
Config::RemoveLayer(Config::LayerType::GlobalGame);
Config::RemoveLayer(Config::LayerType::LocalGame);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_save(
JNIEnv*, jclass, jint layer)
{
HostThreadLock guard;
return GetLayer(layer, {})->Save();
}
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_deleteAllKeys(JNIEnv*, jclass,
jint layer)
{
HostThreadLock guard;
return GetLayer(layer, {})->DeleteAllKeys();
}
JNIEXPORT jboolean JNICALL
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_isOverridden(
JNIEnv* env, jclass, 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<jboolean>(result);
}
JNIEXPORT jboolean JNICALL
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_deleteKey(
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key)
{
HostThreadLock guard;
const Config::Location location = GetLocation(env, file, section, key);
const bool had_value = GetLayer(layer, location)->DeleteKey(location);
if (had_value)
Config::OnConfigChanged();
return static_cast<jboolean>(had_value);
}
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));
}
JNIEXPORT jstring JNICALL
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_getString(
JNIEnv* env, jclass, 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, jint layer, jstring file, jstring section, jstring key,
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(
JNIEnv* env, jclass, 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, 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, jint layer, jstring file, jstring section, jstring key, jstring value)
{
HostThreadLock guard;
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, jint layer, jstring file, jstring section, jstring key, jboolean value)
{
HostThreadLock guard;
return Set(layer, GetLocation(env, file, section, key), static_cast<bool>(value));
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_setInt(
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key, jint value)
{
HostThreadLock guard;
return Set(layer, GetLocation(env, file, section, key), value);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_setFloat(
JNIEnv* env, jclass, jint layer, jstring file, jstring section, jstring key, jfloat value)
{
HostThreadLock guard;
return Set(layer, GetLocation(env, file, section, key), value);
}
}