android: Prevent editing non-savable settings in per-game settings
This commit is contained in:
parent
f6bf8b3ed3
commit
6ae4177b25
|
@ -22,6 +22,9 @@ interface AbstractSetting {
|
||||||
get() = NativeConfig.usingGlobal(key)
|
get() = NativeConfig.usingGlobal(key)
|
||||||
set(value) = NativeConfig.setGlobal(key, value)
|
set(value) = NativeConfig.setGlobal(key, value)
|
||||||
|
|
||||||
|
val isSaveable: Boolean
|
||||||
|
get() = NativeConfig.getIsSaveable(key)
|
||||||
|
|
||||||
fun getValueAsString(needsGlobal: Boolean = false): String
|
fun getValueAsString(needsGlobal: Boolean = false): String
|
||||||
|
|
||||||
fun reset()
|
fun reset()
|
||||||
|
|
|
@ -30,6 +30,11 @@ abstract class SettingsItem(
|
||||||
|
|
||||||
val isEditable: Boolean
|
val isEditable: Boolean
|
||||||
get() {
|
get() {
|
||||||
|
// Can't edit settings that aren't saveable in per-game config even if they are switchable
|
||||||
|
if (NativeConfig.isPerGameConfigLoaded() && !setting.isSaveable) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if (!NativeLibrary.isRunning()) return true
|
if (!NativeLibrary.isRunning()) return true
|
||||||
|
|
||||||
// Prevent editing settings that were modified in per-game config while editing global
|
// Prevent editing settings that were modified in per-game config while editing global
|
||||||
|
@ -37,6 +42,7 @@ abstract class SettingsItem(
|
||||||
if (!NativeConfig.isPerGameConfigLoaded() && !setting.global) {
|
if (!NativeConfig.isPerGameConfigLoaded() && !setting.global) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return setting.isRuntimeModifiable
|
return setting.isRuntimeModifiable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +65,7 @@ abstract class SettingsItem(
|
||||||
val emptySetting = object : AbstractSetting {
|
val emptySetting = object : AbstractSetting {
|
||||||
override val key: String = ""
|
override val key: String = ""
|
||||||
override val defaultValue: Any = false
|
override val defaultValue: Any = false
|
||||||
|
override val isSaveable = true
|
||||||
override fun getValueAsString(needsGlobal: Boolean): String = ""
|
override fun getValueAsString(needsGlobal: Boolean): String = ""
|
||||||
override fun reset() {}
|
override fun reset() {}
|
||||||
}
|
}
|
||||||
|
@ -303,6 +310,8 @@ abstract class SettingsItem(
|
||||||
BooleanSetting.FASTMEM_EXCLUSIVES.global = value
|
BooleanSetting.FASTMEM_EXCLUSIVES.global = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val isSaveable = true
|
||||||
|
|
||||||
override fun getValueAsString(needsGlobal: Boolean): String =
|
override fun getValueAsString(needsGlobal: Boolean): String =
|
||||||
getBoolean().toString()
|
getBoolean().toString()
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,8 @@ object NativeConfig {
|
||||||
@Synchronized
|
@Synchronized
|
||||||
external fun setGlobal(key: String, global: Boolean)
|
external fun setGlobal(key: String, global: Boolean)
|
||||||
|
|
||||||
|
external fun getIsSaveable(key: String): Boolean
|
||||||
|
|
||||||
external fun getDefaultToString(key: String): String
|
external fun getDefaultToString(key: String): String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -249,6 +249,15 @@ void Java_org_yuzu_yuzu_1emu_utils_NativeConfig_setGlobal(JNIEnv* env, jobject o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jboolean Java_org_yuzu_yuzu_1emu_utils_NativeConfig_getIsSaveable(JNIEnv* env, jobject obj,
|
||||||
|
jstring jkey) {
|
||||||
|
auto setting = getSetting<std::string>(env, jkey);
|
||||||
|
if (setting != nullptr) {
|
||||||
|
return setting->Save();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
jstring Java_org_yuzu_yuzu_1emu_utils_NativeConfig_getDefaultToString(JNIEnv* env, jobject obj,
|
jstring Java_org_yuzu_yuzu_1emu_utils_NativeConfig_getDefaultToString(JNIEnv* env, jobject obj,
|
||||||
jstring jkey) {
|
jstring jkey) {
|
||||||
auto setting = getSetting<std::string>(env, jkey);
|
auto setting = getSetting<std::string>(env, jkey);
|
||||||
|
|
Loading…
Reference in New Issue