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 From 2126f62111a95e3a2386467747e5bf94b9943e1d Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 8 Nov 2020 16:57:49 +0100 Subject: Android: Add content provider support to File::ScanDirectoryTree --- Source/Core/Common/FileUtil.cpp | 46 +++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'Source/Core/Common/FileUtil.cpp') diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 450eeea0a5..dc26662a2a 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -497,14 +497,47 @@ FSTEntry ScanDirectoryTree(const std::string& directory, bool recursive) { const std::string virtual_name(TStrToUTF8(ffd.cFileName)); #else - DIR* dirp = opendir(directory.c_str()); - if (!dirp) - return parent_entry; + DIR* dirp = nullptr; + +#ifdef ANDROID + std::vector child_names; + if (IsPathAndroidContent(directory)) + { + child_names = GetAndroidContentChildNames(directory); + } + else +#endif + { + dirp = opendir(directory.c_str()); + if (!dirp) + return parent_entry; + } + +#ifdef ANDROID + auto it = child_names.cbegin(); +#endif // non Windows loop - while (dirent* result = readdir(dirp)) + while (true) { - const std::string virtual_name(result->d_name); + std::string virtual_name; + +#ifdef ANDROID + if (!dirp) + { + if (it == child_names.cend()) + break; + virtual_name = *it; + ++it; + } + else +#endif + { + dirent* result = readdir(dirp); + if (!result) + break; + virtual_name = result->d_name; + } #endif if (virtual_name == "." || virtual_name == "..") continue; @@ -535,7 +568,8 @@ FSTEntry ScanDirectoryTree(const std::string& directory, bool recursive) FindClose(hFind); #else } - closedir(dirp); + if (dirp) + closedir(dirp); #endif return parent_entry; -- cgit v1.2.3