Greatly speed up content URI file listings by using DocumentContract queries.

This commit is contained in:
Henrik Rydgård committed 2021-07-24 00:33:05 +02:00
1 parent 868f5f6189
commit bd99e4a287
2 files changed
+50 -10

No files matched your search

+6 -2
View File
@@ -114,10 +114,11 @@ bool Android_RenameFileTo(const std::string &fileUri, const std::string &newName
return env->CallBooleanMethod(g_nativeActivity, contentUriRenameFileTo, paramFileUri, paramNewName);
}
// NOTE: Does not set fullName - you're supposed to already know it.
static bool ParseFileInfo(const std::string &line, File::FileInfo *fileInfo) {
std::vector<std::string> parts;
SplitString(line, '|', parts);
if (parts.size() != 5) {
if (parts.size() != 4) {
ERROR_LOG(FILESYS, "Bad format: %s", line.c_str());
return false;
}
@@ -125,7 +126,6 @@ static bool ParseFileInfo(const std::string &line, File::FileInfo *fileInfo) {
fileInfo->isDirectory = parts[0][0] == 'D';
fileInfo->exists = true;
sscanf(parts[1].c_str(), "%" PRIu64, &fileInfo->size);
fileInfo->fullName = Path(parts[3]);
fileInfo->isWritable = true; // TODO: Should be passed as part of the string.
fileInfo->access = fileInfo->isDirectory ? 0666 : 0777; // TODO: For read-only mappings, reflect that here, similarly as with isWritable.
@@ -155,6 +155,8 @@ bool Android_GetFileInfo(const std::string &fileUri, File::FileInfo *fileInfo) {
}
const char *charArray = env->GetStringUTFChars(str, 0);
bool retval = ParseFileInfo(std::string(charArray), fileInfo);
fileInfo->fullName = Path(fileUri);
env->DeleteLocalRef(str);
return retval && fileInfo->exists;
}
@@ -189,6 +191,8 @@ std::vector<File::FileInfo> Android_ListContentUri(const std::string &path) {
if (charArray) { // paranoia
File::FileInfo info;
if (ParseFileInfo(std::string(charArray), &info)) {
// We can just reconstruct the URI.
info.fullName = Path(path) / info.name;
items.push_back(info);
}
}