Skip to content

Commit

Permalink
Also handle multi-partition drive insertion/removal
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 25, 2018
1 parent af4a1df commit 5173744
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/native/win/qgswinnative.cpp
Expand Up @@ -173,14 +173,22 @@ bool QgsWinNativeEventFilter::nativeEventFilter( const QByteArray &, void *messa
unsigned long deviceType = reinterpret_cast<DEV_BROADCAST_HDR *>( lParam )->dbch_devicetype; unsigned long deviceType = reinterpret_cast<DEV_BROADCAST_HDR *>( lParam )->dbch_devicetype;
if ( deviceType == DBT_DEVTYP_VOLUME ) if ( deviceType == DBT_DEVTYP_VOLUME )
{ {
// need to handle disks with multiple partitions -- these are given by a single event
unsigned long unitmask = reinterpret_cast<DEV_BROADCAST_VOLUME *>( lParam )->dbcv_unitmask; unsigned long unitmask = reinterpret_cast<DEV_BROADCAST_VOLUME *>( lParam )->dbcv_unitmask;
for ( int i = 0; i < 32; ++i ) std::vector< QString > drives;
char driveName[] = "A:/";
unitmask &= 0x3ffffff;
while ( unitmask )
{ {
if ( ( unitmask & ( 1 << i ) ) != 0 ) if ( unitmask & 0x1 )
{ drives.emplace_back( QString::fromLatin1( driveName ) );
const QChar drive( 65 + i ); ++driveName[0];
emit usbStorageNotification( QStringLiteral( "%1:/" ).arg( drive ), wParam == DBT_DEVICEARRIVAL ); unitmask >>= 1;
} }

for ( const QString &drive : drives )
{
emit usbStorageNotification( QStringLiteral( "%1:/" ).arg( drive ), wParam == DBT_DEVICEARRIVAL );
} }
} }
} }
Expand Down

0 comments on commit 5173744

Please sign in to comment.