From 80a5642ee31d1e47694ebb6e2d0b8b63c670f099 Mon Sep 17 00:00:00 2001 From: Phil Olynyk Date: Tue, 9 Jun 2020 17:10:25 -0400 Subject: [PATCH 1/5] Use QStorageInfo to simplify getDriveList() --- oscar/mainwindow.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/oscar/mainwindow.cpp b/oscar/mainwindow.cpp index 5162e015..58fa16cd 100644 --- a/oscar/mainwindow.cpp +++ b/oscar/mainwindow.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "common_gui.h" @@ -799,7 +800,28 @@ QStringList getDriveList() { QStringList drivelist; -#if defined(Q_OS_MAC) || defined(Q_OS_BSD4) +#if QT_VERSION >= QT_VERSION_CHECK(5,4,0) +#if defined(Q_OS_LINUX) + #define VFAT "vfat" +#elif defined(Q_OS_WIN + #define VFAT "FAT32" +#elif defined(Q_OS_MAC) + #define VFAT "FAT32" +#endif + foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) { + if (storage.isValid() && storage.isReady()) { + qDebug() << "Device:" << storage.device(); + qDebug() << " Path:" << storage.rootPath(); + qDebug() << " Name:" << storage.name(); // ... + qDebug() << " FS Type:" << storage.fileSystemType(); + if (storage.fileSystemType() == VFAT) { + qDebug() << "Adding" << storage.name() << "on" << storage.rootPath() << "to drivelist"; + drivelist.push_back(storage.rootPath()); + } + } + } + +#elif defined(Q_OS_MAC) || defined(Q_OS_BSD4) struct statfs *mounts; int num_mounts = getmntinfo(&mounts, MNT_WAIT); if (num_mounts >= 0) { From c2c61c6629718eccf55395cf917ca3091f3b3490 Mon Sep 17 00:00:00 2001 From: Phil Olynyk Date: Tue, 9 Jun 2020 22:11:34 -0400 Subject: [PATCH 2/5] Correct Mac define value and drop tmpfs from qDebug output --- oscar/mainwindow.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/oscar/mainwindow.cpp b/oscar/mainwindow.cpp index 58fa16cd..a26aa52e 100644 --- a/oscar/mainwindow.cpp +++ b/oscar/mainwindow.cpp @@ -806,14 +806,16 @@ QStringList getDriveList() #elif defined(Q_OS_WIN #define VFAT "FAT32" #elif defined(Q_OS_MAC) - #define VFAT "FAT32" + #define VFAT "msdos" #endif foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) { if (storage.isValid() && storage.isReady()) { - qDebug() << "Device:" << storage.device(); - qDebug() << " Path:" << storage.rootPath(); - qDebug() << " Name:" << storage.name(); // ... - qDebug() << " FS Type:" << storage.fileSystemType(); + if (storage.fileSystemType() != "tmpfs") { // Don't show all the Linux tmpfs mount points! + qDebug() << "Device:" << storage.device(); + qDebug() << " Path:" << storage.rootPath(); + qDebug() << " Name:" << storage.name(); // ... + qDebug() << " FS Type:" << storage.fileSystemType(); + } if (storage.fileSystemType() == VFAT) { qDebug() << "Adding" << storage.name() << "on" << storage.rootPath() << "to drivelist"; drivelist.push_back(storage.rootPath()); From 795a3a5456481bb92c6a3a2b77717f99180c8564 Mon Sep 17 00:00:00 2001 From: Phil Olynyk Date: Wed, 10 Jun 2020 15:47:25 -0400 Subject: [PATCH 3/5] add missing close paren to #elif defined(... --- oscar/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oscar/mainwindow.cpp b/oscar/mainwindow.cpp index a26aa52e..6bcb7169 100644 --- a/oscar/mainwindow.cpp +++ b/oscar/mainwindow.cpp @@ -803,7 +803,7 @@ QStringList getDriveList() #if QT_VERSION >= QT_VERSION_CHECK(5,4,0) #if defined(Q_OS_LINUX) #define VFAT "vfat" -#elif defined(Q_OS_WIN +#elif defined(Q_OS_WIN) #define VFAT "FAT32" #elif defined(Q_OS_MAC) #define VFAT "msdos" From 475bfee924a9e7daf144303052bdbd44cce0fffd Mon Sep 17 00:00:00 2001 From: Phil Olynyk Date: Wed, 10 Jun 2020 16:56:06 -0400 Subject: [PATCH 4/5] Make debug output conditional --- oscar/mainwindow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/oscar/mainwindow.cpp b/oscar/mainwindow.cpp index 6bcb7169..ecf74a2e 100644 --- a/oscar/mainwindow.cpp +++ b/oscar/mainwindow.cpp @@ -810,12 +810,14 @@ QStringList getDriveList() #endif foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) { if (storage.isValid() && storage.isReady()) { +#ifdef DEBUG_SDCARD if (storage.fileSystemType() != "tmpfs") { // Don't show all the Linux tmpfs mount points! qDebug() << "Device:" << storage.device(); qDebug() << " Path:" << storage.rootPath(); qDebug() << " Name:" << storage.name(); // ... qDebug() << " FS Type:" << storage.fileSystemType(); } +#endif if (storage.fileSystemType() == VFAT) { qDebug() << "Adding" << storage.name() << "on" << storage.rootPath() << "to drivelist"; drivelist.push_back(storage.rootPath()); From bbb2f5a5a52e8418e657d4502fa9bb2dcc261fd0 Mon Sep 17 00:00:00 2001 From: Phil Olynyk Date: Fri, 26 Jun 2020 23:17:27 -0400 Subject: [PATCH 5/5] Delete the OS-specif scanning code --- oscar/mainwindow.cpp | 51 -------------------------------------------- 1 file changed, 51 deletions(-) diff --git a/oscar/mainwindow.cpp b/oscar/mainwindow.cpp index ecf74a2e..a91cd1a6 100644 --- a/oscar/mainwindow.cpp +++ b/oscar/mainwindow.cpp @@ -824,57 +824,6 @@ QStringList getDriveList() } } } - -#elif defined(Q_OS_MAC) || defined(Q_OS_BSD4) - struct statfs *mounts; - int num_mounts = getmntinfo(&mounts, MNT_WAIT); - if (num_mounts >= 0) { - for (int i = 0; i < num_mounts; i++) { - QString name = mounts[i].f_mntonname; - - // Only interested in drives mounted under /Volumes - if (name.toLower().startsWith("/volumes/")) { - drivelist.push_back(name); -// qDebug() << QString("Disk type '%1' mounted at: %2").arg(mounts[i].f_fstypename).arg(mounts[i].f_mntonname); - } - } - } - -#elif defined(Q_OS_UNIX) && !defined(Q_OS_HAIKU) - // Unix / Linux (except BSD) - FILE *mtab = setmntent("/etc/mtab", "r"); - struct mntent *m; - struct mntent mnt; - char strings[4096]; - - // NOTE: getmntent_r is a GNU extension, requiring glibc. - while ((m = getmntent_r(mtab, &mnt, strings, sizeof(strings)))) { - - struct statfs fs; - if ((mnt.mnt_dir != NULL) && (statfs(mnt.mnt_dir, &fs) == 0)) { - QString name = mnt.mnt_dir; - quint64 size = fs.f_blocks * fs.f_bsize; - - if (size > 0) { // this should theoretically ignore /dev, /proc, /sys etc.. - drivelist.push_back(name); - } -// quint64 free = fs.f_bfree * fs.f_bsize; -// quint64 avail = fs.f_bavail * fs.f_bsize; - } - } - endmntent(mtab); - -#elif defined(Q_OS_WIN) || defined(Q_OS_HAIKU) - QFileInfoList list = QDir::drives(); - - for (int i = 0; i < list.size(); ++i) { - QFileInfo fileInfo = list.at(i); - QString name = fileInfo.filePath(); - if (name.at(0).toUpper() != QChar('C')) { // Ignore the C drive - drivelist.push_back(name); - } - } - #endif return drivelist; }