From 7d8de15d5de3e026c21f9270cff4e1c212624280 Mon Sep 17 00:00:00 2001 From: Ulrich Huber Date: Mon, 11 Feb 2019 18:23:29 +0100 Subject: [PATCH] Fix timestamp normalization for old backend --- src/control/xojfile/LoadHandler.cpp | 18 +++++++-- src/control/xojfile/LoadHandlerHelper.cpp | 45 +++++++++++++++++++++++ src/control/xojfile/LoadHandlerHelper.h | 2 + src/control/xojfile/SaveHandler.cpp | 2 +- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/control/xojfile/LoadHandler.cpp b/src/control/xojfile/LoadHandler.cpp index 8b8fe122..e3f17fe7 100644 --- a/src/control/xojfile/LoadHandler.cpp +++ b/src/control/xojfile/LoadHandler.cpp @@ -554,10 +554,22 @@ void LoadHandler::parseStroke() stroke->setAudioFilename(fn); } - int ts = 0; - if (LoadHandlerHelper::getAttribInt("ts", true, this, ts)) + + if (this->fileversion < 4) + { + int ts = 0; + if (LoadHandlerHelper::getAttribInt("ts", true, this, ts)) + { + stroke->setTimestamp(ts * 1000); + } + } + else { - stroke->setTimestamp(ts); + size_t ts = 0; + if (LoadHandlerHelper::getAttribSizeT("ts", true, this, ts)) + { + stroke->setTimestamp(ts); + } } int fill = -1; diff --git a/src/control/xojfile/LoadHandlerHelper.cpp b/src/control/xojfile/LoadHandlerHelper.cpp index 5f20398f..f8230aed 100644 --- a/src/control/xojfile/LoadHandlerHelper.cpp +++ b/src/control/xojfile/LoadHandlerHelper.cpp @@ -187,3 +187,48 @@ bool LoadHandlerHelper::getAttribInt(const char* name, bool optional, LoadHandle return true; } + +size_t LoadHandlerHelper::getAttribSizeT(const char* name, LoadHandler* loadHandler) +{ + const char* attrib = getAttrib(name, false, loadHandler); + + if (attrib == NULL) + { + error("%s", FC(_F("Attribute \"{1}\" could not be parsed as size_t, the value is NULL") % name)); + return 0; + } + + char* ptr = NULL; + size_t val = g_ascii_strtoull(attrib, &ptr, 10); + if (ptr == attrib) + { + error("%s", FC(_F("Attribute \"{1}\" could not be parsed as size_t, the value is \"{2}\"") % name % attrib)); + } + + return val; +} + +bool LoadHandlerHelper::getAttribSizeT(const char* name, bool optional, LoadHandler* loadHandler, size_t& rValue) +{ + const char* attrib = getAttrib(name, optional, loadHandler); + + if (attrib == NULL) + { + if (!optional) + { + g_warning("Parser: attribute %s not found!", name); + } + return false; + } + + char* ptr = NULL; + size_t val = strtoull(attrib, &ptr, 10); + if (ptr == attrib) + { + error("%s", FC(_F("Attribute \"{1}\" could not be parsed as size_t, the value is \"{2}\"") % name % attrib)); + } + + rValue = val; + + return true; +} \ No newline at end of file diff --git a/src/control/xojfile/LoadHandlerHelper.h b/src/control/xojfile/LoadHandlerHelper.h index 792847ce..d11d4c0d 100644 --- a/src/control/xojfile/LoadHandlerHelper.h +++ b/src/control/xojfile/LoadHandlerHelper.h @@ -29,4 +29,6 @@ public: static double getAttribDouble(const char* name, LoadHandler* loadHandler); static int getAttribInt(const char* name, LoadHandler* loadHandler); static bool getAttribInt(const char* name, bool optional, LoadHandler* loadHandler, int& rValue); + static size_t getAttribSizeT(const char* name, LoadHandler* loadHandler); + static bool getAttribSizeT(const char* name, bool optional, LoadHandler* loadHandler, size_t& rValue); }; diff --git a/src/control/xojfile/SaveHandler.cpp b/src/control/xojfile/SaveHandler.cpp index 92f75723..c0181224 100644 --- a/src/control/xojfile/SaveHandler.cpp +++ b/src/control/xojfile/SaveHandler.cpp @@ -93,7 +93,7 @@ void SaveHandler::prepareSave(Document* doc) void SaveHandler::writeHeader() { this->root->setAttrib("creator", PROJECT_STRING); - this->root->setAttrib("fileversion", "3"); + this->root->setAttrib("fileversion", "4"); this->root->addChild(new XmlTextNode("title", "Xournal++ document - see " PROJECT_URL)); }