QmlDesigner: Add versioning to exported bundles

Change-Id: Icd7f6eea5e4691388586fc72d65998a74d6d0058
Reviewed-by: Ali Kianian <ali.kianian@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Mahmoud Badri
2024-06-13 15:26:51 +03:00
parent 28af0f1394
commit 4a3b9e78c6
2 changed files with 11 additions and 0 deletions

View File

@@ -807,6 +807,7 @@ void ContentLibraryView::exportLib3DComponent(const ModelNode &node)
auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils(); auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
jsonObj["id"] = compUtils.user3DBundleId(); jsonObj["id"] = compUtils.user3DBundleId();
jsonObj["version"] = BUNDLE_VERSION;
Utils::FilePath jsonFilePath = targetPath.pathAppended(Constants::BUNDLE_JSON_FILENAME); Utils::FilePath jsonFilePath = targetPath.pathAppended(Constants::BUNDLE_JSON_FILENAME);
m_zipWriter->addFile(jsonFilePath.fileName(), QJsonDocument(jsonObj).toJson()); 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(); auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
jsonObj["id"] = node.metaInfo().isQtQuick3DMaterial() ? compUtils.userMaterialsBundleId() jsonObj["id"] = node.metaInfo().isQtQuick3DMaterial() ? compUtils.userMaterialsBundleId()
: compUtils.user3DBundleId(); : compUtils.user3DBundleId();
jsonObj["version"] = BUNDLE_VERSION;
Utils::FilePath jsonFilePath = targetPath.pathAppended(Constants::BUNDLE_JSON_FILENAME); Utils::FilePath jsonFilePath = targetPath.pathAppended(Constants::BUNDLE_JSON_FILENAME);
m_zipWriter->addFile(jsonFilePath.fileName(), QJsonDocument(jsonObj).toJson()); m_zipWriter->addFile(jsonFilePath.fileName(), QJsonDocument(jsonObj).toJson());
@@ -1004,6 +1006,13 @@ void ContentLibraryView::importBundle()
const QJsonArray importedItemsArr = importedJsonObj.value("items").toArray(); const QJsonArray importedItemsArr = importedJsonObj.value("items").toArray();
QTC_ASSERT(!importedItemsArr.isEmpty(), return); 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()); bool isMat = isMaterialBundle(importedJsonObj.value("id").toString());
QString bundleFolderName = isMat ? QLatin1String("materials") : QLatin1String("3d"); QString bundleFolderName = isMat ? QLatin1String("materials") : QLatin1String("3d");

View File

@@ -102,6 +102,8 @@ private:
Utils::FilePath m_iconSavePath; Utils::FilePath m_iconSavePath;
std::unique_ptr<ZipWriter> m_zipWriter; std::unique_ptr<ZipWriter> m_zipWriter;
std::unique_ptr<QTemporaryDir> m_tempDir; std::unique_ptr<QTemporaryDir> m_tempDir;
static constexpr char BUNDLE_VERSION[] = "1.0";
}; };
} // namespace QmlDesigner } // namespace QmlDesigner