Fix bug. QTemporaryFile blocks a file on Windows.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-02-07 13:44:33 +02:00
parent 06b567fa55
commit a740d52861
2 changed files with 22 additions and 26 deletions

View File

@ -84,7 +84,6 @@ QString VAbstractConverter::Convert()
const QString errorMsg(tr("Error openning a temp file file: %1.").arg(m_tmpFile.errorString())); const QString errorMsg(tr("Error openning a temp file file: %1.").arg(m_tmpFile.errorString()));
throw VException(errorMsg); throw VException(errorMsg);
} }
m_tmpFile.close();
m_ver < MaxVer() ? ApplyPatches() : DowngradeToCurrentMaxVersion(); m_ver < MaxVer() ? ApplyPatches() : DowngradeToCurrentMaxVersion();
@ -256,23 +255,6 @@ Q_NORETURN void VAbstractConverter::InvalidVersion(int ver) const
throw VException(errorMsg); throw VException(errorMsg);
} }
//---------------------------------------------------------------------------------------------------------------------
bool VAbstractConverter::SaveDocument(const QString &fileName, QString &error) const
{
try
{
TestUniqueId();
}
catch (const VExceptionWrongId &e)
{
Q_UNUSED(e)
error = tr("Error no unique id.");
return false;
}
return VDomDocument::SaveDocument(fileName, error);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VAbstractConverter::ValidateInputFile(const QString &currentSchema) const void VAbstractConverter::ValidateInputFile(const QString &currentSchema) const
{ {
@ -311,12 +293,28 @@ void VAbstractConverter::ValidateInputFile(const QString &currentSchema) const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VAbstractConverter::Save() const void VAbstractConverter::Save()
{ {
QString error; try
if (SaveDocument(m_convertedFileName, error) == false)
{ {
VException e(error); TestUniqueId();
}
catch (const VExceptionWrongId &e)
{
Q_UNUSED(e)
VException ex(tr("Error no unique id."));
throw ex;
}
m_tmpFile.resize(0);//clear previous content
const int indent = 4;
QTextStream out(&m_tmpFile);
out.setCodec("UTF-8");
save(out, indent);
if (not m_tmpFile.flush())
{
VException e(m_tmpFile.errorString());
throw e; throw e;
} }
} }

View File

@ -53,8 +53,7 @@ public:
explicit VAbstractConverter(const QString &fileName); explicit VAbstractConverter(const QString &fileName);
virtual ~VAbstractConverter() Q_DECL_OVERRIDE; virtual ~VAbstractConverter() Q_DECL_OVERRIDE;
QString Convert(); QString Convert();
virtual bool SaveDocument(const QString &fileName, QString &error) const Q_DECL_OVERRIDE;
static int GetVersion(const QString &version); static int GetVersion(const QString &version);
@ -62,10 +61,9 @@ protected:
int m_ver; int m_ver;
QString m_convertedFileName; QString m_convertedFileName;
void ValidateInputFile(const QString &currentSchema) const; void ValidateInputFile(const QString &currentSchema) const;
Q_NORETURN void InvalidVersion(int ver) const; Q_NORETURN void InvalidVersion(int ver) const;
void Save() const; void Save();
void SetVersion(const QString &version); void SetVersion(const QString &version);
virtual int MinVer() const =0; virtual int MinVer() const =0;