diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java index cbaa7a4292..ad54b93a61 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java @@ -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); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java index 3bcb3e34c1..734839f8ec 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java @@ -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() diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java index 77cf7b339a..6c3c565552 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java @@ -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); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/NativeConfig.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/NativeConfig.java index 07646a2eb8..7fbe96f95e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/NativeConfig.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/NativeConfig.java @@ -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); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java index 6b9cf5226c..480dee0174 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java @@ -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 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 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 diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/StringSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/StringSetting.java index 127852c640..88b37dbbd9 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/StringSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/StringSetting.java @@ -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() diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java index bce24c1c46..4f1e4bdf45 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java @@ -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(); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java index cc235b9863..1b50754fdd 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java @@ -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(); } diff --git a/Source/Android/jni/Config/NativeConfig.cpp b/Source/Android/jni/Config/NativeConfig.cpp index 3c67eb3af4..9681f0ca8e 100644 --- a/Source/Android/jni/Config/NativeConfig.cpp +++ b/Source/Android/jni/Config/NativeConfig.cpp @@ -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 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(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(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,