Merge pull request #8941 from JosJuice/android-ini

Android: Replace Java INI parser with C++ INI parser
This commit is contained in:
JMC47
2020-09-06 07:51:01 -04:00
committed by GitHub
46 changed files with 1610 additions and 2488 deletions
@@ -274,43 +274,6 @@ public final class NativeLibrary
// Angle is in radians and should be non-negative
public static native double GetInputRadiusAtAngle(int emu_pad_id, int stick, double angle);
public static native void NewGameIniFile();
public static native void LoadGameIniFile(String gameId);
public static native void SaveGameIniFile(String gameId);
public static native String GetUserSetting(String gameID, String Section, String Key);
public static native void SetUserSetting(String gameID, String Section, String Key, String Value);
public static native void SetProfileSetting(String profile, String Section, String Key,
String Value);
public static native void InitGameIni(String gameID);
/**
* Gets a value from a key in the given ini-based config file.
*
* @param configFile The ini-based config file to get the value from.
* @param Section The section key that the actual key is in.
* @param Key The key to get the value from.
* @param Default The value to return in the event the given key doesn't exist.
* @return the value stored at the key, or a default value if it doesn't exist.
*/
public static native String GetConfig(String configFile, String Section, String Key,
String Default);
/**
* Sets a value to a key in the given ini config file.
*
* @param configFile The ini-based config file to add the value to.
* @param Section The section key for the ini key
* @param Key The actual ini key to set.
* @param Value The string to set the ini key to.
*/
public static native void SetConfig(String configFile, String Section, String Key, String Value);
/**
* Gets the Dolphin version string.
*
@@ -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;
@@ -47,10 +46,12 @@ import org.dolphinemu.dolphinemu.ui.main.TvMainActivity;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.IniFile;
import org.dolphinemu.dolphinemu.utils.MotionListener;
import org.dolphinemu.dolphinemu.utils.Rumble;
import org.dolphinemu.dolphinemu.utils.TvUtil;
import java.io.File;
import java.lang.annotation.Retention;
import java.util.List;
@@ -519,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);
@@ -962,10 +961,14 @@ public final class EmulationActivity extends AppCompatActivity
(dialog, indexSelected) ->
{
editor.putInt("wiiController", indexSelected);
NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", "Extension",
File wiimoteNewFile = SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
wiimoteNewIni.setString("Wiimote1", "Extension",
getResources().getStringArray(R.array.controllersValues)[indexSelected]);
NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1",
"Options/Sideways Wiimote", indexSelected == 2 ? "True" : "False");
wiimoteNewIni.setBoolean("Wiimote1", "Options/Sideways Wiimote", indexSelected == 2);
wiimoteNewIni.save(wiimoteNewFile);
NativeLibrary.ReloadWiimoteConfig();
});
builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
@@ -994,8 +997,11 @@ public final class EmulationActivity extends AppCompatActivity
else
mMotionListener.disable();
NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", "IMUIR/Enabled",
indexSelected != 1 ? "True" : "False");
File wiimoteNewFile = SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
wiimoteNewIni.setBoolean("Wiimote1", "IMUIR/Enabled", indexSelected != 1);
wiimoteNewIni.save(wiimoteNewFile);
NativeLibrary.ReloadWiimoteConfig();
});
builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> editor.apply());
@@ -1137,15 +1143,15 @@ public final class EmulationActivity extends AppCompatActivity
builder.setView(view);
builder.setPositiveButton(R.string.ok, (dialogInterface, i) ->
{
NativeLibrary.LoadGameIniFile(mSelectedGameId);
NativeLibrary.SetUserSetting(mSelectedGameId, Settings.SECTION_CONTROLS,
SettingsFile.KEY_WIIBIND_IR_PITCH, text_slider_value_pitch.getText().toString());
NativeLibrary.SetUserSetting(mSelectedGameId, Settings.SECTION_CONTROLS,
SettingsFile.KEY_WIIBIND_IR_YAW, text_slider_value_yaw.getText().toString());
NativeLibrary.SetUserSetting(mSelectedGameId, Settings.SECTION_CONTROLS,
SettingsFile.KEY_WIIBIND_IR_VERTICAL_OFFSET,
File file = SettingsFile.getCustomGameSettingsFile(mSelectedGameId);
IniFile ini = new IniFile(file);
ini.setString(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_PITCH,
text_slider_value_pitch.getText().toString());
ini.setString(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_YAW,
text_slider_value_yaw.getText().toString());
ini.setString(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_VERTICAL_OFFSET,
text_slider_value_vertical_offset.getText().toString());
NativeLibrary.SaveGameIniFile(mSelectedGameId);
ini.save(file);
NativeLibrary.ReloadWiimoteConfig();
@@ -16,6 +16,7 @@ import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.IniFile;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.Log;
@@ -65,8 +66,12 @@ public class GamePropertiesDialog extends DialogFragment
.getSupportFragmentManager(), "game_details");
break;
case 1:
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini",
Settings.SECTION_INI_CORE, SettingsFile.KEY_DEFAULT_ISO, path);
File dolphinFile = SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_DOLPHIN);
IniFile dolphinIni = new IniFile(dolphinFile);
dolphinIni.setString(Settings.SECTION_INI_CORE, SettingsFile.KEY_DEFAULT_ISO,
path);
dolphinIni.save(dolphinFile);
NativeLibrary.ReloadConfig();
Toast.makeText(getContext(), "Default ISO set", Toast.LENGTH_SHORT).show();
break;
@@ -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);
}
}
}
@@ -7,7 +7,9 @@ import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivityView;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
import org.dolphinemu.dolphinemu.utils.IniFile;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -40,79 +42,51 @@ public class Settings
public static final String SECTION_CONTROLS = "Controls";
public static final String SECTION_PROFILE = "Profile";
private static final String DSP_HLE = "0";
private static final String DSP_LLE_RECOMPILER = "1";
private static final String DSP_LLE_INTERPRETER = "2";
private static final int DSP_HLE = 0;
private static final int DSP_LLE_RECOMPILER = 1;
private static final int DSP_LLE_INTERPRETER = 2;
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))
{
@@ -126,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)
@@ -180,52 +132,36 @@ 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))
{
switch (NativeLibrary
.GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_ANDROID,
SettingsFile.KEY_DSP_ENGINE, DSP_HLE))
File dolphinFile = SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_DOLPHIN);
IniFile dolphinIni = new IniFile(dolphinFile);
switch (dolphinIni.getInt(Settings.SECTION_INI_ANDROID, SettingsFile.KEY_DSP_ENGINE,
DSP_HLE))
{
case DSP_HLE:
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE,
SettingsFile.KEY_DSP_HLE, "True");
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
SettingsFile.KEY_DSP_ENABLE_JIT, "True");
dolphinIni.setBoolean(Settings.SECTION_INI_CORE, SettingsFile.KEY_DSP_HLE, true);
dolphinIni.setBoolean(Settings.SECTION_INI_DSP, SettingsFile.KEY_DSP_ENABLE_JIT, true);
break;
case DSP_LLE_RECOMPILER:
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE,
SettingsFile.KEY_DSP_HLE, "False");
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
SettingsFile.KEY_DSP_ENABLE_JIT, "True");
dolphinIni.setBoolean(Settings.SECTION_INI_CORE, SettingsFile.KEY_DSP_HLE, false);
dolphinIni.setBoolean(Settings.SECTION_INI_DSP, SettingsFile.KEY_DSP_ENABLE_JIT, true);
break;
case DSP_LLE_INTERPRETER:
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE,
SettingsFile.KEY_DSP_HLE, "False");
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
SettingsFile.KEY_DSP_ENABLE_JIT, "False");
dolphinIni.setBoolean(Settings.SECTION_INI_CORE, SettingsFile.KEY_DSP_HLE, false);
dolphinIni.setBoolean(Settings.SECTION_INI_DSP, SettingsFile.KEY_DSP_ENABLE_JIT, false);
break;
}
dolphinIni.save(dolphinFile);
}
// Notify the native code of the changes
@@ -246,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()
@@ -278,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,26 @@
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;
public final class CheckBoxSetting extends SettingsItem
public class CheckBoxSetting extends SettingsItem
{
private boolean mDefaultValue;
protected 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 settings.getSection(getFile(), getSection()).getBoolean(getKey(), 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(), checked);
}
@Override
@@ -1,39 +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.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 String getFile()
public String getSelectedValue(Settings settings)
{
return mFile + ".ini";
}
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,26 @@
package org.dolphinemu.dolphinemu.features.settings.model.view;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
public class FloatSliderSetting extends SliderSetting
{
protected 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;
}
public int getSelectedValue(Settings settings)
{
float value = settings.getSection(getFile(), getSection()).getFloat(getKey(), mDefaultValue);
return Math.round(value);
}
public void setSelectedValue(Settings settings, float selection)
{
settings.getSection(getFile(), getSection()).setFloat(getKey(), selection);
}
}
@@ -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);
}
}
@@ -0,0 +1,25 @@
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 InvertedCheckBoxSetting extends CheckBoxSetting
{
public InvertedCheckBoxSetting(String file, String section, String key, int titleId,
int descriptionId, boolean defaultValue)
{
super(file, section, key, titleId, descriptionId, !defaultValue);
}
@Override
public boolean isChecked(Settings settings)
{
return !settings.getSection(getFile(), getSection()).getBoolean(getKey(), mDefaultValue);
}
@Override
public void setChecked(Settings settings, boolean checked)
{
settings.getSection(getFile(), getSection()).setBoolean(getKey(), !checked);
}
}
@@ -0,0 +1,25 @@
package org.dolphinemu.dolphinemu.features.settings.model.view;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
public final class PercentSliderSetting extends FloatSliderSetting
{
public PercentSliderSetting(String file, String section, String key, int titleId,
int descriptionId, int max, String units, float defaultValue)
{
super(file, section, key, titleId, descriptionId, max, units, defaultValue / 100);
}
@Override
public int getSelectedValue(Settings settings)
{
float value = settings.getSection(getFile(), getSection()).getFloat(getKey(), mDefaultValue);
return Math.round(value * 100);
}
@Override
public void setSelectedValue(Settings settings, float selection)
{
settings.getSection(getFile(), getSection()).setFloat(getKey(), selection / 100);
}
}
@@ -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));
}
}

Some files were not shown because too many files have changed in this diff Show More