mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 05:40:01 -06:00
Android: Use system cache directory as cache directory
This lets Android automatically delete data in the cache directory when the device is running low on space or when Dolphin is uninstalled.
This commit is contained in:
@ -366,6 +366,8 @@ public final class NativeLibrary
|
||||
*/
|
||||
public static native String GetUserDirectory();
|
||||
|
||||
public static native void SetCacheDirectory(String directory);
|
||||
|
||||
public static native int DefaultCPUCore();
|
||||
|
||||
public static native void ReloadConfig();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.dolphinemu.dolphinemu.model;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
|
||||
public class GameFile
|
||||
@ -54,10 +55,9 @@ public class GameFile
|
||||
|
||||
public native int getBannerHeight();
|
||||
|
||||
public String getCoverPath()
|
||||
public String getCoverPath(Context context)
|
||||
{
|
||||
return Environment.getExternalStorageDirectory().getPath() +
|
||||
"/dolphin-emu/Cache/GameCovers/" + getGameTdbId() + ".png";
|
||||
return context.getExternalCacheDir().getPath() + "/GameCovers/" + getGameTdbId() + ".png";
|
||||
}
|
||||
|
||||
public String getCustomCoverPath()
|
||||
|
@ -64,7 +64,7 @@ public final class DirectoryInitialization
|
||||
{
|
||||
if (PermissionsHandler.hasWriteAccess(context))
|
||||
{
|
||||
if (setDolphinUserDirectory())
|
||||
if (setDolphinUserDirectory(context))
|
||||
{
|
||||
initializeInternalStorage(context);
|
||||
initializeExternalStorage(context);
|
||||
@ -88,22 +88,27 @@ public final class DirectoryInitialization
|
||||
sendBroadcastState(directoryState, context);
|
||||
}
|
||||
|
||||
private static boolean setDolphinUserDirectory()
|
||||
private static boolean setDolphinUserDirectory(Context context)
|
||||
{
|
||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
|
||||
{
|
||||
File externalPath = Environment.getExternalStorageDirectory();
|
||||
if (externalPath != null)
|
||||
{
|
||||
userPath = externalPath.getAbsolutePath() + "/dolphin-emu";
|
||||
Log.debug("[DirectoryInitialization] User Dir: " + userPath);
|
||||
NativeLibrary.SetUserDirectory(userPath);
|
||||
return true;
|
||||
}
|
||||
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
|
||||
return false;
|
||||
|
||||
}
|
||||
File externalPath = Environment.getExternalStorageDirectory();
|
||||
if (externalPath == null)
|
||||
return false;
|
||||
|
||||
return false;
|
||||
userPath = externalPath.getAbsolutePath() + "/dolphin-emu";
|
||||
Log.debug("[DirectoryInitialization] User Dir: " + userPath);
|
||||
NativeLibrary.SetUserDirectory(userPath);
|
||||
|
||||
File cacheDir = context.getExternalCacheDir();
|
||||
if (cacheDir == null)
|
||||
return false;
|
||||
|
||||
Log.debug("[DirectoryInitialization] Cache Dir: " + cacheDir.getPath());
|
||||
NativeLibrary.SetCacheDirectory(cacheDir.getPath());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void initializeInternalStorage(Context context)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.dolphinemu.dolphinemu.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.net.Uri;
|
||||
@ -33,6 +34,7 @@ public class PicassoUtils
|
||||
|
||||
public static void loadGameCover(ImageView imageView, GameFile gameFile)
|
||||
{
|
||||
Context context = imageView.getContext();
|
||||
File cover = new File(gameFile.getCustomCoverPath());
|
||||
if (cover.exists())
|
||||
{
|
||||
@ -46,7 +48,7 @@ public class PicassoUtils
|
||||
.error(R.drawable.no_banner)
|
||||
.into(imageView);
|
||||
}
|
||||
else if ((cover = new File(gameFile.getCoverPath())).exists())
|
||||
else if ((cover = new File(gameFile.getCoverPath(context))).exists())
|
||||
{
|
||||
Picasso.get()
|
||||
.load(cover)
|
||||
@ -76,7 +78,7 @@ public class PicassoUtils
|
||||
public void onSuccess()
|
||||
{
|
||||
CoverHelper.saveCover(((BitmapDrawable) imageView.getDrawable()).getBitmap(),
|
||||
gameFile.getCoverPath());
|
||||
gameFile.getCoverPath(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,7 +100,7 @@ public class PicassoUtils
|
||||
{
|
||||
CoverHelper.saveCover(
|
||||
((BitmapDrawable) imageView.getDrawable()).getBitmap(),
|
||||
gameFile.getCoverPath());
|
||||
gameFile.getCoverPath(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -121,7 +123,7 @@ public class PicassoUtils
|
||||
CoverHelper.saveCover(
|
||||
((BitmapDrawable) imageView.getDrawable())
|
||||
.getBitmap(),
|
||||
gameFile.getCoverPath());
|
||||
gameFile.getCoverPath(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -168,7 +168,7 @@ public class TvUtil
|
||||
{
|
||||
contentUri = getUriForFile(context, getFileProvider(context), cover);
|
||||
}
|
||||
else if ((cover = new File(game.getCoverPath())).exists())
|
||||
else if ((cover = new File(game.getCoverPath(context))).exists())
|
||||
{
|
||||
contentUri = getUriForFile(context, getFileProvider(context), cover);
|
||||
}
|
||||
|
Reference in New Issue
Block a user