From a7c05d7e84df5949e8edf42fa6332d6aa58282f6 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 5 Nov 2020 19:47:23 +0100 Subject: Android: Add content provider support to File::FileInfo --- Source/Core/Common/FileUtil.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'Source/Core/Common/FileUtil.cpp') diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 0d41395209..450eeea0a5 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -78,19 +78,40 @@ FileInfo::FileInfo(const char* path) : FileInfo(std::string(path)) #else FileInfo::FileInfo(const std::string& path) : FileInfo(path.c_str()) { +#ifdef ANDROID + if (IsPathAndroidContent(path)) + AndroidContentInit(path); + else +#endif + m_exists = stat(path.c_str(), &m_stat) == 0; } FileInfo::FileInfo(const char* path) { - m_exists = stat(path, &m_stat) == 0; +#ifdef ANDROID + if (IsPathAndroidContent(path)) + AndroidContentInit(path); + else +#endif + m_exists = stat(path, &m_stat) == 0; } #endif FileInfo::FileInfo(int fd) { - m_exists = fstat(fd, &m_stat); + m_exists = fstat(fd, &m_stat) == 0; } +#ifdef ANDROID +void FileInfo::AndroidContentInit(const std::string& path) +{ + const jlong result = GetAndroidContentSizeAndIsDirectory(path); + m_exists = result != -1; + m_stat.st_mode = result == -2 ? S_IFDIR : S_IFREG; + m_stat.st_size = result >= 0 ? result : 0; +} +#endif + bool FileInfo::Exists() const { return m_exists; -- cgit v1.2.3