Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/File/AndroidStorage.h
5669 views
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
// Note that we don't use string_view much here because NewStringUTF doesn't have a size parameter.
39
40
#if PPSSPP_PLATFORM(ANDROID) && !defined(__LIBRETRO__)
41
42
#include <jni.h>
43
44
void Android_StorageSetActivity(jobject nativeActivity);
45
46
bool Android_IsContentUri(std::string_view uri);
47
int Android_OpenContentUriFd(std::string_view uri, const Android_OpenContentUriMode mode);
48
StorageError Android_CreateDirectory(const std::string &parentTreeUri, const std::string &dirName);
49
StorageError Android_CreateFile(const std::string &parentTreeUri, const std::string &fileName);
50
StorageError Android_MoveFile(const std::string &fileUri, const std::string &srcParentUri, const std::string &destParentUri);
51
StorageError Android_CopyFile(const std::string &fileUri, const std::string &destParentUri);
52
53
// WARNING: This is very powerful, it will delete directories recursively!
54
StorageError Android_RemoveFile(const std::string &fileUri);
55
56
StorageError Android_RenameFileTo(const std::string &fileUri, const std::string &newName);
57
bool Android_GetFileInfo(const std::string &fileUri, File::FileInfo *info);
58
bool Android_FileExists(const std::string &fileUri);
59
int64_t Android_ComputeRecursiveDirectorySize(const std::string &fileUri);
60
int64_t Android_GetFreeSpaceByContentUri(const std::string &uri);
61
int64_t Android_GetFreeSpaceByFilePath(const std::string &filePath);
62
bool Android_IsExternalStoragePreservedLegacy();
63
const char *Android_ErrorToString(StorageError error);
64
65
// TODO: prefix doesn't do anything yet.
66
std::vector<File::FileInfo> Android_ListContentUri(const std::string &uri, const std::string &prefix, bool *exists);
67
68
// Don't need to add these below, they're only used from app-android.cpp.
69
void Android_RegisterStorageCallbacks(JNIEnv * env, jobject obj);
70
void Android_UnregisterStorageCallbacks(JNIEnv * env);
71
72
#else
73
74
// Stub out the Android Storage wrappers, so that we can avoid ifdefs everywhere.
75
76
// See comments for the corresponding functions above.
77
78
inline bool Android_IsContentUri(std::string_view uri) { return false; }
79
inline int Android_OpenContentUriFd(std::string_view uri, const Android_OpenContentUriMode mode) { return -1; }
80
inline StorageError Android_CreateDirectory(const std::string &parentTreeUri, const std::string &dirName) { return StorageError::UNKNOWN; }
81
inline StorageError Android_CreateFile(const std::string &parentTreeUri, const std::string &fileName) { return StorageError::UNKNOWN; }
82
inline StorageError Android_MoveFile(const std::string &fileUri, const std::string &srcParentUri, const std::string &destParentUri) { return StorageError::UNKNOWN; }
83
inline StorageError Android_CopyFile(const std::string &fileUri, const std::string &destParentUri) { return StorageError::UNKNOWN; }
84
inline StorageError Android_RemoveFile(const std::string &fileUri) { return StorageError::UNKNOWN; }
85
inline StorageError Android_RenameFileTo(const std::string &fileUri, const std::string &newName) { return StorageError::UNKNOWN; }
86
inline bool Android_GetFileInfo(const std::string &fileUri, File::FileInfo *info) { return false; }
87
inline bool Android_FileExists(const std::string &fileUri) { return false; }
88
inline int64_t Android_ComputeRecursiveDirectorySize(const std::string &fileUri) { return -1; }
89
inline int64_t Android_GetFreeSpaceByContentUri(const std::string &uri) { return -1; }
90
inline int64_t Android_GetFreeSpaceByFilePath(const std::string &filePath) { return -1; }
91
inline bool Android_IsExternalStoragePreservedLegacy() { return false; }
92
inline const char *Android_ErrorToString(StorageError error) { return ""; }
93
94
inline std::vector<File::FileInfo> Android_ListContentUri(const std::string &uri, const std::string &prefix, bool *exists) {
95
*exists = false;
96
return std::vector<File::FileInfo>();
97
}
98
99
#endif
100
101