From d1065d066f145f2fc3455dddc647f2eb05a6780a Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Fri, 3 Apr 2020 04:26:39 +0200 Subject: [PATCH] Android: Reflect the settings that is being used by the emulator on the UI Per-Game settings now load the settings in this order 1. Emulator Settings 2. Default Settings of the Game that we ship with Dolphin 3. Custom game settings the user have where the later always overides the former in case of collision, then we show that on the UI to make it clear to the user which settings being used. Original commit by mahdihijazi for Dolphin-emu. --- .../settings/model/SettingSection.java | 6 ++++ .../features/settings/model/Settings.java | 34 +++++++++++++++---- .../features/settings/utils/SettingsFile.java | 21 ++++++------ 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/SettingSection.java b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/SettingSection.java index 3ddc8709f..0a291aa6b 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/SettingSection.java +++ b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/SettingSection.java @@ -46,4 +46,10 @@ public final class SettingSection { public HashMap getSettings() { return mSettings; } + + public void mergeSection(SettingSection settingSection) { + for (Setting setting : settingSection.mSettings.values()) { + putSetting(setting); + } + } } diff --git a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/Settings.java b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/Settings.java index f5456d2ff..c667f8a44 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/Settings.java +++ b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/Settings.java @@ -64,14 +64,34 @@ public class Settings { public void loadSettings(SettingsActivityView view) { sections = new Settings.SettingsSectionMap(); - if (TextUtils.isEmpty(gameId)) { - for (Map.Entry> entry : configFileSectionsMap.entrySet()) { - String fileName = entry.getKey(); - sections.putAll(SettingsFile.readFile(fileName, view)); + loadCitraSettings(view); + + if (!TextUtils.isEmpty(gameId)) { + loadCustomGameSettings(gameId, view); + } + } + + private void loadCitraSettings(SettingsActivityView view) { + for (Map.Entry> entry : configFileSectionsMap.entrySet()) { + String fileName = entry.getKey(); + sections.putAll(SettingsFile.readFile(fileName, view)); + } + } + + private void loadCustomGameSettings(String gameId, SettingsActivityView view) { + // custom game settings + mergeSections(SettingsFile.readCustomGameSettings(gameId, view)); + } + + private void mergeSections(HashMap updatedSections) { + for (Map.Entry entry : updatedSections.entrySet()) { + if (sections.containsKey(entry.getKey())) { + SettingSection originalSection = sections.get(entry.getKey()); + SettingSection updatedSection = entry.getValue(); + originalSection.mergeSection(updatedSection); + } else { + sections.put(entry.getKey(), entry.getValue()); } - } else { - // custom game settings - sections.putAll(SettingsFile.readCustomGameSettings(gameId, view)); } } diff --git a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/utils/SettingsFile.java b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/utils/SettingsFile.java index 038dbe040..ae88246fc 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/utils/SettingsFile.java +++ b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/utils/SettingsFile.java @@ -117,16 +117,14 @@ public final class SettingsFile { * effectively a HashMap of key/value settings. If unsuccessful, outputs an error telling why it * failed. * - * @param fileName The name of the settings file without a path or extension. + * @param ini The ini file to load the settings from * @param isCustomGame * @param view The current view. * @return An Observable that emits a HashMap of the file's contents, then completes. */ - static HashMap readFile(final String fileName, boolean isCustomGame, SettingsActivityView view) { + static HashMap readFile(final File ini, boolean isCustomGame, SettingsActivityView view) { HashMap sections = new Settings.SettingsSectionMap(); - File ini = getSettingsFile(fileName); - BufferedReader reader = null; try { @@ -145,17 +143,17 @@ public final class SettingsFile { } } } catch (FileNotFoundException e) { - Log.error("[SettingsFile] File not found: " + fileName + ".ini: " + e.getMessage()); + Log.error("[SettingsFile] File not found: " + ini.getAbsolutePath() + e.getMessage()); view.onSettingsFileNotFound(); } catch (IOException e) { - Log.error("[SettingsFile] Error reading from: " + fileName + ".ini: " + e.getMessage()); + Log.error("[SettingsFile] Error reading from: " + ini.getAbsolutePath() + e.getMessage()); view.onSettingsFileNotFound(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { - Log.error("[SettingsFile] Error closing: " + fileName + ".ini: " + e.getMessage()); + Log.error("[SettingsFile] Error closing: " + ini.getAbsolutePath() + e.getMessage()); } } } @@ -164,7 +162,7 @@ public final class SettingsFile { } public static HashMap readFile(final String fileName, SettingsActivityView view) { - return readFile(fileName, false, view); + return readFile(getSettingsFile(fileName), false, view); } /** @@ -176,8 +174,7 @@ public final class SettingsFile { * @param view The current view. */ public static HashMap readCustomGameSettings(final String gameId, SettingsActivityView view) { - String fileName = "../GameSettings/" + gameId; - return readFile(fileName, true, view); + return readFile(getCustomGameSettingsFile(gameId), true, view); } /** @@ -246,6 +243,10 @@ public final class SettingsFile { DirectoryInitialization.getUserDirectory() + "/config/" + fileName + ".ini"); } + private static File getCustomGameSettingsFile(String gameId) { + return new File(DirectoryInitialization.getUserDirectory() + "/GameSettings/" + gameId + ".ini"); + } + private static SettingSection sectionFromLine(String line, boolean isCustomGame) { String sectionName = line.substring(1, line.length() - 1); if (isCustomGame) {