Skip to content

Commit

Permalink
fix(cpn): halt when multiple locations for read and write models and …
Browse files Browse the repository at this point in the history
…settings detected (#5657)
  • Loading branch information
elecpower authored Nov 10, 2024
1 parent 100906a commit e871ad6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions companion/src/radiointerface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion companion/src/radiointerface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e871ad6

Please sign in to comment.