Windows: Fix QDir::drives() to no longer list ejected media
Add a check using GetVolumeInformation() (modeled after QStorageInfo::ready) within a SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX scope. Remove old #ifdef used for Windows CE. [ChangeLog][QtCore][QDir] On Windows, QDir::drives() no longer returns drives whose media were ejected. Fixes: QTBUG-69029 Change-Id: I2d4a32e9281ccf3c0f2ebfa427122609aa4f327f Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
This commit is contained in:
parent
364d3da3d5
commit
69e68218e5
@ -545,23 +545,33 @@ QString QFSFileEngine::tempPath()
|
||||
return QFileSystemEngine::tempPath();
|
||||
}
|
||||
|
||||
#if !defined(Q_OS_WINRT)
|
||||
// cf QStorageInfo::isReady
|
||||
static inline bool isDriveReady(const wchar_t *path)
|
||||
{
|
||||
DWORD fileSystemFlags;
|
||||
const UINT driveType = GetDriveType(path);
|
||||
return (driveType != DRIVE_REMOVABLE && driveType != DRIVE_CDROM)
|
||||
|| GetVolumeInformation(path, nullptr, 0, nullptr, nullptr,
|
||||
&fileSystemFlags, nullptr, 0) == TRUE;
|
||||
}
|
||||
#endif // !Q_OS_WINRT
|
||||
|
||||
QFileInfoList QFSFileEngine::drives()
|
||||
{
|
||||
QFileInfoList ret;
|
||||
#if !defined(Q_OS_WINRT)
|
||||
# if defined(Q_OS_WIN32)
|
||||
const UINT oldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
||||
quint32 driveBits = (quint32) GetLogicalDrives() & 0x3ffffff;
|
||||
::SetErrorMode(oldErrorMode);
|
||||
# endif
|
||||
char driveName[] = "A:/";
|
||||
wchar_t driveName[] = L"A:\\";
|
||||
|
||||
while (driveBits) {
|
||||
if (driveBits & 1)
|
||||
ret.append(QFileInfo(QLatin1String(driveName)));
|
||||
if ((driveBits & 1) && isDriveReady(driveName))
|
||||
ret.append(QFileInfo(QString::fromWCharArray(driveName)));
|
||||
driveName[0]++;
|
||||
driveBits = driveBits >> 1;
|
||||
}
|
||||
::SetErrorMode(oldErrorMode);
|
||||
return ret;
|
||||
#else // !Q_OS_WINRT
|
||||
ret.append(QFileInfo(QLatin1String("/")));
|
||||
|
Loading…
Reference in New Issue
Block a user