Skip to content
Permalink
Browse files
Merge pull request #9193 from JosJuice/android-clear-motioncontrolsen…
…abled

Android: Re-add motionControlsEnabled to clearWiimoteNewIniLinkedPreferences
  • Loading branch information
leoetlino committed Nov 20, 2020
2 parents 7f7fd4d + 3a119e1 commit 30bffca
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
@@ -186,11 +186,30 @@ public static void stopIgnoringLaunchRequests()
sIgnoreLaunchRequests = false;
}

public static void clearWiimoteNewIniLinkedPreferences(Context context)
public static void updateWiimoteNewIniPreferences(Context context)
{
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.remove("wiiController");
editor.apply();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
updateWiimoteNewController(preferences.getInt("wiiController", 3), context);

updateWiimoteNewImuIr(IntSetting.MAIN_MOTION_CONTROLS.getIntGlobal());
}

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
@@ -847,13 +866,7 @@ private void chooseController()
{
editor.putInt("wiiController", indexSelected);

File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE);
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);

updateWiimoteNewController(indexSelected, this);
NativeLibrary.ReloadWiimoteConfig();
});
builder.setPositiveButton(R.string.ok, (dialogInterface, i) ->
@@ -877,11 +890,7 @@ private void showMotionControlsOptions()

updateMotionListener();

File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
wiimoteNewIni.setBoolean("Wiimote1", "IMUIR/Enabled", indexSelected != 1);
wiimoteNewIni.save(wiimoteNewFile);

updateWiimoteNewImuIr(indexSelected);
NativeLibrary.ReloadWiimoteConfig();
});
builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> dialogInterface.dismiss());
@@ -70,10 +70,17 @@ private static void init(Context context)
if (setDolphinUserDirectory(context))
{
initializeInternalStorage(context);
initializeExternalStorage(context);
boolean wiimoteIniWritten = initializeExternalStorage(context);
NativeLibrary.Initialize();
NativeLibrary.ReportStartToAnalytics();

if (wiimoteIniWritten)
{
// This has to be done after calling NativeLibrary.Initialize(),
// as it relies on the config system
EmulationActivity.updateWiimoteNewIniPreferences(context);
}

directoryState = DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED;
}
else
@@ -137,7 +144,8 @@ private static void initializeInternalStorage(Context context)
SetSysDirectory(sysDirectory.getPath());
}

private static void initializeExternalStorage(Context context)
// Returns whether the WiimoteNew.ini file was written to
private static boolean initializeExternalStorage(Context context)
{
// Create User directory structure and copy some NAND files from the extracted Sys directory.
CreateUserDirectories();
@@ -159,21 +167,20 @@ private static void initializeExternalStorage(Context context)
copyAsset("GCPadNew.ini", new File(configDirectory, "GCPadNew.ini"), true, context);

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (prefs.getInt("WiimoteNewVersion", 0) != WiimoteNewVersion)
boolean overwriteWiimoteIni = prefs.getInt("WiimoteNewVersion", 0) != WiimoteNewVersion;
boolean wiimoteIniWritten = copyAsset("WiimoteNew.ini",
new File(configDirectory, "WiimoteNew.ini"), overwriteWiimoteIni, context);
if (overwriteWiimoteIni)
{
EmulationActivity.clearWiimoteNewIniLinkedPreferences(context);
copyAsset("WiimoteNew.ini", new File(configDirectory, "WiimoteNew.ini"), true, context);
SharedPreferences.Editor sPrefsEditor = prefs.edit();
sPrefsEditor.putInt("WiimoteNewVersion", WiimoteNewVersion);
sPrefsEditor.apply();
}
else
{
copyAsset("WiimoteNew.ini", new File(configDirectory, "WiimoteNew.ini"), false, context);
}

copyAsset("WiimoteProfile.ini", new File(profileDirectory, "WiimoteProfile.ini"), true,
context);

return wiimoteIniWritten;
}

private static void deleteDirectoryRecursively(@NonNull final File file)
@@ -258,26 +265,30 @@ private static void sendBroadcastState(DirectoryInitializationState state, Conte
LocalBroadcastManager.getInstance(context).sendBroadcast(localIntent);
}

private static void copyAsset(String asset, File output, Boolean overwrite, Context context)
private static boolean copyAsset(String asset, File output, Boolean overwrite, Context context)
{
Log.verbose("[DirectoryInitialization] Copying File " + asset + " to " + output);

try
{
if (!output.exists() || overwrite)
{
InputStream in = context.getAssets().open(asset);
OutputStream out = new FileOutputStream(output);
copyFile(in, out);
in.close();
out.close();
try (InputStream in = context.getAssets().open(asset))
{
try (OutputStream out = new FileOutputStream(output))
{
copyFile(in, out);
return true;
}
}
}
}
catch (IOException e)
{
Log.error("[DirectoryInitialization] Failed to copy asset file: " + asset +
e.getMessage());
}
return false;
}

private static void copyAssetFolder(String assetFolder, File outputFolder, Boolean overwrite,

0 comments on commit 30bffca

Please sign in to comment.