diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 85f632878f..28296f75fa 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -534,7 +534,7 @@ public final class NativeLibrary { lock.wait(); } - catch (Exception e) + catch (Exception ignored) { } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java index 09ae7a0075..e720c20ccd 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java @@ -6,7 +6,6 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.FragmentActivity; import android.widget.Toast; @@ -18,6 +17,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.DirectoryInitialization; +import org.dolphinemu.dolphinemu.utils.Log; import java.io.File; @@ -97,12 +97,16 @@ public class GamePropertiesDialog extends DialogFragment private void clearGameSettings(String gameId) { - String path = + String gameSettingsPath = DirectoryInitialization.getUserDirectory() + "/GameSettings/" + gameId + ".ini"; - File gameSettingsFile = new File(path); - if (gameSettingsFile.exists()) + String gameProfilesPath = DirectoryInitialization.getUserDirectory() + "/Config/Profiles/"; + File gameSettingsFile = new File(gameSettingsPath); + File gameProfilesDirectory = new File(gameProfilesPath); + boolean hadGameProfiles = recursivelyDeleteGameProfiles(gameProfilesDirectory, gameId); + + if (gameSettingsFile.exists() || hadGameProfiles) { - if (gameSettingsFile.delete()) + if (gameSettingsFile.delete() || hadGameProfiles) { Toast.makeText(getContext(), "Cleared settings for " + gameId, Toast.LENGTH_SHORT) .show(); @@ -118,4 +122,33 @@ public class GamePropertiesDialog extends DialogFragment Toast.makeText(getContext(), "No game settings to delete", Toast.LENGTH_SHORT).show(); } } + + private boolean recursivelyDeleteGameProfiles(@NonNull final File file, String gameId) + { + boolean hadGameProfiles = false; + + if (file.isDirectory()) + { + File[] files = file.listFiles(); + + if (files == null) + { + return false; + } + + for (File child : files) + { + if (child.getName().startsWith(gameId) && child.isFile()) + { + if (!child.delete()) + { + Log.error("[GamePropertiesDialog] Failed to delete " + child.getAbsolutePath()); + } + hadGameProfiles = true; + } + hadGameProfiles |= recursivelyDeleteGameProfiles(child, gameId); + } + } + return hadGameProfiles; + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java index 8f1d1ea468..359a786321 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java @@ -674,21 +674,21 @@ public final class SettingsFile try { - int valueAsInt = Integer.valueOf(value); + int valueAsInt = Integer.parseInt(value); return new IntSetting(key, current.getName(), valueAsInt); } - catch (NumberFormatException ex) + catch (NumberFormatException ignored) { } try { - float valueAsFloat = Float.valueOf(value); + float valueAsFloat = Float.parseFloat(value); return new FloatSetting(key, current.getName(), valueAsFloat); } - catch (NumberFormatException ex) + catch (NumberFormatException ignored) { } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java index fde1aa0a12..7382826f6d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java @@ -449,9 +449,8 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C File file = new File(path); file.delete(); } - catch (Exception ex) + catch (Exception ignored) { - // fail safely } } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/CoverHelper.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/CoverHelper.java index 2c0cd393a0..08b232f4d9 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/CoverHelper.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/CoverHelper.java @@ -69,9 +69,8 @@ public final class CoverHelper cover.compress(Bitmap.CompressFormat.PNG, 100, out); out.close(); } - catch (Exception e) + catch (Exception ignored) { - // Do nothing } } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java index 62aa4d3cac..c679dbe581 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java @@ -12,6 +12,7 @@ import android.content.SharedPreferences; import android.os.Environment; import android.preference.PreferenceManager; +import androidx.annotation.NonNull; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import org.dolphinemu.dolphinemu.NativeLibrary; @@ -173,14 +174,24 @@ public final class DirectoryInitialization context); } - private static void deleteDirectoryRecursively(File file) + private static void deleteDirectoryRecursively(@NonNull final File file) { if (file.isDirectory()) { - for (File child : file.listFiles()) + File[] files = file.listFiles(); + + if (files == null) + { + return; + } + + for (File child : files) deleteDirectoryRecursively(child); } - file.delete(); + if (!file.delete()) + { + Log.error("[DirectoryInitialization] Failed to delete " + file.getAbsolutePath()); + } } public static boolean areDolphinDirectoriesReady() @@ -285,9 +296,8 @@ public final class DirectoryInitialization OutputStream out = new FileOutputStream(to); copyFile(in, out); } - catch (IOException e) + catch (IOException ignored) { - } }