From 3c779b58de8e9caf39e442f20d15966b3297ff99 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 8 Mar 2019 13:34:16 +0100 Subject: [PATCH] Specialise _isMetadataValid for Cura to check setting_version Because we need to reject loading metadata for containers whose setting_version is incorrect. Contributes to issue CURA-6270. --- cura/Settings/CuraContainerRegistry.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cura/Settings/CuraContainerRegistry.py b/cura/Settings/CuraContainerRegistry.py index 9f44d075e0..6804becf4e 100644 --- a/cura/Settings/CuraContainerRegistry.py +++ b/cura/Settings/CuraContainerRegistry.py @@ -1,11 +1,11 @@ -# Copyright (c) 2018 Ultimaker B.V. +# Copyright (c) 2019 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. import os import re import configparser -from typing import cast, Dict, Optional +from typing import Any, cast, Dict, Optional from PyQt5.QtWidgets import QMessageBox from UM.Decorators import override @@ -327,6 +327,23 @@ class CuraContainerRegistry(ContainerRegistry): self._registerSingleExtrusionMachinesExtruderStacks() self._connectUpgradedExtruderStacksToMachines() + ## Check if the metadata for a container is okay before adding it. + # + # This overrides the one from UM.Settings.ContainerRegistry because we + # also require that the setting_version is correct. + @override(ContainerRegistry) + def _isMetadataValid(self, metadata: Optional[Dict[str, Any]]) -> bool: + if metadata is None: + return False + if "setting_version" not in metadata: + return False + try: + if int(metadata["setting_version"]) != cura.CuraApplication.CuraApplication.SettingVersion: + return False + except ValueError: #Not parsable as int. + return False + return True + ## Update an imported profile to match the current machine configuration. # # \param profile The profile to configure.