-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfinder.cpp
More file actions
114 lines (98 loc) · 3.06 KB
/
Copy pathfinder.cpp
File metadata and controls
114 lines (98 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <QApplication>
#include <QThread>
#include "finder.h"
#include "global.h"
#include <QDebug>
CFinder::CFinder(QObject *parent)
: QObject(parent)
{
hiveChanged(QModelIndex());
}
CFinder::~CFinder() = default;
void CFinder::searchText(const QModelIndex &idx, const QString &text)
{
if (!idx.isValid() || text.isEmpty()) {
hiveChanged(QModelIndex());
Q_EMIT searchFinished();
return;
}
struct nk_key* k = nullptr;
struct hive* h = nullptr;
int hive = 0;
if (!cgl->reg->keyPrepare(idx.internalPointer(),h,hive,k)) {
hiveChanged(QModelIndex());
Q_EMIT searchFinished();
return;
}
searchKeysOfsFlat = cgl->reg->listAllKeysOfsFlat(h,k);
searchHive = hive;
searchLastKeyIdx = -1;
searchString = text;
m_canceled = false;
continueSearch();
}
void CFinder::continueSearch()
{
if (searchKeysOfsFlat.isEmpty() || searchString.isEmpty() || m_canceled) return;
struct hive *h = cgl->reg->getHivePtr(searchHive);
if (h==nullptr) { // OOPS. No more hive. Clean all and exit.
hiveChanged(QModelIndex());
return;
}
Q_EMIT showProgressDialog();
QThread::msleep(250);
bool iok = false;
const quint32 snum = searchString.toUInt(&iok);
while (true) {
searchLastKeyIdx++;
if (searchLastKeyIdx>=searchKeysOfsFlat.count()) {
searchLastKeyIdx=-1;
Q_EMIT hideProgressDialog();
Q_EMIT searchFinished();
return;
}
struct nk_key *k = cgl->reg->getKeyPtr(h,searchKeysOfsFlat.at(searchLastKeyIdx));
if (cgl->reg->getKeyName(h,k).contains(searchString,Qt::CaseInsensitive)) {
Q_EMIT hideProgressDialog();
Q_EMIT keyFound(reinterpret_cast<quintptr>(h),
reinterpret_cast<quintptr>(k), QString());
return;
}
const QList<CValue> vl = cgl->reg->listValues(h, k);
for(const auto &v : vl) {
if (v.name.contains(searchString,Qt::CaseInsensitive) ||
v.vString.contains(searchString,Qt::CaseInsensitive) ||
v.vOther.contains(searchString.toUtf8()) ||
((v.type==REG_DWORD)&&iok&&(v.vDWORD==snum)))
{
Q_EMIT hideProgressDialog();
Q_EMIT keyFound(reinterpret_cast<quintptr>(h),
reinterpret_cast<quintptr>(k), v.name);
return;
}
}
QApplication::processEvents();
if (m_canceled)
break;
}
Q_EMIT hideProgressDialog();
}
void CFinder::destroyFinder()
{
m_canceled = true;
Q_EMIT requestToDestroy();
}
void CFinder::hiveChanged(const QModelIndex &idx)
{
if (idx.isValid()) {
struct nk_key* ck = nullptr;
struct hive* h = nullptr;
int hive = 0;
if (cgl->reg->keyPrepare(idx.internalPointer(),h,hive,ck))
if (searchHive!=hive) return;
}
searchHive = -1;
searchKeysOfsFlat.clear();
searchLastKeyIdx = -1;
searchString.clear();
}