Android: Remove support for the old config system

All settings that we care about from an Android perspective are now
supported by the new config system, so we can remove all the Android code
for the old config system. This should have no impact on users.
This commit is contained in:
JosJuice 2023-03-11 17:48:42 +01:00
parent 53e7090f55
commit 68fd133057
9 changed files with 95 additions and 194 deletions

View File

@ -298,10 +298,7 @@ public enum BooleanSetting implements AbstractBooleanSetting
@Override
public boolean isOverridden(@NonNull Settings settings)
{
if (settings.isGameSpecific() && !NativeConfig.isSettingSaveable(mFile, mSection, mKey))
return settings.getSection(mFile, mSection).exists(mKey);
else
return NativeConfig.isOverridden(mFile, mSection, mKey);
return NativeConfig.isOverridden(mFile, mSection, mKey);
}
@Override
@ -322,53 +319,42 @@ public enum BooleanSetting implements AbstractBooleanSetting
@Override
public boolean delete(@NonNull Settings settings)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
}
else
{
return settings.getSection(mFile, mSection).delete(mKey);
throw new UnsupportedOperationException(
"Unsupported setting: " + mFile + ", " + mSection + ", " + mKey);
}
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
}
@Override
public boolean getBoolean(@NonNull Settings settings)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
return NativeConfig.getBoolean(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey,
mDefaultValue);
}
else
{
return settings.getSection(mFile, mSection).getBoolean(mKey, mDefaultValue);
}
return NativeConfig.getBoolean(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}
@Override
public void setBoolean(@NonNull Settings settings, boolean newValue)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
NativeConfig.setBoolean(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}
else
{
settings.getSection(mFile, mSection).setBoolean(mKey, newValue);
throw new UnsupportedOperationException(
"Unsupported setting: " + mFile + ", " + mSection + ", " + mKey);
}
NativeConfig.setBoolean(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}
public void setBoolean(int layerType, boolean newValue)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
NativeConfig.setBoolean(layerType, mFile, mSection, mKey, newValue);
}
else
{
throw new UnsupportedOperationException("The old config system doesn't support layers");
throw new UnsupportedOperationException(
"Unsupported setting: " + mFile + ", " + mSection + ", " + mKey);
}
NativeConfig.setBoolean(layerType, mFile, mSection, mKey, newValue);
}
public boolean getBooleanGlobal()
@ -378,6 +364,12 @@ public enum BooleanSetting implements AbstractBooleanSetting
public void setBooleanGlobal(int layer, boolean newValue)
{
if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
throw new UnsupportedOperationException(
"Unsupported setting: " + mFile + ", " + mSection + ", " + mKey);
}
NativeConfig.setBoolean(layer, mFile, mSection, mKey, newValue);
}

View File

@ -27,10 +27,7 @@ public enum FloatSetting implements AbstractFloatSetting
@Override
public boolean isOverridden(@NonNull Settings settings)
{
if (settings.isGameSpecific() && !NativeConfig.isSettingSaveable(mFile, mSection, mKey))
return settings.getSection(mFile, mSection).exists(mKey);
else
return NativeConfig.isOverridden(mFile, mSection, mKey);
return NativeConfig.isOverridden(mFile, mSection, mKey);
}
@Override
@ -42,40 +39,31 @@ public enum FloatSetting implements AbstractFloatSetting
@Override
public boolean delete(@NonNull Settings settings)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
}
else
{
return settings.getSection(mFile, mSection).delete(mKey);
throw new UnsupportedOperationException(
"Unsupported setting: " + mFile + ", " + mSection + ", " + mKey);
}
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
}
@Override
public float getFloat(@NonNull Settings settings)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
return NativeConfig.getFloat(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}
else
{
return settings.getSection(mFile, mSection).getFloat(mKey, mDefaultValue);
}
return NativeConfig.getFloat(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}
@Override
public void setFloat(@NonNull Settings settings, float newValue)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
NativeConfig.setFloat(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}
else
{
settings.getSection(mFile, mSection).setFloat(mKey, newValue);
throw new UnsupportedOperationException(
"Unsupported setting: " + mFile + ", " + mSection + ", " + mKey);
}
NativeConfig.setFloat(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}
public float getFloatGlobal()

View File

@ -123,10 +123,7 @@ public enum IntSetting implements AbstractIntSetting
@Override
public boolean isOverridden(@NonNull Settings settings)
{
if (settings.isGameSpecific() && !NativeConfig.isSettingSaveable(mFile, mSection, mKey))
return settings.getSection(mFile, mSection).exists(mKey);
else
return NativeConfig.isOverridden(mFile, mSection, mKey);
return NativeConfig.isOverridden(mFile, mSection, mKey);
}
@Override
@ -147,40 +144,31 @@ public enum IntSetting implements AbstractIntSetting
@Override
public boolean delete(@NonNull Settings settings)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
}
else
{
return settings.getSection(mFile, mSection).delete(mKey);
throw new UnsupportedOperationException(
"Unsupported setting: " + mFile + ", " + mSection + ", " + mKey);
}
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
}
@Override
public int getInt(@NonNull Settings settings)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
return NativeConfig.getInt(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}
else
{
return settings.getSection(mFile, mSection).getInt(mKey, mDefaultValue);
}
return NativeConfig.getInt(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}
@Override
public void setInt(@NonNull Settings settings, int newValue)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
NativeConfig.setInt(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}
else
{
settings.getSection(mFile, mSection).setInt(mKey, newValue);
throw new UnsupportedOperationException(
"Unsupported setting: " + mFile + ", " + mSection + ", " + mKey);
}
NativeConfig.setInt(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}
public int getIntGlobal()
@ -190,6 +178,12 @@ public enum IntSetting implements AbstractIntSetting
public void setIntGlobal(int layer, int newValue)
{
if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
throw new UnsupportedOperationException(
"Unsupported setting: " + mFile + ", " + mSection + ", " + mKey);
}
NativeConfig.setInt(layer, mFile, mSection, mKey, newValue);
}

View File

@ -18,10 +18,14 @@ public class NativeConfig
public static native void save(int layer);
public static native void deleteAllKeys(int layer);
public static native boolean isOverridden(String file, String section, String key);
public static native boolean deleteKey(int layer, String file, String section, String key);
public static native boolean exists(int layer, String file, String section, String key);
public static native String getString(int layer, String file, String section, String key,
String defaultValue);

View File

@ -10,14 +10,9 @@ import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.input.model.MappingCommon;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivityView;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.services.GameFileCacheManager;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.IniFile;
import java.io.Closeable;
import java.util.HashMap;
import java.util.Map;
public class Settings implements Closeable
{
@ -52,40 +47,14 @@ public class Settings implements Closeable
public static final String SECTION_ANALYTICS = "Analytics";
public static final String GAME_SETTINGS_PLACEHOLDER_FILE_NAME = "";
private String mGameId;
private int mRevision;
private boolean mIsWii;
private static final String[] configFiles = new String[]{FILE_DOLPHIN, FILE_GFX, FILE_LOGGER,
FILE_WIIMOTE};
private Map<String, IniFile> mIniFiles = new HashMap<>();
private boolean mSettingsLoaded = false;
private boolean mLoadedRecursiveIsoPathsValue = false;
private IniFile getGameSpecificFile()
{
if (!isGameSpecific() || mIniFiles.size() != 1)
throw new IllegalStateException();
return mIniFiles.get(GAME_SETTINGS_PLACEHOLDER_FILE_NAME);
}
public IniFile.Section getSection(String fileName, String sectionName)
{
if (!isGameSpecific())
{
return mIniFiles.get(fileName).getOrCreateSection(sectionName);
}
else
{
return getGameSpecificFile()
.getOrCreateSection(SettingsFile.mapSectionNameFromIni(sectionName));
}
}
public boolean isGameSpecific()
{
return !TextUtils.isEmpty(mGameId);
@ -101,9 +70,9 @@ public class Settings implements Closeable
return isGameSpecific() ? NativeConfig.LAYER_LOCAL_GAME : NativeConfig.LAYER_BASE_OR_CURRENT;
}
public boolean isEmpty()
public boolean areSettingsLoaded()
{
return mIniFiles.isEmpty();
return mSettingsLoaded;
}
public void loadSettings()
@ -115,43 +84,20 @@ public class Settings implements Closeable
public void loadSettings(SettingsActivityView view, boolean isWii)
{
mIsWii = isWii;
mSettingsLoaded = true;
mIniFiles = new HashMap<>();
if (!isGameSpecific())
{
loadDolphinSettings(view);
}
else
if (isGameSpecific())
{
// Loading game INIs while the core is running will mess with the game INIs loaded by the core
if (NativeLibrary.IsRunning())
throw new IllegalStateException("Attempted to load game INI while emulating");
NativeConfig.loadGameInis(mGameId, mRevision);
loadCustomGameSettings(mGameId, view);
}
mLoadedRecursiveIsoPathsValue = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBoolean(this);
}
private void loadDolphinSettings(SettingsActivityView view)
{
for (String fileName : configFiles)
{
IniFile ini = new IniFile();
SettingsFile.readFile(fileName, ini, view);
mIniFiles.put(fileName, ini);
}
}
private void loadCustomGameSettings(String gameId, SettingsActivityView view)
{
IniFile ini = new IniFile();
SettingsFile.readCustomGameSettings(gameId, ini, view);
mIniFiles.put(GAME_SETTINGS_PLACEHOLDER_FILE_NAME, ini);
}
public void loadSettings(SettingsActivityView view, String gameId, int revision, boolean isWii)
{
mGameId = gameId;
@ -166,22 +112,10 @@ public class Settings implements Closeable
if (context != null)
Toast.makeText(context, R.string.settings_saved, Toast.LENGTH_SHORT).show();
for (Map.Entry<String, IniFile> entry : mIniFiles.entrySet())
{
SettingsFile.saveFile(entry.getKey(), entry.getValue(), view);
}
MappingCommon.save();
NativeConfig.save(NativeConfig.LAYER_BASE);
if (!NativeLibrary.IsRunning())
{
// Notify the native code of the changes to legacy settings
NativeLibrary.ReloadConfig();
}
// LogManager does use the new config system, but doesn't pick up on changes automatically
NativeLibrary.ReloadLoggerConfig();
NativeLibrary.UpdateGCAdapterScanThread();
@ -201,18 +135,13 @@ public class Settings implements Closeable
Toast.LENGTH_SHORT).show();
}
SettingsFile.saveCustomGameSettings(mGameId, getGameSpecificFile());
NativeConfig.save(NativeConfig.LAYER_LOCAL_GAME);
}
}
public void clearSettings()
public void clearGameSettings()
{
for (String fileName : mIniFiles.keySet())
{
mIniFiles.put(fileName, new IniFile());
}
NativeConfig.deleteAllKeys(NativeConfig.LAYER_LOCAL_GAME);
}
public boolean gameIniContainsJunk()
@ -238,7 +167,8 @@ public class Settings implements Closeable
if (!isGameSpecific())
return false;
return getSection(Settings.FILE_DOLPHIN, SECTION_INI_INTERFACE).exists("ThemeName");
return NativeConfig.exists(NativeConfig.LAYER_LOCAL_GAME, FILE_DOLPHIN, SECTION_INI_INTERFACE,
"ThemeName");
}
@Override

View File

@ -67,10 +67,7 @@ public enum StringSetting implements AbstractStringSetting
@Override
public boolean isOverridden(@NonNull Settings settings)
{
if (settings.isGameSpecific() && !NativeConfig.isSettingSaveable(mFile, mSection, mKey))
return settings.getSection(mFile, mSection).exists(mKey);
else
return NativeConfig.isOverridden(mFile, mSection, mKey);
return NativeConfig.isOverridden(mFile, mSection, mKey);
}
@Override
@ -88,41 +85,25 @@ public enum StringSetting implements AbstractStringSetting
@Override
public boolean delete(@NonNull Settings settings)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
}
else
{
return settings.getSection(mFile, mSection).delete(mKey);
}
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
}
@NonNull @Override
public String getString(@NonNull Settings settings)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey,
mDefaultValue);
}
else
{
return settings.getSection(mFile, mSection).getString(mKey, mDefaultValue);
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)
{
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
{
NativeConfig.setString(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}
else
{
settings.getSection(mFile, mSection).setString(mKey, newValue);
}
NativeConfig.setString(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}
public String getStringGlobal()

View File

@ -276,7 +276,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
new MaterialAlertDialogBuilder(this)
.setTitle(getString(R.string.game_ini_junk_title))
.setMessage(getString(R.string.game_ini_junk_question))
.setPositiveButton(R.string.yes, (dialogInterface, i) -> mPresenter.clearSettings())
.setPositiveButton(R.string.yes, (dialogInterface, i) -> mPresenter.clearGameSettings())
.setNegativeButton(R.string.no, null)
.show();
}

View File

@ -66,7 +66,7 @@ public final class SettingsActivityPresenter
{
mView.hideLoading();
if (mSettings.isEmpty())
if (!mSettings.areSettingsLoaded())
{
if (!TextUtils.isEmpty(mGameId))
{
@ -99,9 +99,9 @@ public final class SettingsActivityPresenter
return mSettings;
}
public void clearSettings()
public void clearGameSettings()
{
mSettings.clearSettings();
mSettings.clearGameSettings();
onSettingChanged();
}

View File

@ -138,12 +138,14 @@ Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_unloadGameIn
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_save(
JNIEnv*, jclass, jint layer)
{
const std::shared_ptr<Config::Layer> layer_ptr = GetLayer(layer, {});
return GetLayer(layer, {})->Save();
}
// Workaround for the Settings class carrying around a legacy map of settings it always saves
layer_ptr->MarkAsDirty();
return layer_ptr->Save();
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_deleteAllKeys(JNIEnv*, jclass,
jint layer)
{
return GetLayer(layer, {})->DeleteAllKeys();
}
JNIEXPORT jboolean JNICALL
@ -166,6 +168,16 @@ Java_org_dolphinemu_dolphinemu_features_settings_model_NativeConfig_deleteKey(
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,