summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-05-30 14:59:38 +0200
committerMikaël Capelle <capelle.mikael@gmail.com>2020-05-30 14:59:38 +0200
commit21296a64594729a59360131270beaadf61cbced0 (patch)
tree96b6ba52100431c14d6d8746d084ad942dbfd39d
parenta92fdeb40064738df18d006285dfd05463d64223 (diff)
Allow creation of file using addFile() in ArchiveFileTree.
-rw-r--r--src/archivefiletree.cpp24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/archivefiletree.cpp b/src/archivefiletree.cpp
index 6ba06924..37d80537 100644
--- a/src/archivefiletree.cpp
+++ b/src/archivefiletree.cpp
@@ -84,14 +84,6 @@ protected:
public: // Overrides:
/**
- * @override
- */
- std::shared_ptr<FileTreeEntry> addFile(QString path) override {
- // Cannot add file to an archive.
- throw UnsupportedOperationException(QObject::tr("Cannot create file within an archive."));
- }
-
- /**
*
*/
static void mapToArchive(IFileTree const& tree, QString path, FileData* const* data)
@@ -118,7 +110,9 @@ public: // Overrides:
}
else {
const ArchiveFileEntry& archiveFileEntry = dynamic_cast<const ArchiveFileEntry&>(*entry);
- data[archiveFileEntry.m_Index]->addOutputFileName(path + archiveFileEntry.name());
+ if (archiveFileEntry.m_Index != -1) {
+ data[archiveFileEntry.m_Index]->addOutputFileName(path + archiveFileEntry.name());
+ }
}
}
}
@@ -135,18 +129,20 @@ public: // Overrides:
protected:
- /*
- * Overriding this to create custom FileTreeEntry with index set to -1. No need to
- * override makeFile() since we addFile is overriden. Note that this will not be
- * used to create existing tree since we do this manually in doPopulate.
+ /**
+ * Overriding makeDirectory and makeFile to create file tree or file entry with index -1.
*
- * @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 {
+ 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 {
// Sort by name: