Fixes for restoring preferences on Linux

This commit is contained in:
ChrisTerBeke 2018-05-14 10:16:14 +02:00
parent 30d66fb8de
commit 2ed4b1b014
2 changed files with 12 additions and 10 deletions

View file

@ -38,15 +38,17 @@ class Backup:
""" """
cura_release = CuraApplication.getInstance().getVersion() cura_release = CuraApplication.getInstance().getVersion()
version_data_dir = Resources.getDataStoragePath() version_data_dir = Resources.getDataStoragePath()
preferences_file_name = CuraApplication.getInstance().getApplicationName()
preferences_file = Resources.getPath(Resources.Preferences, "{}.cfg".format(preferences_file_name))
Logger.log("d", "Creating backup for Cura %s, using folder %s", cura_release, version_data_dir) Logger.log("d", "Creating backup for Cura %s, using folder %s", cura_release, version_data_dir)
# We copy the preferences file to the user data directory in Linux as it's in a different location there. # We copy the preferences file to the user data directory in Linux as it's in a different location there.
# When restoring a backup on Linux, we copy it back. # When restoring a backup on Linux, we move it back.
if Platform.isLinux(): if Platform.isLinux():
shutil.copyfile(preferences_file, os.path.join(version_data_dir, "{}.cfg".format(preferences_file_name))) preferences_file_name = CuraApplication.getInstance().getApplicationName()
preferences_file = Resources.getPath(Resources.Preferences, "{}.cfg".format(preferences_file_name))
backup_preferences_file = os.path.join(version_data_dir, "{}.cfg".format(preferences_file_name))
Logger.log("d", "Copying preferences file from %s to %s", preferences_file, backup_preferences_file)
shutil.copyfile(preferences_file, backup_preferences_file)
# Ensure all current settings are saved. # Ensure all current settings are saved.
CuraApplication.getInstance().saveSettings() CuraApplication.getInstance().saveSettings()
@ -127,10 +129,12 @@ class Backup:
extracted = self._extractArchive(archive, version_data_dir) extracted = self._extractArchive(archive, version_data_dir)
# Under Linux, preferences are stored elsewhere, so we copy the file to there. # Under Linux, preferences are stored elsewhere, so we copy the file to there.
preferences_file_name = CuraApplication.getInstance().getApplicationName()
preferences_file = Resources.getPath(Resources.Preferences, "{}.cfg".format(preferences_file_name))
if Platform.isLinux(): if Platform.isLinux():
shutil.move(os.path.join(version_data_dir, "{}.cfg".format(preferences_file)), preferences_file) preferences_file_name = CuraApplication.getInstance().getApplicationName()
preferences_file = Resources.getPath(Resources.Preferences, "{}.cfg".format(preferences_file_name))
backup_preferences_file = os.path.join(version_data_dir, "{}.cfg".format(preferences_file_name))
Logger.log("d", "Moving preferences file from %s to %s", backup_preferences_file, preferences_file)
shutil.move(backup_preferences_file, preferences_file)
return extracted return extracted

View file

@ -36,8 +36,6 @@ class BackupsManager:
Logger.log("w", "Tried to restore a backup without specifying a Cura version number.") Logger.log("w", "Tried to restore a backup without specifying a Cura version number.")
return return
# TODO: first make a new backup to prevent data loss when restoring fails.
self._disableAutoSave() self._disableAutoSave()
backup = Backup(zip_file = zip_file, meta_data = meta_data) backup = Backup(zip_file = zip_file, meta_data = meta_data)
@ -45,7 +43,7 @@ class BackupsManager:
if restored: if restored:
# At this point, Cura will need to restart for the changes to take effect. # At this point, Cura will need to restart for the changes to take effect.
# We don't want to store the data at this point as that would override the just-restored backup. # We don't want to store the data at this point as that would override the just-restored backup.
CuraApplication.getInstance().windowClosed(safe_data=False) CuraApplication.getInstance().windowClosed(save_data=False)
def _disableAutoSave(self): def _disableAutoSave(self):
"""Here we try to disable the auto-save plugin as it might interfere with restoring a backup.""" """Here we try to disable the auto-save plugin as it might interfere with restoring a backup."""