mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-17 19:20:46 +00:00
More refactoring of PRS1Loader::OpenMachine().
This commit is contained in:
parent
02ffeb6c39
commit
7c0c13486c
@ -516,17 +516,67 @@ int PRS1Loader::OpenMachine(const QString & path)
|
||||
emit updateMessage(QObject::tr("Getting Ready..."));
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
emit setProgressValue(0);
|
||||
|
||||
QStringList paths;
|
||||
QString propertyfile;
|
||||
int sessionid_base;
|
||||
sessionid_base = FindSessionDirsAndProperties(path, paths, propertyfile);
|
||||
|
||||
Machine *m = CreateMachineFromProperties(propertyfile);
|
||||
if (m == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
QString backupPath = m->getBackupPath() + path.section("/", -2);
|
||||
|
||||
if (QDir::cleanPath(path).compare(QDir::cleanPath(backupPath)) != 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
int PRS1Loader::FindSessionDirsAndProperties(const QString & path, QStringList & paths, QString & propertyfile)
|
||||
{
|
||||
QDir dir(path);
|
||||
dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks);
|
||||
dir.setSorting(QDir::Name);
|
||||
QFileInfoList flist = dir.entryInfoList();
|
||||
|
||||
QString filename;
|
||||
|
||||
emit setProgressValue(0);
|
||||
|
||||
QStringList paths;
|
||||
int sessionid_base = 10;
|
||||
QString propertyfile;
|
||||
|
||||
for (int i = 0; i < flist.size(); i++) {
|
||||
QFileInfo fi = flist.at(i);
|
||||
@ -547,9 +597,14 @@ int PRS1Loader::OpenMachine(const QString & path)
|
||||
propertyfile = fi.canonicalFilePath();
|
||||
}
|
||||
}
|
||||
return sessionid_base;
|
||||
}
|
||||
|
||||
|
||||
Machine* PRS1Loader::CreateMachineFromProperties(QString propertyfile)
|
||||
{
|
||||
MachineInfo info = newInfo();
|
||||
// Have a peek first to get the serial number.
|
||||
// Have a peek first to get the model number.
|
||||
PeekProperties(info, propertyfile);
|
||||
|
||||
QString modelstr;
|
||||
@ -589,7 +644,7 @@ int PRS1Loader::OpenMachine(const QString & path)
|
||||
QObject::tr("The developers needs a .zip copy of this machines' SD card and matching Encore .pdf reports to make it work with OSCAR.")
|
||||
,QMessageBox::Ok);
|
||||
|
||||
return -1;
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
// model number didn't parse.. Meh... Silently ignore it
|
||||
@ -598,7 +653,7 @@ int PRS1Loader::OpenMachine(const QString & path)
|
||||
// QObject::tr("OSCAR could not parse the model number, this machine can not be imported..") +"\n\n"+
|
||||
// QObject::tr("The developers needs a .zip copy of this machines' SD card and matching Encore .pdf reports to make it work with OSCAR.")
|
||||
// ,QMessageBox::Ok);
|
||||
return -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -607,43 +662,7 @@ int PRS1Loader::OpenMachine(const QString & path)
|
||||
|
||||
// This time supply the machine object so it can populate machine properties..
|
||||
PeekProperties(m->info, propertyfile, m);
|
||||
|
||||
QString backupPath = m->getBackupPath() + path.section("/", -2);
|
||||
|
||||
if (QDir::cleanPath(path).compare(QDir::cleanPath(backupPath)) != 0) {
|
||||
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;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
|
@ -253,7 +253,13 @@ 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.
|
||||
//! \brief Finds the P0,P1,... session paths and property pathname and returns the base (10 or 16) of the session filenames
|
||||
int FindSessionDirsAndProperties(const QString & path, QStringList & paths, QString & propertyfile);
|
||||
|
||||
//! \brief Reads the model number from the property file, evaluates its capabilities, and returns a machine instance
|
||||
Machine* CreateMachineFromProperties(QString propertyfile);
|
||||
|
||||
//! \brief Scans 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
|
||||
|
Loading…
Reference in New Issue
Block a user