Android: Convert StringSetting to Kotlin

This commit is contained in:
Charles Lombardo 2023-03-15 03:26:02 -04:00
parent 2c560e05a8
commit 1553477c09
2 changed files with 104 additions and 113 deletions

View File

@ -1,113 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.settings.model;
import androidx.annotation.NonNull;
import org.dolphinemu.dolphinemu.NativeLibrary;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public enum StringSetting implements AbstractStringSetting
{
// These entries have the same names and order as in C++, just for consistency.
MAIN_DEFAULT_ISO(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "DefaultISO", ""),
MAIN_BBA_MAC(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "BBA_MAC", ""),
MAIN_BBA_XLINK_IP(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "BBA_XLINK_IP", ""),
// Schthack PSO Server - https://schtserv.com/
MAIN_BBA_BUILTIN_DNS(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "BBA_BUILTIN_DNS",
"149.56.167.128"),
MAIN_CUSTOM_RTC_VALUE(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "CustomRTCValue",
"0x386d4380"),
MAIN_GFX_BACKEND(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "GFXBackend",
NativeLibrary.GetDefaultGraphicsBackendName()),
MAIN_DUMP_PATH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, "DumpPath", ""),
MAIN_LOAD_PATH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, "LoadPath", ""),
MAIN_RESOURCEPACK_PATH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, "ResourcePackPath",
""),
MAIN_FS_PATH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, "NANDRootPath", ""),
MAIN_WII_SD_CARD_IMAGE_PATH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, "WiiSDCardPath",
""),
MAIN_WII_SD_CARD_SYNC_FOLDER_PATH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL,
"WiiSDCardSyncFolder", ""),
MAIN_WFS_PATH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, "WFSPath", ""),
GFX_ENHANCE_POST_SHADER(Settings.FILE_GFX, Settings.SECTION_GFX_ENHANCEMENTS,
"PostProcessingShader", "");
private static final StringSetting[] NOT_RUNTIME_EDITABLE_ARRAY = new StringSetting[]{
MAIN_CUSTOM_RTC_VALUE,
MAIN_GFX_BACKEND,
};
private static final Set<StringSetting> NOT_RUNTIME_EDITABLE =
new HashSet<>(Arrays.asList(NOT_RUNTIME_EDITABLE_ARRAY));
private final String mFile;
private final String mSection;
private final String mKey;
private final String mDefaultValue;
StringSetting(String file, String section, String key, String defaultValue)
{
mFile = file;
mSection = section;
mKey = key;
mDefaultValue = defaultValue;
}
@Override
public boolean isOverridden()
{
return NativeConfig.isOverridden(mFile, mSection, mKey);
}
@Override
public boolean isRuntimeEditable()
{
for (StringSetting setting : NOT_RUNTIME_EDITABLE)
{
if (setting == this)
return false;
}
return NativeConfig.isSettingSaveable(mFile, mSection, mKey);
}
@Override
public boolean delete(@NonNull Settings settings)
{
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
}
@NonNull @Override
public String getString()
{
if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
throw new UnsupportedOperationException(
"Unsupported setting: " + mFile + ", " + mSection + ", " + mKey);
}
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}
@Override
public void setString(@NonNull Settings settings, @NonNull String newValue)
{
NativeConfig.setString(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}
public void setString(int layer, String newValue)
{
NativeConfig.setString(layer, mFile, mSection, mKey, newValue);
}
}

View File

@ -0,0 +1,104 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.settings.model
import org.dolphinemu.dolphinemu.NativeLibrary
import java.util.*
enum class StringSetting(
private val file: String,
private val section: String,
private val key: String,
private val defaultValue: String
) : AbstractStringSetting {
// These entries have the same names and order as in C++, just for consistency.
MAIN_DEFAULT_ISO(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "DefaultISO", ""),
MAIN_BBA_MAC(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "BBA_MAC", ""),
MAIN_BBA_XLINK_IP(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "BBA_XLINK_IP", ""),
// Schthack PSO Server - https://schtserv.com/
MAIN_BBA_BUILTIN_DNS(
Settings.FILE_DOLPHIN,
Settings.SECTION_INI_CORE,
"BBA_BUILTIN_DNS",
"149.56.167.128"
),
MAIN_CUSTOM_RTC_VALUE(
Settings.FILE_DOLPHIN,
Settings.SECTION_INI_CORE,
"CustomRTCValue",
"0x386d4380"
),
MAIN_GFX_BACKEND(
Settings.FILE_DOLPHIN,
Settings.SECTION_INI_CORE,
"GFXBackend",
NativeLibrary.GetDefaultGraphicsBackendName()
),
MAIN_DUMP_PATH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, "DumpPath", ""),
MAIN_LOAD_PATH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, "LoadPath", ""),
MAIN_RESOURCEPACK_PATH(
Settings.FILE_DOLPHIN,
Settings.SECTION_INI_GENERAL,
"ResourcePackPath",
""
),
MAIN_FS_PATH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, "NANDRootPath", ""),
MAIN_WII_SD_CARD_IMAGE_PATH(
Settings.FILE_DOLPHIN,
Settings.SECTION_INI_GENERAL,
"WiiSDCardPath",
""
),
MAIN_WII_SD_CARD_SYNC_FOLDER_PATH(
Settings.FILE_DOLPHIN,
Settings.SECTION_INI_GENERAL,
"WiiSDCardSyncFolder",
""
),
MAIN_WFS_PATH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, "WFSPath", ""),
GFX_ENHANCE_POST_SHADER(
Settings.FILE_GFX,
Settings.SECTION_GFX_ENHANCEMENTS,
"PostProcessingShader",
""
);
override val isOverridden: Boolean
get() = NativeConfig.isOverridden(file, section, key)
override val isRuntimeEditable: Boolean
get() {
for (setting in NOT_RUNTIME_EDITABLE) {
if (setting == this) return false
}
return NativeConfig.isSettingSaveable(file, section, key)
}
override fun delete(settings: Settings): Boolean {
return NativeConfig.deleteKey(settings.writeLayer, file, section, key)
}
override val string: String
get() = if (!NativeConfig.isSettingSaveable(file, section, key)) {
throw UnsupportedOperationException("Unsupported setting: $file, $section, $key")
} else NativeConfig.getString(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue)
override fun setString(settings: Settings, newValue: String) {
NativeConfig.setString(settings.writeLayer, file, section, key, newValue)
}
fun setString(layer: Int, newValue: String?) {
NativeConfig.setString(layer, file, section, key, newValue)
}
companion object {
private val NOT_RUNTIME_EDITABLE_ARRAY = arrayOf(
MAIN_CUSTOM_RTC_VALUE,
MAIN_GFX_BACKEND
)
private val NOT_RUNTIME_EDITABLE: Set<StringSetting> =
HashSet(listOf(*NOT_RUNTIME_EDITABLE_ARRAY))
}
}