Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8941 from JosJuice/android-ini
Android: Replace Java INI parser with C++ INI parser
  • Loading branch information
JMC47 committed Sep 6, 2020
2 parents c8c4ec2 + ee9444a commit a390640
Show file tree
Hide file tree
Showing 46 changed files with 1,631 additions and 2,509 deletions.
Expand Up @@ -274,43 +274,6 @@ public static native void SetMotionSensorsEnabled(boolean accelerometerEnabled,
// 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.
*
Expand Down
Expand Up @@ -32,7 +32,6 @@

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;
Expand All @@ -47,10 +46,12 @@
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;

Expand Down Expand Up @@ -519,10 +520,8 @@ public boolean onCreateOptionsMenu(Menu menu)
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);
Expand Down Expand Up @@ -962,10 +961,14 @@ private void chooseController()
(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) ->
Expand Down Expand Up @@ -994,8 +997,11 @@ private void showMotionControlsOptions()
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());
Expand Down Expand Up @@ -1137,15 +1143,15 @@ private void setIRSensitivity()
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();

Expand Down
Expand Up @@ -16,6 +16,7 @@
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;

Expand Down Expand Up @@ -65,8 +66,12 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
.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;
Expand Down
Expand Up @@ -9,6 +9,7 @@
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;
Expand All @@ -27,18 +28,20 @@ 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
*
* @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)
Expand All @@ -48,7 +51,7 @@ public boolean onKeyEvent(int keyCode, KeyEvent event)
{
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.
Expand All @@ -63,7 +66,7 @@ public boolean onKeyLongPress(int keyCode, @NonNull KeyEvent event)
// 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;
}
Expand Down Expand Up @@ -158,7 +161,7 @@ else if (Math.abs(value) < 0.25f && Math.abs(previousValue) > 0.75f)
if (numMovedAxis == 1)
{
mWaitingForEvent = false;
setting.onMotionInput(input, lastMovedRange, lastMovedDir);
setting.onMotionInput(mAdapter.getSettings(), input, lastMovedRange, lastMovedDir);
dismiss();
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit a390640

Please sign in to comment.