OpenToonz - An open-source full-featured 2D animation creation software
C
Package new projects and standalone scene exports
Rodney755bc1e57fe3
diff --git a/toonz/sources/toonz/exportscenepopup.cpp b/toonz/sources/toonz/exportscenepopup.cppindex 7948290fe..3c62b2e95 100644--- a/toonz/sources/toonz/exportscenepopup.cpp+++ b/toonz/sources/toonz/exportscenepopup.cpp@@ -32,6 +32,11 @@#include <QApplication>#include <QMainWindow>#include <QStandardPaths>+#include <QCheckBox>+#include <QDirIterator>+#include <QFileInfo>++#include "simplezipwriter.h"#include <vector>@@ -102,6 +107,56 @@ void decodeLevelsPath(ToonzScene &scene) {}}}++bool zipDirectory(const TFilePath &sourceFolder, const TFilePath &archivePath,+ QString &errorMessage) {+ QDir sourceDir(sourceFolder.getQString());+ if (!sourceDir.exists()) {+ errorMessage = QObject::tr("The exported folder does not exist.");+ return false;+ }++ SimpleZipWriter writer(archivePath.getQString());+ if (!writer.isOpen()) {+ errorMessage = writer.errorString();+ return false;+ }++ const QString rootName = QFileInfo(sourceDir.absolutePath()).fileName();+ if (!writer.addDirectory(rootName)) {+ errorMessage = writer.errorString();+ return false;+ }++ QDirIterator iterator(sourceDir.absolutePath(),+ QDir::AllEntries | QDir::NoDotAndDotDot |+ QDir::Hidden | QDir::System,+ QDirIterator::Subdirectories);+ while (iterator.hasNext()) {+ iterator.next();+ const QFileInfo info = iterator.fileInfo();+ const QString relativePath =+ sourceDir.relativeFilePath(info.absoluteFilePath());+ const QString archiveEntry = rootName + "/" + relativePath;++ bool added = true;+ if (info.isDir())+ added = writer.addDirectory(archiveEntry);+ else if (info.isFile())+ added = writer.addFile(archiveEntry, info.absoluteFilePath());++ if (!added) {+ errorMessage = writer.errorString();+ return false;+ }+ }++ if (!writer.close()) {+ errorMessage = writer.errorString();+ return false;+ }+ return true;+}} // namespace//------------------------------------------------------------------------@@ -614,6 +669,13 @@ ExportScenePopup::ExportScenePopup(std::vector<TFilePath> scenes)lonelyProjectWidget->setLayout(lonelyProjectLayout);layout->addWidget(lonelyProjectWidget);+ m_createZipCheckBox =+ new QCheckBox(tr("Create ZIP archive of exported folder"), this);+ m_createZipCheckBox->setToolTip(+ tr("Create a ZIP archive after exporting a new project or "+ "standalone scene while keeping the exported folder."));+ layout->addWidget(m_createZipCheckBox);+ret = ret &&connect(group, SIGNAL(buttonClicked(int)), this, SLOT(switchMode(int)));@@ -639,6 +701,7 @@ ExportScenePopup::ExportScenePopup(std::vector<TFilePath> scenes)void ExportScenePopup::switchMode(int id) {assert(id < 3);m_mode = id;+ m_createZipCheckBox->setEnabled(id != 0);// m_projectTreeView->setEnabled(true);}@@ -735,12 +798,37 @@ void ExportScenePopup::onExport() {scene.save(newScenePath);Preferences::instance()->setValue(PreferencesItemId::pathAliasPriority,oldPriority, false);++ if (m_createZipCheckBox->isChecked()) {+ TFilePath archivePath(newSceneFolder.getWideString() + L".zip");+ QString zipError;+ if (!zipDirectory(newSceneFolder, archivePath, zipError)) {+ DVGui::warning(+ tr("The scene was exported, but the ZIP archive could not be "+ "created.\n%1")+ .arg(zipError));+ success = false;+ }+ }}progressBar.setValue(i + 1);}progressBar.hide();pm->setCurrentProjectPath(oldProjectPath);+ if (success && m_mode == 1 && m_createZipCheckBox->isChecked()) {+ TFilePath projectFolder = projectPath.getParentDir();+ TFilePath archivePath(projectFolder.getWideString() + L".zip");+ QString zipError;+ if (!zipDirectory(projectFolder, archivePath, zipError)) {+ DVGui::warning(+ tr("The project was exported, but the ZIP archive could not be "+ "created.\n%1")+ .arg(zipError));+ success = false;+ }+ }+QApplication::restoreOverrideCursor();if (!success) return;