From e871ad67d9afbd02956c8b86af031782de115a1d Mon Sep 17 00:00:00 2001 From: Neil Horne <15316949+elecpower@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:49:29 +1100 Subject: [PATCH] fix(cpn): halt when multiple locations for read and write models and settings detected (#5657) --- companion/src/radiointerface.cpp | 23 +++++++++++++---------- companion/src/radiointerface.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/companion/src/radiointerface.cpp b/companion/src/radiointerface.cpp index f3ba59796..4e577bad0 100644 --- a/companion/src/radiointerface.cpp +++ b/companion/src/radiointerface.cpp @@ -195,7 +195,7 @@ bool readSettings(const QString & filename, ProgressWidget * progress) bool readSettingsSDCard(const QString & filename, ProgressWidget * progress) { - QString radioPath = findMassstoragePath("RADIO", true); + QString radioPath = findMassstoragePath("RADIO", true, progress); qDebug() << "Searching for SD card, found" << radioPath; if (radioPath.isEmpty()) { QMessageBox::critical(progress, CPN_STR_TTL_ERROR, @@ -297,29 +297,32 @@ bool writeSettings(const QString & filename, ProgressWidget * progress) return false; } -QString findMassstoragePath(const QString & filename, bool onlyPath) +QString findMassstoragePath(const QString & filename, bool onlyPath, ProgressWidget *progress) { QString temppath; QString probefile; - bool found = false; + int found = 0; QRegularExpression fstypeRe("^(v?fat|msdos|lifs)", QRegularExpression::CaseInsensitiveOption); // Linux: "vfat"; macOS: "msdos" or "lifs"; Win: "FAT32" 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)) + //qDebug() << si.rootPath() << si.name() << si.device() << si.displayName() << si.fileSystemType() << si.isReady() << si.bytesTotal() << si.blockSize(); + if (!si.isReady() || si.isReadOnly() || !QString(si.fileSystemType()).contains(fstypeRe)) continue; temppath = si.rootPath(); probefile = temppath % "/" % filename; qDebug() << "Searching for" << probefile; if (QFile::exists(probefile)) { - found = true; - break; + found++; + qDebug() << probefile << "found"; } } - if (found) + if (found == 1) return onlyPath ? temppath : probefile; - else - return QString(); + else if (found > 1) { + QMessageBox::critical(progress, CPN_STR_TTL_ERROR, filename % " " % QCoreApplication::translate("RadioInterface", "found in multiple locations")); + } + + return QString(); } diff --git a/companion/src/radiointerface.h b/companion/src/radiointerface.h index 28d78bf2a..d97bcd983 100644 --- a/companion/src/radiointerface.h +++ b/companion/src/radiointerface.h @@ -29,7 +29,7 @@ class ProgressWidget; QString getRadioInterfaceCmd(); -QString findMassstoragePath(const QString &filename, bool onlyPath = false); +QString findMassstoragePath(const QString &filename, bool onlyPath = false, ProgressWidget *progress = nullptr); QStringList getSambaArgs(const QString &tcl); QStringList getDfuArgs(const QString &cmd, const QString &filename);