void HashGenerator::spawnThread()
{
    HashThread* temp;
    qDebug() << "Spawning a thread";
    temp = new HashThread(keys);
    //Progress
    this->connect(temp,
                  SIGNAL(hashComputed()),
                  this,
                  SLOT(computeProgress()));
    //Target Found
    this->connect(temp,
                  SIGNAL(matchFound(QString,QString,QString)),
                  this,
                  SIGNAL(targetFound(QString,QString,QString)));
     //Thread Done
    this->connect(temp,
                  SIGNAL(done()),
                  this,
                  SLOT(threadDone()));
    this->threadCount++;
    this->threadPool->append( temp );
    temp->start();
    if(this->hashActive){
        this->threadsActive++;
        temp->hash();
    }
}
示例#2
0
QString HashPool::getFileHash(QCryptographicHash::Algorithm algo, QString fpath)
{
    QFileInfo fi(fpath);
    if (!fi.isFile())
        return QString();
    // search DB
    if (!file_hashes_.contains(QString::number(algo)+fpath)){
        QString h = this->queryFileHash(algo,
                                        fi.fileName(),
                                        QString::number(fi.size()),
                                        fi.lastModified().toString(Qt::ISODate));
        if (!h.isEmpty()){
//            qDebug() << "HashPool::getFileHash() hit DB";
            file_hashes_.insert(QString::number(algo)+fpath, h);
        } else {
//            qDebug() << "HashPool::getFileHash() miss DB" << h;
        }
    }
    // calculate
    if (!file_hashes_.contains(QString::number(algo)+fpath)) {
        qDebug() << "HashPool::getFileHash() threading ..." << fi.filePath();
        HashThread *t = new HashThread(algo,fpath,this);
        connect(t, SIGNAL(finished()), t, SLOT(deleteLater()));
        connect(t, SIGNAL(sigHash(int,QString,QString)),
                this, SLOT(cacheFileHash(int,QString,QString)));

        connect(t, SIGNAL(sigHashingPercent(int, int,QString)),
                this, SIGNAL(sigHashingPercent(int, int,QString)));

        file_hashes_.insert(QString::number(algo)+fpath, ""); // nessary guard too many threads
        t->start();
        return "";
    }