From 86d3baf2c6c6ff3bb987dcd30cd606f0a45ef626 Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 2 Sep 2016 21:23:37 +0200 Subject: Basic Version of FileWidget It checks the DB for md5sums and colors the files accordingly. As I said: very basic! --- helper.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 helper.cpp (limited to 'helper.cpp') diff --git a/helper.cpp b/helper.cpp new file mode 100644 index 0000000..d19cdf1 --- /dev/null +++ b/helper.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +#include "helper.h" + +namespace Helper { + const QString md5Sum(const QString &path){ + QFileInfo info(path); + if(!info.exists() || !info.isFile()){ + return QString(); + } + + QString retval; + QCryptographicHash h(QCryptographicHash::Md5); + QFile file(path); + file.open(QIODevice::ReadOnly); + qint64 read = 0; + if(info.size() < (5 * 1024 * 1024)){ + QByteArray data(4096, '\0'); + do { + read = file.read(data.data(), 4096); + if(read > 0){ + h.addData(data.data(), read); + } + } while (read == 4096); + QByteArray res = h.result(); + retval = res.toHex().toLower(); + }else{ + QByteArray data(512, '\0'); + int offset = info.size() / 3; + file.seek(offset); + int numBytes = 512 * 1024; + int readBytes = 0; + do { + read = file.read(data.data(), 512); + if(read > 0){ + readBytes += read; + }else{ + return QString(); + } + h.addData(data.data(), read); + } while(readBytes < numBytes); + QByteArray res = h.result(); + retval = res.toHex().toLower(); + } + return retval; + } +} -- cgit v1.2.3-70-g09d2