diff options
Diffstat (limited to 'client/DownloadClient.cpp')
-rw-r--r-- | client/DownloadClient.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/client/DownloadClient.cpp b/client/DownloadClient.cpp index 3fe7b59..723dbcb 100644 --- a/client/DownloadClient.cpp +++ b/client/DownloadClient.cpp @@ -1,6 +1,7 @@ #include <QtCore> #include "DownloadClient.h" +#include "Utility.h" DownloadClient::DownloadClient(): isDownloading(false), current(NULL), currentId(-1) @@ -9,7 +10,6 @@ DownloadClient::DownloadClient(): isDownloading(false), current(NULL), currentId DownloadClient::DownloadClient(QString addr): SslClient(addr), isDownloading(false), current(NULL), currentId(-1) { - DownloadClient(); } void DownloadClient::Download(const string &filename) @@ -73,7 +73,6 @@ void DownloadClient::DoDownload() void DownloadClient::FileDataRecieved(SslClient::RequestType &type, QByteArray &data) { Logger::Trace("Recieved file data: %u bytes\n", data.size()); - if (type != RegularFile) { Logger::Error("Invalid reply recieved: %x\n", type); @@ -85,8 +84,6 @@ void DownloadClient::FileDataRecieved(SslClient::RequestType &type, QByteArray & return; } - pair<string, string> file = files[currentId]; - string filename = file.first; if (data.size() != 0) { current->write(data); @@ -94,15 +91,27 @@ void DownloadClient::FileDataRecieved(SslClient::RequestType &type, QByteArray & } else { - Logger::Trace("Last (empty) packet recieved\n"); + Logger::Trace("Last (empty) packet recieved\n"); current->close(); + + // check file's md5 hash value + pair<string, string> file = files[currentId]; + QString md5string = QString::fromLocal8Bit(file.second.c_str()); + QString filename = QString::fromLocal8Bit(file.first.c_str()); + QByteArray md5 = md5_sum(filename); + if (md5 == md5string) + { + Logger::Trace("File %s was downloaded correctly!\n", filename.toStdString().c_str()); + } + else + { + Logger::Error("File %s was downloaded incorrectly! Removing and trying again!\n", filename.toStdString().c_str()); + current->remove(); + currentId--; + } + // free pointer to the current file delete current; current = NULL; - - /** - * @todo md5 hash check - */ - // proceed to the next file DoDownload(); } |