From 1c2db29ccea6ce83413887ab1be22fd6d367a5d5 Mon Sep 17 00:00:00 2001
From: LoudSnorer <Just4Me.1947@gmail.com>
Date: Mon, 30 Oct 2023 12:47:22 -0400
Subject: [PATCH] long vs quint32 issues in Linux. Need for iBreeze on linux
 with i7core

---
 oscar/SleepLib/loader_plugins/prs1_loader.cpp |  2 +-
 oscar/SleepLib/machine.cpp                    |  3 +++
 oscar/SleepLib/machine.h                      |  3 +--
 oscar/SleepLib/machine_common.h               |  5 +++--
 oscar/SleepLib/session.cpp                    | 15 ++++++++-------
 5 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/oscar/SleepLib/loader_plugins/prs1_loader.cpp b/oscar/SleepLib/loader_plugins/prs1_loader.cpp
index d25099a8..b2f18b55 100644
--- a/oscar/SleepLib/loader_plugins/prs1_loader.cpp
+++ b/oscar/SleepLib/loader_plugins/prs1_loader.cpp
@@ -2302,7 +2302,7 @@ QList<PRS1DataChunk *> PRS1Import::CoalesceWaveformChunks(QList<PRS1DataChunk *>
         QFileInfo fi(chunk->m_path);
         bool numeric;
         QString session_s = fi.fileName().section(".", 0, -2);
-        qint32 sid = session_s.toInt(&numeric, m_sessionid_base);
+        quint32 sid = session_s.toInt(&numeric, m_sessionid_base);
         if (!numeric || sid != chunk->sessionid) {
             qWarning() << chunk->m_path << "@" << chunk->m_filepos << "session ID mismatch:" << chunk->sessionid;
         }
diff --git a/oscar/SleepLib/machine.cpp b/oscar/SleepLib/machine.cpp
index a0bdc024..449c47c0 100644
--- a/oscar/SleepLib/machine.cpp
+++ b/oscar/SleepLib/machine.cpp
@@ -628,6 +628,9 @@ void Machine::setInfo(MachineInfo inf)
     m_loader = GetLoader(inf.loadername);
 }
 
+QString toHexid(quint32 id) { return QString("%1").arg(id,8,16,QLatin1Char('0')); };
+QString Machine::hexid() { return toHexid((qint32)m_id);};
+
 const QString Machine::getDataPath()
 {
     // TODO: Rework the underlying database so that file storage doesn't rely on consistent presence or absence of the serial number.
diff --git a/oscar/SleepLib/machine.h b/oscar/SleepLib/machine.h
index 58c6f72c..798964cb 100644
--- a/oscar/SleepLib/machine.h
+++ b/oscar/SleepLib/machine.h
@@ -159,8 +159,7 @@ class Machine
 
 
     //! \brief Returns the machineID as a lower case hexadecimal string
-    QString hexid() { return QString::asprintf("%08lx", m_id); }
-
+    QString hexid() ;
 
     //! \brief Unused, increments the most recent sessionID
     SessionID CreateSessionID() { return highest_sessionid + 1; }
diff --git a/oscar/SleepLib/machine_common.h b/oscar/SleepLib/machine_common.h
index 8b704ebd..f848a4c7 100644
--- a/oscar/SleepLib/machine_common.h
+++ b/oscar/SleepLib/machine_common.h
@@ -23,10 +23,11 @@ using namespace std;
 
 // Do not change these without considering the consequences.. For one the Loader needs changing & version increase
 typedef quint32 ChannelID;
-typedef long MachineID;
-typedef long SessionID;
+typedef quint32 MachineID;
+typedef quint32 SessionID;
 typedef float EventDataType;
 typedef qint16 EventStoreType;
+extern QString toHexid(quint32);
 
 //! \brief Exception class for out of Bounds error.. Unused.
 class BoundsError {};
diff --git a/oscar/SleepLib/session.cpp b/oscar/SleepLib/session.cpp
index 3cc6532b..d5bcd394 100644
--- a/oscar/SleepLib/session.cpp
+++ b/oscar/SleepLib/session.cpp
@@ -21,6 +21,7 @@
 #include <algorithm>
 #include <limits>
 
+#include "SleepLib/machine_common.h"
 #include "SleepLib/calcs.h"
 #include "SleepLib/profiles.h"
 
@@ -110,7 +111,7 @@ void Session::setEnabled(bool b)
 
 QString Session::eventFile() const
 {
-    return s_machine->getEventsPath()+QString::asprintf("%08lx.001", s_session);
+    return s_machine->getEventsPath()+toHexid(s_session)+".001";
 }
 
 //const int max_pack_size=128;
@@ -145,7 +146,7 @@ bool Session::Destroy()
 {
     QDir dir;
     QString base;
-    base=QString::asprintf("%08lx", s_session);
+    base=toHexid(s_session);
 
     QString summaryfile = s_machine->getSummariesPath() + base + ".000";
     QString eventfile = s_machine->getEventsPath() + base + ".001";
@@ -320,7 +321,7 @@ bool Session::StoreSummary()
         return false;
     }
 
-    QString filename = s_machine->getSummariesPath() + QString::asprintf("%08lx.000", s_session) ;
+    QString filename = s_machine->getSummariesPath() + toHexid(s_session) + ".000" ;
 
     QFile file(filename);
     if (!file.open(QIODevice::WriteOnly)) {
@@ -397,7 +398,7 @@ bool Session::LoadSummary()
 //    static int sumcnt = 0;
 
     if (s_summary_loaded) return true;
-    QString filename = s_machine->getSummariesPath() + QString::asprintf("%08lx.000", s_session);
+    QString filename = s_machine->getSummariesPath() + toHexid(s_session) + ".000";
 
     if (filename.isEmpty()) {
         qDebug() << "Empty summary filename";
@@ -448,11 +449,11 @@ bool Session::LoadSummary()
     }
 
 
-    qint32 ts32;
+    quint32 ts32;
     in >> ts32;      // MachineID (dont need this result)
 
     bool upgrade = false;
-    if (ts32 != s_machine->id()) {
+    if ( ts32 != s_machine->id()) {
         upgrade = true;
         qWarning() << "Machine ID does not match in" << filename <<
                    " I will try to load anyway in case you know what your doing.";
@@ -678,7 +679,7 @@ bool Session::StoreEvents()
     QString path = s_machine->getEventsPath();
     QDir dir;
     dir.mkpath(path);
-    QString filename = path+ QString::asprintf("%08lx.001", s_session) ;
+    QString filename = path+ toHexid(s_session) +".001";
 
     QFile file(filename);
     if (!file.open(QIODevice::WriteOnly)) {