mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
Removing unused imports, reorder them and replace windll with ctypes.windll (the same)
This commit is contained in:
parent
6cd1171051
commit
9684ca80d7
1 changed files with 13 additions and 21 deletions
|
@ -2,22 +2,14 @@
|
|||
# Copyright (c) 2013 David Braam
|
||||
# Uranium is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
from . import RemovableDrivePlugin
|
||||
|
||||
import threading
|
||||
import string
|
||||
|
||||
from ctypes import windll
|
||||
from ctypes import wintypes
|
||||
|
||||
import ctypes
|
||||
import time
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
from . import RemovableDrivePlugin
|
||||
|
||||
import string
|
||||
import ctypes
|
||||
|
||||
# WinAPI Constants that we need
|
||||
# Hardcoded here due to stupid WinDLL stuff that does not give us access to these values.
|
||||
DRIVE_REMOVABLE = 2 # [CodeStyle: Windows Enum value]
|
||||
|
@ -37,7 +29,7 @@ class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
|
|||
def checkRemovableDrives(self):
|
||||
drives = {}
|
||||
|
||||
bitmask = windll.kernel32.GetLogicalDrives()
|
||||
bitmask = ctypes.windll.kernel32.GetLogicalDrives()
|
||||
# Check possible drive letters, from A to Z
|
||||
# Note: using ascii_uppercase because we do not want this to change with locale!
|
||||
for letter in string.ascii_uppercase:
|
||||
|
@ -45,11 +37,11 @@ class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
|
|||
|
||||
# Do we really want to skip A and B?
|
||||
# GetDriveTypeA explicitly wants a byte array of type ascii. It will accept a string, but this wont work
|
||||
if bitmask & 1 and windll.kernel32.GetDriveTypeA(drive.encode("ascii")) == DRIVE_REMOVABLE:
|
||||
if bitmask & 1 and ctypes.windll.kernel32.GetDriveTypeA(drive.encode("ascii")) == DRIVE_REMOVABLE:
|
||||
volume_name = ""
|
||||
name_buffer = ctypes.create_unicode_buffer(1024)
|
||||
filesystem_buffer = ctypes.create_unicode_buffer(1024)
|
||||
error = windll.kernel32.GetVolumeInformationW(ctypes.c_wchar_p(drive), name_buffer, ctypes.sizeof(name_buffer), None, None, None, filesystem_buffer, ctypes.sizeof(filesystem_buffer))
|
||||
error = ctypes.windll.kernel32.GetVolumeInformationW(ctypes.c_wchar_p(drive), name_buffer, ctypes.sizeof(name_buffer), None, None, None, filesystem_buffer, ctypes.sizeof(filesystem_buffer))
|
||||
|
||||
if error != 0:
|
||||
volume_name = name_buffer.value
|
||||
|
@ -66,7 +58,7 @@ class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
|
|||
|
||||
# Check for the free space. Some card readers show up as a drive with 0 space free when there is no card inserted.
|
||||
free_bytes = ctypes.c_longlong(0)
|
||||
if windll.kernel32.GetDiskFreeSpaceExA(drive.encode("ascii"), ctypes.byref(free_bytes), None, None) == 0:
|
||||
if ctypes.windll.kernel32.GetDiskFreeSpaceExA(drive.encode("ascii"), ctypes.byref(free_bytes), None, None) == 0:
|
||||
continue
|
||||
|
||||
if free_bytes.value < 1:
|
||||
|
@ -80,19 +72,19 @@ class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
|
|||
def performEjectDevice(self, device):
|
||||
# Magic WinAPI stuff
|
||||
# First, open a handle to the Device
|
||||
handle = windll.kernel32.CreateFileA("\\\\.\\{0}".format(device.getId()[:-1]).encode("ascii"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, None, OPEN_EXISTING, 0, None )
|
||||
handle = ctypes.windll.kernel32.CreateFileA("\\\\.\\{0}".format(device.getId()[:-1]).encode("ascii"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, None, OPEN_EXISTING, 0, None )
|
||||
|
||||
if handle == -1:
|
||||
print(windll.kernel32.GetLastError())
|
||||
print(ctypes.windll.kernel32.GetLastError())
|
||||
return
|
||||
|
||||
result = None
|
||||
# Then, try and tell it to eject
|
||||
if not windll.kernel32.DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, None, None, None, None, None, None):
|
||||
if not ctypes.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)
|
||||
ctypes.windll.kernel32.CloseHandle(handle)
|
||||
return result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue