summaryrefslogtreecommitdiff
path: root/Source/Core/Common/FileUtil.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2020-12-30 11:10:35 +0100
committerGitHub <noreply@github.com>2020-12-30 11:10:35 +0100
commitc1d041b8886e60400721b827dcf2eb7cce45eceb (patch)
tree97cb04428e3338c03e9a82db27fc411e2c2243de /Source/Core/Common/FileUtil.cpp
parent8a3b14d7dca147232a87b51cef12840656292171 (diff)
parentd78277c063d43e3234fe80a38d272500f3dfce3a (diff)
Merge pull request #9318 from JosJuice/android-saf-games
Android: Use storage access framework for game list
Diffstat (limited to 'Source/Core/Common/FileUtil.cpp')
-rw-r--r--Source/Core/Common/FileUtil.cpp71
1 files changed, 63 insertions, 8 deletions
diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp
index 0a58c2417f..a8efba97c3 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;
@@ -476,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;
@@ -514,7 +568,8 @@ FSTEntry ScanDirectoryTree(const std::string& directory, bool recursive)
FindClose(hFind);
#else
}
- closedir(dirp);
+ if (dirp)
+ closedir(dirp);
#endif
return parent_entry;