From bd1d34d7781d35f17666adb3df6abb7c9b7fcc32 Mon Sep 17 00:00:00 2001 From: Alex Borisov Date: Fri, 2 Dec 2011 03:54:00 +0200 Subject: MD5 hash check for existing & downloaded files --- client/FileOpThread.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'client/FileOpThread.cpp') diff --git a/client/FileOpThread.cpp b/client/FileOpThread.cpp index 3340db2..bd0b929 100644 --- a/client/FileOpThread.cpp +++ b/client/FileOpThread.cpp @@ -3,6 +3,7 @@ #include "DownloadClient.h" #include "FileOpThread.h" #include "UpdatedConfig.h" +#include "Utility.h" FileOpThread::~FileOpThread() @@ -44,9 +45,20 @@ void FileOpThread::run() if (fileInfo.exists()) { Logger::Info("File \"%s\" already exists\n", downloadList[i].path.c_str()); - /** - * @todo Compute md5 hash and check if they are the same - */ + QString filename = QString::fromLocal8Bit(downloadList[i].path.c_str()); + QString md5string = QString::fromLocal8Bit(downloadList[i].md5.c_str()); + QByteArray md5 = md5_sum(filename); + + if (md5 == md5string) + { + Logger::Trace("File %s is correct!\n", filename.toStdString().c_str()); + } + else + { + Logger::Error("File %s is incorrect or was updated. Need to download again!\n", filename.toStdString().c_str()); + pair file = make_pair(downloadList[i].path, downloadList[i].md5); + files.push_back(file); + } } else { -- cgit v1.2.3