mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-26 23:10:38 +00:00
Error code support preparations
This commit is contained in:
parent
c6c5a93bf4
commit
729496b60a
@ -18,6 +18,7 @@ static jmethodID contentUriGetFileInfo;
|
||||
static jmethodID contentUriFileExists;
|
||||
static jmethodID contentUriGetFreeStorageSpace;
|
||||
static jmethodID filePathGetFreeStorageSpace;
|
||||
static jmethodID isExternalStoragePreservedLegacy;
|
||||
|
||||
static jobject g_nativeActivity;
|
||||
|
||||
@ -48,6 +49,8 @@ void Android_RegisterStorageCallbacks(JNIEnv * env, jobject obj) {
|
||||
_dbg_assert_(contentUriGetFreeStorageSpace);
|
||||
filePathGetFreeStorageSpace = env->GetMethodID(env->GetObjectClass(obj), "filePathGetFreeStorageSpace", "(Ljava/lang/String;)J");
|
||||
_dbg_assert_(filePathGetFreeStorageSpace);
|
||||
isExternalStoragePreservedLegacy = env->GetMethodID(env->GetObjectClass(obj), "isExternalStoragePreservedLegacy", "()Z");
|
||||
_dbg_assert_(isExternalStoragePreservedLegacy);
|
||||
}
|
||||
|
||||
bool Android_IsContentUri(const std::string &filename) {
|
||||
@ -241,4 +244,22 @@ int64_t Android_GetFreeSpaceByFilePath(const std::string &filePath) {
|
||||
return env->CallLongMethod(g_nativeActivity, filePathGetFreeStorageSpace, param);
|
||||
}
|
||||
|
||||
bool Android_IsExternalStoragePreservedLegacy() {
|
||||
if (!g_nativeActivity) {
|
||||
return false;
|
||||
}
|
||||
auto env = getEnv();
|
||||
return env->CallBooleanMethod(g_nativeActivity, isExternalStoragePreservedLegacy);
|
||||
}
|
||||
|
||||
const char *Android_ErrorToString(ContentError error) {
|
||||
switch (error) {
|
||||
case ContentError::SUCCESS: return "SUCCESS";
|
||||
case ContentError::OTHER: return "OTHER";
|
||||
case ContentError::NOT_FOUND: return "NOT_FOUND";
|
||||
case ContentError::DISK_FULL: return "DISK_FULL";
|
||||
default: return "(UNKNOWN)";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -13,6 +13,22 @@ enum class Android_OpenContentUriMode {
|
||||
READ_WRITE_TRUNCATE = 2, // "rwt"
|
||||
};
|
||||
|
||||
// Matches the constants in PpssppActivity.java.
|
||||
enum class ContentError {
|
||||
SUCCESS = 0,
|
||||
OTHER = -1,
|
||||
NOT_FOUND = -2,
|
||||
DISK_FULL = -3,
|
||||
};
|
||||
|
||||
inline ContentError ContentErrorFromInt(int ival) {
|
||||
if (ival >= 0) {
|
||||
return ContentError::SUCCESS;
|
||||
} else {
|
||||
return (ContentError)ival;
|
||||
}
|
||||
}
|
||||
|
||||
#if PPSSPP_PLATFORM(ANDROID) && !defined(__LIBRETRO__)
|
||||
|
||||
#include <jni.h>
|
||||
@ -32,6 +48,8 @@ bool Android_GetFileInfo(const std::string &fileUri, File::FileInfo *info);
|
||||
bool Android_FileExists(const std::string &fileUri);
|
||||
int64_t Android_GetFreeSpaceByContentUri(const std::string &uri);
|
||||
int64_t Android_GetFreeSpaceByFilePath(const std::string &filePath);
|
||||
bool Android_IsExternalStoragePreservedLegacy();
|
||||
const char *Android_ErrorToString(ContentError error);
|
||||
|
||||
std::vector<File::FileInfo> Android_ListContentUri(const std::string &uri);
|
||||
|
||||
@ -52,6 +70,8 @@ inline bool Android_GetFileInfo(const std::string &fileUri, File::FileInfo *info
|
||||
inline bool Android_FileExists(const std::string &fileUri) { return false; }
|
||||
inline int64_t Android_GetFreeSpaceByContentUri(const std::string &uri) { return -1; }
|
||||
inline int64_t Android_GetFreeSpaceByFilePath(const std::string &filePath) { return -1; }
|
||||
inline bool Android_IsExternalStoragePreservedLegacy() { return false; }
|
||||
inline const char *Android_ErrorToString(ContentError error) { return ""; }
|
||||
inline std::vector<File::FileInfo> Android_ListContentUri(const std::string &uri) {
|
||||
return std::vector<File::FileInfo>();
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ FILE *OpenCFile(const Path &path, const char *mode) {
|
||||
INFO_LOG(COMMON, "Opening content file for read: '%s'", path.c_str());
|
||||
// Read, let's support this - easy one.
|
||||
int descriptor = Android_OpenContentUriFd(path.ToString(), Android_OpenContentUriMode::READ);
|
||||
if (descriptor == -1) {
|
||||
if (descriptor < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return fdopen(descriptor, "rb");
|
||||
@ -133,7 +133,7 @@ FILE *OpenCFile(const Path &path, const char *mode) {
|
||||
|
||||
// TODO: Support append modes and stuff... For now let's go with the most common one.
|
||||
int descriptor = Android_OpenContentUriFd(path.ToString(), Android_OpenContentUriMode::READ_WRITE_TRUNCATE);
|
||||
if (descriptor == -1) {
|
||||
if (descriptor < 0) {
|
||||
INFO_LOG(COMMON, "Opening '%s' for write failed", path.ToString().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ LocalFileLoader::LocalFileLoader(const Path &filename)
|
||||
if (filename.Type() == PathType::CONTENT_URI) {
|
||||
int fd = Android_OpenContentUriFd(filename.ToString(), Android_OpenContentUriMode::READ);
|
||||
INFO_LOG(SYSTEM, "Fd %d for content URI: '%s'", fd, filename.c_str());
|
||||
if (fd == -1) {
|
||||
if (fd < 0) {
|
||||
ERROR_LOG(FILESYS, "LoadFileLoader failed to open content URI: '%s'", filename.c_str());
|
||||
return;
|
||||
}
|
||||
|
@ -31,6 +31,12 @@ public class PpssppActivity extends NativeActivity {
|
||||
|
||||
public static boolean libraryLoaded = false;
|
||||
|
||||
// Matches the enum in AndroidStorage.h.
|
||||
private static final int CONTENT_ERROR_SUCCESS = 0;
|
||||
private static final int CONTENT_ERROR_OTHER = -1;
|
||||
private static final int CONTENT_ERROR_NOT_FOUND = -2;
|
||||
private static final int CONTENT_ERROR_DISK_FULL = -3;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void CheckABIAndLoadLibrary() {
|
||||
if (Build.CPU_ABI.equals("armeabi")) {
|
||||
|
Loading…
Reference in New Issue
Block a user