From d9fb195443b5a191a0c2ec6a9a92eee01a5f529a Mon Sep 17 00:00:00 2001 From: Romolo Manfredini Date: Sat, 2 May 2015 01:00:24 +0200 Subject: [PATCH] Fix scan of floppy drive under win This should fix scan of floppy drives and also detection of non removable drives --- companion/src/radiointerface.cpp | 41 +++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/companion/src/radiointerface.cpp b/companion/src/radiointerface.cpp index de78c4152..b662a544d 100755 --- a/companion/src/radiointerface.cpp +++ b/companion/src/radiointerface.cpp @@ -361,12 +361,29 @@ bool writeEeprom(const QString &filename, ProgressWidget *progress) return false; } +#if defined WIN32 || !defined __GNUC__ +bool isRemovableMedia( QString vol ) +{ + char szDosDeviceName[MAX_PATH]; + UINT DriveType = GetDriveType( vol.replace("/","\\").toLatin1() ); + if ( DriveType != DRIVE_REMOVABLE ) + return false; + QueryDosDevice( vol.replace("/","").toLatin1(), szDosDeviceName, MAX_PATH ); + if ( strstr( szDosDeviceName,"\\Floppy") != NULL ) { // its a floppy + return false; + } + return true; +} +#endif + QString findMassstoragePath(const QString &filename) { QString temppath; QStringList drives; QString eepromfile; QString fsname; + static QStringList blacklist; + #if defined WIN32 || !defined __GNUC__ foreach(QFileInfo drive, QDir::drives()) { WCHAR szVolumeName[256] ; @@ -374,16 +391,22 @@ QString findMassstoragePath(const QString &filename) DWORD dwSerialNumber = 0; DWORD dwMaxFileNameLength=256; DWORD dwFileSystemFlags=0; - bool ret = GetVolumeInformationW( (WCHAR *) drive.absolutePath().utf16(),szVolumeName,256,&dwSerialNumber,&dwMaxFileNameLength,&dwFileSystemFlags,szFileSystemName,256); - if (ret) { - QString vName = QString::fromUtf16 ( (const ushort *) szVolumeName) ; - temppath = drive.absolutePath(); - eepromfile = temppath; - eepromfile.append("/" + filename); - if (QFile::exists(eepromfile)) { - return eepromfile; + if (!blacklist.contains(drive.absolutePath())) { + if (!isRemovableMedia( drive.absolutePath() )) { + blacklist.append(drive.absolutePath()); + } else { + bool ret = GetVolumeInformationW( (WCHAR *) drive.absolutePath().utf16(),szVolumeName,256,&dwSerialNumber,&dwMaxFileNameLength,&dwFileSystemFlags,szFileSystemName,256); + if (ret) { + QString vName = QString::fromUtf16 ( (const ushort *) szVolumeName) ; + temppath = drive.absolutePath(); + eepromfile = temppath; + eepromfile.append("/" + filename); + if (QFile::exists(eepromfile)) { + return eepromfile; + } + } } - } + } } #else struct mount_entry *entry;