47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QVector>
|
|
#include <QString>
|
|
|
|
#include <atomic>
|
|
#include <chrono>
|
|
#include <utility>
|
|
|
|
#include "search_core.h"
|
|
#include "search_cache.h"
|
|
|
|
class SearchEngine final : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
explicit SearchEngine(QObject *parent = nullptr, QString cachePath = {})
|
|
: QObject(parent), cache_(std::move(cachePath)) {}
|
|
|
|
public slots:
|
|
void stop() { cancelled_.store(true, std::memory_order_relaxed); }
|
|
void clearCache()
|
|
{
|
|
cache_.clear();
|
|
emit cacheCleared();
|
|
}
|
|
|
|
void search(const SearchOptions &o);
|
|
|
|
signals:
|
|
void progress(const QString &path, quint64 scanned);
|
|
void phaseProgress(const QString &phase, quint64 completed, quint64 total);
|
|
void cacheCleared();
|
|
void finished(const QVector<FileRecord> &results, const QString &message);
|
|
|
|
private:
|
|
QByteArray cachedSampleSha256(const FileRecord &record);
|
|
QByteArray cachedSha256(const FileRecord &record);
|
|
bool cachedFileContains(const FileRecord &record, const SearchOptions &o);
|
|
|
|
SearchCache cache_;
|
|
std::atomic<quint64> cacheHits_ = 0;
|
|
std::atomic<quint64> cacheMisses_ = 0;
|
|
std::atomic_bool cancelled_ = false;
|
|
bool cancelledByLimit_ = false;
|
|
};
|