This repository has been archived by the owner on Mar 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRefReport.cpp
352 lines (286 loc) · 10.5 KB
/
RefReport.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// RefReport.cpp : implementation file
//
#include "stdafx.h"
#include "NDBView.h"
#include "RefReport.h"
extern CMap<NID, NID, const WCHAR*, const WCHAR*> s_nidToString;
// CRefReport dialog
IMPLEMENT_DYNAMIC(CRefReport, CDialog)
CRefReport::CRefReport(BID bid, NDBViewer * pNDBViewer, CNDBViewDlg * pNDBViewDlg, CWnd* pParent /*=NULL*/)
: CNDBViewChildDlg(pNDBViewDlg, CRefReport::IDD, pParent)
{
m_pNDBViewer = pNDBViewer;
m_bid = BIDStrip(bid);
m_cDiskRefCount = (UINT)-1;
m_cCalculatedCount = 0;
}
CRefReport::~CRefReport()
{
}
void CRefReport::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST3, m_lc);
}
BEGIN_MESSAGE_MAP(CRefReport, CDialog)
ON_NOTIFY(LVN_DELETEITEM, IDC_LIST3, &CRefReport::OnLvnDeleteitemList3)
ON_NOTIFY(NM_DBLCLK, IDC_LIST3, &CRefReport::OnNMDblclkList3)
END_MESSAGE_MAP()
// CRefReport message handlers
bool NBTAddRefs(BTPAGE * pBTPage, PAGETRAILER* pPageTrailer, IB ib, void* pv)
{
((CRefReport*)pv)->NBTPage(pBTPage, pPageTrailer, ib);
return true;
}
bool BBTAddRefs(BTPAGE * pBTPage, PAGETRAILER* pPageTrailer, IB ib, void* pv)
{
((CRefReport*)pv)->BBTPage(pBTPage, pPageTrailer, ib);
return true;
}
BOOL CRefReport::OnInitDialog()
{
RECT r;
CBitmap cbm;
WCHAR buffer[255];
CDialog::OnInitDialog();
CWaitCursor wait;
cbm.LoadBitmap(IDB_BITMAP2);
m_il.Create(16, 16, ILC_COLOR24, 10, 1);
m_il.Add(&cbm, RGB(255, 0, 255));
m_il.SetBkColor(CLR_NONE);
m_lc.SetImageList(&m_il, LVSIL_SMALL);
// TODO: Add extra initialization here
BREF bref;
CB cb;
m_pNDBViewer->LookupBID(m_bid, bref, cb, m_cDiskRefCount);
m_lc.GetClientRect(&r);
m_lc.InsertColumn(0, L"Type", LVCFMT_LEFT, r.right/8);
m_lc.InsertColumn(1, L"BID", LVCFMT_LEFT, r.right/8);
m_lc.InsertColumn(2, L"Info", LVCFMT_LEFT, r.right*3/4);
m_pNDBViewer->ForEachBTPage(ptypeNBT, &NBTAddRefs, feLeaf, this);
m_pNDBViewer->ForEachBTPage(ptypeBBT, &BBTAddRefs, feLeaf, this);
if(m_cDiskRefCount != (UINT)-1)
{
wsprintf(buffer, L"Searching for %u refs, found %u refs", m_cDiskRefCount, m_cCalculatedCount);
GetDlgItem(IDC_STATIC)->SetWindowText(buffer);
}
else
{
wsprintf(buffer, L"Found %u refs", m_cCalculatedCount);
GetDlgItem(IDC_STATIC)->SetWindowText(buffer);
}
wsprintf(buffer, L"References to BID 0x%I64X", m_bid);
SetWindowText(buffer);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CRefReport::NBTPage(BTPAGE * pBTPage, PAGETRAILER * pPT, IB ib)
{
UINT icon = (m_pNDBViewer->FValidPage(ib, ptypeNBT) ? (pBTPage->cLevel == 0 ? iconLeafPage : iconPage ) : iconCorrupt);
WCHAR buffer[255];
const WCHAR * pNidName;
BOOL fGreatSuccess;
// add a ref for the data block and subnodes block of all entries
NBTENTRY *pnbtEntry = (NBTENTRY*)(pBTPage->rgbte);
for(UINT i = 0; i < NBTEnt(*pBTPage); i++, pnbtEntry++)
{
if(BIDStrip(pnbtEntry->bidData) == m_bid)
{
NodeData * pNodeData = new NodeData;
pNodeData->bref.bid = pPT->bid;
pNodeData->bref.ib = ib;
pNodeData->cb = 512;
pNodeData->btkey = 0;
pNodeData->ulFlags = aOpenBTPage;
m_lc.InsertItem(m_cCalculatedCount, L"Page", icon);
wsprintf(buffer, L"0x%I64X", pPT->bid);
m_lc.SetItemText(m_cCalculatedCount, 1, buffer);
fGreatSuccess = s_nidToString.Lookup((NID)pnbtEntry->nid, pNidName);
wsprintf(buffer, L"Data BID for NID 0x%I64X (%s)", pnbtEntry->nid, fGreatSuccess ? pNidName : TYPESTRINGFROMNID(pnbtEntry->nid));
m_lc.SetItemText(m_cCalculatedCount, 2, buffer);
m_lc.SetItemData(m_cCalculatedCount, (DWORD_PTR)pNodeData);
m_cCalculatedCount++;
}
if(BIDStrip(pnbtEntry->bidSub) == m_bid)
{
NodeData * pNodeData = new NodeData;
pNodeData->bref.bid = pPT->bid;
pNodeData->bref.ib = ib;
pNodeData->cb = 512;
pNodeData->btkey = 0;
pNodeData->ulFlags = aOpenBTPage;
m_lc.InsertItem(m_cCalculatedCount, L"Page", icon);
wsprintf(buffer, L"0x%I64X", pPT->bid);
m_lc.SetItemText(m_cCalculatedCount, 1, buffer);
fGreatSuccess = s_nidToString.Lookup((NID)pnbtEntry->nid, pNidName);
wsprintf(buffer, L"Subnode BID for NID 0x%I64X (%s)", pnbtEntry->nid, fGreatSuccess ? pNidName : TYPESTRINGFROMNID(pnbtEntry->nid));
m_lc.SetItemText(m_cCalculatedCount, 2, buffer);
m_lc.SetItemData(m_cCalculatedCount, (DWORD_PTR)pNodeData);
m_cCalculatedCount++;
}
}
}
void CRefReport::BBTPage(BTPAGE * pBTPage, PAGETRAILER * pPT, IB ib)
{
UINT icon = (m_pNDBViewer->FValidPage(ib, ptypeBBT) ? (pBTPage->cLevel == 0 ? iconLeafPage : iconPage ) : iconCorrupt);
BBTENTRY *pbbtEntry = (BBTENTRY*)(pBTPage->rgbte);
WCHAR buffer[255];
BOOL fGreatSuccess;
const WCHAR * pNidName;
for(int i = 0; i < pBTPage->cEnt; i++, pbbtEntry++)
{
if(BIDStrip(pbbtEntry->bref.bid) == m_bid)
{
NodeData * pNodeData = new NodeData;
pNodeData->bref.bid = pPT->bid;
pNodeData->bref.ib = ib;
pNodeData->cb = 512;
pNodeData->btkey = 0;
pNodeData->ulFlags = aOpenBTPage;
m_lc.InsertItem(m_cCalculatedCount, L"Page", icon);
wsprintf(buffer, L"0x%I64X", pPT->bid);
m_lc.SetItemText(m_cCalculatedCount, 1, buffer);
m_lc.SetItemText(m_cCalculatedCount, 2, L"BBT Leaf Page Ref");
m_lc.SetItemData(m_cCalculatedCount, (DWORD_PTR)pNodeData);
m_cCalculatedCount++;
}
// if the bid is an internal bid, we have to open the block and add all of it's refs
if(BIDIsInternal(pbbtEntry->bref.bid))
{
BYTE * blockData = new BYTE[BBufferSize(pbbtEntry->cb)];
UINT iconBlock = (m_pNDBViewer->FValidBlock(pbbtEntry->bref.ib, pbbtEntry->cb, pbbtEntry->bref.bid) ? iconInternalBlock : iconCorrupt);
BLOCKTRAILER bt;
m_pNDBViewer->ReadBlock(blockData, BBufferSize(pbbtEntry->cb), &bt, pbbtEntry->bref.ib, CbAlignDisk(pbbtEntry->cb));
// add all of the refs
if(blockData[0] == btypeSB)
{
SBLOCK * psb = (SBLOCK*)blockData;
if(psb->cLevel > 0)
{
SIENTRY * siEntry = psb->rgsi;
for(UINT i = 0; i < SBIEnt(*psb, BBufferSize(pbbtEntry->cb)); i++, siEntry++)
{
if(BIDStrip(siEntry->bid) == m_bid)
{
NodeData * pNodeData = new NodeData;
pNodeData->bref = pbbtEntry->bref;
pNodeData->cb = pbbtEntry->cb;
pNodeData->btkey = 0;
pNodeData->ulFlags = aOpenBlock | aBrowseBBT;
m_lc.InsertItem(m_cCalculatedCount, L"Block", iconBlock);
wsprintf(buffer, L"0x%I64X", pbbtEntry->bref.bid);
m_lc.SetItemText(m_cCalculatedCount, 1, buffer);
wsprintf(buffer, L"SIENTRY %u", i);
m_lc.SetItemText(m_cCalculatedCount, 2, buffer);
m_lc.SetItemData(m_cCalculatedCount, (DWORD_PTR)pNodeData);
m_cCalculatedCount++;
}
}
}
else
{
SLENTRY * slEntry = psb->rgsl;
for(UINT i = 0; i < SBLEnt(*psb, BBufferSize(pbbtEntry->cb)); i++, slEntry++)
{
if(BIDStrip(slEntry->bidData) == m_bid)
{
NodeData * pNodeData = new NodeData;
pNodeData->bref = pbbtEntry->bref;
pNodeData->cb = pbbtEntry->cb;
pNodeData->btkey = 0;
pNodeData->ulFlags = aOpenBlock | aBrowseBBT;
m_lc.InsertItem(m_cCalculatedCount, L"Block", iconBlock);
wsprintf(buffer, L"0x%I64X", pbbtEntry->bref.bid);
m_lc.SetItemText(m_cCalculatedCount, 1, buffer);
fGreatSuccess = s_nidToString.Lookup((NID)slEntry->nid, pNidName);
wsprintf(buffer, L"Data BID for Subnode NID 0x%X (%s)", slEntry->nid, fGreatSuccess ? pNidName : TYPESTRINGFROMNID(slEntry->nid));
m_lc.SetItemText(m_cCalculatedCount, 2, buffer);
m_lc.SetItemData(m_cCalculatedCount, (DWORD_PTR)pNodeData);
m_cCalculatedCount++;
}
if(BIDStrip(slEntry->bidSub) == m_bid)
{
NodeData * pNodeData = new NodeData;
pNodeData->bref = pbbtEntry->bref;
pNodeData->cb = pbbtEntry->cb;
pNodeData->btkey = 0;
pNodeData->ulFlags = aOpenBlock | aBrowseBBT;
m_lc.InsertItem(m_cCalculatedCount, L"Block", iconBlock);
wsprintf(buffer, L"0x%I64X", pbbtEntry->bref.bid);
m_lc.SetItemText(m_cCalculatedCount, 1, buffer);
fGreatSuccess = s_nidToString.Lookup((NID)slEntry->nid, pNidName);
wsprintf(buffer, L"Subnode BID for Subnode NID 0x%X (%s)", slEntry->nid, fGreatSuccess ? pNidName : TYPESTRINGFROMNID(slEntry->nid));
m_lc.SetItemText(m_cCalculatedCount, 2, buffer);
m_lc.SetItemData(m_cCalculatedCount, (DWORD_PTR)pNodeData);
m_cCalculatedCount++;
}
}
}
}
else if(blockData[0] == btypeXB)
{
XBLOCK *pxb = (XBLOCK*)blockData;
// here we don't care about level, every level XBLOCK is just a list of BIDs
for(UINT i = 0; i < XBEnt(*pxb, BBufferSize(pbbtEntry->cb)); i++)
{
if(BIDStrip(pxb->rgbid[i]) == m_bid)
{
NodeData * pNodeData = new NodeData;
pNodeData->bref = pbbtEntry->bref;
pNodeData->cb = pbbtEntry->cb;
pNodeData->btkey = 0;
pNodeData->ulFlags = aOpenBlock | aBrowseBBT;
m_lc.InsertItem(m_cCalculatedCount, L"Block", iconBlock);
wsprintf(buffer, L"0x%I64X", pbbtEntry->bref.bid);
m_lc.SetItemText(m_cCalculatedCount, 1, buffer);
wsprintf(buffer, L"XBLOCK entry %u", i);
m_lc.SetItemText(m_cCalculatedCount, 2, buffer);
m_lc.SetItemData(m_cCalculatedCount, (DWORD_PTR)pNodeData);
m_cCalculatedCount++;
}
}
}
delete [] blockData;
}
}
}
void CRefReport::OnLvnDeleteitemList3(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
delete (NodeData*)m_lc.GetItemData(pNMLV->iItem);
*pResult = 0;
}
void CRefReport::OnNMDblclkList3(NMHDR *pNMHDR, LRESULT *pResult)
{
Unreferenced(pNMHDR);
// TODO: Add your control notification handler code here
int i = m_lc.GetSelectionMark();
if(i >= 0)
{
NodeData * pNodeData = (NodeData*)m_lc.GetItemData(i);
m_pNDBViewDlg->PerformAction(pNodeData);
}
*pResult = 0;
}
// RefReport.cpp : implementation file
//
#include "stdafx.h"
#include "NDBView.h"
#include "RefReport.h"
// CRefReportBID dialog
IMPLEMENT_DYNAMIC(CRefReportBID, CDialog)
CRefReportBID::CRefReportBID(CWnd* pParent /*=NULL*/)
: CDialog(CRefReportBID::IDD, pParent)
, m_cs(_T(""))
{
}
CRefReportBID::~CRefReportBID()
{
}
void CRefReportBID::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_cs);
}
BEGIN_MESSAGE_MAP(CRefReportBID, CDialog)
END_MESSAGE_MAP()