Android: Update WiimoteNew.ini preferences instead of deleting

This commit is contained in:
JosJuice 2020-10-24 22:45:02 +02:00
parent 563d9365b5
commit 3a119e1ec7
2 changed files with 24 additions and 24 deletions

View File

@ -188,20 +188,30 @@ public final class EmulationActivity extends AppCompatActivity
sIgnoreLaunchRequests = false; sIgnoreLaunchRequests = false;
} }
public static void clearWiimoteNewIniLinkedPreferences(Context context) public static void updateWiimoteNewIniPreferences(Context context)
{ {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
editor.remove("wiiController"); updateWiimoteNewController(preferences.getInt("wiiController", 3), context);
editor.apply();
try (Settings settings = new Settings()) updateWiimoteNewImuIr(IntSetting.MAIN_MOTION_CONTROLS.getIntGlobal());
{
settings.loadSettings(null);
IntSetting.MAIN_MOTION_CONTROLS.delete(settings);
// Context is set to null to avoid toasts
settings.saveSettings(null, null);
} }
private static void updateWiimoteNewController(int value, Context context)
{
File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
wiimoteNewIni.setString("Wiimote1", "Extension",
context.getResources().getStringArray(R.array.controllersValues)[value]);
wiimoteNewIni.setBoolean("Wiimote1", "Options/Sideways Wiimote", value == 2);
wiimoteNewIni.save(wiimoteNewFile);
}
private static void updateWiimoteNewImuIr(int value)
{
File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
wiimoteNewIni.setBoolean("Wiimote1", "IMUIR/Enabled", value != 1);
wiimoteNewIni.save(wiimoteNewFile);
} }
@Override @Override
@ -852,13 +862,7 @@ public final class EmulationActivity extends AppCompatActivity
{ {
editor.putInt("wiiController", indexSelected); editor.putInt("wiiController", indexSelected);
File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE); updateWiimoteNewController(indexSelected, this);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
wiimoteNewIni.setString("Wiimote1", "Extension",
getResources().getStringArray(R.array.controllersValues)[indexSelected]);
wiimoteNewIni.setBoolean("Wiimote1", "Options/Sideways Wiimote", indexSelected == 2);
wiimoteNewIni.save(wiimoteNewFile);
NativeLibrary.ReloadWiimoteConfig(); NativeLibrary.ReloadWiimoteConfig();
}); });
builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> builder.setPositiveButton(R.string.ok, (dialogInterface, i) ->
@ -885,11 +889,7 @@ public final class EmulationActivity extends AppCompatActivity
else else
mMotionListener.disable(); mMotionListener.disable();
File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE); updateWiimoteNewImuIr(indexSelected);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
wiimoteNewIni.setBoolean("Wiimote1", "IMUIR/Enabled", indexSelected != 1);
wiimoteNewIni.save(wiimoteNewFile);
NativeLibrary.ReloadWiimoteConfig(); NativeLibrary.ReloadWiimoteConfig();
}); });
builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> dialogInterface.dismiss()); builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> dialogInterface.dismiss());

View File

@ -78,7 +78,7 @@ public final class DirectoryInitialization
{ {
// This has to be done after calling NativeLibrary.Initialize(), // This has to be done after calling NativeLibrary.Initialize(),
// as it relies on the config system // as it relies on the config system
EmulationActivity.clearWiimoteNewIniLinkedPreferences(context); EmulationActivity.updateWiimoteNewIniPreferences(context);
} }
directoryState = DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED; directoryState = DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED;