Permalink
Browse files

Android: Reflect the settings that is being used by the emulator on t…

…he 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.
  • Loading branch information...
mahdihijazi committed Aug 4, 2018
1 parent ed1c91b commit f41785e1b945e0827cc58fd87f7e565336e786ea
@@ -52,4 +52,12 @@ public Setting getSetting(String key)
{
return mSettings;
}
public void mergeSection(SettingSection settingSection)
{
for (Setting setting : settingSection.mSettings.values())
{
putSetting(setting);
}
}
}
@@ -7,6 +7,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -83,18 +84,62 @@ public boolean isEmpty()
public void loadSettings(SettingsActivityView view)
{
sections = new Settings.SettingsSectionMap();
if (TextUtils.isEmpty(gameId))
HashSet<String> filesToExclude = new HashSet<>();
if (!TextUtils.isEmpty(gameId))
{
for (Map.Entry<String, List<String>> entry : configFileSectionsMap.entrySet())
// for per-game settings, don't load the WiiMoteNew.ini settings
filesToExclude.add(SettingsFile.FILE_NAME_WIIMOTE);
}
loadDolphinSettings(view, filesToExclude);
if (!TextUtils.isEmpty(gameId))
{
loadGenericGameSettings(gameId, view);
loadCustomGameSettings(gameId, view);
}
}
private void loadDolphinSettings(SettingsActivityView view, HashSet<String> filesToExclude)
{
for (Map.Entry<String, List<String>> entry : configFileSectionsMap.entrySet())
{
String fileName = entry.getKey();
if(filesToExclude == null || !filesToExclude.contains(fileName))
{
String fileName = entry.getKey();
sections.putAll(SettingsFile.readFile(fileName, view));
}
}
else
}
private void loadGenericGameSettings(String gameId, SettingsActivityView view)
{
// generic game settings
mergeSections(SettingsFile.readGenericGameSettings(gameId, view));
mergeSections(SettingsFile.readGenericGameSettingsForAllRegions(gameId, 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())
{
// custom game settings
sections.putAll(SettingsFile.readCustomGameSettings(gameId, view));
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());
}
}
}
@@ -260,16 +260,13 @@ private 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 view The current view.
* @return An Observable that emits a HashMap of the file's contents, then completes.
* @param ini The ini file to load the settings from
* @param view The current view.
*/
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
@@ -296,12 +293,12 @@ else if ((current != null))
}
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
@@ -314,22 +311,24 @@ else if ((current != null))
}
catch (IOException e)
{
Log.error("[SettingsFile] Error closing: " + fileName + ".ini: " + e.getMessage());
Log.error("[SettingsFile] Error closing: " + ini.getAbsolutePath()+ e.getMessage());
}
}
}
if (fileName.equals(SettingsFile.FILE_NAME_DOLPHIN))
{
addGcPadSettingsIfTheyDontExist(sections);
}
return sections;
}
public static HashMap<String, SettingSection> readFile(final String fileName, SettingsActivityView view)
{
return readFile(fileName, false, view);
HashMap<String, SettingSection> sections = readFile(getSettingsFile(fileName), false, view);
if (fileName.equals(SettingsFile.FILE_NAME_DOLPHIN))
{
addGcPadSettingsIfTheyDontExist(sections);
}
return sections;
}
/**
@@ -342,10 +341,20 @@ else if ((current != null))
*/
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);
}
public static HashMap<String, SettingSection> readGenericGameSettings(final String gameId, SettingsActivityView view)
{
return readFile(getGenericGameSettingsFile(gameId), true, view);
}
public static HashMap<String, SettingSection> readGenericGameSettingsForAllRegions(final String gameId, SettingsActivityView view)
{
return readFile(getGenericGameSettingsForAllRegions(gameId), true, view);
}
/**
* Saves a Settings HashMap to a given .ini file on disk. If unsuccessful, outputs an error
* telling why it failed.
@@ -436,6 +445,23 @@ private static File getSettingsFile(String fileName)
return new File(DirectoryInitializationService.getUserDirectory() + "/Config/" + fileName + ".ini");
}
private static File getGenericGameSettingsForAllRegions(String gameId)
{
// Use the first 3 chars from the gameId to load the generic game settings for all regions
gameId = gameId.substring(0, 3);
return new File(DirectoryInitializationService.getDolphinInternalDirectory() + "/GameSettings/" + gameId + ".ini");
}
private static File getGenericGameSettingsFile(String gameId)
{
return new File(DirectoryInitializationService.getDolphinInternalDirectory() + "/GameSettings/" + gameId + ".ini");
}
private static File getCustomGameSettingsFile(String gameId)
{
return new File(DirectoryInitializationService.getUserDirectory() + "/GameSettings/" + gameId + ".ini");
}
private static SettingSection sectionFromLine(String line, boolean isCustomGame)
{
String sectionName = line.substring(1, line.length() - 1);

0 comments on commit f41785e

Please sign in to comment.