diff options
| author | Al <26797547+Al12rs@users.noreply.github.com> | 2020-05-23 14:19:54 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-23 14:19:54 -0700 |
| commit | 08ae9db2fd2a07acb2433275fc84c2ca47267a92 (patch) | |
| tree | 5e1232028486d097352aca55ac994cd4e238064f /src/qdirfiletree.cpp | |
| parent | e618afa5d1ef53e62d022f3d233c86e13fd4a215 (diff) | |
| parent | 6374845a28c8f1f65a05fb954b4df1ebd541344b (diff) | |
Merge pull request #1076 from Holt59/moddatachecker
Use the ModDataChecker feature to check mod validity
Diffstat (limited to 'src/qdirfiletree.cpp')
| -rw-r--r-- | src/qdirfiletree.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/qdirfiletree.cpp b/src/qdirfiletree.cpp new file mode 100644 index 00000000..770a9df8 --- /dev/null +++ b/src/qdirfiletree.cpp @@ -0,0 +1,57 @@ +#include "qdirfiletree.h" + +#include <QDirIterator> + +using namespace MOBase; + +class QDirFileTreeImpl : public QDirFileTree { +public: + + + /** + * + */ + QDirFileTreeImpl(std::shared_ptr<const IFileTree> parent, QDir dir) : + FileTreeEntry(parent, dir.dirName()), QDirFileTree(), qDir(dir) { } + +protected: + + /** + * No mutable operations allowed. + */ + bool beforeReplace(IFileTree const* dstTree, FileTreeEntry const* destination, FileTreeEntry const* source) override { return false; } + bool beforeInsert(IFileTree const* entry, FileTreeEntry const* name) override { return false; } + bool beforeRemove(IFileTree const* entry, FileTreeEntry const* name) override { return false; } + std::shared_ptr<FileTreeEntry> makeFile(std::shared_ptr<const IFileTree> parent, QString name) const override { return nullptr; } + std::shared_ptr<IFileTree> makeDirectory(std::shared_ptr<const IFileTree> parent, QString name) const override { return nullptr; } + + bool doPopulate(std::shared_ptr<const IFileTree> parent, std::vector<std::shared_ptr<FileTreeEntry>>& entries) const override { + auto infoList = qDir.entryInfoList(qDir.filter() | QDir::NoDotAndDotDot, QDir::Name | QDir::DirsFirst | QDir::IgnoreCase); + for (auto& info : infoList) { + if (info.isDir()) { + entries.push_back(std::make_shared<QDirFileTreeImpl>(parent, QDir(info.absoluteFilePath()))); + } + else { + entries.push_back(createFileEntry(parent, info.fileName())); + } + } + + // Vector is already sorted: + return true; + } + + std::shared_ptr<IFileTree> QDirFileTree::doClone() const { + return std::make_shared<QDirFileTreeImpl>(nullptr, qDir); + } + +private: + QDir qDir; + +}; + +/** + * + */ +std::shared_ptr<const QDirFileTree> QDirFileTree::makeTree(QDir directory) { + return std::make_shared<QDirFileTreeImpl>(nullptr, directory); +} |
