Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 : dirPath(entry.filePath())
19 , nativePath(entry.nativeFilePath())
20 , findFileHandle(INVALID_HANDLE_VALUE)
21 , uncFallback(false)
22 , uncShareIndex(0)
23 , onlyDirs(false)
24{
25 if (nativePath.endsWith(u".lnk"_s) && !QFileSystemEngine::isDirPath(dirPath, nullptr)) {
26 QFileSystemMetaData metaData;
28 nativePath = link.nativeFilePath();
29 }
30 if (!nativePath.endsWith(u'\\'))
31 nativePath.append(u'\\');
32 nativePath.append(u'*');
33 // In MSVC2015+ case we prepend //?/ for longer file-name support
34 if (!dirPath.endsWith(u'/'))
35 dirPath.append(u'/');
37 onlyDirs = true;
38}
39
41{
42 if (findFileHandle != INVALID_HANDLE_VALUE)
43 FindClose(findFileHandle);
44}
45
47{
48 bool haveData = false;
49 WIN32_FIND_DATA findData;
50
51 if (findFileHandle == INVALID_HANDLE_VALUE && !uncFallback) {
52 haveData = true;
53 int infoLevel = 0 ; // FindExInfoStandard;
54 DWORD dwAdditionalFlags = 0;
55 dwAdditionalFlags = 2; // FIND_FIRST_EX_LARGE_FETCH
56 infoLevel = 1 ; // FindExInfoBasic;
57 int searchOps = 0; // FindExSearchNameMatch
58 if (onlyDirs)
59 searchOps = 1 ; // FindExSearchLimitToDirectories
60 findFileHandle = FindFirstFileEx((const wchar_t *)nativePath.utf16(), FINDEX_INFO_LEVELS(infoLevel), &findData,
61 FINDEX_SEARCH_OPS(searchOps), 0, dwAdditionalFlags);
62 if (findFileHandle == INVALID_HANDLE_VALUE) {
63 if (nativePath.startsWith("\\\\?\\UNC\\"_L1)) {
64 const auto parts = QStringView{nativePath}.split(u'\\', Qt::SkipEmptyParts);
65 if (parts.count() == 4 && QFileSystemEngine::uncListSharesOnServer(
66 "\\\\"_L1 + parts.at(2), &uncShares)) {
67 if (uncShares.isEmpty())
68 return false; // No shares found in the server
69 uncFallback = true;
70 }
71 }
72 }
73 }
74 if (findFileHandle == INVALID_HANDLE_VALUE && !uncFallback)
75 return false;
76 // Retrieve the new file information.
77 if (!haveData) {
78 if (uncFallback) {
79 if (++uncShareIndex >= uncShares.count())
80 return false;
81 } else {
82 if (!FindNextFile(findFileHandle, &findData))
83 return false;
84 }
85 }
86 // Create the new file system entry & meta data.
87 if (uncFallback) {
88 fileEntry = QFileSystemEntry(dirPath + uncShares.at(uncShareIndex));
89 metaData.fillFromFileAttribute(FILE_ATTRIBUTE_DIRECTORY);
90 return true;
91 } else {
92 QString fileName = QString::fromWCharArray(findData.cFileName);
93 fileEntry = QFileSystemEntry(dirPath + fileName);
94 metaData = QFileSystemMetaData();
95 if (!fileName.endsWith(".lnk"_L1)) {
96 metaData.fillFromFindData(findData, true);
97 }
98 return true;
99 }
100 return false;
101}
102
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
@ Files
Definition qdir.h:23
@ Drives
Definition qdir.h:24
@ Dirs
Definition qdir.h:22
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)
\inmodule QtCore
Definition qstringview.h:78
Q_CORE_EXPORT QList< QStringView > split(QStringView sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the view into substring views wherever sep occurs, and returns the list of those string views.
Definition qstring.cpp:8249
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
Definition qstring.h:1309
Combined button and popup list for selecting options.
@ SkipEmptyParts
Definition qnamespace.h:128
GLuint entry
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]