Save resume data using QSaveFile (Qt5 only)

This commit is contained in:
Vladimir Golovnev (Glassez) 2016-01-16 15:18:04 +03:00
parent 245f424014
commit 732f46cc69

View File

@ -27,8 +27,13 @@
*/
#include <QDebug>
#ifdef QBT_USES_QT5
#include <QSaveFile>
#else
#include <QFile>
#endif
#include "base/logger.h"
#include "base/utils/fs.h"
#include "resumedatasavingmanager.h"
@ -43,7 +48,18 @@ void ResumeDataSavingManager::saveResumeData(QString infoHash, QByteArray data)
QString filepath = m_resumeDataDir.absoluteFilePath(filename);
qDebug() << "Saving resume data in" << filepath;
#ifdef QBT_USES_QT5
QSaveFile resumeFile(filepath);
#else
QFile resumeFile(filepath);
if (resumeFile.open(QIODevice::WriteOnly))
#endif
if (resumeFile.open(QIODevice::WriteOnly)) {
resumeFile.write(data);
#ifdef QBT_USES_QT5
if (!resumeFile.commit()) {
Logger::instance()->addMessage(QString("Couldn't save resume data in %1. Error: %2")
.arg(filepath).arg(resumeFile.errorString()), Log::WARNING);
}
#endif
}
}