diff --git a/plugins/LegacyProfileReader/LegacyProfileReader.py b/plugins/LegacyProfileReader/LegacyProfileReader.py index 61fbe3d815..bd38b50a84 100644 --- a/plugins/LegacyProfileReader/LegacyProfileReader.py +++ b/plugins/LegacyProfileReader/LegacyProfileReader.py @@ -23,6 +23,19 @@ class LegacyProfileReader(ProfileReader): def __init__(self): super().__init__() + ## Prepares the default values of all legacy settings. + # + # These are loaded from the Dictionary of Doom. + # + # \param json The JSON file to load the default setting values from. This + # should not be a URL but a pre-loaded JSON handle. + # \return A dictionary of the default values of the legacy Cura version. + def prepareDefaults(self, json): + defaults = {} + for key in json["defaults"]: #We have to copy over all defaults from the JSON handle to a normal dict. + defaults[key] = json["defaults"][key] + return defaults + ## Prepares the local variables that can be used in evaluation of computing # new setting values from the old ones. # @@ -34,14 +47,11 @@ class LegacyProfileReader(ProfileReader): # legacy profile. # \param config_section The section in the profile where the settings # should be found. - # \param json The JSON file to load the default setting values from. This - # should not be an URL but a pre-loaded JSON handle. + # \param defaults The default values for all settings in the legacy Cura. # \return A set of local variables, one for each setting in the legacy # profile. - def prepareLocals(self, config_parser, config_section, json): - locals = {} - for key in json["defaults"]: #We have to copy over all defaults from the JSON handle to a normal dict. - locals[key] = json["defaults"][key] + def prepareLocals(self, config_parser, config_section, defaults): + locals = defaults.copy() #Don't edit the original! for option in config_parser.options(config_section): locals[option] = config_parser.get(config_section, option) return locals @@ -84,7 +94,8 @@ class LegacyProfileReader(ProfileReader): Logger.log("e", "Could not parse DictionaryOfDoom.json: %s", str(e)) return None - legacy_settings = self.prepareLocals(parser, section, dict_of_doom) #Gets the settings from the legacy profile. + defaults = self.prepareDefaults(dict_of_doom) + legacy_settings = self.prepareLocals(parser, section, defaults) #Gets the settings from the legacy profile. #Check the target version in the Dictionary of Doom with this application version. if "target_version" not in dict_of_doom: @@ -102,10 +113,11 @@ class LegacyProfileReader(ProfileReader): compiled = compile(old_setting_expression, new_setting, "eval") try: new_value = eval(compiled, {"math": math}, legacy_settings) #Pass the legacy settings as local variables to allow access to in the evaluation. + value_using_defaults = eval(compiled, {"math": math}, defaults) #Evaluate again using only the default values to try to see if they are default. except Exception as e: #Probably some setting name that was missing or something else that went wrong in the ini file. Logger.log("w", "Setting " + new_setting + " could not be set because the evaluation failed. Something is probably missing from the imported legacy profile.") continue - if profile.getSettingValue(new_setting) != new_value: #Not equal to the default. + if new_value != value_using_defaults and profile.getSettingValue(new_setting) != new_value: #Not equal to the default in the new Cura OR the default in the legacy Cura. profile.setSettingValue(new_setting, new_value) #Store the setting in the profile! return profile \ No newline at end of file