Pandroid: Storage Access Framework (SAF) (#408)

This commit is contained in:
Gabriel Machado 2024-02-17 12:09:46 -04:00 committed by GitHub
parent 3c25be4c63
commit 6af4a04987
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 292 additions and 63 deletions

View file

@ -21,6 +21,10 @@
#include <unistd.h> // For ftruncate
#endif
#ifdef __ANDROID__
#include "android_utils.hpp"
#endif
IOFile::IOFile(const std::filesystem::path& path, const char* permissions) : handle(nullptr) { open(path, permissions); }
bool IOFile::open(const std::filesystem::path& path, const char* permissions) {
@ -34,8 +38,19 @@ bool IOFile::open(const char* filename, const char* permissions) {
if (isOpen()) {
close();
}
#ifdef __ANDROID__
std::string path(filename);
// Check if this is a URI directory, which will need special handling due to SAF
if (path.find("://") != std::string::npos ) {
handle = fdopen(AndroidUtils::openDocument(filename, permissions), permissions);
} else {
handle = std::fopen(filename, permissions);
}
#else
handle = std::fopen(filename, permissions);
#endif
handle = std::fopen(filename, permissions);
return isOpen();
}