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.
This commit is contained in:
FearlessTobi 2020-04-03 04:26:39 +02:00 committed by bunnei
parent 5841556fb0
commit fe32c0f474
3 changed files with 44 additions and 17 deletions

View File

@ -46,4 +46,10 @@ public final class SettingSection {
public HashMap<String, Setting> getSettings() {
return mSettings;
}
public void mergeSection(SettingSection settingSection) {
for (Setting setting : settingSection.mSettings.values()) {
putSetting(setting);
}
}
}

View File

@ -64,14 +64,34 @@ public class Settings {
public void loadSettings(SettingsActivityView view) {
sections = new Settings.SettingsSectionMap();
if (TextUtils.isEmpty(gameId)) {
for (Map.Entry<String, List<String>> 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<String, List<String>> 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<String, SettingSection> updatedSections) {
for (Map.Entry<String, SettingSection> 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));
}
}

View File

@ -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<String, SettingSection> readFile(final String fileName, boolean isCustomGame, SettingsActivityView view) {
static HashMap<String, SettingSection> readFile(final File ini, boolean isCustomGame, SettingsActivityView view) {
HashMap<String, SettingSection> 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<String, SettingSection> 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<String, SettingSection> 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) {