Method Convert.
--HG-- branch : feature
This commit is contained in:
parent
1d9fd7109d
commit
1d1b3e3670
|
@ -29,6 +29,8 @@
|
||||||
#include "vabstractconverter.h"
|
#include "vabstractconverter.h"
|
||||||
#include "exception/vexception.h"
|
#include "exception/vexception.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VAbstractConverter::VAbstractConverter(const QString &fileName)
|
VAbstractConverter::VAbstractConverter(const QString &fileName)
|
||||||
:VDomDocument(), ver(0x0), fileName(fileName)
|
:VDomDocument(), ver(0x0), fileName(fileName)
|
||||||
|
@ -42,6 +44,28 @@ VAbstractConverter::VAbstractConverter(const QString &fileName)
|
||||||
VAbstractConverter::~VAbstractConverter()
|
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
|
QString VAbstractConverter::GetVersionStr() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,8 +38,11 @@ public:
|
||||||
VAbstractConverter(const QString &fileName);
|
VAbstractConverter(const QString &fileName);
|
||||||
virtual ~VAbstractConverter();
|
virtual ~VAbstractConverter();
|
||||||
|
|
||||||
|
void Convert() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int ver;
|
int ver;
|
||||||
|
QString fileName;
|
||||||
|
|
||||||
int GetVersion(const QString &version) const;
|
int GetVersion(const QString &version) const;
|
||||||
void CheckVersion(int ver) const;
|
void CheckVersion(int ver) const;
|
||||||
|
@ -51,10 +54,10 @@ protected:
|
||||||
virtual QString MaxVerStr() const =0;
|
virtual QString MaxVerStr() const =0;
|
||||||
|
|
||||||
virtual QString XSDSchema(int ver) const =0;
|
virtual QString XSDSchema(int ver) const =0;
|
||||||
|
virtual void ApplyPatches() const =0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VAbstractConverter)
|
Q_DISABLE_COPY(VAbstractConverter)
|
||||||
QString fileName;
|
|
||||||
|
|
||||||
QString GetVersionStr() const;
|
QString GetVersionStr() const;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include "vpatternconverter.h"
|
#include "vpatternconverter.h"
|
||||||
#include "exception/vexception.h"
|
#include "exception/vexception.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.1");
|
const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.1");
|
||||||
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.1.1");
|
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.1.1");
|
||||||
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.1.1.xsd");
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -47,7 +47,8 @@ protected:
|
||||||
virtual QString MinVerStr() const;
|
virtual QString MinVerStr() const;
|
||||||
virtual QString MaxVerStr() const;
|
virtual QString MaxVerStr() const;
|
||||||
|
|
||||||
QString XSDSchema(int ver) const;
|
QString XSDSchema(int ver) const;
|
||||||
|
virtual void ApplyPatches() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VPatternConverter)
|
Q_DISABLE_COPY(VPatternConverter)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user