Android: Replace Java INI parser with C++ INI parser
Fixes https://bugs.dolphin-emu.org/issues/12096.
This commit is contained in:
parent
74f197caed
commit
c6a308380c
|
@ -32,7 +32,6 @@ import android.widget.Toast;
|
|||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
import org.dolphinemu.dolphinemu.fragments.EmulationFragment;
|
||||
|
@ -521,10 +520,8 @@ public final class EmulationActivity extends AppCompatActivity
|
|||
showUnpauseEmulationButton();
|
||||
}
|
||||
|
||||
BooleanSetting enableSaveStates =
|
||||
(BooleanSetting) mSettings.getSection(Settings.SECTION_INI_CORE)
|
||||
.getSetting(SettingsFile.KEY_ENABLE_SAVE_STATES);
|
||||
if (enableSaveStates != null && enableSaveStates.getValue())
|
||||
if (mSettings.getSection(SettingsFile.FILE_NAME_DOLPHIN, Settings.SECTION_INI_CORE)
|
||||
.getBoolean(SettingsFile.KEY_ENABLE_SAVE_STATES, false))
|
||||
{
|
||||
menu.findItem(R.id.menu_quicksave).setVisible(true);
|
||||
menu.findItem(R.id.menu_quickload).setVisible(true);
|
||||
|
|
|
@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
|
||||
import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
import org.dolphinemu.dolphinemu.utils.TvUtil;
|
||||
|
@ -27,6 +28,7 @@ public final class MotionAlertDialog extends AlertDialog
|
|||
private final ArrayList<Float> mPreviousValues = new ArrayList<>();
|
||||
private int mPrevDeviceId = 0;
|
||||
private boolean mWaitingForEvent = true;
|
||||
private SettingsAdapter mAdapter;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -34,11 +36,12 @@ public final class MotionAlertDialog extends AlertDialog
|
|||
* @param context The current {@link Context}.
|
||||
* @param setting The Preference to show this dialog for.
|
||||
*/
|
||||
public MotionAlertDialog(Context context, InputBindingSetting setting)
|
||||
public MotionAlertDialog(Context context, InputBindingSetting setting, SettingsAdapter adapter)
|
||||
{
|
||||
super(context);
|
||||
|
||||
this.setting = setting;
|
||||
mAdapter = adapter;
|
||||
}
|
||||
|
||||
public boolean onKeyEvent(int keyCode, KeyEvent event)
|
||||
|
@ -48,7 +51,7 @@ public final class MotionAlertDialog extends AlertDialog
|
|||
{
|
||||
if (!ControllerMappingHelper.shouldKeyBeIgnored(event.getDevice(), keyCode))
|
||||
{
|
||||
setting.onKeyInput(event);
|
||||
setting.onKeyInput(mAdapter.getSettings(), event);
|
||||
dismiss();
|
||||
}
|
||||
// Even if we ignore the key, we still consume it. Thus return true regardless.
|
||||
|
@ -63,7 +66,7 @@ public final class MotionAlertDialog extends AlertDialog
|
|||
// Option to clear by long back is only needed on the TV interface
|
||||
if (TvUtil.isLeanback(getContext()) && keyCode == KeyEvent.KEYCODE_BACK)
|
||||
{
|
||||
setting.clearValue();
|
||||
setting.clearValue(mAdapter.getSettings());
|
||||
dismiss();
|
||||
return true;
|
||||
}
|
||||
|
@ -158,7 +161,7 @@ public final class MotionAlertDialog extends AlertDialog
|
|||
if (numMovedAxis == 1)
|
||||
{
|
||||
mWaitingForEvent = false;
|
||||
setting.onMotionInput(input, lastMovedRange, lastMovedDir);
|
||||
setting.onMotionInput(mAdapter.getSettings(), input, lastMovedRange, lastMovedDir);
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
public final class BooleanSetting extends Setting
|
||||
{
|
||||
private boolean mValue;
|
||||
|
||||
public BooleanSetting(String key, String section, boolean value)
|
||||
{
|
||||
super(key, section);
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
public boolean getValue()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void setValue(boolean value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString()
|
||||
{
|
||||
return mValue ? "True" : "False";
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
public final class FloatSetting extends Setting
|
||||
{
|
||||
private float mValue;
|
||||
|
||||
public FloatSetting(String key, String section, float value)
|
||||
{
|
||||
super(key, section);
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
public float getValue()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void setValue(float value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString()
|
||||
{
|
||||
return Float.toString(mValue);
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
|
||||
|
||||
public final class IntSetting extends Setting
|
||||
{
|
||||
private int mValue;
|
||||
private MenuTag menuTag;
|
||||
|
||||
public IntSetting(String key, String section, int value)
|
||||
{
|
||||
super(key, section);
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
public IntSetting(String key, String section, int value, MenuTag menuTag)
|
||||
{
|
||||
super(key, section);
|
||||
mValue = value;
|
||||
this.menuTag = menuTag;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void setValue(int value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString()
|
||||
{
|
||||
return Integer.toString(mValue);
|
||||
}
|
||||
|
||||
public MenuTag getMenuTag()
|
||||
{
|
||||
return menuTag;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
/**
|
||||
* Abstraction for a setting item as read from / written to Dolphin's configuration ini files.
|
||||
* These files generally consist of a key/value pair, though the type of value is ambiguous and
|
||||
* must be inferred at read-time. The type of value determines which child of this class is used
|
||||
* to represent the Setting.
|
||||
*/
|
||||
public abstract class Setting
|
||||
{
|
||||
private String mKey;
|
||||
private String mSection;
|
||||
|
||||
/**
|
||||
* Base constructor.
|
||||
*
|
||||
* @param key Everything to the left of the = in a line from the ini file.
|
||||
* @param section The corresponding recent section header; e.g. [Core] or [Enhancements] without the brackets.
|
||||
*/
|
||||
public Setting(String key, String section)
|
||||
{
|
||||
mKey = key;
|
||||
mSection = section;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The identifier used to write this setting to the ini file.
|
||||
*/
|
||||
public String getKey()
|
||||
{
|
||||
return mKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The name of the header under which this Setting should be written in the ini file.
|
||||
*/
|
||||
public String getSection()
|
||||
{
|
||||
return mSection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A representation of this Setting's backing value converted to a String (e.g. for serialization).
|
||||
*/
|
||||
public abstract String getValueAsString();
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* A semantically-related group of Settings objects. These Settings are
|
||||
* internally stored as a HashMap.
|
||||
*/
|
||||
public final class SettingSection
|
||||
{
|
||||
private String mName;
|
||||
|
||||
private HashMap<String, Setting> mSettings = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Create a new SettingSection with no Settings in it.
|
||||
*
|
||||
* @param name The header of this section; e.g. [Core] or [Enhancements] without the brackets.
|
||||
*/
|
||||
public SettingSection(String name)
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method; inserts a value directly into the backing HashMap.
|
||||
*
|
||||
* @param setting The Setting to be inserted.
|
||||
*/
|
||||
public void putSetting(Setting setting)
|
||||
{
|
||||
mSettings.put(setting.getKey(), setting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method; gets a value directly from the backing HashMap.
|
||||
*
|
||||
* @param key Used to retrieve the Setting.
|
||||
* @return A Setting object (you should probably cast this before using)
|
||||
*/
|
||||
public Setting getSetting(String key)
|
||||
{
|
||||
return mSettings.get(key);
|
||||
}
|
||||
|
||||
public HashMap<String, Setting> getSettings()
|
||||
{
|
||||
return mSettings;
|
||||
}
|
||||
|
||||
public void mergeSection(SettingSection settingSection)
|
||||
{
|
||||
for (Setting setting : settingSection.mSettings.values())
|
||||
{
|
||||
putSetting(setting);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,73 +48,45 @@ public class Settings
|
|||
|
||||
public static final String SECTION_ANALYTICS = "Analytics";
|
||||
|
||||
public static final String GAME_SETTINGS_PLACEHOLDER_FILE_NAME = "";
|
||||
|
||||
private String gameId;
|
||||
|
||||
private static final Map<String, List<String>> configFileSectionsMap = new HashMap<>();
|
||||
private static final String[] configFiles = new String[]{SettingsFile.FILE_NAME_DOLPHIN,
|
||||
SettingsFile.FILE_NAME_GFX, SettingsFile.FILE_NAME_LOGGER,
|
||||
SettingsFile.FILE_NAME_WIIMOTE};
|
||||
|
||||
static
|
||||
private HashMap<String, IniFile> mIniFiles = new HashMap<>();
|
||||
|
||||
private IniFile getGameSpecificFile()
|
||||
{
|
||||
configFileSectionsMap.put(SettingsFile.FILE_NAME_DOLPHIN,
|
||||
Arrays
|
||||
.asList(SECTION_INI_ANDROID, SECTION_INI_GENERAL, SECTION_INI_CORE,
|
||||
SECTION_INI_INTERFACE,
|
||||
SECTION_INI_DSP, SECTION_BINDINGS, SECTION_ANALYTICS, SECTION_DEBUG));
|
||||
configFileSectionsMap.put(SettingsFile.FILE_NAME_GFX,
|
||||
Arrays.asList(SECTION_GFX_SETTINGS, SECTION_GFX_ENHANCEMENTS, SECTION_GFX_HACKS,
|
||||
SECTION_STEREOSCOPY));
|
||||
configFileSectionsMap.put(SettingsFile.FILE_NAME_LOGGER,
|
||||
Arrays.asList(SECTION_LOGGER_LOGS, SECTION_LOGGER_OPTIONS));
|
||||
configFileSectionsMap.put(SettingsFile.FILE_NAME_WIIMOTE,
|
||||
Arrays.asList(SECTION_WIIMOTE + 1, SECTION_WIIMOTE + 2, SECTION_WIIMOTE + 3,
|
||||
SECTION_WIIMOTE + 4));
|
||||
if (TextUtils.isEmpty(gameId) || mIniFiles.size() != 1)
|
||||
throw new IllegalStateException();
|
||||
|
||||
return mIniFiles.get(GAME_SETTINGS_PLACEHOLDER_FILE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* A HashMap<String, SettingSection> that constructs a new SettingSection instead of returning null
|
||||
* when getting a key not already in the map
|
||||
*/
|
||||
public static final class SettingsSectionMap extends HashMap<String, SettingSection>
|
||||
public IniFile.Section getSection(String fileName, String sectionName)
|
||||
{
|
||||
@Override
|
||||
public SettingSection get(Object key)
|
||||
if (TextUtils.isEmpty(gameId))
|
||||
{
|
||||
if (!(key instanceof String))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String stringKey = (String) key;
|
||||
|
||||
if (!super.containsKey(stringKey))
|
||||
{
|
||||
SettingSection section = new SettingSection(stringKey);
|
||||
super.put(stringKey, section);
|
||||
return section;
|
||||
}
|
||||
return super.get(key);
|
||||
return mIniFiles.get(fileName).getOrCreateSection(sectionName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return getGameSpecificFile()
|
||||
.getOrCreateSection(SettingsFile.mapSectionNameFromIni(sectionName));
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, SettingSection> sections = new Settings.SettingsSectionMap();
|
||||
|
||||
public SettingSection getSection(String sectionName)
|
||||
{
|
||||
return sections.get(sectionName);
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return sections.isEmpty();
|
||||
}
|
||||
|
||||
public HashMap<String, SettingSection> getSections()
|
||||
{
|
||||
return sections;
|
||||
return mIniFiles.isEmpty();
|
||||
}
|
||||
|
||||
public void loadSettings(SettingsActivityView view)
|
||||
{
|
||||
sections = new Settings.SettingsSectionMap();
|
||||
mIniFiles = new HashMap<>();
|
||||
|
||||
if (TextUtils.isEmpty(gameId))
|
||||
{
|
||||
|
@ -128,46 +100,24 @@ public class Settings
|
|||
|
||||
private void loadDolphinSettings(SettingsActivityView view)
|
||||
{
|
||||
for (Map.Entry<String, List<String>> entry : configFileSectionsMap.entrySet())
|
||||
for (String fileName : configFiles)
|
||||
{
|
||||
String fileName = entry.getKey();
|
||||
sections.putAll(SettingsFile.readFile(fileName, view));
|
||||
IniFile ini = new IniFile();
|
||||
SettingsFile.readFile(fileName, ini, view);
|
||||
mIniFiles.put(fileName, ini);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
IniFile ini = new IniFile();
|
||||
SettingsFile.readCustomGameSettings(gameId, ini, view);
|
||||
mIniFiles.put(GAME_SETTINGS_PLACEHOLDER_FILE_NAME, ini);
|
||||
}
|
||||
|
||||
public void loadWiimoteProfile(String gameId, String padId)
|
||||
public void loadWiimoteProfile(String gameId, int padId)
|
||||
{
|
||||
mergeSections(SettingsFile.readWiimoteProfile(gameId, padId));
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
SettingsFile.readWiimoteProfile(gameId, getGameSpecificFile(), padId);
|
||||
}
|
||||
|
||||
public void loadSettings(String gameId, SettingsActivityView view)
|
||||
|
@ -182,17 +132,9 @@ public class Settings
|
|||
{
|
||||
view.showToastMessage("Saved settings to INI files");
|
||||
|
||||
for (Map.Entry<String, List<String>> entry : configFileSectionsMap.entrySet())
|
||||
for (Map.Entry<String, IniFile> entry : mIniFiles.entrySet())
|
||||
{
|
||||
String fileName = entry.getKey();
|
||||
List<String> sectionNames = entry.getValue();
|
||||
TreeMap<String, SettingSection> iniSections = new TreeMap<>();
|
||||
for (String section : sectionNames)
|
||||
{
|
||||
iniSections.put(section, sections.get(section));
|
||||
}
|
||||
|
||||
SettingsFile.saveFile(fileName, iniSections, view);
|
||||
SettingsFile.saveFile(entry.getKey(), entry.getValue(), view);
|
||||
}
|
||||
|
||||
if (modifiedSettings.contains(SettingsFile.KEY_DSP_ENGINE))
|
||||
|
@ -240,13 +182,16 @@ public class Settings
|
|||
{
|
||||
// custom game settings
|
||||
view.showToastMessage("Saved settings for " + gameId);
|
||||
SettingsFile.saveCustomGameSettings(gameId, sections);
|
||||
SettingsFile.saveCustomGameSettings(gameId, getGameSpecificFile());
|
||||
}
|
||||
}
|
||||
|
||||
public void clearSettings()
|
||||
{
|
||||
sections.clear();
|
||||
for (String fileName : mIniFiles.keySet())
|
||||
{
|
||||
mIniFiles.put(fileName, new IniFile());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean gameIniContainsJunk()
|
||||
|
@ -272,7 +217,6 @@ public class Settings
|
|||
if (TextUtils.isEmpty(gameId))
|
||||
return false;
|
||||
|
||||
SettingSection interfaceSection = sections.get("Interface");
|
||||
return interfaceSection != null && interfaceSection.getSetting("ThemeName") != null;
|
||||
return getSection(SettingsFile.FILE_NAME_DOLPHIN, SECTION_INI_INTERFACE).exists("ThemeName");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
public final class StringSetting extends Setting
|
||||
{
|
||||
private String mValue;
|
||||
|
||||
public StringSetting(String key, String section, String value)
|
||||
{
|
||||
super(key, section);
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void setValue(String value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
}
|
|
@ -1,51 +1,39 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
|
||||
public final class CheckBoxSetting extends SettingsItem
|
||||
{
|
||||
private boolean mDefaultValue;
|
||||
|
||||
public CheckBoxSetting(String key, String section, int titleId, int descriptionId,
|
||||
boolean defaultValue, Setting setting)
|
||||
public CheckBoxSetting(String file, String section, String key, int titleId, int descriptionId,
|
||||
boolean defaultValue)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
super(file, section, key, titleId, descriptionId);
|
||||
mDefaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public boolean isChecked()
|
||||
public boolean isChecked(Settings settings)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof BooleanSetting))
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
||||
|
||||
BooleanSetting setting = (BooleanSetting) getSetting();
|
||||
return setting.getValue();
|
||||
return invertIfNeeded(settings.getSection(getFile(), getSection())
|
||||
.getBoolean(getKey(), invertIfNeeded(mDefaultValue)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing boolean. If that boolean was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param checked Pretty self explanatory.
|
||||
* @return null if overwritten successfully; otherwise, a newly created BooleanSetting.
|
||||
*/
|
||||
public BooleanSetting setChecked(boolean checked)
|
||||
public void setChecked(Settings settings, boolean checked)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof BooleanSetting))
|
||||
{
|
||||
BooleanSetting setting = new BooleanSetting(getKey(), getSection(), checked);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
BooleanSetting setting = (BooleanSetting) getSetting();
|
||||
setting.setValue(checked);
|
||||
return null;
|
||||
}
|
||||
settings.getSection(getFile(), getSection()).setBoolean(getKey(), invertIfNeeded(checked));
|
||||
}
|
||||
|
||||
private boolean invertIfNeeded(boolean x)
|
||||
{
|
||||
return isInverted() ? !x : x;
|
||||
}
|
||||
|
||||
private boolean isInverted()
|
||||
{
|
||||
return getKey().equals(SettingsFile.KEY_SKIP_EFB) ||
|
||||
getKey().equals(SettingsFile.KEY_IGNORE_FORMAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,42 +1,23 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
|
||||
import java.io.File;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
|
||||
public final class FilePicker extends SettingsItem
|
||||
{
|
||||
private String mFile;
|
||||
private String mDefaultValue;
|
||||
private int mRequestType;
|
||||
|
||||
public FilePicker(String file, String key, String section, int titleId, int descriptionId,
|
||||
String defaultVault, int requestType, Setting setting)
|
||||
public FilePicker(String file, String section, String key, int titleId, int descriptionId,
|
||||
String defaultVault, int requestType)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
mFile = file;
|
||||
super(file, section, key, titleId, descriptionId);
|
||||
mDefaultValue = defaultVault;
|
||||
mRequestType = requestType;
|
||||
}
|
||||
|
||||
public File getFile()
|
||||
public String getSelectedValue(Settings settings)
|
||||
{
|
||||
return SettingsFile.getSettingsFile(mFile);
|
||||
}
|
||||
|
||||
public String getSelectedValue()
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof StringSetting))
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringSetting setting = (StringSetting) getSetting();
|
||||
return setting.getValue();
|
||||
}
|
||||
return settings.getSection(getFile(), getSection()).getString(getKey(), mDefaultValue);
|
||||
}
|
||||
|
||||
public int getRequestType()
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
|
||||
public final class FloatSliderSetting extends SliderSetting
|
||||
{
|
||||
private float mDefaultValue;
|
||||
|
||||
public FloatSliderSetting(String file, String section, String key, int titleId, int descriptionId,
|
||||
int max, String units, float defaultValue)
|
||||
{
|
||||
super(file, section, key, titleId, descriptionId, max, units);
|
||||
mDefaultValue = defaultValue;
|
||||
|
||||
if (isPercentSetting())
|
||||
mDefaultValue /= 100;
|
||||
}
|
||||
|
||||
public int getSelectedValue(Settings settings)
|
||||
{
|
||||
float value = settings.getSection(getFile(), getSection()).getFloat(getKey(), mDefaultValue);
|
||||
return Math.round(isPercentSetting() ? value * 100 : value);
|
||||
}
|
||||
|
||||
public void setSelectedValue(Settings settings, float selection)
|
||||
{
|
||||
if (isPercentSetting())
|
||||
selection /= 100;
|
||||
|
||||
settings.getSection(getFile(), getSection()).setFloat(getKey(), selection);
|
||||
}
|
||||
|
||||
private boolean isPercentSetting()
|
||||
{
|
||||
return getKey().equals(SettingsFile.KEY_OVERCLOCK_PERCENT)
|
||||
|| getKey().equals(SettingsFile.KEY_SPEED_LIMIT);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
|
||||
public final class HeaderSetting extends SettingsItem
|
||||
{
|
||||
public HeaderSetting(String key, Setting setting, int titleId, int descriptionId)
|
||||
public HeaderSetting(String key, int titleId, int descriptionId)
|
||||
{
|
||||
super(key, null, setting, titleId, descriptionId);
|
||||
super(null, null, key, titleId, descriptionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,29 +6,21 @@ import android.view.InputDevice;
|
|||
import android.view.KeyEvent;
|
||||
|
||||
import org.dolphinemu.dolphinemu.DolphinApplication;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
|
||||
public class InputBindingSetting extends SettingsItem
|
||||
{
|
||||
private String gameId;
|
||||
|
||||
public InputBindingSetting(String key, String section, int titleId, Setting setting,
|
||||
String gameId)
|
||||
public InputBindingSetting(String file, String section, String key, int titleId, String gameId)
|
||||
{
|
||||
super(key, section, setting, titleId, 0);
|
||||
super(file, section, key, titleId, 0);
|
||||
this.gameId = gameId;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
public String getValue(Settings settings)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof StringSetting))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
StringSetting setting = (StringSetting) getSetting();
|
||||
return setting.getValue();
|
||||
return settings.getSection(getFile(), getSection()).getString(getKey(), "");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,12 +29,12 @@ public class InputBindingSetting extends SettingsItem
|
|||
*
|
||||
* @param keyEvent KeyEvent of this key press.
|
||||
*/
|
||||
public void onKeyInput(KeyEvent keyEvent)
|
||||
public void onKeyInput(Settings settings, KeyEvent keyEvent)
|
||||
{
|
||||
InputDevice device = keyEvent.getDevice();
|
||||
String bindStr = "Device '" + device.getDescriptor() + "'-Button " + keyEvent.getKeyCode();
|
||||
String uiString = device.getName() + ": Button " + keyEvent.getKeyCode();
|
||||
setValue(bindStr, uiString);
|
||||
setValue(settings, bindStr, uiString);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,23 +45,16 @@ public class InputBindingSetting extends SettingsItem
|
|||
* @param motionRange MotionRange of the movement
|
||||
* @param axisDir Either '-' or '+'
|
||||
*/
|
||||
public void onMotionInput(InputDevice device, InputDevice.MotionRange motionRange,
|
||||
char axisDir)
|
||||
public void onMotionInput(Settings settings, InputDevice device,
|
||||
InputDevice.MotionRange motionRange, char axisDir)
|
||||
{
|
||||
String bindStr =
|
||||
"Device '" + device.getDescriptor() + "'-Axis " + motionRange.getAxis() + axisDir;
|
||||
String uiString = device.getName() + ": Axis " + motionRange.getAxis() + axisDir;
|
||||
setValue(bindStr, uiString);
|
||||
setValue(settings, bindStr, uiString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing string. If that string was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param bind The input that will be bound
|
||||
* @return null if overwritten successfully; otherwise, a newly created StringSetting.
|
||||
*/
|
||||
public StringSetting setValue(String bind, String ui)
|
||||
public void setValue(Settings settings, String bind, String ui)
|
||||
{
|
||||
SharedPreferences
|
||||
preferences =
|
||||
|
@ -78,23 +63,12 @@ public class InputBindingSetting extends SettingsItem
|
|||
editor.putString(getKey() + gameId, ui);
|
||||
editor.apply();
|
||||
|
||||
if (getSetting() == null || !(getSetting() instanceof StringSetting))
|
||||
{
|
||||
StringSetting setting = new StringSetting(getKey(), getSection(), bind);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringSetting setting = (StringSetting) getSetting();
|
||||
setting.setValue(bind);
|
||||
return null;
|
||||
}
|
||||
settings.getSection(getFile(), getSection()).setString(getKey(), bind);
|
||||
}
|
||||
|
||||
public void clearValue()
|
||||
public void clearValue(Settings settings)
|
||||
{
|
||||
setValue("", "");
|
||||
setValue(settings, "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
|
||||
public final class IntSliderSetting extends SliderSetting
|
||||
{
|
||||
private int mDefaultValue;
|
||||
|
||||
public IntSliderSetting(String file, String section, String key, int titleId, int descriptionId,
|
||||
int max, String units, int defaultValue)
|
||||
{
|
||||
super(file, section, key, titleId, descriptionId, max, units);
|
||||
mDefaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public int getSelectedValue(Settings settings)
|
||||
{
|
||||
return settings.getSection(getFile(), getSection()).getInt(getKey(), mDefaultValue);
|
||||
}
|
||||
|
||||
public void setSelectedValue(Settings settings, int selection)
|
||||
{
|
||||
settings.getSection(getFile(), getSection()).setInt(getKey(), selection);
|
||||
}
|
||||
}
|
|
@ -6,62 +6,46 @@ import android.view.KeyEvent;
|
|||
|
||||
import org.dolphinemu.dolphinemu.DolphinApplication;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.utils.Rumble;
|
||||
|
||||
public class RumbleBindingSetting extends InputBindingSetting
|
||||
{
|
||||
|
||||
public RumbleBindingSetting(String key, String section, int titleId, Setting setting,
|
||||
String gameId)
|
||||
public RumbleBindingSetting(String file, String section, String key, int titleId, String gameId)
|
||||
{
|
||||
super(key, section, titleId, setting, gameId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue()
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof StringSetting))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
StringSetting setting = (StringSetting) getSetting();
|
||||
return setting.getValue();
|
||||
super(file, section, key, titleId, gameId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Just need the device when saving rumble.
|
||||
*/
|
||||
@Override
|
||||
public void onKeyInput(KeyEvent keyEvent)
|
||||
public void onKeyInput(Settings settings, KeyEvent keyEvent)
|
||||
{
|
||||
saveRumble(keyEvent.getDevice());
|
||||
saveRumble(settings, keyEvent.getDevice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Just need the device when saving rumble.
|
||||
*/
|
||||
@Override
|
||||
public void onMotionInput(InputDevice device,
|
||||
InputDevice.MotionRange motionRange,
|
||||
char axisDir)
|
||||
public void onMotionInput(Settings settings, InputDevice device,
|
||||
InputDevice.MotionRange motionRange, char axisDir)
|
||||
{
|
||||
saveRumble(device);
|
||||
saveRumble(settings, device);
|
||||
}
|
||||
|
||||
private void saveRumble(InputDevice device)
|
||||
private void saveRumble(Settings settings, InputDevice device)
|
||||
{
|
||||
Vibrator vibrator = device.getVibrator();
|
||||
if (vibrator != null && vibrator.hasVibrator())
|
||||
{
|
||||
setValue(device.getDescriptor(), device.getName());
|
||||
setValue(settings, device.getDescriptor(), device.getName());
|
||||
Rumble.doRumble(vibrator);
|
||||
}
|
||||
else
|
||||
{
|
||||
setValue("",
|
||||
setValue(settings, "",
|
||||
DolphinApplication.getAppContext().getString(R.string.rumble_not_found));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
|
||||
/**
|
||||
* ViewModel abstraction for an Item in the RecyclerView powering SettingsFragments.
|
||||
* Each one corresponds to a {@link Setting} object, so this class's subclasses
|
||||
* should vaguely correspond to those subclasses. There are a few with multiple analogues
|
||||
* and a few with none (Headers, for example, do not correspond to anything in the ini
|
||||
* file.)
|
||||
* Most of them correspond to a single line in an INI file, but there are a few with multiple
|
||||
* analogues and a few with none (Headers, for example, do not correspond to anything on disk.)
|
||||
*/
|
||||
public abstract class SettingsItem
|
||||
{
|
||||
|
@ -24,36 +21,50 @@ public abstract class SettingsItem
|
|||
public static final int TYPE_FILE_PICKER = 9;
|
||||
public static final int TYPE_CONFIRM_RUNNABLE = 10;
|
||||
|
||||
private String mKey;
|
||||
private String mFile;
|
||||
private String mSection;
|
||||
|
||||
private Setting mSetting;
|
||||
private String mKey;
|
||||
|
||||
private int mNameId;
|
||||
private int mDescriptionId;
|
||||
|
||||
/**
|
||||
* Base constructor. Takes a key / section name in case the third parameter, the Setting,
|
||||
* is null; in which case, one can be constructed and saved using the key / section.
|
||||
* Base constructor.
|
||||
*
|
||||
* @param key Identifier for the Setting represented by this Item.
|
||||
* @param file File to which the Setting belongs.
|
||||
* @param section Section to which the Setting belongs.
|
||||
* @param setting A possibly-null backing Setting, to be modified on UI events.
|
||||
* @param key Identifier for the Setting represented by this Item.
|
||||
* @param nameId Resource ID for a text string to be displayed as this setting's name.
|
||||
* @param descriptionId Resource ID for a text string to be displayed as this setting's description.
|
||||
*/
|
||||
|
||||
public SettingsItem(String key, String section, Setting setting, int nameId, int descriptionId)
|
||||
public SettingsItem(String file, String section, String key, int nameId, int descriptionId)
|
||||
{
|
||||
mKey = key;
|
||||
mFile = file;
|
||||
mSection = section;
|
||||
mSetting = setting;
|
||||
mKey = key;
|
||||
mNameId = nameId;
|
||||
mDescriptionId = descriptionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The identifier for the backing Setting.
|
||||
* @return The file in which the backing setting belongs.
|
||||
*/
|
||||
public String getFile()
|
||||
{
|
||||
return mFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The header under which the backing setting belongs.
|
||||
*/
|
||||
public String getSection()
|
||||
{
|
||||
return mSection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The identifier for the backing setting.
|
||||
*/
|
||||
public String getKey()
|
||||
{
|
||||
|
@ -61,35 +72,7 @@ public abstract class SettingsItem
|
|||
}
|
||||
|
||||
/**
|
||||
* @return The header under which the backing Setting belongs.
|
||||
*/
|
||||
public String getSection()
|
||||
{
|
||||
return mSection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The backing Setting, possibly null.
|
||||
*/
|
||||
public Setting getSetting()
|
||||
{
|
||||
return mSetting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the backing setting with a new one. Generally used in cases where
|
||||
* the backing setting is null.
|
||||
*
|
||||
* @param setting A non-null Setting.
|
||||
*/
|
||||
public void setSetting(Setting setting)
|
||||
{
|
||||
mSetting = setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A resource ID for a text string representing this Setting's name.
|
||||
* @return A resource ID for a text string representing this setting's name.
|
||||
*/
|
||||
public int getNameId()
|
||||
{
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
|
||||
|
||||
public final class SingleChoiceSetting extends SettingsItem
|
||||
|
@ -12,20 +11,20 @@ public final class SingleChoiceSetting extends SettingsItem
|
|||
private int mValuesId;
|
||||
private MenuTag menuTag;
|
||||
|
||||
public SingleChoiceSetting(String key, String section, int titleId, int descriptionId,
|
||||
int choicesId, int valuesId, int defaultValue, Setting setting, MenuTag menuTag)
|
||||
public SingleChoiceSetting(String file, String section, String key, int titleId,
|
||||
int descriptionId, int choicesId, int valuesId, int defaultValue, MenuTag menuTag)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
super(file, section, key, titleId, descriptionId);
|
||||
mValuesId = valuesId;
|
||||
mChoicesId = choicesId;
|
||||
mDefaultValue = defaultValue;
|
||||
this.menuTag = menuTag;
|
||||
}
|
||||
|
||||
public SingleChoiceSetting(String key, String section, int titleId, int descriptionId,
|
||||
int choicesId, int valuesId, int defaultValue, Setting setting)
|
||||
public SingleChoiceSetting(String file, String section, String key, int titleId,
|
||||
int descriptionId, int choicesId, int valuesId, int defaultValue)
|
||||
{
|
||||
this(key, section, titleId, descriptionId, choicesId, valuesId, defaultValue, setting, null);
|
||||
this(file, section, key, titleId, descriptionId, choicesId, valuesId, defaultValue, null);
|
||||
}
|
||||
|
||||
public int getChoicesId()
|
||||
|
@ -38,17 +37,9 @@ public final class SingleChoiceSetting extends SettingsItem
|
|||
return mValuesId;
|
||||
}
|
||||
|
||||
public int getSelectedValue()
|
||||
public int getSelectedValue(Settings settings)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof IntSetting))
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntSetting setting = (IntSetting) getSetting();
|
||||
return setting.getValue();
|
||||
}
|
||||
return settings.getSection(getFile(), getSection()).getInt(getKey(), mDefaultValue);
|
||||
}
|
||||
|
||||
public MenuTag getMenuTag()
|
||||
|
@ -56,27 +47,9 @@ public final class SingleChoiceSetting extends SettingsItem
|
|||
return menuTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing int. If that int was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param selection New value of the int.
|
||||
* @return null if overwritten successfully otherwise; a newly created IntSetting.
|
||||
*/
|
||||
public IntSetting setSelectedValue(int selection)
|
||||
public void setSelectedValue(Settings settings, int selection)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof IntSetting))
|
||||
{
|
||||
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntSetting setting = (IntSetting) getSetting();
|
||||
setting.setValue(selection);
|
||||
return null;
|
||||
}
|
||||
settings.getSection(getFile(), getSection()).setInt(getKey(), selection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
|
||||
|
||||
public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
|
||||
|
@ -14,12 +13,11 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
|
|||
private int mDescriptionValuesId;
|
||||
private MenuTag menuTag;
|
||||
|
||||
public SingleChoiceSettingDynamicDescriptions(String key, String section, int titleId,
|
||||
int descriptionId,
|
||||
int choicesId, int valuesId, int descriptionChoicesId, int descriptionValuesId,
|
||||
int defaultValue, Setting setting, MenuTag menuTag)
|
||||
public SingleChoiceSettingDynamicDescriptions(String file, String section, String key,
|
||||
int titleId, int descriptionId, int choicesId, int valuesId, int descriptionChoicesId,
|
||||
int descriptionValuesId, int defaultValue, MenuTag menuTag)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
super(file, section, key, titleId, descriptionId);
|
||||
mValuesId = valuesId;
|
||||
mChoicesId = choicesId;
|
||||
mDescriptionChoicesId = descriptionChoicesId;
|
||||
|
@ -28,13 +26,12 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
|
|||
this.menuTag = menuTag;
|
||||
}
|
||||
|
||||
public SingleChoiceSettingDynamicDescriptions(String key, String section, int titleId,
|
||||
int descriptionId,
|
||||
int choicesId, int valuesId, int descriptionChoicesId, int descriptionValuesId,
|
||||
int defaultValue, Setting setting)
|
||||
public SingleChoiceSettingDynamicDescriptions(String file, String section, String key,
|
||||
int titleId, int descriptionId, int choicesId, int valuesId, int descriptionChoicesId,
|
||||
int descriptionValuesId, int defaultValue)
|
||||
{
|
||||
this(key, section, titleId, descriptionId, choicesId, valuesId, descriptionChoicesId,
|
||||
descriptionValuesId, defaultValue, setting, null);
|
||||
this(file, section, key, titleId, descriptionId, choicesId, valuesId, descriptionChoicesId,
|
||||
descriptionValuesId, defaultValue, null);
|
||||
}
|
||||
|
||||
public int getChoicesId()
|
||||
|
@ -57,17 +54,9 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
|
|||
return mDescriptionValuesId;
|
||||
}
|
||||
|
||||
public int getSelectedValue()
|
||||
public int getSelectedValue(Settings settings)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof IntSetting))
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntSetting setting = (IntSetting) getSetting();
|
||||
return setting.getValue();
|
||||
}
|
||||
return settings.getSection(getFile(), getSection()).getInt(getKey(), mDefaultValue);
|
||||
}
|
||||
|
||||
public MenuTag getMenuTag()
|
||||
|
@ -75,27 +64,9 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
|
|||
return menuTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing int. If that int was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param selection New value of the int.
|
||||
* @return null if overwritten successfully otherwise; a newly created IntSetting.
|
||||
*/
|
||||
public IntSetting setSelectedValue(int selection)
|
||||
public void setSelectedValue(Settings settings, int selection)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof IntSetting))
|
||||
{
|
||||
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntSetting setting = (IntSetting) getSetting();
|
||||
setting.setValue(selection);
|
||||
return null;
|
||||
}
|
||||
settings.getSection(getFile(), getSection()).setInt(getKey(), selection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,117 +1,28 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.FloatSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
|
||||
public final class SliderSetting extends SettingsItem
|
||||
public abstract class SliderSetting extends SettingsItem
|
||||
{
|
||||
private int mMax;
|
||||
private int mDefaultValue;
|
||||
|
||||
private String mUnits;
|
||||
|
||||
public SliderSetting(String key, String section, int titleId, int descriptionId, int max,
|
||||
String units, int defaultValue, Setting setting)
|
||||
public SliderSetting(String file, String section, String key, int nameId, int descriptionId,
|
||||
int max, String units)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
super(file, section, key, nameId, descriptionId);
|
||||
mMax = max;
|
||||
mUnits = units;
|
||||
mDefaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public abstract int getSelectedValue(Settings settings);
|
||||
|
||||
public int getMax()
|
||||
{
|
||||
return mMax;
|
||||
}
|
||||
|
||||
public int getSelectedValue()
|
||||
{
|
||||
Setting setting = getSetting();
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
||||
|
||||
if (setting instanceof IntSetting)
|
||||
{
|
||||
IntSetting intSetting = (IntSetting) setting;
|
||||
return intSetting.getValue();
|
||||
}
|
||||
else if (setting instanceof FloatSetting)
|
||||
{
|
||||
FloatSetting floatSetting = (FloatSetting) setting;
|
||||
if (isPercentSetting())
|
||||
{
|
||||
return Math.round(floatSetting.getValue() * 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Math.round(floatSetting.getValue());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.error("[SliderSetting] Error casting setting type.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPercentSetting()
|
||||
{
|
||||
return getKey().equals(SettingsFile.KEY_OVERCLOCK_PERCENT)
|
||||
|| getKey().equals(SettingsFile.KEY_SPEED_LIMIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing int. If that int was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param selection New value of the int.
|
||||
* @return null if overwritten successfully otherwise; a newly created IntSetting.
|
||||
*/
|
||||
public IntSetting setSelectedValue(int selection)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof IntSetting))
|
||||
{
|
||||
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntSetting setting = (IntSetting) getSetting();
|
||||
setting.setValue(selection);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing float. If that float was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param selection New value of the float.
|
||||
* @return null if overwritten successfully otherwise; a newly created FloatSetting.
|
||||
*/
|
||||
public FloatSetting setSelectedValue(float selection)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof FloatSetting))
|
||||
{
|
||||
FloatSetting setting = new FloatSetting(getKey(), getSection(), selection);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
FloatSetting setting = (FloatSetting) getSetting();
|
||||
setting.setValue(selection);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getUnits()
|
||||
{
|
||||
return mUnits;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.DolphinApplication;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
|
||||
|
||||
public class StringSingleChoiceSetting extends SettingsItem
|
||||
|
@ -13,37 +12,37 @@ public class StringSingleChoiceSetting extends SettingsItem
|
|||
private String[] mValuesId;
|
||||
private MenuTag mMenuTag;
|
||||
|
||||
public StringSingleChoiceSetting(String key, String section, int titleId, int descriptionId,
|
||||
String[] choicesId, String[] valuesId, String defaultValue, Setting setting,
|
||||
public StringSingleChoiceSetting(String file, String section, String key, int titleId,
|
||||
int descriptionId, String[] choicesId, String[] valuesId, String defaultValue,
|
||||
MenuTag menuTag)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
super(file, section, key, titleId, descriptionId);
|
||||
mChoicesId = choicesId;
|
||||
mValuesId = valuesId;
|
||||
mDefaultValue = defaultValue;
|
||||
mMenuTag = menuTag;
|
||||
}
|
||||
|
||||
public StringSingleChoiceSetting(String key, String section, int titleId, int descriptionId,
|
||||
String[] choicesId, String[] valuesId, String defaultValue, Setting setting)
|
||||
public StringSingleChoiceSetting(String file, String section, String key, int titleId,
|
||||
int descriptionId, String[] choicesId, String[] valuesId, String defaultValue)
|
||||
{
|
||||
this(key, section, titleId, descriptionId, choicesId, valuesId, defaultValue, setting, null);
|
||||
this(file, section, key, titleId, descriptionId, choicesId, valuesId, defaultValue, null);
|
||||
}
|
||||
|
||||
public StringSingleChoiceSetting(String key, String section, int titleId, int descriptionId,
|
||||
int choicesId, int valuesId, String defaultValue, Setting setting, MenuTag menuTag)
|
||||
public StringSingleChoiceSetting(String file, String section, String key, int titleId,
|
||||
int descriptionId, int choicesId, int valuesId, String defaultValue, MenuTag menuTag)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
super(file, section, key, titleId, descriptionId);
|
||||
mChoicesId = DolphinApplication.getAppContext().getResources().getStringArray(choicesId);
|
||||
mValuesId = DolphinApplication.getAppContext().getResources().getStringArray(valuesId);
|
||||
mDefaultValue = defaultValue;
|
||||
mMenuTag = menuTag;
|
||||
}
|
||||
|
||||
public StringSingleChoiceSetting(String key, String section, int titleId, int descriptionId,
|
||||
int choicesId, int valuesId, String defaultValue, Setting setting)
|
||||
public StringSingleChoiceSetting(String file, String section, String key, int titleId,
|
||||
int descriptionId, int choicesId, int valuesId, String defaultValue)
|
||||
{
|
||||
this(key, section, titleId, descriptionId, choicesId, valuesId, defaultValue, setting, null);
|
||||
this(file, section, key, titleId, descriptionId, choicesId, valuesId, defaultValue, null);
|
||||
}
|
||||
|
||||
public String[] getChoicesId()
|
||||
|
@ -69,22 +68,14 @@ public class StringSingleChoiceSetting extends SettingsItem
|
|||
return "";
|
||||
}
|
||||
|
||||
public String getSelectedValue()
|
||||
public String getSelectedValue(Settings settings)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof StringSetting))
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringSetting setting = (StringSetting) getSetting();
|
||||
return setting.getValue();
|
||||
}
|
||||
return settings.getSection(getFile(), getSection()).getString(getKey(), mDefaultValue);
|
||||
}
|
||||
|
||||
public int getSelectValueIndex()
|
||||
public int getSelectValueIndex(Settings settings)
|
||||
{
|
||||
String selectedValue = getSelectedValue();
|
||||
String selectedValue = getSelectedValue(settings);
|
||||
for (int i = 0; i < mValuesId.length; i++)
|
||||
{
|
||||
if (mValuesId[i].equals(selectedValue))
|
||||
|
@ -101,27 +92,9 @@ public class StringSingleChoiceSetting extends SettingsItem
|
|||
return mMenuTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing int. If that int was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param selection New value of the int.
|
||||
* @return null if overwritten successfully otherwise; a newly created IntSetting.
|
||||
*/
|
||||
public StringSetting setSelectedValue(String selection)
|
||||
public void setSelectedValue(Settings settings, String selection)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof StringSetting))
|
||||
{
|
||||
StringSetting setting = new StringSetting(getKey(), getSection(), selection);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringSetting setting = (StringSetting) getSetting();
|
||||
setting.setValue(selection);
|
||||
return null;
|
||||
}
|
||||
settings.getSection(getFile(), getSection()).setString(getKey(), selection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
|
||||
|
||||
public final class SubmenuSetting extends SettingsItem
|
||||
{
|
||||
private MenuTag mMenuKey;
|
||||
|
||||
public SubmenuSetting(String key, Setting setting, int titleId, MenuTag menuKey)
|
||||
public SubmenuSetting(String key, int titleId, MenuTag menuKey)
|
||||
{
|
||||
super(key, null, setting, titleId, 0);
|
||||
super(null, null, key, titleId, 0);
|
||||
mMenuKey = menuKey;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,14 +15,12 @@ import android.widget.TextView;
|
|||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.dialogs.MotionAlertDialog;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.FloatSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.CheckBoxSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.FilePicker;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.FloatSliderSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.IntSliderSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.RumbleBindingSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSetting;
|
||||
|
@ -45,6 +43,7 @@ import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
|
|||
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
|
||||
import org.dolphinemu.dolphinemu.utils.IniFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
@ -152,6 +151,11 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
return getItem(position).getType();
|
||||
}
|
||||
|
||||
public Settings getSettings()
|
||||
{
|
||||
return mView.getSettings();
|
||||
}
|
||||
|
||||
public void setSettings(ArrayList<SettingsItem> settings)
|
||||
{
|
||||
mSettings = settings;
|
||||
|
@ -160,20 +164,9 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
|
||||
public void onBooleanClick(CheckBoxSetting item, int position, boolean checked)
|
||||
{
|
||||
BooleanSetting setting = item.setChecked(checked);
|
||||
item.setChecked(getSettings(), checked);
|
||||
notifyItemChanged(position);
|
||||
|
||||
if (setting != null)
|
||||
{
|
||||
mView.putSetting(setting);
|
||||
}
|
||||
|
||||
if (item.getKey().equals(SettingsFile.KEY_SKIP_EFB) ||
|
||||
item.getKey().equals(SettingsFile.KEY_IGNORE_FORMAT))
|
||||
{
|
||||
mView.putSetting(new BooleanSetting(item.getKey(), item.getSection(), !checked));
|
||||
}
|
||||
|
||||
mView.onSettingChanged(item.getKey());
|
||||
}
|
||||
|
||||
|
@ -202,7 +195,8 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
R.style.DolphinDialogBase);
|
||||
|
||||
builder.setTitle(item.getNameId());
|
||||
builder.setSingleChoiceItems(item.getChoicesId(), item.getSelectValueIndex(), this);
|
||||
builder.setSingleChoiceItems(item.getChoicesId(), item.getSelectValueIndex(getSettings()),
|
||||
this);
|
||||
|
||||
mDialog = builder.show();
|
||||
}
|
||||
|
@ -228,7 +222,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
{
|
||||
mClickedItem = item;
|
||||
mClickedPosition = position;
|
||||
mSeekbarProgress = item.getSelectedValue();
|
||||
mSeekbarProgress = item.getSelectedValue(getSettings());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity(),
|
||||
R.style.DolphinDialogBase);
|
||||
|
||||
|
@ -262,7 +256,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
|
||||
public void onInputBindingClick(final InputBindingSetting item, final int position)
|
||||
{
|
||||
final MotionAlertDialog dialog = new MotionAlertDialog(mContext, item);
|
||||
final MotionAlertDialog dialog = new MotionAlertDialog(mContext, item, this);
|
||||
dialog.setTitle(R.string.input_binding);
|
||||
dialog.setMessage(String.format(mContext.getString(
|
||||
item instanceof RumbleBindingSetting ?
|
||||
|
@ -270,14 +264,10 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
mContext.getString(item.getNameId())));
|
||||
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, mContext.getString(R.string.cancel), this);
|
||||
dialog.setButton(AlertDialog.BUTTON_NEUTRAL, mContext.getString(R.string.clear),
|
||||
(dialogInterface, i) -> item.clearValue());
|
||||
(dialogInterface, i) -> item.clearValue(getSettings()));
|
||||
dialog.setOnDismissListener(dialog1 ->
|
||||
{
|
||||
StringSetting setting = new StringSetting(item.getKey(), item.getSection(), item.getValue());
|
||||
notifyItemChanged(position);
|
||||
|
||||
mView.putSetting(setting);
|
||||
|
||||
mView.onSettingChanged(item.getKey());
|
||||
});
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
|
@ -316,13 +306,14 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
extensions);
|
||||
}
|
||||
|
||||
public void onFilePickerConfirmation(String file)
|
||||
public void onFilePickerConfirmation(String selectedFile)
|
||||
{
|
||||
FilePicker filePicker = (FilePicker) mClickedItem;
|
||||
|
||||
IniFile ini = new IniFile(filePicker.getFile());
|
||||
ini.setString(filePicker.getSection(), filePicker.getKey(), file);
|
||||
ini.save(filePicker.getFile());
|
||||
File file = SettingsFile.getSettingsFile(filePicker.getFile());
|
||||
IniFile ini = new IniFile(file);
|
||||
ini.setString(filePicker.getSection(), filePicker.getKey(), selectedFile);
|
||||
ini.save(file);
|
||||
|
||||
NativeLibrary.ReloadConfig();
|
||||
|
||||
|
@ -331,40 +322,31 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
|
||||
public void resetPaths()
|
||||
{
|
||||
StringSetting defaultISO =
|
||||
new StringSetting(SettingsFile.KEY_DEFAULT_ISO, Settings.SECTION_INI_CORE, "");
|
||||
StringSetting NANDRootPath =
|
||||
new StringSetting(SettingsFile.KEY_NAND_ROOT_PATH, Settings.SECTION_INI_GENERAL,
|
||||
SettingsFragmentPresenter.getDefaultNANDRootPath());
|
||||
StringSetting dumpPath =
|
||||
new StringSetting(SettingsFile.KEY_DUMP_PATH, Settings.SECTION_INI_GENERAL,
|
||||
SettingsFragmentPresenter.getDefaultDumpPath());
|
||||
StringSetting loadPath =
|
||||
new StringSetting(SettingsFile.KEY_LOAD_PATH, Settings.SECTION_INI_GENERAL,
|
||||
SettingsFragmentPresenter.getDefaultLoadPath());
|
||||
StringSetting resourcePackPath =
|
||||
new StringSetting(SettingsFile.KEY_RESOURCE_PACK_PATH, Settings.SECTION_INI_GENERAL,
|
||||
SettingsFragmentPresenter.getDefaultResourcePackPath());
|
||||
StringSetting sdPath =
|
||||
new StringSetting(SettingsFile.KEY_WII_SD_CARD_PATH, Settings.SECTION_INI_GENERAL,
|
||||
SettingsFragmentPresenter.getDefaultSDPath());
|
||||
IniFile.Section coreSection = mView.getSettings().getSection(SettingsFile.FILE_NAME_DOLPHIN,
|
||||
Settings.SECTION_INI_CORE);
|
||||
IniFile.Section generalSection = mView.getSettings().getSection(SettingsFile.FILE_NAME_DOLPHIN,
|
||||
Settings.SECTION_INI_GENERAL);
|
||||
|
||||
mView.putSetting(defaultISO);
|
||||
mView.putSetting(NANDRootPath);
|
||||
mView.putSetting(dumpPath);
|
||||
mView.putSetting(loadPath);
|
||||
mView.putSetting(resourcePackPath);
|
||||
mView.putSetting(sdPath);
|
||||
coreSection.delete(SettingsFile.KEY_DEFAULT_ISO);
|
||||
generalSection.delete(SettingsFile.KEY_NAND_ROOT_PATH);
|
||||
generalSection.delete(SettingsFile.KEY_DUMP_PATH);
|
||||
generalSection.delete(SettingsFile.KEY_LOAD_PATH);
|
||||
generalSection.delete(SettingsFile.KEY_RESOURCE_PACK_PATH);
|
||||
generalSection.delete(SettingsFile.KEY_WII_SD_CARD_PATH);
|
||||
|
||||
mView.onSettingChanged(null);
|
||||
}
|
||||
|
||||
public void setAllLogTypes(String value)
|
||||
public void setAllLogTypes(boolean value)
|
||||
{
|
||||
IniFile.Section section = mView.getSettings().getSection(SettingsFile.FILE_NAME_LOGGER,
|
||||
Settings.SECTION_LOGGER_LOGS);
|
||||
|
||||
for (Map.Entry<String, String> entry : SettingsFragmentPresenter.LOG_TYPE_NAMES.entrySet())
|
||||
{
|
||||
mView.putSetting(new StringSetting(entry.getKey(), Settings.SECTION_LOGGER_LOGS, value));
|
||||
section.setBoolean(entry.getKey(), value);
|
||||
}
|
||||
|
||||
mView.onSettingChanged(null);
|
||||
}
|
||||
|
||||
|
@ -397,17 +379,12 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
SingleChoiceSetting scSetting = (SingleChoiceSetting) mClickedItem;
|
||||
|
||||
int value = getValueForSingleChoiceSelection(scSetting, which);
|
||||
if (scSetting.getSelectedValue() != value)
|
||||
if (scSetting.getSelectedValue(getSettings()) != value)
|
||||
mView.onSettingChanged(mClickedItem.getKey());
|
||||
|
||||
handleMenuTag(scSetting.getMenuTag(), value);
|
||||
|
||||
// Get the backing Setting, which may be null (if for example it was missing from the file)
|
||||
IntSetting setting = scSetting.setSelectedValue(value);
|
||||
if (setting != null)
|
||||
{
|
||||
mView.putSetting(setting);
|
||||
}
|
||||
scSetting.setSelectedValue(getSettings(), value);
|
||||
|
||||
closeDialog();
|
||||
}
|
||||
|
@ -417,15 +394,10 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
(SingleChoiceSettingDynamicDescriptions) mClickedItem;
|
||||
|
||||
int value = getValueForSingleChoiceDynamicDescriptionsSelection(scSetting, which);
|
||||
if (scSetting.getSelectedValue() != value)
|
||||
if (scSetting.getSelectedValue(getSettings()) != value)
|
||||
mView.onSettingChanged(mClickedItem.getKey());
|
||||
|
||||
// Get the backing Setting, which may be null (if for example it was missing from the file)
|
||||
IntSetting setting = scSetting.setSelectedValue(value);
|
||||
if (setting != null)
|
||||
{
|
||||
mView.putSetting(setting);
|
||||
}
|
||||
scSetting.setSelectedValue(getSettings(), value);
|
||||
|
||||
closeDialog();
|
||||
}
|
||||
|
@ -433,52 +405,32 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
{
|
||||
StringSingleChoiceSetting scSetting = (StringSingleChoiceSetting) mClickedItem;
|
||||
String value = scSetting.getValueAt(which);
|
||||
if (!scSetting.getSelectedValue().equals(value))
|
||||
if (!scSetting.getSelectedValue(getSettings()).equals(value))
|
||||
mView.onSettingChanged(mClickedItem.getKey());
|
||||
|
||||
handleMenuTag(scSetting.getMenuTag(), which);
|
||||
|
||||
StringSetting setting = scSetting.setSelectedValue(value);
|
||||
if (setting != null)
|
||||
{
|
||||
mView.putSetting(setting);
|
||||
}
|
||||
scSetting.setSelectedValue(getSettings(), value);
|
||||
|
||||
closeDialog();
|
||||
}
|
||||
else if (mClickedItem instanceof SliderSetting)
|
||||
else if (mClickedItem instanceof IntSliderSetting)
|
||||
{
|
||||
SliderSetting sliderSetting = (SliderSetting) mClickedItem;
|
||||
if (sliderSetting.getSelectedValue() != mSeekbarProgress)
|
||||
IntSliderSetting sliderSetting = (IntSliderSetting) mClickedItem;
|
||||
if (sliderSetting.getSelectedValue(getSettings()) != mSeekbarProgress)
|
||||
mView.onSettingChanged(mClickedItem.getKey());
|
||||
|
||||
if (sliderSetting.isPercentSetting() || sliderSetting.getSetting() instanceof FloatSetting)
|
||||
{
|
||||
float value;
|
||||
sliderSetting.setSelectedValue(getSettings(), mSeekbarProgress);
|
||||
|
||||
if (sliderSetting.isPercentSetting())
|
||||
{
|
||||
value = mSeekbarProgress / 100.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (float) mSeekbarProgress;
|
||||
}
|
||||
closeDialog();
|
||||
}
|
||||
else if (mClickedItem instanceof FloatSliderSetting)
|
||||
{
|
||||
FloatSliderSetting sliderSetting = (FloatSliderSetting) mClickedItem;
|
||||
if (sliderSetting.getSelectedValue(getSettings()) != mSeekbarProgress)
|
||||
mView.onSettingChanged(mClickedItem.getKey());
|
||||
|
||||
FloatSetting setting = sliderSetting.setSelectedValue(value);
|
||||
if (setting != null)
|
||||
{
|
||||
mView.putSetting(setting);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IntSetting setting = sliderSetting.setSelectedValue(mSeekbarProgress);
|
||||
if (setting != null)
|
||||
{
|
||||
mView.putSetting(setting);
|
||||
}
|
||||
}
|
||||
sliderSetting.setSelectedValue(getSettings(), mSeekbarProgress);
|
||||
|
||||
closeDialog();
|
||||
}
|
||||
|
@ -535,7 +487,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
|
||||
private int getSelectionForSingleChoiceValue(SingleChoiceSetting item)
|
||||
{
|
||||
int value = item.getSelectedValue();
|
||||
int value = item.getSelectedValue(getSettings());
|
||||
int valuesId = item.getValuesId();
|
||||
|
||||
if (valuesId > 0)
|
||||
|
@ -577,7 +529,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
private int getSelectionForSingleChoiceDynamicDescriptionsValue(
|
||||
SingleChoiceSettingDynamicDescriptions item)
|
||||
{
|
||||
int value = item.getSelectedValue();
|
||||
int value = item.getSelectedValue(getSettings());
|
||||
int valuesId = item.getValuesId();
|
||||
|
||||
if (valuesId > 0)
|
||||
|
|
|
@ -14,7 +14,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
|
||||
import org.dolphinemu.dolphinemu.ui.DividerItemDecoration;
|
||||
|
||||
|
@ -188,9 +188,9 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void putSetting(Setting setting)
|
||||
public Settings getSettings()
|
||||
{
|
||||
mPresenter.putSetting(setting);
|
||||
return mPresenter.getSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,6 @@ package org.dolphinemu.dolphinemu.features.settings.ui;
|
|||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
|
||||
|
||||
|
@ -23,9 +22,9 @@ public interface SettingsFragmentView
|
|||
void onSettingsFileLoaded(Settings settings);
|
||||
|
||||
/**
|
||||
* Pass an ArrayList to the View so that it can be displayed on screen.
|
||||
* Pass an ArrayList of settings to the View so that it can be displayed on screen.
|
||||
*
|
||||
* @param settingsList The result of converting the HashMap to an ArrayList
|
||||
* @param settingsList The settings to display
|
||||
*/
|
||||
void showSettingsList(ArrayList<SettingsItem> settingsList);
|
||||
|
||||
|
@ -61,11 +60,9 @@ public interface SettingsFragmentView
|
|||
void showToastMessage(String message);
|
||||
|
||||
/**
|
||||
* Have the fragment add a setting to the HashMap.
|
||||
*
|
||||
* @param setting The (possibly previously missing) new setting.
|
||||
* @return The backing settings store.
|
||||
*/
|
||||
void putSetting(Setting setting);
|
||||
Settings getSettings();
|
||||
|
||||
/**
|
||||
* Have the fragment tell the containing Activity that a setting was modified.
|
||||
|
|
|
@ -57,7 +57,7 @@ public final class CheckBoxSettingViewHolder extends SettingViewHolder
|
|||
mTextSettingDescription.setText("");
|
||||
}
|
||||
|
||||
mCheckbox.setChecked(mItem.isChecked());
|
||||
mCheckbox.setChecked(mItem.isChecked(getAdapter().getSettings()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.dolphinemu.dolphinemu.R;
|
|||
import org.dolphinemu.dolphinemu.features.settings.model.view.FilePicker;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
|
||||
import org.dolphinemu.dolphinemu.utils.IniFile;
|
||||
|
||||
|
@ -45,9 +46,9 @@ public final class FilePickerViewHolder extends SettingViewHolder
|
|||
else
|
||||
{
|
||||
// TODO: Reopening INI files all the time is slow
|
||||
IniFile ini = new IniFile(mFilePicker.getFile());
|
||||
IniFile ini = new IniFile(SettingsFile.getSettingsFile(mFilePicker.getFile()));
|
||||
mTextSettingDescription.setText(ini.getString(item.getSection(), item.getKey(),
|
||||
mFilePicker.getSelectedValue()));
|
||||
mFilePicker.getSelectedValue(getAdapter().getSettings())));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
|
|||
else if (item instanceof SingleChoiceSetting)
|
||||
{
|
||||
SingleChoiceSetting setting = (SingleChoiceSetting) item;
|
||||
int selected = setting.getSelectedValue();
|
||||
int selected = setting.getSelectedValue(getAdapter().getSettings());
|
||||
Resources resMgr = mTextSettingDescription.getContext().getResources();
|
||||
String[] choices = resMgr.getStringArray(setting.getChoicesId());
|
||||
int[] values = resMgr.getIntArray(setting.getValuesId());
|
||||
|
@ -60,7 +60,7 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
|
|||
{
|
||||
StringSingleChoiceSetting setting = (StringSingleChoiceSetting) item;
|
||||
String[] choices = setting.getChoicesId();
|
||||
int valueIndex = setting.getSelectValueIndex();
|
||||
int valueIndex = setting.getSelectValueIndex(getAdapter().getSettings());
|
||||
if (valueIndex != -1)
|
||||
mTextSettingDescription.setText(choices[valueIndex]);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
|
|||
{
|
||||
SingleChoiceSettingDynamicDescriptions setting =
|
||||
(SingleChoiceSettingDynamicDescriptions) item;
|
||||
int selected = setting.getSelectedValue();
|
||||
int selected = setting.getSelectedValue(getAdapter().getSettings());
|
||||
Resources resMgr = mTextSettingDescription.getContext().getResources();
|
||||
String[] choices = resMgr.getStringArray(setting.getDescriptionChoicesId());
|
||||
int[] values = resMgr.getIntArray(setting.getDescriptionValuesId());
|
||||
|
|
|
@ -46,8 +46,8 @@ public final class SliderViewHolder extends SettingViewHolder
|
|||
else
|
||||
{
|
||||
mTextSettingDescription.setText(mContext
|
||||
.getString(R.string.slider_setting_value, mItem.getSelectedValue(),
|
||||
mItem.getUnits()));
|
||||
.getString(R.string.slider_setting_value,
|
||||
mItem.getSelectedValue(getAdapter().getSettings()), mItem.getUnits()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,33 +2,14 @@ package org.dolphinemu.dolphinemu.features.settings.utils;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
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;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.SettingSection;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivityView;
|
||||
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
|
||||
import org.dolphinemu.dolphinemu.utils.BiMap;
|
||||
import org.dolphinemu.dolphinemu.utils.IniFile;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Contains static methods for interacting with .ini files in which settings are stored.
|
||||
|
@ -308,196 +289,103 @@ public final class SettingsFile
|
|||
}
|
||||
|
||||
/**
|
||||
* Reads a given .ini file from disk and returns it as a HashMap of Settings, themselves
|
||||
* effectively a HashMap of key/value settings. If unsuccessful, outputs an error telling why it
|
||||
* failed.
|
||||
* Reads a given .ini file from disk and returns it.
|
||||
* If unsuccessful, outputs an error telling why it failed.
|
||||
*
|
||||
* @param ini The ini file to load the settings from
|
||||
* @param file The ini file to load the settings from
|
||||
* @param ini The object to load into
|
||||
* @param view The current view.
|
||||
*/
|
||||
static HashMap<String, SettingSection> readFile(final File ini, boolean isCustomGame,
|
||||
SettingsActivityView view)
|
||||
static void readFile(final File file, IniFile ini, SettingsActivityView view)
|
||||
{
|
||||
HashMap<String, SettingSection> sections = new Settings.SettingsSectionMap();
|
||||
|
||||
BufferedReader reader = null;
|
||||
|
||||
try
|
||||
if (!ini.load(file, true))
|
||||
{
|
||||
reader = new BufferedReader(new FileReader(ini));
|
||||
|
||||
SettingSection current = null;
|
||||
for (String line; (line = reader.readLine()) != null; )
|
||||
{
|
||||
if (line.startsWith("[") && line.endsWith("]"))
|
||||
{
|
||||
current = sectionFromLine(line, isCustomGame);
|
||||
sections.put(current.getName(), current);
|
||||
}
|
||||
else if ((current != null))
|
||||
{
|
||||
Setting setting = settingFromLine(current, line);
|
||||
if (setting != null)
|
||||
{
|
||||
current.putSetting(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
Log.error("[SettingsFile] File not found: " + ini.getAbsolutePath() + e.getMessage());
|
||||
Log.error("[SettingsFile] Error reading from: " + file.getAbsolutePath());
|
||||
if (view != null)
|
||||
view.onSettingsFileNotFound();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Log.error("[SettingsFile] Error reading from: " + ini.getAbsolutePath() + e.getMessage());
|
||||
if (view != null)
|
||||
view.onSettingsFileNotFound();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (reader != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Log.error("[SettingsFile] Error closing: " + ini.getAbsolutePath() + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sections;
|
||||
}
|
||||
|
||||
public static HashMap<String, SettingSection> readFile(final String fileName,
|
||||
SettingsActivityView view)
|
||||
public static void readFile(final String fileName, IniFile ini, SettingsActivityView view)
|
||||
{
|
||||
HashMap<String, SettingSection> sections = readFile(getSettingsFile(fileName), false, view);
|
||||
readFile(getSettingsFile(fileName), ini, view);
|
||||
|
||||
if (fileName.equals(SettingsFile.FILE_NAME_DOLPHIN))
|
||||
{
|
||||
addGcPadSettingsIfTheyDontExist(sections);
|
||||
addGcPadSettingsIfTheyDontExist(ini);
|
||||
}
|
||||
|
||||
return sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Reads a given .ini file from disk and returns it.
|
||||
* If unsuccessful, outputs an error telling why it failed.
|
||||
*
|
||||
* @param gameId the id of the game to load it's settings.
|
||||
* @param gameId the id of the game to load settings for.
|
||||
* @param ini The object to load into
|
||||
* @param view The current view.
|
||||
*/
|
||||
public static HashMap<String, SettingSection> readCustomGameSettings(final String gameId,
|
||||
public static void readCustomGameSettings(final String gameId, IniFile ini,
|
||||
SettingsActivityView view)
|
||||
{
|
||||
return readFile(getCustomGameSettingsFile(gameId), true, view);
|
||||
readFile(getCustomGameSettingsFile(gameId), ini, view);
|
||||
}
|
||||
|
||||
public static HashMap<String, SettingSection> readGenericGameSettings(final String gameId,
|
||||
public static void readGenericGameSettings(final String gameId, IniFile ini,
|
||||
SettingsActivityView view)
|
||||
{
|
||||
return readFile(getGenericGameSettingsFile(gameId), true, view);
|
||||
readFile(getGenericGameSettingsFile(gameId), ini, view);
|
||||
}
|
||||
|
||||
public static HashMap<String, SettingSection> readGenericGameSettingsForAllRegions(
|
||||
final String gameId, SettingsActivityView view)
|
||||
public static void readGenericGameSettingsForAllRegions(final String gameId,
|
||||
IniFile ini, SettingsActivityView view)
|
||||
{
|
||||
return readFile(getGenericGameSettingsForAllRegions(gameId), true, view);
|
||||
readFile(getGenericGameSettingsForAllRegions(gameId), ini, view);
|
||||
}
|
||||
|
||||
public static HashMap<String, SettingSection> readWiimoteProfile(final String gameId,
|
||||
final String padId)
|
||||
public static void readWiimoteProfile(final String gameId, IniFile ini, final int padId)
|
||||
{
|
||||
String profile = gameId + "_Wii" + padId;
|
||||
return readFile(getWiiProfile(profile, padId), true, null);
|
||||
readFile(getWiiProfile(profile), ini, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a Settings HashMap to a given .ini file on disk. If unsuccessful, outputs an error
|
||||
* telling why it failed.
|
||||
* Saves 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 ini The IniFile we want to serialize.
|
||||
* @param view The current view.
|
||||
*/
|
||||
public static void saveFile(final String fileName, TreeMap<String, SettingSection> sections,
|
||||
SettingsActivityView view)
|
||||
public static void saveFile(final String fileName, IniFile ini, SettingsActivityView view)
|
||||
{
|
||||
File ini = getSettingsFile(fileName);
|
||||
|
||||
try (PrintWriter writer = new PrintWriter(ini, "UTF-8"))
|
||||
if (!ini.save(getSettingsFile(fileName)))
|
||||
{
|
||||
|
||||
Set<String> keySet = sections.keySet();
|
||||
Set<String> sortedKeySet = new TreeSet<>(keySet);
|
||||
|
||||
for (String key : sortedKeySet)
|
||||
{
|
||||
SettingSection section = sections.get(key);
|
||||
writeSection(writer, section);
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
Log.error("[SettingsFile] File not found: " + fileName + ".ini: " + e.getMessage());
|
||||
Log.error("[SettingsFile] Error saving to: " + fileName + ".ini");
|
||||
if (view != null)
|
||||
view.showToastMessage("Error saving " + fileName + ".ini: " + e.getMessage());
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
Log.error("[SettingsFile] Bad encoding; please file a bug report: " + fileName + ".ini: " +
|
||||
e.getMessage());
|
||||
if (view != null)
|
||||
view.showToastMessage("Error saving " + fileName + ".ini: " + e.getMessage());
|
||||
view.showToastMessage("Error saving " + fileName + ".ini");
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveCustomGameSettings(final String gameId,
|
||||
final HashMap<String, SettingSection> sections)
|
||||
public static void saveCustomGameSettings(final String gameId, IniFile ini)
|
||||
{
|
||||
Set<String> sortedSections = new TreeSet<>(sections.keySet());
|
||||
IniFile iniCopy = new IniFile(ini);
|
||||
|
||||
IniFile ini = new IniFile();
|
||||
for (String sectionKey : sortedSections)
|
||||
// Profile options(wii extension) are not saved, only used to properly display values
|
||||
iniCopy.deleteSection(Settings.SECTION_PROFILE);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
SettingSection section = sections.get(sectionKey);
|
||||
HashMap<String, Setting> settings = section.getSettings();
|
||||
Set<String> sortedKeySet = new TreeSet<>(settings.keySet());
|
||||
|
||||
// Profile options(wii extension) are not saved, only used to properly display values
|
||||
if (sectionKey.contains(Settings.SECTION_PROFILE))
|
||||
String key = SettingsFile.KEY_WIIMOTE_EXTENSION + i;
|
||||
if (iniCopy.exists(Settings.SECTION_CONTROLS, key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String settingKey : sortedKeySet)
|
||||
{
|
||||
Setting setting = settings.get(settingKey);
|
||||
// Special case. Extension gets saved into a controller profile
|
||||
if (settingKey.contains(SettingsFile.KEY_WIIMOTE_EXTENSION))
|
||||
{
|
||||
String padId =
|
||||
setting.getKey()
|
||||
.substring(setting.getKey().length() - 1, setting.getKey().length());
|
||||
saveCustomWiimoteSetting(gameId, KEY_WIIMOTE_EXTENSION, setting.getValueAsString(),
|
||||
padId);
|
||||
}
|
||||
else
|
||||
{
|
||||
ini.setString(mapSectionNameFromIni(section.getName()), setting.getKey(),
|
||||
setting.getValueAsString());
|
||||
}
|
||||
String value = iniCopy.getString(Settings.SECTION_CONTROLS, key, "");
|
||||
saveCustomWiimoteSetting(gameId, KEY_WIIMOTE_EXTENSION, value, i);
|
||||
iniCopy.deleteKey(Settings.SECTION_CONTROLS, key);
|
||||
}
|
||||
}
|
||||
ini.save(getCustomGameSettingsFile(gameId));
|
||||
|
||||
iniCopy.save(getCustomGameSettingsFile(gameId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -509,13 +397,13 @@ public final class SettingsFile
|
|||
* @param padId
|
||||
*/
|
||||
private static void saveCustomWiimoteSetting(final String gameId, final String key,
|
||||
final String value, final String padId)
|
||||
final String value, final int padId)
|
||||
{
|
||||
String profile = gameId + "_Wii" + padId;
|
||||
String wiiConfigPath =
|
||||
DirectoryInitialization.getUserDirectory() + "/Config/Profiles/Wiimote/" +
|
||||
profile + ".ini";
|
||||
File wiiProfile = getWiiProfile(profile, padId);
|
||||
File wiiProfile = getWiiProfile(profile);
|
||||
// If it doesn't exist, create it
|
||||
boolean wiiProfileExists = wiiProfile.exists();
|
||||
if (!wiiProfileExists)
|
||||
|
@ -531,7 +419,7 @@ public final class SettingsFile
|
|||
if (!wiiProfileExists)
|
||||
{
|
||||
wiiProfileIni.setString(Settings.SECTION_PROFILE, "Device",
|
||||
"Android/" + (Integer.parseInt(padId) + 4) + "/Touchscreen");
|
||||
"Android/" + (padId + 4) + "/Touchscreen");
|
||||
}
|
||||
|
||||
wiiProfileIni.setString(Settings.SECTION_PROFILE, key, value);
|
||||
|
@ -540,12 +428,12 @@ public final class SettingsFile
|
|||
// Enable the profile
|
||||
File gameSettingsFile = SettingsFile.getCustomGameSettingsFile(gameId);
|
||||
IniFile gameSettingsIni = new IniFile(gameSettingsFile);
|
||||
gameSettingsIni.setString(Settings.SECTION_CONTROLS,
|
||||
KEY_WIIMOTE_PROFILE + (Integer.parseInt(padId) + 1), profile);
|
||||
gameSettingsIni.setString(Settings.SECTION_CONTROLS, KEY_WIIMOTE_PROFILE + (padId + 1),
|
||||
profile);
|
||||
gameSettingsIni.save(gameSettingsFile);
|
||||
}
|
||||
|
||||
private static String mapSectionNameFromIni(String generalSectionName)
|
||||
public static String mapSectionNameFromIni(String generalSectionName)
|
||||
{
|
||||
if (sectionsMap.getForward(generalSectionName) != null)
|
||||
{
|
||||
|
@ -555,7 +443,7 @@ public final class SettingsFile
|
|||
return generalSectionName;
|
||||
}
|
||||
|
||||
private static String mapSectionNameToIni(String generalSectionName)
|
||||
public static String mapSectionNameToIni(String generalSectionName)
|
||||
{
|
||||
if (sectionsMap.getBackward(generalSectionName) != null)
|
||||
{
|
||||
|
@ -594,7 +482,7 @@ public final class SettingsFile
|
|||
DirectoryInitialization.getUserDirectory() + "/GameSettings/" + gameId + ".ini");
|
||||
}
|
||||
|
||||
private static File getWiiProfile(String profile, String padId)
|
||||
private static File getWiiProfile(String profile)
|
||||
{
|
||||
String wiiConfigPath =
|
||||
DirectoryInitialization.getUserDirectory() + "/Config/Profiles/Wiimote/" +
|
||||
|
@ -603,136 +491,29 @@ public final class SettingsFile
|
|||
return new File(wiiConfigPath);
|
||||
}
|
||||
|
||||
private static SettingSection sectionFromLine(String line, boolean isCustomGame)
|
||||
private static void addGcPadSettingsIfTheyDontExist(IniFile ini)
|
||||
{
|
||||
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)
|
||||
{
|
||||
SettingSection coreSection = sections.get(Settings.SECTION_INI_CORE);
|
||||
IniFile.Section coreSection = ini.getOrCreateSection(Settings.SECTION_INI_CORE);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
String key = SettingsFile.KEY_GCPAD_TYPE + i;
|
||||
if (coreSection.getSetting(key) == null)
|
||||
if (!coreSection.exists(key))
|
||||
{
|
||||
// Set GameCube controller 1 to enabled, all others disabled
|
||||
Setting gcPadSetting = new IntSetting(key, Settings.SECTION_INI_CORE, i == 0 ? 6 : 0);
|
||||
coreSection.putSetting(gcPadSetting);
|
||||
coreSection.setInt(key, i == 0 ? 6 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
sections.put(Settings.SECTION_INI_CORE, coreSection);
|
||||
}
|
||||
|
||||
public static void firstAnalyticsAdd(boolean enabled)
|
||||
{
|
||||
HashMap<String, SettingSection> dolphinSections =
|
||||
readFile(SettingsFile.FILE_NAME_DOLPHIN, null);
|
||||
SettingSection analyticsSection = dolphinSections.get(Settings.SECTION_ANALYTICS);
|
||||
IniFile dolphinIni = new IniFile();
|
||||
readFile(SettingsFile.FILE_NAME_DOLPHIN, dolphinIni, null);
|
||||
|
||||
Setting analyticsEnabled = new StringSetting(KEY_ANALYTICS_ENABLED, Settings.SECTION_ANALYTICS,
|
||||
enabled ? "True" : "False");
|
||||
Setting analyticsFirstAsk =
|
||||
new StringSetting(KEY_ANALYTICS_PERMISSION_ASKED, Settings.SECTION_ANALYTICS, "True");
|
||||
dolphinIni.setBoolean(Settings.SECTION_ANALYTICS, KEY_ANALYTICS_ENABLED, enabled);
|
||||
dolphinIni.setBoolean(Settings.SECTION_ANALYTICS, KEY_ANALYTICS_PERMISSION_ASKED, true);
|
||||
|
||||
analyticsSection.putSetting(analyticsFirstAsk);
|
||||
analyticsSection.putSetting(analyticsEnabled);
|
||||
|
||||
dolphinSections.put(Settings.SECTION_ANALYTICS, analyticsSection);
|
||||
|
||||
TreeMap<String, SettingSection> saveSection = new TreeMap<>(dolphinSections);
|
||||
saveFile(SettingsFile.FILE_NAME_DOLPHIN, saveSection, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* For a line of text, determines what type of data is being represented, and returns
|
||||
* a Setting object containing this data.
|
||||
*
|
||||
* @param current The section currently being parsed by the consuming method.
|
||||
* @param line The line of text being parsed.
|
||||
* @return A typed Setting containing the key/value contained in the line.
|
||||
*/
|
||||
private static Setting settingFromLine(SettingSection current, String line)
|
||||
{
|
||||
String[] splitLine = line.split("=");
|
||||
|
||||
if (splitLine.length != 2)
|
||||
{
|
||||
Log.warning("Skipping invalid config line \"" + line + "\"");
|
||||
return null;
|
||||
}
|
||||
|
||||
String key = splitLine[0].trim();
|
||||
String value = splitLine[1].trim();
|
||||
|
||||
try
|
||||
{
|
||||
int valueAsInt = Integer.parseInt(value);
|
||||
|
||||
return new IntSetting(key, current.getName(), valueAsInt);
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
float valueAsFloat = Float.parseFloat(value);
|
||||
|
||||
return new FloatSetting(key, current.getName(), valueAsFloat);
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
{
|
||||
}
|
||||
|
||||
switch (value)
|
||||
{
|
||||
case "True":
|
||||
return new BooleanSetting(key, current.getName(), true);
|
||||
case "False":
|
||||
return new BooleanSetting(key, current.getName(), false);
|
||||
default:
|
||||
return new StringSetting(key, current.getName(), value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the contents of a Section HashMap to disk.
|
||||
*
|
||||
* @param writer A PrintWriter pointed at a file on disk.
|
||||
* @param section A section containing settings to be written to the file.
|
||||
*/
|
||||
private static void writeSection(PrintWriter writer, SettingSection section)
|
||||
{
|
||||
// Write the section header.
|
||||
String header = sectionAsString(section);
|
||||
writer.println(header);
|
||||
|
||||
// Write this section's values.
|
||||
HashMap<String, Setting> settings = section.getSettings();
|
||||
Set<String> keySet = settings.keySet();
|
||||
Set<String> sortedKeySet = new TreeSet<>(keySet);
|
||||
|
||||
for (String key : sortedKeySet)
|
||||
{
|
||||
Setting setting = settings.get(key);
|
||||
String valueAsString = setting.getValueAsString();
|
||||
if (!TextUtils.isEmpty(valueAsString))
|
||||
{
|
||||
writer.println(setting.getKey() + " = " + valueAsString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String sectionAsString(SettingSection section)
|
||||
{
|
||||
return "[" + section.getName() + "]";
|
||||
saveFile(SettingsFile.FILE_NAME_DOLPHIN, dolphinIni, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import android.widget.TextView;
|
|||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
|
||||
|
@ -72,12 +71,11 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
|
|||
showUnpauseEmulationButton();
|
||||
}
|
||||
|
||||
BooleanSetting enableSaveStates =
|
||||
(BooleanSetting) ((EmulationActivity) getActivity()).getSettings()
|
||||
.getSection(Settings.SECTION_INI_CORE)
|
||||
.getSetting(SettingsFile.KEY_ENABLE_SAVE_STATES);
|
||||
boolean enableSaveStates = ((EmulationActivity) getActivity()).getSettings()
|
||||
.getSection(SettingsFile.FILE_NAME_DOLPHIN, Settings.SECTION_INI_CORE)
|
||||
.getBoolean(SettingsFile.KEY_ENABLE_SAVE_STATES, false);
|
||||
|
||||
if (enableSaveStates != null && enableSaveStates.getValue())
|
||||
if (enableSaveStates)
|
||||
{
|
||||
options.findViewById(R.id.menu_quicksave).setVisibility(View.VISIBLE);
|
||||
options.findViewById(R.id.menu_quickload).setVisibility(View.VISIBLE);
|
||||
|
|
|
@ -15,6 +15,26 @@ public class IniFile
|
|||
{
|
||||
mPointer = pointer;
|
||||
}
|
||||
|
||||
public native boolean exists(String key);
|
||||
|
||||
public native boolean delete(String key);
|
||||
|
||||
public native String getString(String key, String defaultValue);
|
||||
|
||||
public native boolean getBoolean(String key, boolean defaultValue);
|
||||
|
||||
public native int getInt(String key, int defaultValue);
|
||||
|
||||
public native float getFloat(String key, float defaultValue);
|
||||
|
||||
public native void setString(String key, String newValue);
|
||||
|
||||
public native void setBoolean(String key, boolean newValue);
|
||||
|
||||
public native void setInt(String key, int newValue);
|
||||
|
||||
public native void setFloat(String key, float newFloat);
|
||||
}
|
||||
|
||||
private long mPointer; // Do not rename or move without editing the native code
|
||||
|
@ -24,6 +44,11 @@ public class IniFile
|
|||
mPointer = newIniFile();
|
||||
}
|
||||
|
||||
public IniFile(IniFile other)
|
||||
{
|
||||
mPointer = copyIniFile(other);
|
||||
}
|
||||
|
||||
public IniFile(String path)
|
||||
{
|
||||
this();
|
||||
|
@ -50,20 +75,36 @@ public class IniFile
|
|||
return save(file.getPath());
|
||||
}
|
||||
|
||||
public native Section getOrCreateSection(String sectionName);
|
||||
|
||||
public native boolean exists(String sectionName);
|
||||
|
||||
public native boolean exists(String sectionName, String key);
|
||||
|
||||
public native boolean deleteSection(String sectionName);
|
||||
|
||||
public native boolean deleteKey(String sectionName, String key);
|
||||
|
||||
public native String getString(String sectionName, String key, String defaultValue);
|
||||
|
||||
public native boolean getBoolean(String sectionName, String key, boolean defaultValue);
|
||||
|
||||
public native int getInt(String sectionName, String key, int defaultValue);
|
||||
|
||||
public native float getFloat(String sectionName, String key, float defaultValue);
|
||||
|
||||
public native void setString(String sectionName, String key, String newValue);
|
||||
|
||||
public native void setBoolean(String sectionName, String key, boolean newValue);
|
||||
|
||||
public native void setInt(String sectionName, String key, int newValue);
|
||||
|
||||
public native void setFloat(String sectionName, String key, float newValue);
|
||||
|
||||
@Override
|
||||
public native void finalize();
|
||||
|
||||
private native long newIniFile();
|
||||
|
||||
private native long copyIniFile(IniFile other);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import android.view.InputDevice;
|
|||
|
||||
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
|
||||
public class Rumble
|
||||
|
@ -29,15 +28,16 @@ public class Rumble
|
|||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
StringSetting deviceName =
|
||||
(StringSetting) activity.getSettings().getSection(Settings.SECTION_BINDINGS)
|
||||
.getSetting(SettingsFile.KEY_EMU_RUMBLE + i);
|
||||
if (deviceName != null && !deviceName.getValue().isEmpty())
|
||||
String deviceName = activity.getSettings()
|
||||
.getSection(SettingsFile.FILE_NAME_DOLPHIN, Settings.SECTION_BINDINGS)
|
||||
.getString(SettingsFile.KEY_EMU_RUMBLE + i, "");
|
||||
|
||||
if (!deviceName.isEmpty())
|
||||
{
|
||||
for (int id : InputDevice.getDeviceIds())
|
||||
{
|
||||
InputDevice device = InputDevice.getDevice(id);
|
||||
if (deviceName.getValue().equals(device.getDescriptor()))
|
||||
if (deviceName.equals(device.getDescriptor()))
|
||||
{
|
||||
Vibrator vib = device.getVibrator();
|
||||
if (vib != null && vib.hasVibrator())
|
||||
|
|
|
@ -28,6 +28,20 @@ static jobject SectionToJava(JNIEnv* env, jobject ini_file, IniFile::Section* se
|
|||
ini_file, reinterpret_cast<jlong>(section));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T GetInSection(JNIEnv* env, jobject obj, jstring key, T default_value)
|
||||
{
|
||||
T result;
|
||||
GetSectionPointer(env, obj)->Get(GetJString(env, key), &result, default_value);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void SetInSection(JNIEnv* env, jobject obj, jstring key, T new_value)
|
||||
{
|
||||
GetSectionPointer(env, obj)->Set(GetJString(env, key), new_value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T Get(JNIEnv* env, jobject obj, jstring section_name, jstring key, T default_value)
|
||||
{
|
||||
|
@ -50,6 +64,66 @@ static void Set(JNIEnv* env, jobject obj, jstring section_name, jstring key, T n
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_exists(
|
||||
JNIEnv* env, jobject obj, jstring key)
|
||||
{
|
||||
return static_cast<jboolean>(GetSectionPointer(env, obj)->Exists(GetJString(env, key)));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_delete(
|
||||
JNIEnv* env, jobject obj, jstring key)
|
||||
{
|
||||
return static_cast<jboolean>(GetSectionPointer(env, obj)->Delete(GetJString(env, key)));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_getString(
|
||||
JNIEnv* env, jobject obj, jstring key, jstring default_value)
|
||||
{
|
||||
return ToJString(env, GetInSection(env, obj, key, GetJString(env, default_value)));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_getBoolean(
|
||||
JNIEnv* env, jobject obj, jstring key, jboolean default_value)
|
||||
{
|
||||
return static_cast<jboolean>(GetInSection(env, obj, key, static_cast<bool>(default_value)));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_getInt(
|
||||
JNIEnv* env, jobject obj, jstring key, jint default_value)
|
||||
{
|
||||
return GetInSection(env, obj, key, default_value);
|
||||
}
|
||||
|
||||
JNIEXPORT jfloat JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_getFloat(
|
||||
JNIEnv* env, jobject obj, jstring key, jfloat default_value)
|
||||
{
|
||||
return GetInSection(env, obj, key, default_value);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_setString(
|
||||
JNIEnv* env, jobject obj, jstring key, jstring new_value)
|
||||
{
|
||||
SetInSection(env, obj, key, GetJString(env, new_value));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_setBoolean(
|
||||
JNIEnv* env, jobject obj, jstring key, jboolean new_value)
|
||||
{
|
||||
SetInSection(env, obj, key, static_cast<bool>(new_value));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_setInt(
|
||||
JNIEnv* env, jobject obj, jstring key, jint new_value)
|
||||
{
|
||||
SetInSection(env, obj, key, new_value);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_00024Section_setFloat(
|
||||
JNIEnv* env, jobject obj, jstring key, jfloat new_value)
|
||||
{
|
||||
SetInSection(env, obj, key, new_value);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_load(
|
||||
JNIEnv* env, jobject obj, jstring path, jboolean keep_current_data)
|
||||
{
|
||||
|
@ -64,6 +138,41 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_save(JNI
|
|||
return static_cast<jboolean>(GetIniFilePointer(env, obj)->Save(GetJString(env, path)));
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_getOrCreateSection(
|
||||
JNIEnv* env, jobject obj, jstring section_name)
|
||||
{
|
||||
return SectionToJava(
|
||||
env, obj, GetIniFilePointer(env, obj)->GetOrCreateSection(GetJString(env, section_name)));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_exists__Ljava_lang_String_2(
|
||||
JNIEnv* env, jobject obj, jstring section_name)
|
||||
{
|
||||
return static_cast<jboolean>(GetIniFilePointer(env, obj)->Exists(GetJString(env, section_name)));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_utils_IniFile_exists__Ljava_lang_String_2Ljava_lang_String_2(
|
||||
JNIEnv* env, jobject obj, jstring section_name, jstring key)
|
||||
{
|
||||
return static_cast<jboolean>(
|
||||
GetIniFilePointer(env, obj)->Exists(GetJString(env, section_name), GetJString(env, key)));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_deleteSection(
|
||||
JNIEnv* env, jobject obj, jstring section_name)
|
||||
{
|
||||
return static_cast<jboolean>(
|
||||
GetIniFilePointer(env, obj)->DeleteSection(GetJString(env, section_name)));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_deleteKey(
|
||||
JNIEnv* env, jobject obj, jstring section_name, jstring key)
|
||||
{
|
||||
return static_cast<jboolean>(
|
||||
GetIniFilePointer(env, obj)->DeleteKey(GetJString(env, section_name), GetJString(env, key)));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_getString(
|
||||
JNIEnv* env, jobject obj, jstring section_name, jstring key, jstring default_value)
|
||||
{
|
||||
|
@ -84,6 +193,12 @@ JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_getInt(JNIEn
|
|||
return Get(env, obj, section_name, key, default_value);
|
||||
}
|
||||
|
||||
JNIEXPORT jfloat JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_getFloat(
|
||||
JNIEnv* env, jobject obj, jstring section_name, jstring key, jfloat default_value)
|
||||
{
|
||||
return Get(env, obj, section_name, key, default_value);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_setString(
|
||||
JNIEnv* env, jobject obj, jstring section_name, jstring key, jstring new_value)
|
||||
{
|
||||
|
@ -104,6 +219,12 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_setInt(JNIEn
|
|||
Set(env, obj, section_name, key, new_value);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_setFloat(
|
||||
JNIEnv* env, jobject obj, jstring section_name, jstring key, jfloat new_value)
|
||||
{
|
||||
Set(env, obj, section_name, key, new_value);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_finalize(JNIEnv* env,
|
||||
jobject obj)
|
||||
{
|
||||
|
@ -116,6 +237,13 @@ JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_newIniFile(
|
|||
return reinterpret_cast<jlong>(new IniFile);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_utils_IniFile_copyIniFile(JNIEnv* env,
|
||||
jobject obj,
|
||||
jobject other)
|
||||
{
|
||||
return reinterpret_cast<jlong>(new IniFile(*GetIniFilePointer(env, other)));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue