diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 6321dbf670..c3477ed252 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -26,7 +26,6 @@ from UM.Settings.Validator import Validator from UM.Message import Message from UM.i18n import i18nCatalog from UM.Workspace.WorkspaceReader import WorkspaceReader -from UM.Platform import Platform from UM.Decorators import deprecated from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation @@ -268,6 +267,9 @@ class CuraApplication(QtApplication): with ContainerRegistry.getInstance().lockFile(): ContainerRegistry.getInstance().load() + # set the setting version for Preferences + Preferences.getInstance().setSettingVersion(CuraApplication.SettingVersion) + Preferences.getInstance().addPreference("cura/active_mode", "simple") Preferences.getInstance().addPreference("cura/categories_expanded", "") diff --git a/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py b/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py index d3e22ba5d2..7d728884cb 100644 --- a/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py +++ b/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py @@ -61,8 +61,13 @@ class VersionUpgrade25to26(VersionUpgrade): parser["general"]["visible_settings"] = ";".join(new_visible_settings) #Change the version number in the file. + if "general" not in parser: + parser["general"] = {} parser.set("general", "version", "4") - parser.set("general", "setting_version", "1") + + if "metadata" not in parser: + parser["metadata"] = {} + parser.set("metadata", "setting_version", "1") #Re-serialise the file. output = io.StringIO() diff --git a/plugins/VersionUpgrade/VersionUpgrade26to27/VersionUpgrade26to27.py b/plugins/VersionUpgrade/VersionUpgrade26to27/VersionUpgrade26to27.py index 38031765d5..e2d7817077 100644 --- a/plugins/VersionUpgrade/VersionUpgrade26to27/VersionUpgrade26to27.py +++ b/plugins/VersionUpgrade/VersionUpgrade26to27/VersionUpgrade26to27.py @@ -87,6 +87,50 @@ class VersionUpgrade26to27(VersionUpgrade): setting_version = int(parser.get("metadata", "setting_version", fallback = 0)) return format_version * 1000000 + setting_version + ## Upgrades a preferences file from version 2.6 to 2.7. + # + # \param serialised The serialised form of a preferences file. + # \param filename The name of the file to upgrade. + def upgradePreferences(self, serialised, filename): + parser = configparser.ConfigParser(interpolation=None) + parser.read_string(serialised) + + # Update version numbers + if "general" not in parser: + parser["general"] = {} + parser["general"]["version"] = "4" + + if "metadata" not in parser: + parser["metadata"] = {} + parser["metadata"]["setting_version"] = "2" + + # Re-serialise the file. + output = io.StringIO() + parser.write(output) + return [filename], [output.getvalue()] + + ## Upgrades a container file other than a container stack file from version 2.6 to 2.7. + # + # \param serialised The serialised form of a container file. + # \param filename The name of the file to upgrade. + def upgradeOtherContainer(self, serialised, filename): + parser = configparser.ConfigParser(interpolation=None) + parser.read_string(serialised) + + # Update version numbers + if "general" not in parser: + parser["general"] = {} + parser["general"]["version"] = "2" + + if "metadata" not in parser: + parser["metadata"] = {} + parser["metadata"]["setting_version"] = "2" + + # Re-serialise the file. + output = io.StringIO() + parser.write(output) + return [filename], [output.getvalue()] + ## Upgrades a container stack from version 2.6 to 2.7. # # \param serialised The serialised form of a container stack. @@ -108,12 +152,15 @@ class VersionUpgrade26to27(VersionUpgrade): if not parser.has_section(each_section): parser.add_section(each_section) - # Change the version number in the file. - parser["metadata"]["setting_version"] = str(CuraApplication.SettingVersion) - - # Update version + # Update version numbers + if "general" not in parser: + parser["general"] = {} parser["general"]["version"] = "3" + if "metadata" not in parser: + parser["metadata"] = {} + parser["metadata"]["setting_version"] = "2" + # Re-serialise the file. output = io.StringIO() parser.write(output) diff --git a/plugins/VersionUpgrade/VersionUpgrade26to27/__init__.py b/plugins/VersionUpgrade/VersionUpgrade26to27/__init__.py index 8ddf4aa7ea..b0c0d70ae2 100644 --- a/plugins/VersionUpgrade/VersionUpgrade26to27/__init__.py +++ b/plugins/VersionUpgrade/VersionUpgrade26to27/__init__.py @@ -14,6 +14,21 @@ def getMetaData(): # From To Upgrade function ("machine_stack", 3000000): ("machine_stack", 3000002, upgrade.upgradeStack), ("extruder_train", 3000000): ("extruder_train", 3000002, upgrade.upgradeStack), + + # In 2.6.x, Preferences are saved with "version = 4" and no setting_version. + # This means those Preferences files will still be treated as "4.0" as defined in VersionUpgrade25to26, + # so the 25to26 upgrade routine will be called again. + # + # To fix this, we first fix the upgrade routine for 25to26 so it actually upgrades to "4.1", and then + # here we can upgrade from "4.1" to "4.2" safely. + # + ("preferences", 4000001): ("preferences", 4000002, upgrade.upgradePreferences), + # NOTE: All the instance containers share the same general/version, so we have to update all of them + # if any is updated. + ("quality_changes", 2000001): ("quality_changes", 2000002, upgrade.upgradeOtherContainer), + ("user", 2000001): ("user", 2000002, upgrade.upgradeOtherContainer), + ("quality", 2000001): ("quality", 2000002, upgrade.upgradeOtherContainer), + ("definition_changes", 2000001): ("definition_changes", 2000002, upgrade.upgradeOtherContainer), }, "sources": { "machine_stack": { @@ -24,6 +39,22 @@ def getMetaData(): "get_version": upgrade.getCfgVersion, "location": {"./extruders"} }, + "preferences": { + "get_version": upgrade.getCfgVersion, + "location": {"."} + }, + "quality_changes": { + "get_version": upgrade.getCfgVersion, + "location": {"./quality"} + }, + "user": { + "get_version": upgrade.getCfgVersion, + "location": {"./user"} + }, + "definition_changes": { + "get_version": upgrade.getCfgVersion, + "location": {"./machine_instances"} + } } }