diff --git a/Htmldocs/release_notes.html b/Htmldocs/release_notes.html index e1dd695c..aace2ff3 100644 --- a/Htmldocs/release_notes.html +++ b/Htmldocs/release_notes.html @@ -15,6 +15,7 @@
Portions of OSCAR are © 2019-2022 by The OSCAR Team

diff --git a/oscar/SleepLib/loader_plugins/icon_loader.cpp b/oscar/SleepLib/loader_plugins/icon_loader.cpp index 097d1e85..e0e2aa0a 100644 --- a/oscar/SleepLib/loader_plugins/icon_loader.cpp +++ b/oscar/SleepLib/loader_plugins/icon_loader.cpp @@ -35,8 +35,114 @@ FPIconLoader::~FPIconLoader() { } +/* + * getIconDir - returns the path to the ICON directory + */ +QString getIconDir2 (QString givenpath) { + + QString path = givenpath; + + path = path.replace("\\", "/"); + + if (path.endsWith("/")) { + path.chop(1); + } + + if (path.endsWith("/" + FPHCARE)) { + path = path.section("/",0,-2); + } + + QDir dir(path); + + if (!dir.exists()) { + return ""; + } + + // If this is a backup directory, higher level directories have been + // omitted. + if (path.endsWith("/Backup/", Qt::CaseInsensitive)) + return path; + + // F&P Icon have a folder called FPHCARE in the root directory + if (!dir.exists(FPHCARE)) { + return ""; + } + + // CHECKME: I can't access F&P ICON data right now + if (!dir.exists("FPHCARE/ICON")) { + return ""; + } + + return dir.filePath("FPHCARE/ICON"); +} + +/* + * getIconMachines returns a list of all Iocn machine folders in the ICON directory + */ +QStringList getIconMachines (QString iconPath) { + QStringList iconMachines; + + QDir iconDir (iconPath); + + iconDir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks); + iconDir.setSorting(QDir::Name); + + QFileInfoList flist = iconDir.entryInfoList(); // List of Icon subdirectories + + // Walk though directory list and save those that appear to be for SleepStyle machins. + for (int i = 0; i < flist.size(); i++) { + QFileInfo fi = flist.at(i); + QString filename = fi.fileName(); + + // directory is serial number and must have a SUM*.FPH file within it to be an Icon or SleepStyle folder + + QDir machineDir (iconPath + "/" + filename); + machineDir.setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::Hidden | QDir::NoSymLinks); + machineDir.setSorting(QDir::Name); + QStringList filters; + filters << "SUM*.fph"; + machineDir.setNameFilters(filters); + QFileInfoList flist = machineDir.entryInfoList(); + if (flist.size() <= 0) { + continue; + } + + // Find out what machine model this is + QFile sumFile (flist.at(0).absoluteFilePath()); + + QString line; + + sumFile.open(QIODevice::ReadOnly); + QTextStream instr(&sumFile); + for (int j = 0; j < 5; j++) { + line = ""; + QString c = ""; + while ((c = instr.read(1)) != "\r") { + line += c; + } + } + sumFile.close(); + if (line.toUpper() == "ICON") + iconMachines.push_back(filename); + + } + + return iconMachines; +} + bool FPIconLoader::Detect(const QString & givenpath) { + QString iconPath = getIconDir2(givenpath); + if (iconPath.isEmpty()) + return false; + + QStringList machines = getIconMachines(iconPath); + if (machines.length() <= 0) + // Did not find any SleepStyle machine directories + return false; + + return true; +/**** QString path = givenpath; path = path.replace("\\", "/"); @@ -87,66 +193,32 @@ bool FPIconLoader::Detect(const QString & givenpath) } } return true; +****/ } int FPIconLoader::Open(const QString & path) { - QString tmp = path; + QString iconPath = getIconDir2(path); + if (iconPath.isEmpty()) + return false; - tmp = tmp.replace("\\", "/"); - if (tmp.endsWith("/")) { - tmp.chop(1); - } - - QString newpath; - - if (tmp.endsWith("/" + FPHCARE)) { - newpath = tmp; - } else { - newpath = tmp + "/" + FPHCARE; - } - - newpath += "/ICON/"; - - QString filename; - - QDir dir(newpath); - - if ((!dir.exists() || !dir.isReadable())) { - return -1; - } - - dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks); - dir.setSorting(QDir::Name); - QFileInfoList flist = dir.entryInfoList(); - - QStringList SerialNumbers; - - bool ok; - - for (int i = 0; i < flist.size(); i++) { - QFileInfo fi = flist.at(i); - QString filename = fi.fileName(); - - filename.toInt(&ok); - - if (ok) { - SerialNumbers.push_back(filename); - } - } + QStringList serialNumbers = getIconMachines(iconPath); + if (serialNumbers.length() <= 0) + // Did not find any SleepStyle machine directories + return false; Machine *m; QString npath; int c = 0; - for (int i = 0; i < SerialNumbers.size(); i++) { + for (int i = 0; i < serialNumbers.size(); i++) { MachineInfo info = newInfo(); - info.serial = SerialNumbers[i]; + info.serial = serialNumbers[i]; m = p_profile->CreateMachine(info); - npath = newpath + "/" + info.serial; + npath = iconPath + "/" + info.serial; try { if (m) { diff --git a/oscar/SleepLib/loader_plugins/sleepstyle_loader.cpp b/oscar/SleepLib/loader_plugins/sleepstyle_loader.cpp index 01be2fe5..96ceb380 100644 --- a/oscar/SleepLib/loader_plugins/sleepstyle_loader.cpp +++ b/oscar/SleepLib/loader_plugins/sleepstyle_loader.cpp @@ -95,38 +95,47 @@ QStringList getSleepStyleMachines (QString iconPath) { QDir iconDir (iconPath); - // SleepStyle are mixed alpha and numeric; ICON serial numbers (directory names) are all digits iconDir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks); iconDir.setSorting(QDir::Name); QFileInfoList flist = iconDir.entryInfoList(); // List of Icon subdirectories - bool isIconFilename; - // Walk though directory list and save those that appear to be for SleepStyle machins. for (int i = 0; i < flist.size(); i++) { QFileInfo fi = flist.at(i); QString filename = fi.fileName(); - filename.toInt(&isIconFilename); - if (isIconFilename) // Ignore this directory if named as used for older F&P Icon machine - continue; - if (filename.length() < 8) // F&P machine names are 8 characters long, but we allow more just in case... - continue; - // directory is serial number and must not be all digits (which would make it an ICON directory) - // and it must have *.FPH files within it to be a SleepStyle folder + // directory is serial number and must have a SUM*.FPH file within it to be an Icon or SleepStyle folder QDir machineDir (iconPath + "/" + filename); machineDir.setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::Hidden | QDir::NoSymLinks); machineDir.setSorting(QDir::Name); QStringList filters; - filters << "*.fph"; + filters << "SUM*.fph"; machineDir.setNameFilters(filters); QFileInfoList flist = machineDir.entryInfoList(); if (flist.size() <= 0) { continue; } - ssMachines.push_back(filename); + + // Find out what machine model this is + QFile sumFile (flist.at(0).absoluteFilePath()); + + QString line; + + sumFile.open(QIODevice::ReadOnly); + QTextStream instr(&sumFile); + for (int j = 0; j < 5; j++) { + line = ""; + QString c = ""; + while ((c = instr.read(1)) != "\r") { + line += c; + } + } + sumFile.close(); + if (line.toUpper() == "SLEEPSTYLE") + ssMachines.push_back(filename); + } return ssMachines; diff --git a/oscar/main.cpp b/oscar/main.cpp index 3967cf5b..7e270b6a 100644 --- a/oscar/main.cpp +++ b/oscar/main.cpp @@ -666,8 +666,8 @@ int main(int argc, char *argv[]) { PRS1Loader::Register(); ResmedLoader::Register(); IntellipapLoader::Register(); - FPIconLoader::Register(); SleepStyleLoader::Register(); + FPIconLoader::Register(); WeinmannLoader::Register(); CMS50Loader::Register(); CMS50F37Loader::Register();