From 4a3b9e78c664be292b1b2f6ec2f3511d00a8f175 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Thu, 13 Jun 2024 15:26:51 +0300 Subject: [PATCH] QmlDesigner: Add versioning to exported bundles Change-Id: Icd7f6eea5e4691388586fc72d65998a74d6d0058 Reviewed-by: Ali Kianian Reviewed-by: Miikka Heikkinen --- .../components/contentlibrary/contentlibraryview.cpp | 9 +++++++++ .../components/contentlibrary/contentlibraryview.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp index 7e703354cb5..ac623eaf2ad 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp @@ -807,6 +807,7 @@ void ContentLibraryView::exportLib3DComponent(const ModelNode &node) auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils(); jsonObj["id"] = compUtils.user3DBundleId(); + jsonObj["version"] = BUNDLE_VERSION; Utils::FilePath jsonFilePath = targetPath.pathAppended(Constants::BUNDLE_JSON_FILENAME); m_zipWriter->addFile(jsonFilePath.fileName(), QJsonDocument(jsonObj).toJson()); @@ -960,6 +961,7 @@ void ContentLibraryView::exportLib3DItem(const ModelNode &node, const QPixmap &i auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils(); jsonObj["id"] = node.metaInfo().isQtQuick3DMaterial() ? compUtils.userMaterialsBundleId() : compUtils.user3DBundleId(); + jsonObj["version"] = BUNDLE_VERSION; Utils::FilePath jsonFilePath = targetPath.pathAppended(Constants::BUNDLE_JSON_FILENAME); m_zipWriter->addFile(jsonFilePath.fileName(), QJsonDocument(jsonObj).toJson()); @@ -1004,6 +1006,13 @@ void ContentLibraryView::importBundle() const QJsonArray importedItemsArr = importedJsonObj.value("items").toArray(); QTC_ASSERT(!importedItemsArr.isEmpty(), return); + QString bundleVersion = importedJsonObj.value("version").toString(); + bool bundleVersionOk = !bundleVersion.isEmpty() && bundleVersion == BUNDLE_VERSION; + if (!bundleVersionOk) { + QMessageBox::warning(m_widget, tr("Unsupported bundle file"), + tr("The chosen bundle was created with an incompatible version of Qt Design Studio")); + return; + } bool isMat = isMaterialBundle(importedJsonObj.value("id").toString()); QString bundleFolderName = isMat ? QLatin1String("materials") : QLatin1String("3d"); diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h index 91c4b2e6a5d..9cf4c8834f7 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h @@ -102,6 +102,8 @@ private: Utils::FilePath m_iconSavePath; std::unique_ptr m_zipWriter; std::unique_ptr m_tempDir; + + static constexpr char BUNDLE_VERSION[] = "1.0"; }; } // namespace QmlDesigner