Windows: Properly check for hidden files when enumerating files

This commit is contained in:
Silent 2019-06-27 10:37:49 +02:00
parent 71ab845564
commit 2479427992
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1

View File

@ -211,20 +211,19 @@ bool FileInfo::operator <(const FileInfo &other) const {
size_t getFilesInDir(const char *directory, std::vector<FileInfo> *files, const char *filter, int flags) {
size_t foundEntries = 0;
std::set<std::string> filters;
std::string tmp;
if (filter) {
std::string tmp;
while (*filter) {
if (*filter == ':') {
filters.insert(tmp);
tmp = "";
filters.insert(std::move(tmp));
} else {
tmp.push_back(*filter);
}
filter++;
}
if (!tmp.empty())
filters.insert(std::move(tmp));
}
if (tmp.size())
filters.insert(tmp);
#ifdef _WIN32
// Find the first file in the directory.
WIN32_FIND_DATA ffd;
@ -252,14 +251,20 @@ size_t getFilesInDir(const char *directory, std::vector<FileInfo> *files, const
const std::string virtualName(result->d_name);
#endif
// check for "." and ".."
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
((virtualName[0] == '.') && (virtualName[1] == '.') &&
(virtualName[2] == '\0')))
if (virtualName == "." || virtualName == "..")
continue;
// Remove dotfiles (optional with flag.)
if (!(flags & GETFILES_GETHIDDEN) && virtualName[0] == '.')
continue;
if (!(flags & GETFILES_GETHIDDEN))
{
#ifdef _WIN32
if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0)
continue;
#else
if (virtualName[0] == '.')
continue;
#endif
}
FileInfo info;
info.name = virtualName;
@ -283,7 +288,7 @@ size_t getFilesInDir(const char *directory, std::vector<FileInfo> *files, const
}
if (files)
files->push_back(info);
files->push_back(std::move(info));
foundEntries++;
#ifdef _WIN32
} while (FindNextFile(hFind, &ffd) != 0);