Merge branch 'develop' of github.com:MultiMC/MultiMC5 into develop

This commit is contained in:
Sky 2014-01-11 00:22:21 +00:00
commit c00946c855
2 changed files with 24 additions and 30 deletions

View File

@ -42,6 +42,13 @@ void CacheDownload::start()
// if there already is a file and md5 checking is in effect and it can be opened // if there already is a file and md5 checking is in effect and it can be opened
if (!ensureFilePathExists(m_target_path)) if (!ensureFilePathExists(m_target_path))
{ {
QLOG_ERROR() << "Could not create folder for " + m_target_path;
emit failed(m_index_within_job);
return;
}
if(!m_output_file.open(QIODevice::WriteOnly))
{
QLOG_ERROR() << "Could not open " + m_target_path + " for writing";
emit failed(m_index_within_job); emit failed(m_index_within_job);
return; return;
} }
@ -85,26 +92,21 @@ void CacheDownload::downloadFinished()
// if the download succeeded // if the download succeeded
if (m_status != Job_Failed) if (m_status != Job_Failed)
{ {
// nothing went wrong... // nothing went wrong...
m_status = Job_Finished; m_status = Job_Finished;
if (m_output_file.isOpen()) if (m_output_file.commit())
{ {
// save the data to the downloadable if we aren't saving to file
m_output_file.close();
m_entry->md5sum = md5sum.result().toHex().constData(); m_entry->md5sum = md5sum.result().toHex().constData();
} }
else else
{ {
if (m_output_file.open(QIODevice::ReadOnly)) QLOG_ERROR() << "Failed to commit changes to " << m_target_path;
{ m_output_file.cancelWriting();
m_entry->md5sum = m_reply.reset();
QCryptographicHash::hash(m_output_file.readAll(), QCryptographicHash::Md5) emit failed(m_index_within_job);
.toHex() return;
.constData();
m_output_file.close();
}
} }
QFileInfo output_file_info(m_target_path); QFileInfo output_file_info(m_target_path);
m_entry->etag = m_reply->rawHeader("ETag").constData(); m_entry->etag = m_reply->rawHeader("ETag").constData();
@ -124,8 +126,7 @@ void CacheDownload::downloadFinished()
// else the download failed // else the download failed
else else
{ {
m_output_file.close(); m_output_file.cancelWriting();
m_output_file.remove();
m_reply.reset(); m_reply.reset();
emit failed(m_index_within_job); emit failed(m_index_within_job);
return; return;
@ -134,19 +135,12 @@ void CacheDownload::downloadFinished()
void CacheDownload::downloadReadyRead() void CacheDownload::downloadReadyRead()
{ {
if (!m_output_file.isOpen())
{
if (!m_output_file.open(QIODevice::WriteOnly))
{
/*
* Can't open the file... the job failed
*/
m_reply->abort();
emit failed(m_index_within_job);
return;
}
}
QByteArray ba = m_reply->readAll(); QByteArray ba = m_reply->readAll();
md5sum.addData(ba); md5sum.addData(ba);
m_output_file.write(ba); if(m_output_file.write(ba) != ba.size())
{
QLOG_ERROR() << "Failed writing into " + m_target_path;
m_reply->abort();
emit failed(m_index_within_job);
}
} }

View File

@ -17,8 +17,8 @@
#include "NetAction.h" #include "NetAction.h"
#include "HttpMetaCache.h" #include "HttpMetaCache.h"
#include <QFile> #include <QCryptographicHash>
#include <qcryptographichash.h> #include <QSaveFile>
typedef std::shared_ptr<class CacheDownload> CacheDownloadPtr; typedef std::shared_ptr<class CacheDownload> CacheDownloadPtr;
class CacheDownload : public NetAction class CacheDownload : public NetAction
@ -29,7 +29,7 @@ public:
/// if saving to file, use the one specified in this string /// if saving to file, use the one specified in this string
QString m_target_path; QString m_target_path;
/// this is the output file, if any /// this is the output file, if any
QFile m_output_file; QSaveFile m_output_file;
/// the hash-as-you-download /// the hash-as-you-download
QCryptographicHash md5sum; QCryptographicHash md5sum;