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)
{
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();
}