summaryrefslogtreecommitdiffstats
path: root/helper.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2016-09-02 21:23:37 +0200
committerArno <arno@disconnect.de>2016-09-02 21:23:37 +0200
commit86d3baf2c6c6ff3bb987dcd30cd606f0a45ef626 (patch)
tree59200a68c08325a46a144a2f1c9e393eadec4e86 /helper.cpp
parent8203bdcbdbc8c121831db0d197a89842b7178f59 (diff)
downloadShemovCleaner-86d3baf2c6c6ff3bb987dcd30cd606f0a45ef626.tar.gz
ShemovCleaner-86d3baf2c6c6ff3bb987dcd30cd606f0a45ef626.tar.bz2
ShemovCleaner-86d3baf2c6c6ff3bb987dcd30cd606f0a45ef626.zip
Basic Version of FileWidget
It checks the DB for md5sums and colors the files accordingly. As I said: very basic!
Diffstat (limited to 'helper.cpp')
-rw-r--r--helper.cpp50
1 files changed, 50 insertions, 0 deletions
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 <QFile>
+#include <QFileInfo>
+#include <QCryptographicHash>
+#include <QByteArray>
+
+#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;
+ }
+}