Merge pull request #9193 from JosJuice/android-clear-motioncontrolsenabled

Android: Re-add motionControlsEnabled to clearWiimoteNewIniLinkedPreferences
This commit is contained in:
Léo Lam 2020-11-20 02:37:51 +01:00 committed by GitHub
commit 30bffca5c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 31 deletions

View File

@ -186,11 +186,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();
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 @Override
@ -847,13 +866,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) ->
@ -877,11 +890,7 @@ public final class EmulationActivity extends AppCompatActivity
updateMotionListener(); updateMotionListener();
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

@ -70,10 +70,17 @@ public final class DirectoryInitialization
if (setDolphinUserDirectory(context)) if (setDolphinUserDirectory(context))
{ {
initializeInternalStorage(context); initializeInternalStorage(context);
initializeExternalStorage(context); boolean wiimoteIniWritten = initializeExternalStorage(context);
NativeLibrary.Initialize(); NativeLibrary.Initialize();
NativeLibrary.ReportStartToAnalytics(); 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; directoryState = DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED;
} }
else else
@ -137,7 +144,8 @@ public final class DirectoryInitialization
SetSysDirectory(sysDirectory.getPath()); 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. // Create User directory structure and copy some NAND files from the extracted Sys directory.
CreateUserDirectories(); CreateUserDirectories();
@ -159,21 +167,20 @@ public final class DirectoryInitialization
copyAsset("GCPadNew.ini", new File(configDirectory, "GCPadNew.ini"), true, context); copyAsset("GCPadNew.ini", new File(configDirectory, "GCPadNew.ini"), true, context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(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(); SharedPreferences.Editor sPrefsEditor = prefs.edit();
sPrefsEditor.putInt("WiimoteNewVersion", WiimoteNewVersion); sPrefsEditor.putInt("WiimoteNewVersion", WiimoteNewVersion);
sPrefsEditor.apply(); sPrefsEditor.apply();
} }
else
{
copyAsset("WiimoteNew.ini", new File(configDirectory, "WiimoteNew.ini"), false, context);
}
copyAsset("WiimoteProfile.ini", new File(profileDirectory, "WiimoteProfile.ini"), true, copyAsset("WiimoteProfile.ini", new File(profileDirectory, "WiimoteProfile.ini"), true,
context); context);
return wiimoteIniWritten;
} }
private static void deleteDirectoryRecursively(@NonNull final File file) private static void deleteDirectoryRecursively(@NonNull final File file)
@ -258,7 +265,7 @@ public final class DirectoryInitialization
LocalBroadcastManager.getInstance(context).sendBroadcast(localIntent); 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); Log.verbose("[DirectoryInitialization] Copying File " + asset + " to " + output);
@ -266,11 +273,14 @@ public final class DirectoryInitialization
{ {
if (!output.exists() || overwrite) if (!output.exists() || overwrite)
{ {
InputStream in = context.getAssets().open(asset); try (InputStream in = context.getAssets().open(asset))
OutputStream out = new FileOutputStream(output); {
copyFile(in, out); try (OutputStream out = new FileOutputStream(output))
in.close(); {
out.close(); copyFile(in, out);
return true;
}
}
} }
} }
catch (IOException e) catch (IOException e)
@ -278,6 +288,7 @@ public final class DirectoryInitialization
Log.error("[DirectoryInitialization] Failed to copy asset file: " + asset + Log.error("[DirectoryInitialization] Failed to copy asset file: " + asset +
e.getMessage()); e.getMessage());
} }
return false;
} }
private static void copyAssetFolder(String assetFolder, File outputFolder, Boolean overwrite, private static void copyAssetFolder(String assetFolder, File outputFolder, Boolean overwrite,