Android: Clear game profiles and GameSettings
This commit is contained in:
parent
f96f3b3278
commit
e7d53224b2
|
@ -527,7 +527,7 @@ public final class NativeLibrary
|
||||||
{
|
{
|
||||||
lock.wait();
|
lock.wait();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception ignored)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import android.os.Bundle;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
|
||||||
|
|
||||||
import android.widget.Toast;
|
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.features.settings.utils.SettingsFile;
|
||||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
||||||
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
|
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
|
||||||
|
import org.dolphinemu.dolphinemu.utils.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
@ -97,12 +97,16 @@ public class GamePropertiesDialog extends DialogFragment
|
||||||
|
|
||||||
private void clearGameSettings(String gameId)
|
private void clearGameSettings(String gameId)
|
||||||
{
|
{
|
||||||
String path =
|
String gameSettingsPath =
|
||||||
DirectoryInitialization.getUserDirectory() + "/GameSettings/" + gameId + ".ini";
|
DirectoryInitialization.getUserDirectory() + "/GameSettings/" + gameId + ".ini";
|
||||||
File gameSettingsFile = new File(path);
|
String gameProfilesPath = DirectoryInitialization.getUserDirectory() + "/Config/Profiles/";
|
||||||
if (gameSettingsFile.exists())
|
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)
|
Toast.makeText(getContext(), "Cleared settings for " + gameId, Toast.LENGTH_SHORT)
|
||||||
.show();
|
.show();
|
||||||
|
@ -118,4 +122,33 @@ public class GamePropertiesDialog extends DialogFragment
|
||||||
Toast.makeText(getContext(), "No game settings to delete", Toast.LENGTH_SHORT).show();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -670,21 +670,21 @@ public final class SettingsFile
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int valueAsInt = Integer.valueOf(value);
|
int valueAsInt = Integer.parseInt(value);
|
||||||
|
|
||||||
return new IntSetting(key, current.getName(), valueAsInt);
|
return new IntSetting(key, current.getName(), valueAsInt);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (NumberFormatException ignored)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
float valueAsFloat = Float.valueOf(value);
|
float valueAsFloat = Float.parseFloat(value);
|
||||||
|
|
||||||
return new FloatSetting(key, current.getName(), valueAsFloat);
|
return new FloatSetting(key, current.getName(), valueAsFloat);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (NumberFormatException ignored)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -446,9 +446,8 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ignored)
|
||||||
{
|
{
|
||||||
// fail safely
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,9 +69,8 @@ public final class CoverHelper
|
||||||
cover.compress(Bitmap.CompressFormat.PNG, 100, out);
|
cover.compress(Bitmap.CompressFormat.PNG, 100, out);
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception ignored)
|
||||||
{
|
{
|
||||||
// Do nothing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import android.content.SharedPreferences;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
|
|
||||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||||
|
@ -173,14 +174,24 @@ public final class DirectoryInitialization
|
||||||
context);
|
context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void deleteDirectoryRecursively(File file)
|
private static void deleteDirectoryRecursively(@NonNull final File file)
|
||||||
{
|
{
|
||||||
if (file.isDirectory())
|
if (file.isDirectory())
|
||||||
{
|
{
|
||||||
for (File child : file.listFiles())
|
File[] files = file.listFiles();
|
||||||
|
|
||||||
|
if (files == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (File child : files)
|
||||||
deleteDirectoryRecursively(child);
|
deleteDirectoryRecursively(child);
|
||||||
}
|
}
|
||||||
file.delete();
|
if (!file.delete())
|
||||||
|
{
|
||||||
|
Log.error("[DirectoryInitialization] Failed to delete " + file.getAbsolutePath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean areDolphinDirectoriesReady()
|
public static boolean areDolphinDirectoriesReady()
|
||||||
|
@ -285,9 +296,8 @@ public final class DirectoryInitialization
|
||||||
OutputStream out = new FileOutputStream(to);
|
OutputStream out = new FileOutputStream(to);
|
||||||
copyFile(in, out);
|
copyFile(in, out);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException ignored)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue