Make search for PRS1 "P-Series" folder truly case-insensitive.

This commit is contained in:
sawinglogz 2020-03-09 10:48:10 -04:00
parent c8520c8449
commit 485be366aa
2 changed files with 22 additions and 6 deletions

View File

@ -470,18 +470,31 @@ QString PRS1Loader::checkDir(const QString & path)
return machpath;
}
QString PRS1Loader::GetPSeriesPath(const QString & path)
{
QString outpath = "";
QDir root(path);
QStringList dirs = root.entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks);
for (auto & dir : dirs) {
// We've seen P-Series, P-SERIES, and p-series, so we need to search for the directory
// in a way that won't break on a case-sensitive filesystem.
if (dir.toUpper() == "P-SERIES") {
outpath = path + QDir::separator() + dir;
break;
}
}
return outpath;
}
QStringList PRS1Loader::FindMachinesOnCard(const QString & cardPath)
{
QStringList machinePaths;
QString pseriesPath = this->GetPSeriesPath(cardPath);
QDir pseries(pseriesPath);
// If it contains a P-Series folder, it's a PRS1 SD card
QDir pseries(cardPath + QDir::separator() + "P-Series");
if (!pseries.exists()) {
// Check for the all-caps version in case this is on a case-sensitive filesystem.
pseries = QDir(cardPath + QDir::separator() + "P-SERIES");
}
if (pseries.exists()) {
if (!pseriesPath.isEmpty() && pseries.exists()) {
pseries.setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks);
pseries.setSorting(QDir::Name);
QFileInfoList plist = pseries.entryInfoList();

View File

@ -444,6 +444,9 @@ class PRS1Loader : public CPAPLoader
QString last;
QHash<QString, Machine *> PRS1List;
//! \brief Returns the path of the P-Series folder (whatever case) if present on the card
QString GetPSeriesPath(const QString & path);
//! \brief Returns the path for each machine detected on an SD card, from oldest to newest
QStringList FindMachinesOnCard(const QString & cardPath);