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.
This commit is contained in:
mahdihijazi 2018-07-29 12:44:45 +02:00
parent c664bb7458
commit ed1c91b4f6
3 changed files with 110 additions and 12 deletions

View File

@ -94,7 +94,7 @@ public class Settings
else
{
// custom game settings
sections.putAll(SettingsFile.readFile("../GameSettings/" + gameId, view));
sections.putAll(SettingsFile.readCustomGameSettings(gameId, view));
}
}
@ -127,9 +127,7 @@ public class Settings
{
// 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);
}
}

View File

@ -2,6 +2,7 @@ package org.dolphinemu.dolphinemu.features.settings.utils;
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.Settings;
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 @@ public final class SettingsFile
// 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 @@ public final class 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 @@ public final class SettingsFile
{
if (line.startsWith("[") && line.endsWith("]"))
{
current = sectionFromLine(line);
current = sectionFromLine(line, isCustomGame);
sections.put(current.getName(), current);
}
else if ((current != null))
@ -315,6 +327,25 @@ public final class SettingsFile
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.
@ -322,7 +353,6 @@ public final class SettingsFile
* @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 final class SettingsFile
}
}
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)
{

View File

@ -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);
}
}