Skip to content

Commit

Permalink
Use GetDiskFreeSpace instead; this filters unmounted removable drives…
Browse files Browse the repository at this point in the history
… (which GetDriveType returns as removable)

Maybe require size to be greater than some amount, but for now that is good.
  • Loading branch information
akedrou committed Jul 19, 2011
1 parent 846621b commit e62670f
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/Dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,18 +510,21 @@ def __init__(self, engine, masks, path, prompt = "", dirSelect = False):
self.time = 0.0
self.menu = None

self.TOPLEVEL = "?top" #An invalid filesystem character so the top-level-ness is marked

self.driveLetters = None
if os.name == "nt":
import win32api, win32file
driveLetters=win32api.GetLogicalDriveStrings().split('\x00')[:-1]
self.driveLetters = []
#Here we should filter some drives out. Unmounted drives for sure, but also optical drives and RAM disks.
#This leaves fixed, removable, and remote drives.
okDrives = [win32file.DRIVE_REMOVABLE, win32file.DRIVE_FIXED, win32file.DRIVE_REMOTE]
#Here we should filter some drives out. Anything inaccessible, or with no space.
for drive in driveLetters:
driveType = win32file.GetDriveType(drive)
if driveType in okDrives:
self.driveLetters.append(drive)
try:
size = win32file.GetDiskFreeSpaceEx(drive)
if size > 0:
self.driveLetters.append(drive)
except:
pass

if self.engine.data.logClassInits == 1:
Log.debug("FileChooser class init (Dialogs.py)...")
Expand All @@ -535,7 +538,7 @@ def _getFileText(self, fileName):
f = os.path.join(self.path, fileName)
if fileName == "..":
return _("[Parent Folder]")
if self.path == "?toplevel":
if self.path == self.TOPLEVEL:
return _("%s [Drive]") % fileName
else:
if self.dirSelect == True:
Expand All @@ -559,7 +562,7 @@ def getFiles(self):
continue
files.append(fn)
files.sort()
if self.dirSelect == True and self.path!="?toplevel":
if self.dirSelect == True and self.path!=self.TOPLEVEL:
files.insert(0, self.path)
return files

Expand All @@ -570,17 +573,17 @@ def updateFiles(self):
if self.menu:
self.engine.view.popLayer(self.menu)

if self.path == "?toplevel" and os.name != "nt":
if self.path == self.TOPLEVEL and os.name != "nt":
self.path = "/"

if self.path == "?toplevel":
if self.path == self.TOPLEVEL:
self.menu = Menu(self.engine, choices = [(self._getFileText(f), self._getFileCallback(f)) for f in self.getDisks()], onClose = self.close, onCancel = self.cancel)
else:
self.menu = Menu(self.engine, choices = [(self._getFileText(f), self._getFileCallback(f)) for f in self.getFiles()], onClose = self.close, onCancel = self.cancel)
self.engine.view.pushLayer(self.menu)

def chooseFile(self, fileName):
if self.dirSelect == True and self.path != "?toplevel":
if self.dirSelect == True and self.path != self.TOPLEVEL:
for mask in self.masks:
if fnmatch.fnmatch(fileName, mask):
self.selectedFile = fileName
Expand All @@ -590,13 +593,13 @@ def chooseFile(self, fileName):
self.menu = None
return

if self.path == "?toplevel":
if self.path == self.TOPLEVEL:
self.path = ""
path = os.path.abspath(os.path.join(self.path, fileName))

if os.path.isdir(path):
if path == self.path and fileName == "..":
self.path = "?toplevel"
self.path = self.TOPLEVEL
else:
self.path = path
self.updateFiles()
Expand Down

0 comments on commit e62670f

Please sign in to comment.