Permalink
Browse files

Android: Fix custom game settings

Apparently there was a different section names used by the custom game
settings that caused Android to have those settings broken for
some sections like the graphics one. This adds the map between the generic
settings <> custom settings.
  • Loading branch information...
mahdihijazi committed Jul 29, 2018
1 parent c664bb7 commit ed1c91b4f6c29570a67d866d01318b11aec70564
@@ -94,7 +94,7 @@ public void loadSettings(SettingsActivityView view)
else
{
// custom game settings
sections.putAll(SettingsFile.readFile("../GameSettings/" + gameId, view));
sections.putAll(SettingsFile.readCustomGameSettings(gameId, view));
}
}
@@ -127,9 +127,7 @@ public void saveSettings(SettingsActivityView view)
{
// custom game settings
view.showToastMessage("Saved settings for " + gameId);
TreeMap<String, SettingSection> iniSections = new TreeMap<>(sections);
SettingsFile.saveFile("../GameSettings/" + gameId, iniSections, view);
SettingsFile.saveCustomGameSettings(gameId, sections);
}
}
@@ -2,6 +2,7 @@
import android.support.annotation.NonNull;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.FloatSetting;
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
@@ -11,6 +12,7 @@
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivityView;
import org.dolphinemu.dolphinemu.utils.BiMap;
import org.dolphinemu.dolphinemu.utils.Log;
import java.io.BufferedReader;
@@ -239,6 +241,16 @@
// Internal only, not actually found in settings file.
public static final String KEY_VIDEO_BACKEND_INDEX = "VideoBackendIndex";
private static BiMap<String, String> sectionsMap = new BiMap<>();
static {
sectionsMap.add("Hardware", "Video_Hardware");
sectionsMap.add("Settings", "Video_Settings");
sectionsMap.add("Enhancements", "Video_Enhancements");
sectionsMap.add("Stereoscopy", "Video_Stereoscopy");
sectionsMap.add("Hacks", "Video_Hacks");
sectionsMap.add("GameSpecific", "Video");
}
private SettingsFile()
{
}
@@ -252,7 +264,7 @@ private SettingsFile()
* @param view The current view.
* @return An Observable that emits a HashMap of the file's contents, then completes.
*/
public static HashMap<String, SettingSection> readFile(final String fileName, SettingsActivityView view)
static HashMap<String, SettingSection> readFile(final String fileName, boolean isCustomGame, SettingsActivityView view)
{
HashMap<String, SettingSection> sections = new Settings.SettingsSectionMap();
@@ -269,7 +281,7 @@ private SettingsFile()
{
if (line.startsWith("[") && line.endsWith("]"))
{
current = sectionFromLine(line);
current = sectionFromLine(line, isCustomGame);
sections.put(current.getName(), current);
}
else if ((current != null))
@@ -315,14 +327,32 @@ else if ((current != null))
return sections;
}
public static HashMap<String, SettingSection> readFile(final String fileName, SettingsActivityView view)
{
return readFile(fileName, false, view);
}
/**
* Reads a given .ini file from disk and returns it as a HashMap of SettingSections, themselves
* effectively a HashMap of key/value settings. If unsuccessful, outputs an error telling why it
* failed.
*
* @param gameId the id of the game to load it's settings.
* @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);
}
/**
* Saves a Settings HashMap to a given .ini file on disk. If unsuccessful, outputs an error
* telling why it failed.
*
* @param fileName The target filename without a path or extension.
* @param sections The HashMap containing the Settings we want to serialize.
* @param view The current view.
* @return An Observable representing the operation.
*/
public static void saveFile(final String fileName, TreeMap<String, SettingSection> sections, SettingsActivityView view)
{
@@ -361,17 +391,60 @@ public static void saveFile(final String fileName, TreeMap<String, SettingSectio
}
}
public static void saveCustomGameSettings(final String gameId, final HashMap<String, SettingSection> sections)
{
Set<String> sortedSections = new TreeSet<>(sections.keySet());
for (String sectionKey : sortedSections)
{
SettingSection section = sections.get(sectionKey);
HashMap<String, Setting> settings = section.getSettings();
Set<String> sortedKeySet = new TreeSet<>(settings.keySet());
for (String settingKey : sortedKeySet)
{
Setting setting = settings.get(settingKey);
NativeLibrary.SetUserSetting(gameId, mapSectionNameFromIni(section.getName()), setting.getKey(), setting.getValueAsString());
}
}
}
private static String mapSectionNameFromIni(String generalSectionName)
{
if (sectionsMap.getForward(generalSectionName) != null)
{
return sectionsMap.getForward(generalSectionName);
}
return generalSectionName;
}
private static String mapSectionNameToIni(String generalSectionName)
{
if (sectionsMap.getBackward(generalSectionName) != null)
{
return sectionsMap.getBackward(generalSectionName);
}
return generalSectionName;
}
@NonNull
private static File getSettingsFile(String fileName)
{
return new File(DirectoryInitializationService.getUserDirectory() + "/Config/" + fileName + ".ini");
}
private static SettingSection sectionFromLine(String line)
{
String sectionName = line.substring(1, line.length() - 1);
return new SettingSection(sectionName);
}
private static SettingSection sectionFromLine(String line, boolean isCustomGame)
{
String sectionName = line.substring(1, line.length() - 1);
if (isCustomGame)
{
sectionName = mapSectionNameToIni(sectionName);
}
return new SettingSection(sectionName);
}
private static void addGcPadSettingsIfTheyDontExist(HashMap<String, SettingSection> sections)
{
@@ -0,0 +1,27 @@
package org.dolphinemu.dolphinemu.utils;
import java.util.HashMap;
import java.util.Map;
public class BiMap<K, V>
{
private Map<K, V> forward = new HashMap<K, V>();
private Map<V, K> backward = new HashMap<V, K>();
public synchronized void add(K key, V value)
{
forward.put(key, value);
backward.put(value, key);
}
public synchronized V getForward(K key)
{
return forward.get(key);
}
public synchronized K getBackward(V key)
{
return backward.get(key);
}
}

0 comments on commit ed1c91b

Please sign in to comment.