From de533b660e2b7bcb66ec7c7f6215b51b60ed7aed Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Tue, 29 Sep 2015 16:27:13 +0200 Subject: [PATCH] Catch any exception that happens while trying to eject This should prevent crashes on eject on any platform. CURA-106 #done --- .../RemovableDriveOutputDevice/RemovableDrivePlugin.py | 6 +++++- .../WindowsRemovableDrivePlugin.py | 9 +++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/RemovableDriveOutputDevice/RemovableDrivePlugin.py b/plugins/RemovableDriveOutputDevice/RemovableDrivePlugin.py index 2cf1cafde9..1a095e2a68 100644 --- a/plugins/RemovableDriveOutputDevice/RemovableDrivePlugin.py +++ b/plugins/RemovableDriveOutputDevice/RemovableDrivePlugin.py @@ -37,7 +37,11 @@ class RemovableDrivePlugin(OutputDevicePlugin): raise NotImplementedError() def ejectDevice(self, device): - result = self.performEjectDevice(device) + try: + result = self.performEjectDevice(device) + except Exception as e: + result = False + if result: message = Message(catalog.i18nc("@info:status", "Ejected {0}. You can now safely remove the drive.").format(device.getName())) message.show() diff --git a/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py b/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py index 5e14bf933e..3723d48231 100644 --- a/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py +++ b/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py @@ -88,13 +88,10 @@ class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin): result = None # Then, try and tell it to eject - try: - if not windll.kernel32.DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, None, None, None, None, None, None): - result = False - else: - result = True - except Exception as e: + if not windll.kernel32.DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, None, None, None, None, None, None): result = False + else: + result = True # Finally, close the handle windll.kernel32.CloseHandle(handle)