CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/File/AndroidStorage.h
Views: 1401
1
#pragma once
2
3
#include <vector>
4
#include <string>
5
#include <string_view>
6
7
#include "Common/File/DirListing.h"
8
9
// To emphasize that Android storage mode strings are different, let's just use
10
// an enum.
11
enum class Android_OpenContentUriMode {
12
READ = 0, // "r"
13
READ_WRITE = 1, // "rw"
14
READ_WRITE_TRUNCATE = 2, // "rwt"
15
};
16
17
// Matches the constants in PpssppActivity.java.
18
enum class StorageError {
19
SUCCESS = 0,
20
UNKNOWN = -1,
21
NOT_FOUND = -2,
22
DISK_FULL = -3,
23
ALREADY_EXISTS = -4,
24
};
25
26
inline StorageError StorageErrorFromInt(int ival) {
27
if (ival >= 0) {
28
return StorageError::SUCCESS;
29
} else {
30
return (StorageError)ival;
31
}
32
}
33
34
extern std::string g_extFilesDir;
35
extern std::string g_externalDir;
36
extern std::string g_nativeLibDir;
37
38
#if PPSSPP_PLATFORM(ANDROID) && !defined(__LIBRETRO__)
39
40
#include <jni.h>
41
42
void Android_StorageSetNativeActivity(jobject nativeActivity);
43
44
bool Android_IsContentUri(std::string_view uri);
45
int Android_OpenContentUriFd(std::string_view uri, const Android_OpenContentUriMode mode);
46
StorageError Android_CreateDirectory(const std::string &parentTreeUri, const std::string &dirName);
47
StorageError Android_CreateFile(const std::string &parentTreeUri, const std::string &fileName);
48
StorageError Android_MoveFile(const std::string &fileUri, const std::string &srcParentUri, const std::string &destParentUri);
49
StorageError Android_CopyFile(const std::string &fileUri, const std::string &destParentUri);
50
51
// WARNING: This is very powerful, it will delete directories recursively!
52
StorageError Android_RemoveFile(const std::string &fileUri);
53
54
StorageError Android_RenameFileTo(const std::string &fileUri, const std::string &newName);
55
bool Android_GetFileInfo(const std::string &fileUri, File::FileInfo *info);
56
bool Android_FileExists(const std::string &fileUri);
57
int64_t Android_ComputeRecursiveDirectorySize(const std::string &fileUri);
58
int64_t Android_GetFreeSpaceByContentUri(const std::string &uri);
59
int64_t Android_GetFreeSpaceByFilePath(const std::string &filePath);
60
bool Android_IsExternalStoragePreservedLegacy();
61
const char *Android_ErrorToString(StorageError error);
62
63
std::vector<File::FileInfo> Android_ListContentUri(const std::string &uri, bool *exists);
64
65
void Android_RegisterStorageCallbacks(JNIEnv * env, jobject obj);
66
67
#else
68
69
// Stub out the Android Storage wrappers, so that we can avoid ifdefs everywhere.
70
71
// See comments for the corresponding functions above.
72
73
inline bool Android_IsContentUri(std::string_view uri) { return false; }
74
inline int Android_OpenContentUriFd(std::string_view uri, const Android_OpenContentUriMode mode) { return -1; }
75
inline StorageError Android_CreateDirectory(const std::string &parentTreeUri, const std::string &dirName) { return StorageError::UNKNOWN; }
76
inline StorageError Android_CreateFile(const std::string &parentTreeUri, const std::string &fileName) { return StorageError::UNKNOWN; }
77
inline StorageError Android_MoveFile(const std::string &fileUri, const std::string &srcParentUri, const std::string &destParentUri) { return StorageError::UNKNOWN; }
78
inline StorageError Android_CopyFile(const std::string &fileUri, const std::string &destParentUri) { return StorageError::UNKNOWN; }
79
inline StorageError Android_RemoveFile(const std::string &fileUri) { return StorageError::UNKNOWN; }
80
inline StorageError Android_RenameFileTo(const std::string &fileUri, const std::string &newName) { return StorageError::UNKNOWN; }
81
inline bool Android_GetFileInfo(const std::string &fileUri, File::FileInfo *info) { return false; }
82
inline bool Android_FileExists(const std::string &fileUri) { return false; }
83
inline int64_t Android_ComputeRecursiveDirectorySize(const std::string &fileUri) { return -1; }
84
inline int64_t Android_GetFreeSpaceByContentUri(const std::string &uri) { return -1; }
85
inline int64_t Android_GetFreeSpaceByFilePath(const std::string &filePath) { return -1; }
86
inline bool Android_IsExternalStoragePreservedLegacy() { return false; }
87
inline const char *Android_ErrorToString(StorageError error) { return ""; }
88
inline std::vector<File::FileInfo> Android_ListContentUri(const std::string &uri, bool *exists) {
89
*exists = false;
90
return std::vector<File::FileInfo>();
91
}
92
93
#endif
94
95