Split out PRS1Loader::ScanFiles() from PRS1Loader::OpenMachine().

This commit is contained in:
sawinglogz 2019-05-03 15:07:15 -04:00
parent 4599dd781f
commit 7937b57b5f
2 changed files with 43 additions and 32 deletions

View File

@ -525,9 +525,7 @@ int PRS1Loader::OpenMachine(const QString & path)
emit setProgressValue(0);
QStringList paths;
int sessionid_base = 10;
QString propertyfile;
for (int i = 0; i < flist.size(); i++) {
@ -616,10 +614,48 @@ int PRS1Loader::OpenMachine(const QString & path)
copyPath(path, backupPath);
}
emit updateMessage(QObject::tr("Scanning Files..."));
QCoreApplication::processEvents();
// Walk through the files and create an import task for each logical session.
ScanFiles(paths, sessionid_base, m);
int tasks = countTasks();
unknownCodes.clear();
emit updateMessage(QObject::tr("Importing Sessions..."));
QCoreApplication::processEvents();
runTasks(AppSetting->multithreading());
emit updateMessage(QObject::tr("Finishing up..."));
QCoreApplication::processEvents();
finishAddingSessions();
if (unknownCodes.size() > 0) {
for (auto it = unknownCodes.begin(), end=unknownCodes.end(); it != end; ++it) {
qDebug() << QString("Unknown CPAP Codes '0x%1' was detected during import").arg((short)it.key(), 2, 16, QChar(0));
QStringList & strlist = it.value();
for (int i=0;i<it.value().size(); ++i) {
qDebug() << strlist.at(i);
}
}
}
return m->unsupported() ? -1 : tasks;
}
void PRS1Loader::ScanFiles(const QStringList & paths, int sessionid_base, Machine * m)
{
SessionID sid;
long ext;
QDir dir;
dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks);
dir.setSorting(QDir::Name);
int size = paths.size();
sesstasks.clear();
@ -629,9 +665,6 @@ int PRS1Loader::OpenMachine(const QString & path)
PRS1Import * task = nullptr;
// Note, I have observed p0/p1/etc folders containing duplicates session files (in Robin Sanders data.)
emit updateMessage(QObject::tr("Scanning Files..."));
QCoreApplication::processEvents();
QDateTime datetime;
QDateTime ignoreBefore = p_profile->session->ignoreOlderSessionsDate();
@ -643,12 +676,13 @@ int PRS1Loader::OpenMachine(const QString & path)
if (!dir.exists() || !dir.isReadable()) { continue; }
flist = dir.entryInfoList();
QFileInfoList flist = dir.entryInfoList();
// Scan for individual session files
for (int i = 0; i < flist.size(); i++) {
if (isAborted()) break;
QFileInfo fi = flist.at(i);
bool ok;
QString ext_s = fi.fileName().section(".", -1);
ext = ext_s.toInt(&ok);
@ -756,32 +790,6 @@ int PRS1Loader::OpenMachine(const QString & path)
}
if (isAborted()) break;
}
int tasks = countTasks();
unknownCodes.clear();
emit updateMessage(QObject::tr("Importing Sessions..."));
QCoreApplication::processEvents();
runTasks(AppSetting->multithreading());
emit updateMessage(QObject::tr("Finishing up..."));
QCoreApplication::processEvents();
finishAddingSessions();
if (unknownCodes.size() > 0) {
for (auto it = unknownCodes.begin(), end=unknownCodes.end(); it != end; ++it) {
qDebug() << QString("Unknown CPAP Codes '0x%1' was detected during import").arg((short)it.key(), 2, 16, QChar(0));
QStringList & strlist = it.value();
for (int i=0;i<it.value().size(); ++i) {
qDebug() << strlist.at(i);
}
}
}
return m->unsupported() ? -1 : tasks;
}
bool PRS1Import::ParseF5EventsFV3()

View File

@ -252,6 +252,9 @@ class PRS1Loader : public CPAPLoader
//! \brief Opens the SD folder structure for this machine, scans for data files and imports any new sessions
int OpenMachine(const QString & path);
//! \brief Scan the given directories for session data and create an import task for each logical session.
void ScanFiles(const QStringList & paths, int sessionid_base, Machine * m);
// //! \brief Parses "properties.txt" file containing machine information
// bool ParseProperties(Machine *m, QString filename);