-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkadsearch.cpp
73 lines (59 loc) · 1.51 KB
/
kadsearch.cpp
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
#include "StdAfx.h"
#include "kadsearch.h"
#include <QList>
KadSearch::KadSearch(QString key, int seconds, QObject *parent)
: QObject(parent)
{
m_key = key;
m_seconds = seconds;
memset(m_seed, 0, 16);
m_elapsedTimer.start();
#ifdef LOCAL_KAD_LIB
#else
pStartKadSearch(key.toLocal8Bit().data(), strlen(key.toLocal8Bit().data()), m_seed);
#endif
m_pTimer = new QTimer();
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(on_getResult_timeout()));
m_pTimer->start(FIFTY_MILLI_SECONDS);
}
KadSearch::~KadSearch()
{
m_pTimer->stop();
#ifdef LOCAL_KAD_LIB
#else
pStopKadSearch(m_seed);
#endif
}
void KadSearch::on_getResult_timeout()
{
#ifdef LOCAL_KAD_LIB
#else
if(m_elapsedTimer.elapsed() < m_seconds * ONE_SECOND)
{
DWORD buffer = 0;
pGetKadSearchResult(m_seed, &buffer);
if(buffer != 0)
{
DWORD dwItemCount = *(PDWORD)(buffer + 0);
DWORD dwFirstItemAddress = *(PDWORD)(buffer + 4);
//QList<SRESULT> results;
for(int i=0; i<(int)dwItemCount; i++)
{
DWORD itemAddress = dwFirstItemAddress + i * sizeof(SRESULT);
SRESULT result;
memcpy(&result, (void *)itemAddress, sizeof(SRESULT));
//results.append(result);
KadResult kadResult;
kadResult.Name = QString::fromLocal8Bit(result.Name);
kadResult.Size = result.Size;
kadResult.Type = GetFileType(result.Name);
kadResult.Resource = result.Resource;
kadResult.Ed2k = GetEd2k(result);
emit insertResult(kadResult);
}
//db::InsertKadSearchResult(results);
pDeleteFileBasicInfoTable(buffer);
}
}
#endif
}