#include "hashconsumer.h"
+#include <QCryptographicHash>
+
#include <QDebug>
namespace AniDBUdpClient {
HashConsumer::HashConsumer(Buffer *buffer, QObject *parent) : QThread(parent)
{
this->buffer = buffer;
- hash = new QCryptographicHash(QCryptographicHash::Md4);
restart = false;
abort = false;
mutex.unlock();
wait();
- delete hash;
}
void HashConsumer::hashFile(const QString &file)
qint64 read = 0;
mutex.unlock();
+ QCryptographicHash hash(QCryptographicHash::Md4);
+
while (!(buffer->end() || abort))
{
// qDebug() << "hash->while(" << buffer->end() << ")";
while (!(buffer->get(&data) || abort));
- hash->addData(QCryptographicHash::hash(data, QCryptographicHash::Md4));
+ hash.addData(QCryptographicHash::hash(data, QCryptographicHash::Md4));
read += data.size();
emit progress(read, totalSize);
mutex.lock();
if (!restart)
{
- emit finishedHashing(hash->result().toHex());
+ emit finishedHashing(hash.result().toHex());
condition.wait(&mutex);
}
restart = false;
mutex.unlock();
- hash->reset();
+ hash.reset();
}
qDebug() << "Thread consumer is stopping";
}