Use LAST . to find file extension

This commit is contained in:
Phil Olynyk 2017-11-12 11:40:02 -05:00
parent e5bcb16b30
commit c3fc4bb267
3 changed files with 16 additions and 8 deletions

View File

@ -121,7 +121,7 @@ int CMS50Loader::Open(QString path)
setStatus(LIVE); setStatus(LIVE);
return 1; return 1;
} }
QString ext = path.section(".",1); QString ext = path.section(".", -1); // find the last '.'
if ((ext.compare("spo2", Qt::CaseInsensitive)==0) || (ext.compare("spo", Qt::CaseInsensitive)==0) || (ext.compare("spor", Qt::CaseInsensitive)==0)) { if ((ext.compare("spo2", Qt::CaseInsensitive)==0) || (ext.compare("spo", Qt::CaseInsensitive)==0) || (ext.compare("spor", Qt::CaseInsensitive)==0)) {
// try to read and process SpoR file.. // try to read and process SpoR file..
return readSpoRFile(path) ? 1 : 0; return readSpoRFile(path) ? 1 : 0;
@ -536,17 +536,21 @@ bool CMS50Loader::readSpoRFile(QString path)
{ {
QFile file(path); QFile file(path);
if (!file.exists()) { if (!file.exists()) {
qWarning() << "Can't find the oximeter file: " << path;
return false; return false;
} }
if (!file.open(QFile::ReadOnly)) { if (!file.open(QFile::ReadOnly)) {
qWarning() << "Can't open the oximeter file: " << path;
return false; return false;
} }
bool spo2header = false; bool spo2header = false;
QString ext = path.section('.', -1); QString ext = path.section('.', -1);
qDebug() << "Oximeter file extention is " << ext;
if (ext.compare("spo2",Qt::CaseInsensitive) == 0) { if (ext.compare("spo2",Qt::CaseInsensitive) == 0) {
spo2header = true; spo2header = true;
qDebug() << "Oximeter file looks like an SpO2 type" ;
} }
QByteArray data; QByteArray data;
@ -591,7 +595,7 @@ bool CMS50Loader::readSpoRFile(QString path)
quint32 hour, minute, second; quint32 hour, minute, second;
if (data.at(pos) != 1) { if (data.at(pos) != 1) {
qWarning() << ".spo2 file" << path << "might be a different"; qWarning() << "oximeter file" << path << "might be odd format";
} }
// Unknown cruft header... // Unknown cruft header...

View File

@ -72,7 +72,7 @@ bool CMS50F37Loader::openDevice()
b = scanDevice("rfcomm", 0, 0); // Linux b = scanDevice("rfcomm", 0, 0); // Linux
} }
if (!b) { if (!b) {
qDebug() << "No oximeter found"; qWarning() << "No oximeter found";
return false; return false;
} }
} }
@ -154,7 +154,7 @@ int CMS50F37Loader::Open(QString path)
} else if (path.compare("live") == 0) { } else if (path.compare("live") == 0) {
return 0; return 0;
} }
QString ext = path.section(".",1); QString ext = path.section(".", -1); // find the LAST '.'
if ((ext.compare("spo2", Qt::CaseInsensitive)==0) || (ext.compare("spo", Qt::CaseInsensitive)==0) || (ext.compare("spor", Qt::CaseInsensitive)==0)) { if ((ext.compare("spo2", Qt::CaseInsensitive)==0) || (ext.compare("spo", Qt::CaseInsensitive)==0) || (ext.compare("spor", Qt::CaseInsensitive)==0)) {
// try to read and process SpoR file.. // try to read and process SpoR file..
return readSpoRFile(path) ? 1 : 0; return readSpoRFile(path) ? 1 : 0;
@ -815,7 +815,7 @@ void CMS50F37Loader::resetImportTimeout()
qDebug() << "Oximeter device stopped transmitting.. Transfer complete"; qDebug() << "Oximeter device stopped transmitting.. Transfer complete";
// We were importing, but now are done // We were importing, but now are done
if (!finished_import && (started_import && started_reading)) { if (!finished_import && (started_import && started_reading)) {
qDebug() << "Switching CMS50 back to live mode and finalizing import"; qDebug() << "Switching CMS50F37 back to live mode and finalizing import";
// Turn back on live streaming so the end of capture can be dealt with // Turn back on live streaming so the end of capture can be dealt with
@ -835,7 +835,7 @@ void CMS50F37Loader::resetImportTimeout()
return; return;
} }
qDebug() << "Should CMS50 resetImportTimeout reach here?"; qDebug() << "Should CMS50F37 resetImportTimeout reach here?";
// else what??? // else what???
} }
cb_reset = imp_callbacks; cb_reset = imp_callbacks;
@ -853,17 +853,21 @@ bool CMS50F37Loader::readSpoRFile(QString path)
{ {
QFile file(path); QFile file(path);
if (!file.exists()) { if (!file.exists()) {
qWarning() << "Can't find the oximeter file: " << path;
return false; return false;
} }
if (!file.open(QFile::ReadOnly)) { if (!file.open(QFile::ReadOnly)) {
qWarning() << "Can't open the oximeter file: " << path;
return false; return false;
} }
bool spo2header = false; bool spo2header = false;
QString ext = path.section('.', -1); QString ext = path.section('.', -1);
qDebug() << "Oximeter file extention is " << ext;
if (ext.compare("spo2",Qt::CaseInsensitive) == 0) { if (ext.compare("spo2",Qt::CaseInsensitive) == 0) {
spo2header = true; spo2header = true;
qDebug() << "Oximeter file looks like an SpO2 type" ;
} }
QByteArray data; QByteArray data;
@ -897,7 +901,7 @@ bool CMS50F37Loader::readSpoRFile(QString path)
QString dstr(dchr); QString dstr(dchr);
m_startTime = QDateTime::fromString(dstr, "MM/dd/yy HH:mm:ss"); m_startTime = QDateTime::fromString(dstr, "MM/dd/yy HH:mm:ss");
if (m_startTime.date().year() < 2000) { m_startTime = m_startTime.addYears(100); } if (m_startTime.date().year() < 2000) { m_startTime = m_startTime.addYears(100); }
} else { } else { // this should probaly find the most recent SH data day
m_startTime = QDateTime(QDate::currentDate(), QTime(0,0,0)); m_startTime = QDateTime(QDate::currentDate(), QTime(0,0,0));
} }
} else { // !spo2header } else { // !spo2header

View File

@ -95,7 +95,7 @@ int MD300W1Loader::Open(QString path)
setStatus(LIVE); setStatus(LIVE);
return 1; return 1;
} }
QString ext = path.section(".",1); QString ext = path.section(".", -1); // find the last '.'
if (ext.compare("dat", Qt::CaseInsensitive)==0) { if (ext.compare("dat", Qt::CaseInsensitive)==0) {
// try to read and process SpoR file.. // try to read and process SpoR file..
return readDATFile(path) ? 1 : 0; return readDATFile(path) ? 1 : 0;