diff options
| author | JosJuice <josjuice@gmail.com> | 2020-11-08 16:57:49 +0100 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2020-12-20 13:24:54 +0100 |
| commit | 2126f62111a95e3a2386467747e5bf94b9943e1d (patch) | |
| tree | 450f264e9068e665fbe5107981e1a39eb5b3b528 /Source/Core/Common/FileUtil.cpp | |
| parent | 525268f043a25116dbb5e362d9e3e84b3f4ca5e5 (diff) | |
Android: Add content provider support to File::ScanDirectoryTree
Diffstat (limited to 'Source/Core/Common/FileUtil.cpp')
| -rw-r--r-- | Source/Core/Common/FileUtil.cpp | 46 |
1 files changed, 40 insertions, 6 deletions
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<std::string> 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; |
