Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qfilesystemiterator_win.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
7#include "qplatformdefs.h"
8
9#include <QtCore/qt_windows.h>
10
12
13using namespace Qt::StringLiterals;
14
15bool done = true;
16
18 const QStringList &nameFilters, QDirIterator::IteratorFlags flags)
19 : nativePath(entry.nativeFilePath())
20 , dirPath(entry.filePath())
21 , findFileHandle(INVALID_HANDLE_VALUE)
22 , uncFallback(false)
23 , uncShareIndex(0)
24 , onlyDirs(false)
25{
26 Q_UNUSED(nameFilters);
28 if (nativePath.endsWith(u".lnk"_s) && !QFileSystemEngine::isDirPath(dirPath, nullptr)) {
29 QFileSystemMetaData metaData;
31 nativePath = link.nativeFilePath();
32 }
33 if (!nativePath.endsWith(u'\\'))
34 nativePath.append(u'\\');
35 nativePath.append(u'*');
36 // In MSVC2015+ case we prepend //?/ for longer file-name support
37 if (!dirPath.endsWith(u'/'))
38 dirPath.append(u'/');
40 onlyDirs = true;
41}
42
44{
45 if (findFileHandle != INVALID_HANDLE_VALUE)
46 FindClose(findFileHandle);
47}
48
50{
51 bool haveData = false;
52 WIN32_FIND_DATA findData;
53
54 if (findFileHandle == INVALID_HANDLE_VALUE && !uncFallback) {
55 haveData = true;
56 int infoLevel = 0 ; // FindExInfoStandard;
57 DWORD dwAdditionalFlags = 0;
58 dwAdditionalFlags = 2; // FIND_FIRST_EX_LARGE_FETCH
59 infoLevel = 1 ; // FindExInfoBasic;
60 int searchOps = 0; // FindExSearchNameMatch
61 if (onlyDirs)
62 searchOps = 1 ; // FindExSearchLimitToDirectories
63 findFileHandle = FindFirstFileEx((const wchar_t *)nativePath.utf16(), FINDEX_INFO_LEVELS(infoLevel), &findData,
64 FINDEX_SEARCH_OPS(searchOps), 0, dwAdditionalFlags);
65 if (findFileHandle == INVALID_HANDLE_VALUE) {
66 if (nativePath.startsWith("\\\\?\\UNC\\"_L1)) {
67 const auto parts = QStringView{nativePath}.split(u'\\', Qt::SkipEmptyParts);
68 if (parts.count() == 4 && QFileSystemEngine::uncListSharesOnServer(
69 "\\\\"_L1 + parts.at(2), &uncShares)) {
70 if (uncShares.isEmpty())
71 return false; // No shares found in the server
72 uncFallback = true;
73 }
74 }
75 }
76 }
77 if (findFileHandle == INVALID_HANDLE_VALUE && !uncFallback)
78 return false;
79 // Retrieve the new file information.
80 if (!haveData) {
81 if (uncFallback) {
82 if (++uncShareIndex >= uncShares.count())
83 return false;
84 } else {
85 if (!FindNextFile(findFileHandle, &findData))
86 return false;
87 }
88 }
89 // Create the new file system entry & meta data.
90 if (uncFallback) {
91 fileEntry = QFileSystemEntry(dirPath + uncShares.at(uncShareIndex));
92 metaData.fillFromFileAttribute(FILE_ATTRIBUTE_DIRECTORY);
93 return true;
94 } else {
95 QString fileName = QString::fromWCharArray(findData.cFileName);
96 fileEntry = QFileSystemEntry(dirPath + fileName);
97 metaData = QFileSystemMetaData();
98 if (!fileName.endsWith(".lnk"_L1)) {
99 metaData.fillFromFindData(findData, true);
100 }
101 return true;
102 }
103 return false;
104}
105
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays.
bool startsWith(QByteArrayView bv) const
Definition qbytearray.h:170
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
@ Files
Definition qdir.h:22
@ Drives
Definition qdir.h:23
@ Dirs
Definition qdir.h:21
static QFileSystemEntry getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data)
Q_AUTOTEST_EXPORT NativePath nativeFilePath() const
bool advance(QFileSystemEntry &fileEntry, QFileSystemMetaData &metaData)
QFileSystemIterator(const QFileSystemEntry &entry, QDir::Filters filters, const QStringList &nameFilters, QDirIterator::IteratorFlags flags=QDirIterator::FollowSymlinks|QDirIterator::Subdirectories)
\inmodule QtCore
\inmodule QtCore
Definition qstringview.h:76
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
Definition qstring.h:1164
Combined button and popup list for selecting options.
@ SkipEmptyParts
Definition qnamespace.h:127
GLbitfield flags
GLuint entry
#define Q_UNUSED(x)
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]