fix(cpn): halt when multiple locations for read and write models and settings detected (#5657)

This commit is contained in:
Neil Horne
2024-11-11 09:49:29 +10:00
committed by GitHub
parent 100906a576
commit e871ad67d9
2 changed files with 14 additions and 11 deletions
+13 -10
View File
@@ -195,7 +195,7 @@ bool readSettings(const QString & filename, ProgressWidget * progress)
bool readSettingsSDCard(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; qDebug() << "Searching for SD card, found" << radioPath;
if (radioPath.isEmpty()) { if (radioPath.isEmpty()) {
QMessageBox::critical(progress, CPN_STR_TTL_ERROR, QMessageBox::critical(progress, CPN_STR_TTL_ERROR,
@@ -297,29 +297,32 @@ bool writeSettings(const QString & filename, ProgressWidget * progress)
return false; return false;
} }
QString findMassstoragePath(const QString & filename, bool onlyPath) QString findMassstoragePath(const QString & filename, bool onlyPath, ProgressWidget *progress)
{ {
QString temppath; QString temppath;
QString probefile; QString probefile;
bool found = false; int found = 0;
QRegularExpression fstypeRe("^(v?fat|msdos|lifs)", QRegularExpression::CaseInsensitiveOption); // Linux: "vfat"; macOS: "msdos" or "lifs"; Win: "FAT32" QRegularExpression fstypeRe("^(v?fat|msdos|lifs)", QRegularExpression::CaseInsensitiveOption); // Linux: "vfat"; macOS: "msdos" or "lifs"; Win: "FAT32"
foreach(const QStorageInfo & si, QStorageInfo::mountedVolumes()) { foreach(const QStorageInfo & si, QStorageInfo::mountedVolumes()) {
//qDebug() << si.rootPath() << si.name() << si.device() << si.displayName() << si.fileSystemType() << si.isReady(); //qDebug() << si.rootPath() << si.name() << si.device() << si.displayName() << si.fileSystemType() << si.isReady() << si.bytesTotal() << si.blockSize();
if (!si.isReady() || !QString(si.fileSystemType()).contains(fstypeRe)) if (!si.isReady() || si.isReadOnly() || !QString(si.fileSystemType()).contains(fstypeRe))
continue; continue;
temppath = si.rootPath(); temppath = si.rootPath();
probefile = temppath % "/" % filename; probefile = temppath % "/" % filename;
qDebug() << "Searching for" << probefile; qDebug() << "Searching for" << probefile;
if (QFile::exists(probefile)) { if (QFile::exists(probefile)) {
found = true; found++;
break; qDebug() << probefile << "found";
} }
} }
if (found) if (found == 1)
return onlyPath ? temppath : probefile; return onlyPath ? temppath : probefile;
else else if (found > 1) {
return QString(); QMessageBox::critical(progress, CPN_STR_TTL_ERROR, filename % " " % QCoreApplication::translate("RadioInterface", "found in multiple locations"));
}
return QString();
} }
+1 -1
View File
@@ -29,7 +29,7 @@ class ProgressWidget;
QString getRadioInterfaceCmd(); 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 getSambaArgs(const QString &tcl);
QStringList getDfuArgs(const QString &cmd, const QString &filename); QStringList getDfuArgs(const QString &cmd, const QString &filename);