diff --git a/src/libs/ifc/xml/vabstractconverter.cpp b/src/libs/ifc/xml/vabstractconverter.cpp index 814c22b58..580e1a9c2 100644 --- a/src/libs/ifc/xml/vabstractconverter.cpp +++ b/src/libs/ifc/xml/vabstractconverter.cpp @@ -31,6 +31,7 @@ #include "exception/vexceptionwrongid.h" #include +#include //--------------------------------------------------------------------------------------------------------------------- VAbstractConverter::VAbstractConverter(const QString &fileName) @@ -57,10 +58,12 @@ void VAbstractConverter::Convert() const QString backupFileName = fileName +".backup"; if (SafeCopy(fileName, backupFileName, error) == false) { - const QString errorMsg(tr("Error creation backup file: %1.").arg(error)); + const QString errorMsg(tr("Error creating a backup file: %1.").arg(error)); throw VException(errorMsg); } + ReserveFile(); + ApplyPatches(); QFile file(backupFileName); @@ -144,6 +147,25 @@ void VAbstractConverter::ValidateVersion(const QString &version) const } } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractConverter::ReserveFile() const +{ + //It's not possible in all cases make conversion without lose data. + //For such cases we will store old version in a reserve file. + QString error; + QFileInfo info(fileName); + const QString reserveFileName = QString("%1/%2(v%3).%4") + .arg(info.absoluteDir().absolutePath()) + .arg(info.baseName()) + .arg(GetVersionStr()) + .arg(info.completeSuffix()); + if (SafeCopy(fileName, reserveFileName, error) == false) + { + const QString errorMsg(tr("Error creating a reserv copy: %1.").arg(error)); + throw VException(errorMsg); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractConverter::Replace(QString &formula, const QString &newName, int position, const QString &token, int &bias) const diff --git a/src/libs/ifc/xml/vabstractconverter.h b/src/libs/ifc/xml/vabstractconverter.h index ea5f48223..4964d830a 100644 --- a/src/libs/ifc/xml/vabstractconverter.h +++ b/src/libs/ifc/xml/vabstractconverter.h @@ -69,6 +69,8 @@ private: QString GetVersionStr() const; void ValidateVersion(const QString &version) const; + + void ReserveFile() const; }; #endif // VABSTRACTCONVERTER_H