Reserve a pattern file before conversion.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-08-27 11:45:31 +03:00
parent 62a22b122e
commit a69223299c
2 changed files with 25 additions and 1 deletions

View File

@ -31,6 +31,7 @@
#include "exception/vexceptionwrongid.h"
#include <QFile>
#include <QFileInfo>
//---------------------------------------------------------------------------------------------------------------------
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

View File

@ -69,6 +69,8 @@ private:
QString GetVersionStr() const;
void ValidateVersion(const QString &version) const;
void ReserveFile() const;
};
#endif // VABSTRACTCONVERTER_H