From eb2ef1cbb9d92310d02a9615ef2eadf1984b9399 Mon Sep 17 00:00:00 2001
From: Phil Olynyk <phil@pholynyk.ca>
Date: Thu, 19 Mar 2020 17:54:48 -0400
Subject: [PATCH 1/6] Move S9 to front of model name

---
 .../SleepLib/loader_plugins/resmed_loader.cpp | 30 +++++++++++--------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/oscar/SleepLib/loader_plugins/resmed_loader.cpp b/oscar/SleepLib/loader_plugins/resmed_loader.cpp
index 625262cc..24f3836a 100644
--- a/oscar/SleepLib/loader_plugins/resmed_loader.cpp
+++ b/oscar/SleepLib/loader_plugins/resmed_loader.cpp
@@ -331,8 +331,8 @@ int ResmedLoader::Open(const QString & dirpath)
     if ( ! parseIdentTGT(path, & info, idmap) )
         return -1;
  
-#ifdef DEBUG_IDENT
     qDebug() << "Info:" << info.series << info.model << info.modelnumber << info.serial;
+#ifdef DEBUG_IDENT
     qDebug() << "IdMap size:" << idmap.size();
     foreach ( QString st , idmap.keys() ) {
         qDebug() << "Key" << st << "Value" << idmap[st];
@@ -1559,22 +1559,26 @@ QHash<QString, QString> parseIdentLine( const QString line, MachineInfo * info)
         } else if (key == "PNA") {  // Product Name
             value.replace("_"," ");
 
-        //  if (value.contains(STR_ResMed_S9)) {
-        //      value.replace(STR_ResMed_S9, "");
-        //      info->series = STR_ResMed_S9;
-        //  } else if (value.contains(STR_ResMed_AirSense10)) {
-            if (value.contains(STR_ResMed_AirSense10)) {
-                value.replace(STR_ResMed_AirSense10, "");
+            if (value.contains(STR_ResMed_S9)) {
+                value.replace("(","");
+                value.replace(")","");
+                if ( ! value.startsWith(STR_ResMed_S9)) {
+                    value.replace(STR_ResMed_S9, "");
+                    value.insert(0, " ");               // There's proablely a better way than this
+                    value.insert(0, STR_ResMed_S9);     // two step way to put "S9 " at the start
+                }
+                info->series = STR_ResMed_S9;
+            } else if (value.contains(STR_ResMed_AirSense10)) {
+        //  if (value.contains(STR_ResMed_AirSense10)) {
+        //      value.replace(STR_ResMed_AirSense10, "");
                 info->series = STR_ResMed_AirSense10;
             } else if (value.contains(STR_ResMed_AirCurve10)) {
-                value.replace(STR_ResMed_AirCurve10, "");
+        //      value.replace(STR_ResMed_AirCurve10, "");
                 info->series = STR_ResMed_AirCurve10;
-            } else {
-                value.replace(STR_ResMed_S9, "");
-                info->series = STR_ResMed_S9;
+        //  } else {
+        //      value.replace(STR_ResMed_S9, "");
+        //      info->series = STR_ResMed_S9;
             }
-        //  value.replace("(","");
-        //  value.replace(")","");
         //  if (value.contains("Adapt", Qt::CaseInsensitive)) {
         //      if (!value.contains("VPAP")) {
         //          value.replace("Adapt", QObject::tr("VPAP Adapt"));

From 0071a44f9e46f8e69f0fd0d0b1a3e3e9e58f6315 Mon Sep 17 00:00:00 2001
From: Guy Scharf <guy.oscar@moxis.com>
Date: Fri, 20 Mar 2020 10:17:28 -0700
Subject: [PATCH 2/6] Correct version identification in Windows builds.

---
 oscar/update_gitinfo.bat | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/oscar/update_gitinfo.bat b/oscar/update_gitinfo.bat
index 5e695421..4b05e755 100755
--- a/oscar/update_gitinfo.bat
+++ b/oscar/update_gitinfo.bat
@@ -12,7 +12,7 @@ git rev-parse --git-dir >nul 2>&1
 if errorlevel 1 goto GitFail
 
   for /f %%i in ('git rev-parse --abbrev-ref HEAD') do set GIT_BRANCH=%%i
-  if "%GIT_BRANCH%"=="HEAD" set GIT_BRANCH=""
+  if "%GIT_BRANCH%"=="HEAD" set GIT_BRANCH=
   for /f %%i in ('git rev-parse --short HEAD') do set GIT_REVISION=%%i
 
   git diff-index --quiet HEAD --

From da0b4e0a1f30e7795ab63235b5e7983971beb12d Mon Sep 17 00:00:00 2001
From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com>
Date: Sat, 21 Mar 2020 17:40:58 -0400
Subject: [PATCH 3/6] Bump the version number so that we don't accidentally
 call future versions beta-2 any more.

---
 oscar/VERSION | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/oscar/VERSION b/oscar/VERSION
index 3b76319b..fa5b86f6 100644
--- a/oscar/VERSION
+++ b/oscar/VERSION
@@ -1,4 +1,4 @@
 // Update the string below to set OSCAR's version and release status.
 // See https://semver.org/spec/v2.0.0.html for details on format.
 
-#define VERSION "1.1.0-beta-2"
+#define VERSION "1.1.0-beta-2.1"

From 84a2b5cfd1bad61adfc76adb99569d7c8f845ddc Mon Sep 17 00:00:00 2001
From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com>
Date: Sat, 21 Mar 2020 17:41:35 -0400
Subject: [PATCH 4/6] Fix a crash when canceling a Zeo import.

Also apply the same fix to Dreem import.

Resolves #237.
---
 oscar/SleepLib/loader_plugins/dreem_loader.cpp | 11 +++++++++++
 oscar/SleepLib/loader_plugins/dreem_loader.h   |  4 ++--
 oscar/SleepLib/loader_plugins/zeo_loader.cpp   |  2 ++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/oscar/SleepLib/loader_plugins/dreem_loader.cpp b/oscar/SleepLib/loader_plugins/dreem_loader.cpp
index 6a08dd22..872dacca 100644
--- a/oscar/SleepLib/loader_plugins/dreem_loader.cpp
+++ b/oscar/SleepLib/loader_plugins/dreem_loader.cpp
@@ -23,6 +23,17 @@
 
 static QSet<QString> s_unexpectedMessages;
 
+DreemLoader::DreemLoader()
+{
+    m_type = MT_SLEEPSTAGE;
+    csv = nullptr;
+}
+
+DreemLoader::~DreemLoader()
+{
+    closeCSV();
+}
+
 bool
 DreemLoader::Detect(const QString & path)
 {
diff --git a/oscar/SleepLib/loader_plugins/dreem_loader.h b/oscar/SleepLib/loader_plugins/dreem_loader.h
index 7fd7ed52..d318d44e 100644
--- a/oscar/SleepLib/loader_plugins/dreem_loader.h
+++ b/oscar/SleepLib/loader_plugins/dreem_loader.h
@@ -20,8 +20,8 @@ const int dreem_data_version = 2;
 class DreemLoader : public MachineLoader
 {
   public:
-    DreemLoader() { m_type = MT_SLEEPSTAGE; }
-    virtual ~DreemLoader() { }
+    DreemLoader();
+    virtual ~DreemLoader();
 
     virtual bool Detect(const QString & path);
 
diff --git a/oscar/SleepLib/loader_plugins/zeo_loader.cpp b/oscar/SleepLib/loader_plugins/zeo_loader.cpp
index c9e0c467..e282d075 100644
--- a/oscar/SleepLib/loader_plugins/zeo_loader.cpp
+++ b/oscar/SleepLib/loader_plugins/zeo_loader.cpp
@@ -23,6 +23,7 @@
 ZEOLoader::ZEOLoader()
 {
     m_type = MT_SLEEPSTAGE;
+    csv = nullptr;
 }
 
 ZEOLoader::~ZEOLoader()
@@ -85,6 +86,7 @@ int ZEOLoader::Open(const QString & dirpath)
 int ZEOLoader::OpenFile(const QString & filename)
 {
     if (!openCSV(filename)) {
+        closeCSV();
         return -1;
     }
     int count = 0;

From 9e005ac27fff43b0986326961c286318faee184d Mon Sep 17 00:00:00 2001
From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com>
Date: Sat, 21 Mar 2020 23:42:32 +0000
Subject: [PATCH 5/6] Update CONTRIBUTING with branch character limitations.

Also update the mirroring URL to Gitlab's new (September) requirement.
---
 CONTRIBUTING.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index abcdd562..99a25e9a 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -24,13 +24,14 @@ Setting aside the religious wars that can arise over any development methodology
 0. Create your own fork of the repo and configure it to stay up-to-date with the upstream repo.
 	* Go to https://gitlab.com/pholy/OSCAR-code and click on **Fork** in the top right of the project page.
 	* In your fork's sidebar, go to **Settings > Repository** then click on **Expand** for "Mirroring repositories".
-	* Enter "https://gitlab.com/pholy/OSCAR-code" for the repository **URL**, make sure the mirror is set to **Pull** and then click **Mirror repository**.
+	* Enter "https://gitlab.com/pholy/OSCAR-code.git" for the repository **URL**, make sure the mirror is set to **Pull** and then click **Mirror repository**.
 
 1. Create a branch to work on your feature or bugfix:
 
         git clone https://gitlab.com/my-repo/OSCAR-code.git
         cd OSCAR-code
         git checkout -b my-branch
+    **Note:** Because OSCAR includes the branch name in its [version string](https://semver.org/spec/v2.0.0.html), **the branch name must contain only alphanumeric characters or "-"** ([0-9a-zA-Z-]).
 
 2. Write your code, committing to your branch as you go, using `git add` and `git commit -a`.
 

From fd142ec40cf29c515f3010ec53142832c43ae492 Mon Sep 17 00:00:00 2001
From: Phil Olynyk <phil@pholynyk.ca>
Date: Mon, 23 Mar 2020 14:41:31 -0400
Subject: [PATCH 6/6] Always include sthe series name in the model name - Also
 ignore (for now) the new file type and signals of the 36039.

---
 .../SleepLib/loader_plugins/resmed_EDFinfo.h  |  2 +-
 .../SleepLib/loader_plugins/resmed_loader.cpp | 25 +++++++++++--------
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/oscar/SleepLib/loader_plugins/resmed_EDFinfo.h b/oscar/SleepLib/loader_plugins/resmed_EDFinfo.h
index 2cd8c45c..107f8adf 100644
--- a/oscar/SleepLib/loader_plugins/resmed_EDFinfo.h
+++ b/oscar/SleepLib/loader_plugins/resmed_EDFinfo.h
@@ -15,7 +15,7 @@
 #include "SleepLib/profiles.h"
 #include "SleepLib/loader_plugins/edfparser.h"
 
-enum EDFType { EDF_UNKNOWN, EDF_BRP, EDF_PLD, EDF_SAD, EDF_EVE, EDF_CSL };
+enum EDFType { EDF_UNKNOWN, EDF_BRP, EDF_PLD, EDF_SAD, EDF_EVE, EDF_CSL, EDF_AEV };
 
 EDFType lookupEDFType(const QString & filename);
 
diff --git a/oscar/SleepLib/loader_plugins/resmed_loader.cpp b/oscar/SleepLib/loader_plugins/resmed_loader.cpp
index 24f3836a..cc6441d9 100644
--- a/oscar/SleepLib/loader_plugins/resmed_loader.cpp
+++ b/oscar/SleepLib/loader_plugins/resmed_loader.cpp
@@ -1559,8 +1559,14 @@ QHash<QString, QString> parseIdentLine( const QString line, MachineInfo * info)
         } else if (key == "PNA") {  // Product Name
             value.replace("_"," ");
 
-            if (value.contains(STR_ResMed_S9)) {
-                value.replace("(","");
+            if (value.contains(STR_ResMed_AirSense10)) {
+        //      value.replace(STR_ResMed_AirSense10, "");
+                info->series = STR_ResMed_AirSense10;
+            } else if (value.contains(STR_ResMed_AirCurve10)) {
+        //      value.replace(STR_ResMed_AirCurve10, "");
+                info->series = STR_ResMed_AirCurve10;
+            } else {    // it will be a Series 9, and might not contain (STR_ResMed_S9)) 
+                value.replace("("," ");     // might sometimes have a double space... 
                 value.replace(")","");
                 if ( ! value.startsWith(STR_ResMed_S9)) {
                     value.replace(STR_ResMed_S9, "");
@@ -1568,16 +1574,7 @@ QHash<QString, QString> parseIdentLine( const QString line, MachineInfo * info)
                     value.insert(0, STR_ResMed_S9);     // two step way to put "S9 " at the start
                 }
                 info->series = STR_ResMed_S9;
-            } else if (value.contains(STR_ResMed_AirSense10)) {
-        //  if (value.contains(STR_ResMed_AirSense10)) {
-        //      value.replace(STR_ResMed_AirSense10, "");
-                info->series = STR_ResMed_AirSense10;
-            } else if (value.contains(STR_ResMed_AirCurve10)) {
-        //      value.replace(STR_ResMed_AirCurve10, "");
-                info->series = STR_ResMed_AirCurve10;
-        //  } else {
         //      value.replace(STR_ResMed_S9, "");
-        //      info->series = STR_ResMed_S9;
             }
         //  if (value.contains("Adapt", Qt::CaseInsensitive)) {
         //      if (!value.contains("VPAP")) {
@@ -1607,6 +1604,8 @@ EDFType lookupEDFType(const QString & filename)
         return EDF_SAD;
     } else if (text == "CSL") {
         return EDF_CSL;
+    } else if (text == "AEV") {
+        return EDF_AEV;
     } else return EDF_UNKNOWN;
 }
 
@@ -2111,6 +2110,7 @@ void ResDayTask::run()
                 break;
             case EDF_EVE:
             case EDF_CSL:
+            case EDF_AEV:   // this is in the 36039 - must figure out what to do with it
                 break;
             default:
                 qWarning() << "Unrecognized file type for" << filename;
@@ -2724,7 +2724,10 @@ bool ResmedLoader::LoadPLD(Session *sess, const QString & path)
             a = sess->AddEventList(code, EVL_Waveform, es.gain, es.offset, 0, 0, rate);
             a->AddWaveform(edf.startdate, es.dataArray, recs, duration);
 //          a = ToTimeDelta(sess,edf,es, code,recs,duration,0,0);
+        } else if (es.label == "Va") {  // Signal used in 36039... What to do with it???
+            a = nullptr;                // We'll skip it for now
         } else if (es.label == "") { // What the hell resmed??
+        // these empty lables should be changed in resmed_EDFInfo to something unique
             if (emptycnt == 0) {
                 code = RMS9_E01;
 //                ToTimeDelta(sess, edf, es, code, recs, duration);