diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/organizercore.cpp | 3 | ||||
| -rw-r--r-- | src/organizercore.h | 2 | ||||
| -rw-r--r-- | src/organizerproxy.cpp | 5 | ||||
| -rw-r--r-- | src/organizerproxy.h | 5 | ||||
| -rw-r--r-- | src/qdirfiletree.cpp | 56 | ||||
| -rw-r--r-- | src/qdirfiletree.h | 4 | ||||
| -rw-r--r-- | src/version.rc | 2 | ||||
| -rw-r--r-- | src/virtualfiletree.cpp | 59 | ||||
| -rw-r--r-- | src/virtualfiletree.h | 60 |
10 files changed, 184 insertions, 13 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f8da6f2..7f1f642a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,6 +37,7 @@ add_filter(NAME src/core GROUPS apiuseraccount processrunner qdirfiletree + virtualfiletree uilocker ) diff --git a/src/organizercore.cpp b/src/organizercore.cpp index e47a6e30..7cf3212a 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -32,6 +32,7 @@ #include "envmodule.h" #include "envfs.h" #include "directoryrefresher.h" +#include "virtualfiletree.h" #include "shared/directoryentry.h" #include "shared/filesorigin.h" #include "shared/fileentry.h" @@ -97,6 +98,7 @@ OrganizerCore::OrganizerCore(Settings &settings) , m_PluginList(*this) , m_DirectoryRefresher(new DirectoryRefresher(settings.refreshThreadCount())) , m_DirectoryStructure(new DirectoryEntry(L"data", nullptr, 0)) + , m_VirtualFileTree([this]() { return VirtualFileTree::makeTree(m_DirectoryStructure); }) , m_DownloadManager(&NexusInterface::instance(), this) , m_DirectoryUpdate(false) , m_ArchivesInit(false) @@ -1521,6 +1523,7 @@ void OrganizerCore::directory_refreshed() } std::swap(m_DirectoryStructure, newStructure); + m_VirtualFileTree.invalidate(); if (m_StructureDeleter.joinable()) { m_StructureDeleter.join(); diff --git a/src/organizercore.h b/src/organizercore.h index e6274e36..c9e2bdb3 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -11,6 +11,7 @@ #include "executableslist.h"
#include "usvfsconnector.h"
#include "moshortcut.h"
+#include "memoizedlock.h"
#include "processrunner.h"
#include "uilocker.h"
#include "envdump.h"
@@ -476,6 +477,7 @@ private: std::unique_ptr<DirectoryRefresher> m_DirectoryRefresher;
MOShared::DirectoryEntry *m_DirectoryStructure;
+ MOBase::MemoizedLocked<std::shared_ptr<const MOBase::IFileTree>> m_VirtualFileTree;
DownloadManager m_DownloadManager;
InstallationManager m_InstallationManager;
diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index b416153b..e9fe61c2 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -272,6 +272,11 @@ QList<MOBase::IOrganizer::FileInfo> OrganizerProxy::findFileInfos(const QString return m_Proxied->findFileInfos(path, filter);
}
+std::shared_ptr<const MOBase::IFileTree> OrganizerProxy::virtualFileTree() const
+{
+ return m_Proxied->m_VirtualFileTree.value();
+}
+
MOBase::IDownloadManager *OrganizerProxy::downloadManager() const
{
return m_DownloadManagerProxy.get();
diff --git a/src/organizerproxy.h b/src/organizerproxy.h index 7a91a347..f419ba59 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -49,8 +49,9 @@ public: // IOrganizer interface virtual QStringList listDirectories(const QString &directoryName) const;
virtual QStringList findFiles(const QString &path, const std::function<bool(const QString &)> &filter) const override;
virtual QStringList findFiles(const QString &path, const QStringList &globFilters) const override;
- virtual QStringList getFileOrigins(const QString &fileName) const;
- virtual QList<FileInfo> findFileInfos(const QString &path, const std::function<bool(const FileInfo&)> &filter) const;
+ virtual QStringList getFileOrigins(const QString &fileName) const override;
+ virtual QList<FileInfo> findFileInfos(const QString &path, const std::function<bool(const FileInfo&)> &filter) const override;
+ virtual std::shared_ptr<const MOBase::IFileTree> virtualFileTree() const override;
virtual MOBase::IDownloadManager *downloadManager() const;
virtual MOBase::IPluginList *pluginList() const;
diff --git a/src/qdirfiletree.cpp b/src/qdirfiletree.cpp index 770a9df8..6fd370bf 100644 --- a/src/qdirfiletree.cpp +++ b/src/qdirfiletree.cpp @@ -7,10 +7,6 @@ using namespace MOBase; class QDirFileTreeImpl : public QDirFileTree { public: - - /** - * - */ QDirFileTreeImpl(std::shared_ptr<const IFileTree> parent, QDir dir) : FileTreeEntry(parent, dir.dirName()), QDirFileTree(), qDir(dir) { } @@ -25,7 +21,8 @@ protected: 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 { + 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()) { @@ -40,18 +37,59 @@ protected: return true; } - std::shared_ptr<IFileTree> QDirFileTree::doClone() const { + std::shared_ptr<IFileTree> QDirFileTree::doClone() const + { return std::make_shared<QDirFileTreeImpl>(nullptr, qDir); } -private: +protected: QDir qDir; }; +// subclass of QDirFileTreeImpl that ignores meta.ini +// +// only used for the root folder, subdirectories are actually QDirFileTreeImpl +class QDirRootFileTreeImpl : public QDirFileTreeImpl { +public: + + + QDirRootFileTreeImpl(QDir dir) : FileTreeEntry(nullptr, dir.dirName()), QDirFileTreeImpl(nullptr, dir) { } + +protected: + + 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 if (info.fileName().compare("meta.ini", Qt::CaseInsensitive) != 0) { + entries.push_back(createFileEntry(parent, info.fileName())); + } + } + + // Vector is already sorted: + return true; + } + + std::shared_ptr<IFileTree> QDirFileTree::doClone() const + { + return std::make_shared<QDirRootFileTreeImpl>(qDir); + } + +}; + /** * */ -std::shared_ptr<const QDirFileTree> QDirFileTree::makeTree(QDir directory) { - return std::make_shared<QDirFileTreeImpl>(nullptr, directory); +std::shared_ptr<const QDirFileTree> QDirFileTree::makeTree(QDir directory, bool ignoreRootMeta) +{ + if (ignoreRootMeta) { + return std::make_shared<QDirRootFileTreeImpl>(directory); + } + else { + return std::make_shared<QDirFileTreeImpl>(nullptr, directory); + } } diff --git a/src/qdirfiletree.h b/src/qdirfiletree.h index 219a3a6f..e9229bf5 100644 --- a/src/qdirfiletree.h +++ b/src/qdirfiletree.h @@ -41,10 +41,12 @@ public: * @brief Create a new file tree representing the given directory. * * @param directory Directory to represent. + * @param ignoreRootMeta If true, the meta.ini file in the root folder will + * be ignored. * * @return a file tree representing the given directory. */ - static std::shared_ptr<const QDirFileTree> makeTree(QDir directory); + static std::shared_ptr<const QDirFileTree> makeTree(QDir directory, bool ignoreRootMeta = true); protected: diff --git a/src/version.rc b/src/version.rc index 05396df9..1a668daf 100644 --- a/src/version.rc +++ b/src/version.rc @@ -4,7 +4,7 @@ // Otherwise, if letters are used in VER_FILEVERSION_STR, uses the full MOBase::VersionInfo parser // Otherwise, uses the numbers from VER_FILEVERSION and sets the release type as pre-alpha #define VER_FILEVERSION 2,4,2 -#define VER_FILEVERSION_STR "2.4.2rc1.1\0" +#define VER_FILEVERSION_STR "2.4.2\0" VS_VERSION_INFO VERSIONINFO FILEVERSION VER_FILEVERSION diff --git a/src/virtualfiletree.cpp b/src/virtualfiletree.cpp new file mode 100644 index 00000000..983523e6 --- /dev/null +++ b/src/virtualfiletree.cpp @@ -0,0 +1,59 @@ +#include "virtualfiletree.h" + +#include "shared/directoryentry.h" +#include "shared/filesorigin.h" +#include "shared/fileentry.h" +// #include "shared/util.h" + +using namespace MOBase; +using namespace MOShared; + +class VirtualFileTreeImpl : public VirtualFileTree { +public: + + + /** + * + */ + VirtualFileTreeImpl(std::shared_ptr<const IFileTree> parent, const DirectoryEntry* dir) : + FileTreeEntry(parent, parent ? QString::fromStdWString(dir->getName()) : ""), + VirtualFileTree(), + m_dirEntry(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 { + for (auto* subdirEntry : m_dirEntry->getSubDirectories()) { + entries.push_back(std::make_shared<VirtualFileTreeImpl>(parent, subdirEntry)); + } + for (auto& file : m_dirEntry->getFiles()) { + entries.push_back(createFileEntry(parent, QString::fromStdWString(file->getName()))); + } + + // Vector is already sorted: + return true; + } + + std::shared_ptr<IFileTree> doClone() const { + return std::make_shared<VirtualFileTreeImpl>(nullptr, m_dirEntry); + } + +private: + const DirectoryEntry* m_dirEntry; +}; + +/** + * + */ +std::shared_ptr<const VirtualFileTree> VirtualFileTree::makeTree(const DirectoryEntry* rootEntry) { + return std::make_shared<VirtualFileTreeImpl>(nullptr, rootEntry); +} diff --git a/src/virtualfiletree.h b/src/virtualfiletree.h new file mode 100644 index 00000000..ebce5486 --- /dev/null +++ b/src/virtualfiletree.h @@ -0,0 +1,60 @@ +/* +Copyright (C) MO2 Team. All rights reserved. + +This file is part of Mod Organizer. + +Mod Organizer is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Mod Organizer is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef ARCHIVEFILENETRY_H +#define ARCHIVEFILENTRY_H + +#include <QDir> + +#include "ifiletree.h" + +namespace MOShared +{ + class DirectoryEntry; +} + +/** + * @brief Class that expose the VFS main directory structure as a `MOBase::IFileTree`. + * + * The tree is lazily populated: each subtree is only populated when needed, + * as specified by IFileTree. + * + * This class does not expose mutable operations, so any mutable operations will + * fail. + */ +class VirtualFileTree : public MOBase::IFileTree { +public: + + /** + * @brief Create a new file tree representing the given VFS directory. + * + * @param root Root directory. + * + * @return a file tree representing the VFS directory. + */ + static std::shared_ptr<const VirtualFileTree> makeTree(const MOShared::DirectoryEntry* root); + +protected: + + using IFileTree::IFileTree; + + virtual bool doPopulate(std::shared_ptr<const IFileTree> parent, std::vector<std::shared_ptr<FileTreeEntry>>& entries) const = 0; +}; + +#endif |
