[Companion] Speed up/fix findMassstoragePath(): Use Qt methods when available (v5.4+) and only check for path on FAT[32] file systems; For older Qt, skip root (/), /net, /proc, & /run devices on Linux/macOS; Fixes long delay on eg. macOS due to network access. Remove unused #include "mountlist.h" in process_flash.cpp. (#4937)

This commit is contained in:
Max Paperno
2017-05-20 21:34:26 +02:00
committed by Bertrand Songis
parent 1a85956dcb
commit 69576cb17d
2 changed files with 49 additions and 42 deletions
-1
View File
@@ -34,7 +34,6 @@
#define sleep(x) Sleep(x*1000) #define sleep(x) Sleep(x*1000)
#else #else
#include <unistd.h> #include <unistd.h>
#include "mountlist.h"
#endif #endif
FlashProcess::FlashProcess(const QString &cmd, const QStringList &args, ProgressWidget *progress): FlashProcess::FlashProcess(const QString &cmd, const QStringList &args, ProgressWidget *progress):
+48 -40
View File
@@ -25,15 +25,10 @@
#include "radionotfound.h" #include "radionotfound.h"
#include "burnconfigdialog.h" #include "burnconfigdialog.h"
#include "helpers.h" #include "helpers.h"
#include "mountlist.h"
#include "process_copy.h" #include "process_copy.h"
#include "storage.h" #include "storage.h"
#include "progresswidget.h" #include "progresswidget.h"
#if defined WIN32 || !defined __GNUC__
#include <windows.h>
#endif
QString getRadioInterfaceCmd() QString getRadioInterfaceCmd()
{ {
burnConfigDialog bcd; burnConfigDialog bcd;
@@ -401,7 +396,9 @@ bool writeEeprom(const QString & filename, ProgressWidget * progress)
return false; return false;
} }
#if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0))
#if defined WIN32 || !defined __GNUC__ #if defined WIN32 || !defined __GNUC__
#include <windows.h>
bool isRemovableMedia(const QString & vol) bool isRemovableMedia(const QString & vol)
{ {
char szDosDeviceName[MAX_PATH]; char szDosDeviceName[MAX_PATH];
@@ -415,61 +412,69 @@ bool isRemovableMedia(const QString & vol)
} }
return true; return true;
} }
#endif #else
#include "mountlist.h"
#endif // defined WIN32 || !defined __GNUC__
#endif // (QT_VERSION < QT_VERSION_CHECK(5, 4, 0))
QString findMassstoragePath(const QString & filename, bool onlyPath) QString findMassstoragePath(const QString & filename, bool onlyPath)
{ {
QString temppath; QString temppath;
QStringList drives;
QString eepromfile; QString eepromfile;
QString fsname; bool found = false;
QRegularExpression fstypeRe("^(v?fat|msdos)", QRegularExpression::CaseInsensitiveOption); // Linux: "vfat"; macOS: "msdos"; Win: "FAT32"
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
foreach(const QStorageInfo & si, QStorageInfo::mountedVolumes()) {
//qDebug() << si.rootPath() << si.name() << si.device() << si.displayName() << si.fileSystemType() << si.isReady();
if (!si.isReady() || !QString(si.fileSystemType()).contains(fstypeRe))
continue;
temppath = si.rootPath();
eepromfile = temppath % "/" % filename;
qDebug() << "Searching for" << eepromfile;
if (QFile::exists(eepromfile)) {
found = true;
break;
}
}
#elif defined WIN32 || !defined __GNUC__
static QStringList blacklist; static QStringList blacklist;
foreach(const QFileInfo & drive, QDir::drives()) {
#if defined WIN32 || !defined __GNUC__ temppath = drive.absolutePath();
foreach(QFileInfo drive, QDir::drives()) { if (blacklist.contains(temppath))
continue;
if (!isRemovableMedia(temppath)) {
blacklist.append(temppath);
continue;
}
WCHAR szVolumeName[256] ; WCHAR szVolumeName[256] ;
WCHAR szFileSystemName[256]; WCHAR szFileSystemName[256];
DWORD dwSerialNumber = 0; DWORD dwSerialNumber = 0;
DWORD dwMaxFileNameLength=256; DWORD dwMaxFileNameLength=256;
DWORD dwFileSystemFlags=0; DWORD dwFileSystemFlags=0;
if (!blacklist.contains(drive.absolutePath())) { if (!GetVolumeInformationW( (WCHAR *) drive.absolutePath().utf16(),szVolumeName,256,&dwSerialNumber,&dwMaxFileNameLength,&dwFileSystemFlags,szFileSystemName,256))
if (!isRemovableMedia( drive.absolutePath() )) { continue;
blacklist.append(drive.absolutePath()); eepromfile = temppath % "/" % filename;
} else { qDebug() << "Searching for" << eepromfile;
bool ret = GetVolumeInformationW( (WCHAR *) drive.absolutePath().utf16(),szVolumeName,256,&dwSerialNumber,&dwMaxFileNameLength,&dwFileSystemFlags,szFileSystemName,256); if (QFile::exists(eepromfile)) {
if (ret) { found = true;
QString vName = QString::fromUtf16 ( (const ushort *) szVolumeName) ; break;
temppath = drive.absolutePath();
eepromfile = temppath;
eepromfile.append("/" + filename);
if (QFile::exists(eepromfile)) {
return onlyPath ? temppath : eepromfile;
}
}
}
} }
} }
#else #else
const static QStringList blacklist = QStringList() << "/" << "/net" << "/proc" << "/run";
QStringList drives;
struct mount_entry *entry; struct mount_entry *entry;
struct mount_entry *firstEntry; struct mount_entry *firstEntry;
firstEntry = entry = read_file_system_list(true); firstEntry = entry = read_file_system_list(true);
while (entry != NULL) { while (entry != NULL) {
if (!drives.contains(entry->me_devname)) { temppath = entry->me_mountdir;
if (!drives.contains(entry->me_devname) && !blacklist.contains(temppath) && QString(entry->me_type).contains(fstypeRe)) {
drives.append(entry->me_devname); drives.append(entry->me_devname);
temppath = entry->me_mountdir; eepromfile = temppath % "/" % filename;
eepromfile = temppath;
eepromfile.append("/" + filename);
qDebug() << "Searching for" << eepromfile; qDebug() << "Searching for" << eepromfile;
#if !defined __APPLE__
QString fstype = entry->me_type;
// qDebug() << eepromfile;
if (fstype.contains("fat") && QFile::exists(eepromfile)) {
#else
if (QFile::exists(eepromfile)) { if (QFile::exists(eepromfile)) {
#endif found = true;
free_file_system_list(firstEntry); break;
return onlyPath ? temppath : eepromfile;
} }
} }
entry = entry->me_next; entry = entry->me_next;
@@ -477,5 +482,8 @@ QString findMassstoragePath(const QString & filename, bool onlyPath)
free_file_system_list(firstEntry); free_file_system_list(firstEntry);
#endif #endif
return QString(); if (found)
return onlyPath ? temppath : eepromfile;
else
return QString();
} }