Android: Re-add motionControlsEnabled to clearWiimoteNewIniLinkedPreferences

This was removed in cc5802b when it should have
been converted to the new setting instead,
and it seems like I didn't notice when reviewing it.

I'm changing the DirectoryInitialization logic a little
so that clearWiimoteNewIniLinkedPreferences also is called
when there was no WiimoteNew.ini previously, in case the
user deleted WiimoteNew.ini but not Dolphin.ini.
This commit is contained in:
JosJuice 2020-10-24 13:08:29 +02:00
parent c42b80a156
commit 563d9365b5
2 changed files with 35 additions and 15 deletions

View File

@ -193,6 +193,15 @@ public final class EmulationActivity extends AppCompatActivity
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.remove("wiiController"); editor.remove("wiiController");
editor.apply(); editor.apply();
try (Settings settings = new Settings())
{
settings.loadSettings(null);
IntSetting.MAIN_MOTION_CONTROLS.delete(settings);
// Context is set to null to avoid toasts
settings.saveSettings(null, null);
}
} }
@Override @Override

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.clearWiimoteNewIniLinkedPreferences(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); {
try (OutputStream out = new FileOutputStream(output))
{
copyFile(in, out); copyFile(in, out);
in.close(); return true;
out.close(); }
}
} }
} }
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,