summaryrefslogtreecommitdiff
path: root/src/archivefiletree.cpp
diff options
context:
space:
mode:
authorMikaƫl Capelle <capelle.mikael@gmail.com>2023-07-09 17:36:03 +0200
committerGitHub <noreply@github.com>2023-07-09 17:36:03 +0200
commitef94aee28464039672b277243a0181ae93550d6c (patch)
tree0575a68af5f154e9d6d0738edbaefb16a11d6f5c /src/archivefiletree.cpp
parent7d6cb8528d20e36a4cee822263865ee2f7f32481 (diff)
parent3de050e9c03e553f7ae3f780f6bd080a30ae123e (diff)
Merge pull request #1839 from Holt59/ci/initial-gh-action-for-build
Clang-Format + Github Workflow
Diffstat (limited to 'src/archivefiletree.cpp')
-rw-r--r--src/archivefiletree.cpp161
1 files changed, 87 insertions, 74 deletions
diff --git a/src/archivefiletree.cpp b/src/archivefiletree.cpp
index 11e165b8..b90c4798 100644
--- a/src/archivefiletree.cpp
+++ b/src/archivefiletree.cpp
@@ -29,9 +29,9 @@ using namespace MOBase;
/**
* We use custom file entries to store the index.
*/
-class ArchiveFileEntry : public virtual FileTreeEntry {
+class ArchiveFileEntry : public virtual FileTreeEntry
+{
public:
-
/**
* @brief Create a new entry.
*
@@ -39,11 +39,12 @@ public:
* @param name The name of this entry.
* @param index The index of the entry in the archive.
*/
- ArchiveFileEntry(std::shared_ptr<const IFileTree> parent, QString name, int index) :
- FileTreeEntry(parent, name), m_Index(index) {
- }
+ ArchiveFileEntry(std::shared_ptr<const IFileTree> parent, QString name, int index)
+ : FileTreeEntry(parent, name), m_Index(index)
+ {}
- virtual std::shared_ptr<FileTreeEntry> clone() const override {
+ virtual std::shared_ptr<FileTreeEntry> clone() const override
+ {
return std::make_shared<ArchiveFileEntry>(nullptr, name(), m_Index);
}
@@ -51,67 +52,70 @@ public:
const int m_Index;
};
-
/**
*
*/
-class ArchiveFileTreeImpl: public virtual ArchiveFileTree, public virtual ArchiveFileEntry {
+class ArchiveFileTreeImpl : public virtual ArchiveFileTree,
+ public virtual ArchiveFileEntry
+{
public:
-
using File = std::tuple<QStringList, bool, int>;
-public: // Public for make_shared (but not accessible by other since not exposed in .h):
+public
+ : // Public for make_shared (but not accessible by other since not exposed in .h):
+ ArchiveFileTreeImpl(std::shared_ptr<const IFileTree> parent, QString name, int index,
+ std::vector<File> files)
+ : FileTreeEntry(parent, name), ArchiveFileEntry(parent, name, index), IFileTree(),
+ m_Files(std::move(files))
+ {}
- ArchiveFileTreeImpl(std::shared_ptr<const IFileTree> parent, QString name, int index, std::vector<File> files)
- : FileTreeEntry(parent, name), ArchiveFileEntry(parent, name, index), IFileTree(), m_Files(std::move(files)) { }
+public: // Override to avoid VS warnings:
+ virtual std::shared_ptr<IFileTree> astree() override { return IFileTree::astree(); }
-public: // Override to avoid VS warnings:
-
- virtual std::shared_ptr<IFileTree> astree() override {
- return IFileTree::astree();
- }
-
- virtual std::shared_ptr<const IFileTree> astree() const override {
+ virtual std::shared_ptr<const IFileTree> astree() const override
+ {
return IFileTree::astree();
}
protected:
-
- virtual std::shared_ptr<FileTreeEntry> clone() const override {
+ virtual std::shared_ptr<FileTreeEntry> clone() const override
+ {
return IFileTree::clone();
}
-public: // Overrides:
-
+public: // Overrides:
/**
*
*/
- static void mapToArchive(IFileTree const& tree, QString path, std::vector<FileData*> const& data)
+ static void mapToArchive(IFileTree const& tree, QString path,
+ std::vector<FileData*> const& data)
{
if (path.length() > 0) {
- // when using a long windows path (starting with \\?\) we apparently can have redundant
- // . components in the path. This wasn't a problem with "regular" path names.
+ // when using a long windows path (starting with \\?\) we apparently can have
+ // redundant . components in the path. This wasn't a problem with "regular" path
+ // names.
if (path == ".") {
path.clear();
- }
- else {
+ } else {
path.append("\\");
}
}
for (auto const& entry : tree) {
if (entry->isDir()) {
- const ArchiveFileTreeImpl& archiveEntry = dynamic_cast<const ArchiveFileTreeImpl&>(*entry);
+ const ArchiveFileTreeImpl& archiveEntry =
+ dynamic_cast<const ArchiveFileTreeImpl&>(*entry);
QString tmp = path + archiveEntry.name();
if (archiveEntry.m_Index != -1) {
data[archiveEntry.m_Index]->addOutputFilePath(tmp.toStdWString());
}
mapToArchive(*archiveEntry.astree(), tmp, data);
- }
- else {
- const ArchiveFileEntry& archiveFileEntry = dynamic_cast<const ArchiveFileEntry&>(*entry);
+ } else {
+ const ArchiveFileEntry& archiveFileEntry =
+ dynamic_cast<const ArchiveFileEntry&>(*entry);
if (archiveFileEntry.m_Index != -1) {
- data[archiveFileEntry.m_Index]->addOutputFilePath((path + archiveFileEntry.name()).toStdWString());
+ data[archiveFileEntry.m_Index]->addOutputFilePath(
+ (path + archiveFileEntry.name()).toStdWString());
}
}
}
@@ -120,36 +124,42 @@ public: // Overrides:
/**
*
*/
- void mapToArchive(Archive &archive) const override {
+ void mapToArchive(Archive& archive) const override
+ {
mapToArchive(*this, "", archive.getFileList());
}
protected:
-
/**
- * Overriding makeDirectory and makeFile to create file tree or file entry with index -1.
+ * Overriding makeDirectory and makeFile to create file tree or file entry with index
+ * -1.
*
*/
- virtual std::shared_ptr<IFileTree> makeDirectory(
- std::shared_ptr<const IFileTree> parent, QString name) const override {
+ virtual std::shared_ptr<IFileTree>
+ makeDirectory(std::shared_ptr<const IFileTree> parent, QString name) const override
+ {
return std::make_shared<ArchiveFileTreeImpl>(parent, name, -1, std::vector<File>{});
}
- virtual std::shared_ptr<FileTreeEntry> makeFile(
- std::shared_ptr<const IFileTree> parent, QString name) const override {
+ virtual std::shared_ptr<FileTreeEntry>
+ makeFile(std::shared_ptr<const IFileTree> parent, QString name) const override
+ {
return std::make_shared<ArchiveFileEntry>(parent, name, -1);
}
- virtual bool doPopulate(std::shared_ptr<const IFileTree> parent, std::vector<std::shared_ptr<FileTreeEntry>>& entries) const override {
+ virtual bool
+ doPopulate(std::shared_ptr<const IFileTree> parent,
+ std::vector<std::shared_ptr<FileTreeEntry>>& entries) const override
+ {
// Sort by name:
- std::sort(std::begin(m_Files), std::end(m_Files),
- [](const auto& a, const auto& b) {
- return std::get<0>(a)[0].compare(std::get<0>(b)[0], Qt::CaseInsensitive) < 0; });
+ std::sort(std::begin(m_Files), std::end(m_Files), [](const auto& a, const auto& b) {
+ return std::get<0>(a)[0].compare(std::get<0>(b)[0], Qt::CaseInsensitive) < 0;
+ });
// We know that the files are sorted:
QString currentName = "";
- int currentIndex = -1;
+ int currentIndex = -1;
std::vector<File> currentFiles;
for (auto& p : m_Files) {
@@ -162,11 +172,12 @@ protected:
// accumulated:
if (currentName != std::get<0>(p)[0]) {
- // We may or may not have an index here, it depends on the type of archive (some archives list
- // intermediate non-empty folders, some don't):
- entries.push_back(std::make_shared<ArchiveFileTreeImpl>(parent, currentName, currentIndex, std::move(currentFiles)));
+ // We may or may not have an index here, it depends on the type of archive (some
+ // archives list intermediate non-empty folders, some don't):
+ entries.push_back(std::make_shared<ArchiveFileTreeImpl>(
+ parent, currentName, currentIndex, std::move(currentFiles)));
- currentFiles.clear(); // Back to a valid state.
+ currentFiles.clear(); // Back to a valid state.
// Reset the index:
currentIndex = -1;
@@ -181,36 +192,35 @@ protected:
// If it is not a directory, then it is a file in directly under this tree:
if (!std::get<1>(p)) {
entries.push_back(
- std::make_shared<ArchiveFileEntry>(parent, currentName, std::get<2>(p)));
+ std::make_shared<ArchiveFileEntry>(parent, currentName, std::get<2>(p)));
currentName = "";
- }
- else {
- // Otherwize, it is the actual "file" corresponding to the directory we are listing, so we can retrieve
- // the index here:
+ } else {
+ // Otherwize, it is the actual "file" corresponding to the directory we are
+ // listing, so we can retrieve the index here:
currentIndex = std::get<2>(p);
}
- }
- else {
- currentFiles.push_back({
- QStringList(std::get<0>(p).begin() + 1, std::get<0>(p).end()), std::get<1>(p), std::get<2>(p)
- });
+ } else {
+ currentFiles.push_back(
+ {QStringList(std::get<0>(p).begin() + 1, std::get<0>(p).end()),
+ std::get<1>(p), std::get<2>(p)});
}
}
if (currentName != "") {
- entries.push_back(std::make_shared<ArchiveFileTreeImpl>(parent, currentName, currentIndex, std::move(currentFiles)));
+ entries.push_back(std::make_shared<ArchiveFileTreeImpl>(
+ parent, currentName, currentIndex, std::move(currentFiles)));
}
// Let the parent class sort the entries:
return false;
}
- virtual std::shared_ptr<IFileTree> doClone() const override {
+ virtual std::shared_ptr<IFileTree> doClone() const override
+ {
return std::make_shared<ArchiveFileTreeImpl>(nullptr, name(), m_Index, m_Files);
}
private:
-
mutable std::vector<File> m_Files;
};
@@ -224,15 +234,15 @@ std::shared_ptr<ArchiveFileTree> ArchiveFileTree::makeTree(Archive const& archiv
for (size_t i = 0; i < data.size(); ++i) {
// Ignore "." and ".." as they're useless and muck things up
if (data[i]->getArchiveFilePath().compare(L".") == 0 ||
- data[i]->getArchiveFilePath().compare(L"..") == 0)
- {
+ data[i]->getArchiveFilePath().compare(L"..") == 0) {
continue;
}
- files.push_back(std::make_tuple(
- QString::fromStdWString(data[i]->getArchiveFilePath()).replace("\\", "/").split("/", Qt::SkipEmptyParts),
- data[i]->isDirectory(),
- (int) i));
+ files.push_back(
+ std::make_tuple(QString::fromStdWString(data[i]->getArchiveFilePath())
+ .replace("\\", "/")
+ .split("/", Qt::SkipEmptyParts),
+ data[i]->isDirectory(), (int)i));
}
auto tree = std::make_shared<ArchiveFileTreeImpl>(nullptr, "", -1, std::move(files));
@@ -240,15 +250,16 @@ std::shared_ptr<ArchiveFileTree> ArchiveFileTree::makeTree(Archive const& archiv
}
/**
- * @brief Recursive function for the ArchiveFileTree::mapToArchive method. Need a template
- * here because iterators from a vector of entries are not exactly the same as the iterators
- * returned by a IFileTree.
+ * @brief Recursive function for the ArchiveFileTree::mapToArchive method. Need a
+ * template here because iterators from a vector of entries are not exactly the same as
+ * the iterators returned by a IFileTree.
*
*/
template <class It>
-void mapToArchive(std::vector<FileData*> const& data, It begin, It end) {
+void mapToArchive(std::vector<FileData*> const& data, It begin, It end)
+{
for (auto it = begin; it != end; ++it) {
- auto entry = *it;
+ auto entry = *it;
auto* aentry = dynamic_cast<const ArchiveFileEntry*>(entry.get());
if (aentry->m_Index != -1) {
@@ -262,6 +273,8 @@ void mapToArchive(std::vector<FileData*> const& data, It begin, It end) {
}
}
-void ArchiveFileTree::mapToArchive(Archive &archive, std::vector<std::shared_ptr<const FileTreeEntry>> const& entries) {
+void ArchiveFileTree::mapToArchive(
+ Archive& archive, std::vector<std::shared_ptr<const FileTreeEntry>> const& entries)
+{
::mapToArchive(archive.getFileList(), entries.cbegin(), entries.cend());
}