Merge pull request #8949 from JosJuice/android-cache
Android: Use system cache directory as cache directory
This commit is contained in:
commit
a98df567b1
|
@ -366,6 +366,8 @@ public final class NativeLibrary
|
||||||
*/
|
*/
|
||||||
public static native String GetUserDirectory();
|
public static native String GetUserDirectory();
|
||||||
|
|
||||||
|
public static native void SetCacheDirectory(String directory);
|
||||||
|
|
||||||
public static native int DefaultCPUCore();
|
public static native int DefaultCPUCore();
|
||||||
|
|
||||||
public static native void ReloadConfig();
|
public static native void ReloadConfig();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.dolphinemu.dolphinemu.model;
|
package org.dolphinemu.dolphinemu.model;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
public class GameFile
|
public class GameFile
|
||||||
|
@ -54,10 +55,9 @@ public class GameFile
|
||||||
|
|
||||||
public native int getBannerHeight();
|
public native int getBannerHeight();
|
||||||
|
|
||||||
public String getCoverPath()
|
public String getCoverPath(Context context)
|
||||||
{
|
{
|
||||||
return Environment.getExternalStorageDirectory().getPath() +
|
return context.getExternalCacheDir().getPath() + "/GameCovers/" + getGameTdbId() + ".png";
|
||||||
"/dolphin-emu/Cache/GameCovers/" + getGameTdbId() + ".png";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCustomCoverPath()
|
public String getCustomCoverPath()
|
||||||
|
|
|
@ -64,7 +64,7 @@ public final class DirectoryInitialization
|
||||||
{
|
{
|
||||||
if (PermissionsHandler.hasWriteAccess(context))
|
if (PermissionsHandler.hasWriteAccess(context))
|
||||||
{
|
{
|
||||||
if (setDolphinUserDirectory())
|
if (setDolphinUserDirectory(context))
|
||||||
{
|
{
|
||||||
initializeInternalStorage(context);
|
initializeInternalStorage(context);
|
||||||
initializeExternalStorage(context);
|
initializeExternalStorage(context);
|
||||||
|
@ -88,22 +88,27 @@ public final class DirectoryInitialization
|
||||||
sendBroadcastState(directoryState, context);
|
sendBroadcastState(directoryState, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean setDolphinUserDirectory()
|
private static boolean setDolphinUserDirectory(Context context)
|
||||||
{
|
|
||||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
|
|
||||||
{
|
{
|
||||||
|
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
|
||||||
|
return false;
|
||||||
|
|
||||||
File externalPath = Environment.getExternalStorageDirectory();
|
File externalPath = Environment.getExternalStorageDirectory();
|
||||||
if (externalPath != null)
|
if (externalPath == null)
|
||||||
{
|
return false;
|
||||||
|
|
||||||
userPath = externalPath.getAbsolutePath() + "/dolphin-emu";
|
userPath = externalPath.getAbsolutePath() + "/dolphin-emu";
|
||||||
Log.debug("[DirectoryInitialization] User Dir: " + userPath);
|
Log.debug("[DirectoryInitialization] User Dir: " + userPath);
|
||||||
NativeLibrary.SetUserDirectory(userPath);
|
NativeLibrary.SetUserDirectory(userPath);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
File cacheDir = context.getExternalCacheDir();
|
||||||
|
if (cacheDir == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Log.debug("[DirectoryInitialization] Cache Dir: " + cacheDir.getPath());
|
||||||
|
NativeLibrary.SetCacheDirectory(cacheDir.getPath());
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initializeInternalStorage(Context context)
|
private static void initializeInternalStorage(Context context)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.dolphinemu.dolphinemu.utils;
|
package org.dolphinemu.dolphinemu.utils;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -33,6 +34,7 @@ public class PicassoUtils
|
||||||
|
|
||||||
public static void loadGameCover(ImageView imageView, GameFile gameFile)
|
public static void loadGameCover(ImageView imageView, GameFile gameFile)
|
||||||
{
|
{
|
||||||
|
Context context = imageView.getContext();
|
||||||
File cover = new File(gameFile.getCustomCoverPath());
|
File cover = new File(gameFile.getCustomCoverPath());
|
||||||
if (cover.exists())
|
if (cover.exists())
|
||||||
{
|
{
|
||||||
|
@ -46,7 +48,7 @@ public class PicassoUtils
|
||||||
.error(R.drawable.no_banner)
|
.error(R.drawable.no_banner)
|
||||||
.into(imageView);
|
.into(imageView);
|
||||||
}
|
}
|
||||||
else if ((cover = new File(gameFile.getCoverPath())).exists())
|
else if ((cover = new File(gameFile.getCoverPath(context))).exists())
|
||||||
{
|
{
|
||||||
Picasso.get()
|
Picasso.get()
|
||||||
.load(cover)
|
.load(cover)
|
||||||
|
@ -76,7 +78,7 @@ public class PicassoUtils
|
||||||
public void onSuccess()
|
public void onSuccess()
|
||||||
{
|
{
|
||||||
CoverHelper.saveCover(((BitmapDrawable) imageView.getDrawable()).getBitmap(),
|
CoverHelper.saveCover(((BitmapDrawable) imageView.getDrawable()).getBitmap(),
|
||||||
gameFile.getCoverPath());
|
gameFile.getCoverPath(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -98,7 +100,7 @@ public class PicassoUtils
|
||||||
{
|
{
|
||||||
CoverHelper.saveCover(
|
CoverHelper.saveCover(
|
||||||
((BitmapDrawable) imageView.getDrawable()).getBitmap(),
|
((BitmapDrawable) imageView.getDrawable()).getBitmap(),
|
||||||
gameFile.getCoverPath());
|
gameFile.getCoverPath(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,7 +123,7 @@ public class PicassoUtils
|
||||||
CoverHelper.saveCover(
|
CoverHelper.saveCover(
|
||||||
((BitmapDrawable) imageView.getDrawable())
|
((BitmapDrawable) imageView.getDrawable())
|
||||||
.getBitmap(),
|
.getBitmap(),
|
||||||
gameFile.getCoverPath());
|
gameFile.getCoverPath(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -168,7 +168,7 @@ public class TvUtil
|
||||||
{
|
{
|
||||||
contentUri = getUriForFile(context, getFileProvider(context), cover);
|
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);
|
contentUri = getUriForFile(context, getFileProvider(context), cover);
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,6 +240,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirec
|
||||||
JNIEnv* env, jobject obj, jstring jDirectory);
|
JNIEnv* env, jobject obj, jstring jDirectory);
|
||||||
JNIEXPORT jstring JNICALL
|
JNIEXPORT jstring JNICALL
|
||||||
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv* env, jobject obj);
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv* env, jobject obj);
|
||||||
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetCacheDirectory(
|
||||||
|
JNIEnv* env, jobject obj, jstring jDirectory);
|
||||||
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv* env,
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv* env,
|
||||||
jobject obj);
|
jobject obj);
|
||||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv* env,
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv* env,
|
||||||
|
@ -534,6 +536,13 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDi
|
||||||
return ToJString(env, File::GetUserPath(D_USER_IDX).c_str());
|
return ToJString(env, File::GetUserPath(D_USER_IDX).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetCacheDirectory(
|
||||||
|
JNIEnv* env, jobject obj, jstring jDirectory)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
||||||
|
File::SetUserPath(D_CACHE_IDX, GetJString(env, jDirectory) + DIR_SEP);
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv* env,
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv* env,
|
||||||
jobject obj)
|
jobject obj)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue