NOISSUE use QSaveFile for saving patch order

This commit is contained in:
Petr Mrázek 2015-02-28 10:20:25 +01:00
parent 5359f4499a
commit 5ff2681da6

View File

@ -6,6 +6,7 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonArray> #include <QJsonArray>
#include <QRegularExpression> #include <QRegularExpression>
#include <QSaveFile>
namespace ProfileUtils namespace ProfileUtils
{ {
@ -22,14 +23,25 @@ bool writeOverrideOrders(QString path, const PatchOrder &order)
orderArray.append(str); orderArray.append(str);
} }
obj.insert("order", orderArray); obj.insert("order", orderArray);
QFile orderFile(path); QSaveFile orderFile(path);
if (!orderFile.open(QFile::WriteOnly)) if (!orderFile.open(QFile::WriteOnly))
{ {
QLOG_ERROR() << "Couldn't open" << orderFile.fileName() QLOG_ERROR() << "Couldn't open" << orderFile.fileName()
<< "for writing:" << orderFile.errorString(); << "for writing:" << orderFile.errorString();
return false; return false;
} }
orderFile.write(QJsonDocument(obj).toJson(QJsonDocument::Indented)); auto data = QJsonDocument(obj).toJson(QJsonDocument::Indented);
if(orderFile.write(data) != data.size())
{
qCritical() << "Couldn't write all the data into" << orderFile.fileName()
<< "because:" << orderFile.errorString();
return false;
}
if(!orderFile.commit())
{
qCritical() << "Couldn't save" << orderFile.fileName()
<< "because:" << orderFile.errorString();
}
return true; return true;
} }