Route DirectoryFileSystem::Open to Android storage.

This commit is contained in:
Henrik Rydgård 2021-05-16 12:37:08 +02:00
parent c86c7686a8
commit ccc78c42f5
3 changed files with 71 additions and 8 deletions

View file

@ -105,6 +105,8 @@ FILE *OpenCFile(const Path &path, const char *mode) {
// Read, let's support this - easy one.
int descriptor = Android_OpenContentUriFd(path.ToString(), Android_OpenContentUriMode::READ);
if (descriptor == -1) {
// Set last error message?
// We're gonna need some error codes..
return nullptr;
}
return fdopen(descriptor, "rb");
@ -125,6 +127,25 @@ FILE *OpenCFile(const Path &path, const char *mode) {
#endif
}
int OpenFD(const Path &path, OpenFlag flags) {
switch (path.Type()) {
case PathType::CONTENT_URI:
break;
default:
// Not yet supported.
return -1;
}
if (flags != OPEN_READ) {
// TODO
ERROR_LOG(COMMON, "Modes other than plain OPEN_READ not yet supported");
return -1;
}
int descriptor = Android_OpenContentUriFd(path.ToString(), Android_OpenContentUriMode::READ);
return descriptor;
}
#ifdef _WIN32
static bool ResolvePathVista(const std::wstring &path, wchar_t *buf, DWORD bufSize) {
typedef DWORD(WINAPI *getFinalPathNameByHandleW_f)(HANDLE hFile, LPWSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags);
@ -721,7 +742,7 @@ bool CreateEmptyFile(const Path &filename) {
INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());
FILE *pFile = OpenCFile(filename, "wb");
if (!pFile) {
ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s", filename.c_str(), GetLastErrorMsg().c_str());
ERROR_LOG(COMMON, "CreateEmptyFile: failed to create '%s': %s", filename.c_str(), GetLastErrorMsg().c_str());
return false;
}
fclose(pFile);