| 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 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #include "qresource.h" |
| 6 | #include "qresource_iterator_p.h" |
| 7 | |
| 8 | #include <QtCore/qvariant.h> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | QResourceFileEngineIterator::QResourceFileEngineIterator(const QString &path, QDir::Filters filters, |
| 13 | const QStringList &filterNames) |
| 14 | : QAbstractFileEngineIterator(path, filters, filterNames), |
| 15 | index(-1) |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | QResourceFileEngineIterator::QResourceFileEngineIterator(const QString &path, |
| 20 | QDirListing::IteratorFlags filters, |
| 21 | const QStringList &filterNames) |
| 22 | : QAbstractFileEngineIterator(path, filters, filterNames), |
| 23 | index(-1) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | QResourceFileEngineIterator::~QResourceFileEngineIterator() |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | bool QResourceFileEngineIterator::advance() |
| 32 | { |
| 33 | if (index == -1) { |
| 34 | // Lazy initialization of the iterator |
| 35 | QResource resource(path()); |
| 36 | if (!resource.isValid()) |
| 37 | return false; |
| 38 | |
| 39 | // Initialize and move to the first entry. |
| 40 | entries = resource.children(); |
| 41 | if (entries.isEmpty()) |
| 42 | return false; |
| 43 | |
| 44 | index = 0; |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | if (index < entries.size() - 1) { |
| 49 | ++index; |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | QString QResourceFileEngineIterator::currentFileName() const |
| 57 | { |
| 58 | if (index < 0 || index > entries.size()) |
| 59 | return QString(); |
| 60 | return entries.at(i: index); |
| 61 | } |
| 62 | |
| 63 | QFileInfo QResourceFileEngineIterator::currentFileInfo() const |
| 64 | { |
| 65 | m_fileInfo = QFileInfo(currentFilePath()); |
| 66 | return m_fileInfo; |
| 67 | } |
| 68 | |
| 69 | QT_END_NAMESPACE |
| 70 | |