diff options
Diffstat (limited to 'helper.cpp')
-rw-r--r-- | helper.cpp | 45 |
1 files changed, 22 insertions, 23 deletions
@@ -10,12 +10,7 @@ #include <QFileInfo> #include <QFile> #include <QSettings> - -#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 -#include <md5.h> -#include <files.h> -#include <filters.h> -#include <hex.h> +#include <QCryptographicHash> #include "helper.h" @@ -41,8 +36,8 @@ namespace Helper { retval = "video/"; } } - return retval; } + return retval; } const QString md5Sum(const QString &path){ @@ -51,28 +46,32 @@ namespace Helper { return QString(); } - using namespace CryptoPP; - Weak::MD5 hash; - std::string res; QString retval; + QCryptographicHash h(QCryptographicHash::Md5); + QFile file(path); + file.open(QIODevice::ReadOnly); + qint64 read = 0; if(info.size() < (5 * 1024 * 1024)){ - FileSource f(qPrintable(path), true, new HashFilter(hash, new HexEncoder(new StringSink(res)))); - retval = QString::fromStdString(res).toLower(); + QByteArray data(4096, '\0'); + do { + read = file.read(data.data(), 4096); + h.addData(data.data(), read); + } while (read == 4096); + QByteArray res = h.result(); + retval = res.toHex().toLower(); }else{ - QFile file(path); - file.open(QIODevice::ReadOnly); + QByteArray data(512, '\0'); int offset = info.size() / 3; file.seek(offset); int numBytes = 512 * 1024; - char *data = new char[numBytes]; - int read = file.read(data, numBytes); - if(read != numBytes){ - delete [] data; - return QString(); - } - StringSource s((byte*)data, numBytes, true, new HashFilter(hash, new HexEncoder(new StringSink(res)))); - retval = QString::fromStdString(res).toLower(); - delete [] data; + int readBytes = 0; + do { + read = file.read(data.data(), 512); + readBytes += read; + h.addData(data.data(), read); + } while(readBytes < numBytes); + QByteArray res = h.result(); + retval = res.toHex().toLower(); } return retval; } |