Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading