Browse Source

Fixes for early crash dialog

CURA-4895
Lipu Fei 7 years ago
parent
commit
30b1e74881
2 changed files with 8 additions and 2 deletions
  1. 7 1
      cura/CrashHandler.py
  2. 1 1
      cura_app.py

+ 7 - 1
cura/CrashHandler.py

@@ -13,6 +13,7 @@ import ssl
 import urllib.request
 import urllib.error
 import shutil
+import sys
 
 from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QTextEdit, QGroupBox, QCheckBox, QPushButton
@@ -140,6 +141,11 @@ class CrashHandler:
         if cache_path not in (config_path, data_path):
             folders_to_remove.append(cache_path)
 
+        # need to close the redirected stdout and stderr files, otherwise, on Windows, those opened files will prevent
+        # the directory removal calls below.
+        sys.stdout.close()
+        sys.stderr.close()
+
         for folder in folders_to_remove:
             shutil.rmtree(folder, ignore_errors = True)
         for folder in folders_to_backup:
@@ -159,7 +165,7 @@ class CrashHandler:
                 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)
+                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)
 

+ 1 - 1
cura_app.py

@@ -101,7 +101,7 @@ def exceptHook(hook_type, value, traceback):
         _crash_handler = CrashHandler(hook_type, value, traceback, has_started)
         if not has_started:
             CuraApplication.getInstance().removePostedEvents(None)
-            _crash_handler.show()
+            _crash_handler.early_crash_dialog.show()
             sys.exit(CuraApplication.getInstance().exec_())
         else:
             _crash_handler.show()