From feaef445591e9028c1ad41f33f7f2daae5f31f70 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 12 May 2016 08:46:13 +0200 Subject: Windows: Suppress error dialogs when querying logical drives. Set the error mode flag SEM_NOOPENFILEERRORBOX when calling Win32 API GetLogicalDrives() to prevent it from prompting to insert media as does QStorageInfoPrivate::mountedVolumes(). Task-number: QTBUG-18729 Task-number: QTBUG-32457 Change-Id: I5c76afbb5bf2ec5ec84194650c316fe531578d5b Reviewed-by: Oliver Wolff --- src/corelib/io/qfilesystemengine_win.cpp | 2 ++ src/corelib/io/qfsfileengine_win.cpp | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src') diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index e55ab0b544..257bd4a50e 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -879,7 +879,9 @@ static bool tryDriveUNCFallback(const QFileSystemEntry &fname, QFileSystemMetaDa #if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) if (fname.isDriveRoot()) { // a valid drive ?? + const UINT oldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); DWORD drivesBitmask = ::GetLogicalDrives(); + ::SetErrorMode(oldErrorMode); int drivebit = 1 << (fname.filePath().at(0).toUpper().unicode() - QLatin1Char('A').unicode()); if (drivesBitmask & drivebit) { fileAttrib = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM; diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 886d526fb1..689251a6c7 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -626,7 +626,9 @@ QFileInfoList QFSFileEngine::drives() QFileInfoList ret; #if !defined(Q_OS_WINCE) && !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:/"; -- cgit v1.2.3