From 1d1b3e36709fe0e4d7a754b286ddb3ee356e2f6b Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 11 Dec 2014 22:54:33 +0200 Subject: [PATCH] Method Convert. --HG-- branch : feature --- src/libs/ifc/xml/vabstractconverter.cpp | 24 +++++++++++++++++ src/libs/ifc/xml/vabstractconverter.h | 5 +++- src/libs/ifc/xml/vpatternconverter.cpp | 34 +++++++++++++++++++++++++ src/libs/ifc/xml/vpatternconverter.h | 3 ++- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/libs/ifc/xml/vabstractconverter.cpp b/src/libs/ifc/xml/vabstractconverter.cpp index b9980e384..a5fec8d05 100644 --- a/src/libs/ifc/xml/vabstractconverter.cpp +++ b/src/libs/ifc/xml/vabstractconverter.cpp @@ -29,6 +29,8 @@ #include "vabstractconverter.h" #include "exception/vexception.h" +#include + //--------------------------------------------------------------------------------------------------------------------- VAbstractConverter::VAbstractConverter(const QString &fileName) :VDomDocument(), ver(0x0), fileName(fileName) @@ -42,6 +44,28 @@ VAbstractConverter::VAbstractConverter(const QString &fileName) VAbstractConverter::~VAbstractConverter() {} +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractConverter::Convert() const +{ + if (ver == MaxVer()) + { + return; + } + + QString error; + const QString backupFileName = fileName +".backup"; + if (SafeCopy(fileName, backupFileName, error) == false) + { + const QString errorMsg(tr("Error creation backup file: %1.").arg(error)); + throw VException(errorMsg); + } + + ApplyPatches(); + + QFile file(backupFileName); + file.remove(); +} + //--------------------------------------------------------------------------------------------------------------------- QString VAbstractConverter::GetVersionStr() const { diff --git a/src/libs/ifc/xml/vabstractconverter.h b/src/libs/ifc/xml/vabstractconverter.h index 56e41143d..a4cc94ecd 100644 --- a/src/libs/ifc/xml/vabstractconverter.h +++ b/src/libs/ifc/xml/vabstractconverter.h @@ -38,8 +38,11 @@ public: VAbstractConverter(const QString &fileName); virtual ~VAbstractConverter(); + void Convert() const; + protected: int ver; + QString fileName; int GetVersion(const QString &version) const; void CheckVersion(int ver) const; @@ -51,10 +54,10 @@ protected: virtual QString MaxVerStr() const =0; virtual QString XSDSchema(int ver) const =0; + virtual void ApplyPatches() const =0; private: Q_DISABLE_COPY(VAbstractConverter) - QString fileName; QString GetVersionStr() const; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index ed0e2cce9..fc4241195 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -29,6 +29,8 @@ #include "vpatternconverter.h" #include "exception/vexception.h" +#include + const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.1"); const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.1.1"); const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.1.1.xsd"); @@ -86,3 +88,35 @@ QString VPatternConverter::XSDSchema(int ver) const } } } + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ApplyPatches() const +{ + try + { + switch(ver) + { + case (0x000101): + break; + default: + break; + } + } + catch (VException &e) + { + QString error; + const QString backupFileName = fileName +".backup"; + if (SafeCopy(backupFileName, fileName, error) == false) + { + const QString errorMsg(tr("Error restoring backup file: %1.").arg(error)); + VException excep(errorMsg); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + + QFile file(backupFileName); + file.remove(); + + throw e; + } +} diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index d9ae74e7b..e4d3db2b3 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -47,7 +47,8 @@ protected: virtual QString MinVerStr() const; virtual QString MaxVerStr() const; - QString XSDSchema(int ver) const; + QString XSDSchema(int ver) const; + virtual void ApplyPatches() const; private: Q_DISABLE_COPY(VPatternConverter)