From fce703536bad4600ed38f35a99199d4f876a34d6 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 28 Mar 2018 08:43:46 +0200 Subject: [PATCH] Move factory reset to Uranium This way it can be called from other crash handling routines there too, such as ConfigurationErrorMessage which may be triggered by arbitrary configuration errors in Uranium. Contributes to issue CURA-5045. --- cura/CrashHandler.py | 54 +------------------------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/cura/CrashHandler.py b/cura/CrashHandler.py index 4c955fe59f..46544ca0ef 100644 --- a/cura/CrashHandler.py +++ b/cura/CrashHandler.py @@ -132,59 +132,7 @@ class CrashHandler: ## Backup the current resource directories and create clean ones. def _backupAndStartClean(self): - from cura.CuraVersion import CuraVersion - # The early crash may happen before those information is set in Resources, so we need to set them here to - # make sure that Resources can find the correct place. - Resources.ApplicationIdentifier = "cura" - Resources.ApplicationVersion = CuraVersion - config_path = Resources.getConfigStoragePath() - data_path = Resources.getDataStoragePath() - cache_path = Resources.getCacheStoragePath() - - folders_to_backup = [] - folders_to_remove = [] # only cache folder needs to be removed - - folders_to_backup.append(config_path) - if data_path != config_path: - folders_to_backup.append(data_path) - - # Only remove the cache folder if it's not the same as data or config - if cache_path not in (config_path, data_path): - folders_to_remove.append(cache_path) - - for folder in folders_to_remove: - shutil.rmtree(folder, ignore_errors = True) - for folder in folders_to_backup: - base_name = os.path.basename(folder) - root_dir = os.path.dirname(folder) - - import datetime - date_now = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") - idx = 0 - file_name = base_name + "_" + date_now - zip_file_path = os.path.join(root_dir, file_name + ".zip") - while os.path.exists(zip_file_path): - idx += 1 - file_name = base_name + "_" + date_now + "_" + idx - zip_file_path = os.path.join(root_dir, file_name + ".zip") - try: - # only create the zip backup when the folder exists - if os.path.exists(folder): - # remove the .zip extension because make_archive() adds it - zip_file_path = zip_file_path[:-4] - shutil.make_archive(zip_file_path, "zip", root_dir = root_dir, base_dir = base_name) - - # remove the folder only when the backup is successful - shutil.rmtree(folder, ignore_errors = True) - - # create an empty folder so Resources will not try to copy the old ones - os.makedirs(folder, 0o0755, exist_ok=True) - - except Exception as e: - Logger.logException("e", "Failed to backup [%s] to file [%s]", folder, zip_file_path) - if not self.has_started: - print("Failed to backup [%s] to file [%s]: %s", folder, zip_file_path, e) - + Resources.factoryReset() self.early_crash_dialog.close() def _showConfigurationFolder(self):