Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

642 lines
16 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (c) 2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. * testmap.cpp
  7. *
  8. * Abstract:
  9. * UI tool for enumerating the change log/restore map
  10. *
  11. * Revision History:
  12. * Brijesh Krishnaswami (brijeshk) 06/09/2000
  13. * created
  14. *
  15. *****************************************************************************/
  16. #include "stdafx.h"
  17. #include "resource.h"
  18. #include <commctrl.h>
  19. #include "srrpcapi.h"
  20. #include "stdio.h"
  21. #ifdef THIS_FILE
  22. #undef THIS_FILE
  23. #endif
  24. static char __szTraceSourceFile[] = __FILE__;
  25. #define THIS_FILE __szTraceSourceFile
  26. #include "dbgtrace.h"
  27. #include "restmap.h"
  28. #include "enumlogs.h"
  29. #include "shellapi.h"
  30. #include "srapi.h"
  31. //
  32. // Macros:
  33. //
  34. #define MAX_LOADSTRING 100
  35. #define LocalRealloc(a, b) LocalReAlloc(a, b, LMEM_MOVEABLE)
  36. #define MSG(a) MessageBox(NULL, a, L"", MB_OK);
  37. #define CHGLOG_COLS 8
  38. //
  39. // Global Variables:
  40. //
  41. HINSTANCE hInst;
  42. WCHAR szTitle[MAX_LOADSTRING];
  43. WCHAR szWindowClass[MAX_LOADSTRING];
  44. HWND g_hwndChgLog = 0, g_hwndRestMap = 0, g_hwndMain = 0;
  45. HANDLE g_hDevice = 0, g_hFile = 0;
  46. WCHAR g_szLogDir[ MAX_PATH ];
  47. WCHAR g_szActiveLogFile[ MAX_PATH ];
  48. BOOL g_fTraceStatus = FALSE;
  49. WCHAR g_bBuffer[4096*16];
  50. WCHAR g_szCmdLine[MAX_PATH];
  51. int g_nRPNum = 0;
  52. int g_nOption = 1;
  53. WCHAR g_szDrive[MAX_PATH];
  54. WCHAR g_szRstrmap[MAX_PATH] = L"c:\\rstrmap.dat";
  55. typedef struct _CHGLOG_ITEM
  56. {
  57. LPWSTR aCols[CHGLOG_COLS];
  58. } CHGLOG_ITEM;
  59. LPWSTR CHGLOG_COLUMNS[CHGLOG_COLS] =
  60. {
  61. L"Seq",
  62. L"Size",
  63. L"Operation",
  64. L"Attributes",
  65. L"TmpFile",
  66. L"Src Path",
  67. L"Dest Path",
  68. L"Acl"
  69. };
  70. INT CHGLOG_WIDTHS[CHGLOG_COLS] =
  71. { 50, 50, 80, 80, 150, 250, 100, 50 };
  72. WCHAR g_szBuffer [4096];
  73. WCHAR g_achLogTemp[256];
  74. WCHAR g_achTemp [256];
  75. BYTE mapEnt[ 4096 ];
  76. WCHAR szBuffer[4096];
  77. //
  78. // Foward declarations of functions included in this code module:
  79. //
  80. ATOM RegisterRestoreMapClass(HINSTANCE hInstance);
  81. BOOL InitInstance(HINSTANCE, int);
  82. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  83. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  84. void Log(char *ctl, int len);
  85. struct _EVENT_STR_MAP
  86. {
  87. DWORD EventId;
  88. LPWSTR pEventStr;
  89. } EventMap[ 12 ] =
  90. {
  91. {SrEventInvalid , L"INVALID " },
  92. {SrEventStreamChange, L"FILE-MODIFY" },
  93. {SrEventAclChange, L"ACL-CHANGE " },
  94. {SrEventAttribChange, L"ATTR-CHANGE" },
  95. {SrEventStreamOverwrite,L"FILE-MODIFY" },
  96. {SrEventFileDelete, L"FILE-DELETE" },
  97. {SrEventFileCreate, L"FILE-CREATE" },
  98. {SrEventFileRename, L"FILE-RENAME" },
  99. {SrEventDirectoryCreate,L"DIR-CREATE " },
  100. {SrEventDirectoryRename,L"DIR-RENAME " },
  101. {SrEventDirectoryDelete,L"DIR-DELETE " },
  102. {SrEventMaximum, L"INVALID-MAX" }
  103. };
  104. LPWSTR
  105. GetEventString(
  106. DWORD EventId
  107. )
  108. {
  109. LPWSTR pStr = L"NOT-FOUND";
  110. for( int i=0; i<sizeof(EventMap)/sizeof(_EVENT_STR_MAP);i++)
  111. {
  112. if ( EventMap[i].EventId == EventId )
  113. {
  114. pStr = EventMap[i].pEventStr;
  115. }
  116. }
  117. return pStr;
  118. }
  119. LPWSTR DupString(LPWSTR lpsz)
  120. {
  121. int cb = (lstrlen(lpsz) + 1) * sizeof(WCHAR);
  122. LPWSTR lpszNew = (LPWSTR)LocalAlloc(LMEM_FIXED, cb);
  123. if (lpszNew != NULL)
  124. CopyMemory(lpszNew, lpsz, cb);
  125. return lpszNew;
  126. }
  127. BOOL WINAPI
  128. ChgLog_Insert(
  129. HWND hwnd,
  130. LPWSTR szSeqNo,
  131. LPWSTR szSize,
  132. LPWSTR szOperation,
  133. LPWSTR szAttr,
  134. LPWSTR szTmpFile,
  135. LPWSTR szSrc,
  136. LPWSTR szDest,
  137. LPWSTR szAcl)
  138. {
  139. LVITEM lvi;
  140. static int iItem = 0;
  141. CHGLOG_ITEM *pItem = (CHGLOG_ITEM *)LocalAlloc(LPTR, sizeof(CHGLOG_ITEM));
  142. lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  143. lvi.state = 0;
  144. lvi.stateMask = 0;
  145. lvi.pszText = LPSTR_TEXTCALLBACK; // app. maintains text
  146. lvi.iImage = 0;
  147. pItem->aCols[0] = DupString(szSeqNo);
  148. pItem->aCols[1] = DupString(szSize);
  149. pItem->aCols[2] = DupString(szOperation);
  150. pItem->aCols[3] = DupString(szAttr);
  151. pItem->aCols[4] = DupString(szTmpFile);
  152. pItem->aCols[5] = DupString(szSrc);
  153. pItem->aCols[6] = DupString(szDest);
  154. pItem->aCols[7] = DupString(szAcl);
  155. // Initialize item-specific LVITEM members.
  156. lvi.iItem = iItem;
  157. lvi.iSubItem = 0;
  158. lvi.lParam = (LPARAM)pItem; // item data
  159. // Add the item.
  160. ListView_InsertItem(hwnd, &lvi);
  161. iItem++;
  162. return TRUE;
  163. }
  164. VOID WINAPI
  165. ChgLog_OnGetDispInfo(NMLVDISPINFO * pnmv)
  166. {
  167. // Provide the item or subitem's text, if requested.
  168. if (pnmv->item.mask & LVIF_TEXT)
  169. {
  170. CHGLOG_ITEM *pItem = (CHGLOG_ITEM *) (pnmv->item.lParam);
  171. lstrcpy(pnmv->item.pszText,
  172. pItem->aCols[pnmv->item.iSubItem]);
  173. }
  174. }
  175. BOOL WINAPI
  176. ChgLog_InitColumns(HWND hwnd)
  177. {
  178. LVCOLUMN lvc;
  179. int iCol;
  180. // Initialize the LVCOLUMN structure.
  181. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  182. lvc.fmt = LVCFMT_LEFT;
  183. lvc.cx = 100;
  184. lvc.pszText = g_achTemp;
  185. // Add the columns.
  186. for (iCol = 0; iCol < CHGLOG_COLS; iCol++) {
  187. lvc.iSubItem = iCol;
  188. lvc.cx = CHGLOG_WIDTHS[iCol];
  189. lstrcpy(g_achTemp, CHGLOG_COLUMNS[iCol]);
  190. if (ListView_InsertColumn(hwnd, iCol, &lvc) == -1)
  191. return FALSE;
  192. }
  193. return TRUE;
  194. }
  195. BOOL
  196. ChgLog_FillWindow()
  197. {
  198. WCHAR szSeqNo[50];
  199. WCHAR szSize[50];
  200. WCHAR szOperation[50];
  201. WCHAR szAttr[50];
  202. WCHAR szTmpFile[150];
  203. WCHAR szSrc [MAX_PATH];
  204. WCHAR szDest[MAX_PATH];
  205. WCHAR szAcl[MAX_PATH];
  206. if (g_nOption == 3)
  207. {
  208. if (ERROR_SUCCESS != SRSwitchLog())
  209. goto done;
  210. }
  211. {
  212. CChangeLogEntryEnum ChangeLog(g_szDrive, (g_nOption == 3), g_nRPNum, (g_nOption == 3));
  213. CChangeLogEntry cle;
  214. if (ERROR_SUCCESS != ChangeLog.FindFirstChangeLogEntry(cle))
  215. goto done;
  216. do
  217. {
  218. wsprintf( szSeqNo , L"%ld", cle.GetSequenceNum());
  219. wsprintf( szSize , L"%d" , 0);
  220. wsprintf( szOperation, L"%s" , GetEventString(cle.GetType()) );
  221. wsprintf( szAttr , L"%08x" , cle.GetAttributes() );
  222. wsprintf( szTmpFile , L"%s" , cle.GetTemp() ? cle.GetTemp() : L"" );
  223. wsprintf( szSrc , L"%s" , cle.GetPath1() ? cle.GetPath1() : L"");
  224. wsprintf( szDest, L"%s", cle.GetPath2() ? cle.GetPath2() : L"");
  225. wsprintf( szAcl, L"%s", cle.GetAcl() ? (cle.GetAclInline() ? L"Inline" : (LPWSTR) cle.GetAcl()) : L"");
  226. ChgLog_Insert(
  227. g_hwndChgLog,
  228. szSeqNo,
  229. szSize,
  230. szOperation,
  231. szAttr,
  232. szTmpFile,
  233. szSrc,
  234. szDest,
  235. szAcl);
  236. } while (ChangeLog.FindNextChangeLogEntry(cle) == ERROR_SUCCESS);
  237. ChangeLog.FindClose();
  238. }
  239. done:
  240. return TRUE;
  241. }
  242. BOOL
  243. RestMap_FillWindow()
  244. {
  245. WCHAR szSeqNo[50];
  246. WCHAR szSize[50];
  247. WCHAR szOperation[50];
  248. WCHAR szAttr[50];
  249. WCHAR szTmpFile[150];
  250. WCHAR szSrc [MAX_PATH];
  251. WCHAR szDest[MAX_PATH];
  252. WCHAR szAcl[MAX_PATH];
  253. LPWSTR pszSrc, pszDest, pszTemp;
  254. LPBYTE pbAcl = NULL;
  255. RestoreMapEntry *prme = NULL;
  256. HANDLE hFile;
  257. PVOID pOpt = NULL;
  258. hFile = CreateFile(g_szRstrmap, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  259. if (hFile == INVALID_HANDLE_VALUE)
  260. goto Err;
  261. while (ERROR_SUCCESS == ReadRestoreMapEntry(hFile, &prme))
  262. {
  263. GetPaths(prme, &pszSrc, &pszTemp, &pszDest, &pbAcl);
  264. wsprintf( szSeqNo , L"%ld", 0);
  265. wsprintf( szSize , L"%d" , prme->m_dwSize);
  266. wsprintf( szOperation, L"%s" , GetEventString(prme->m_dwOperation));
  267. wsprintf( szAttr , L"%08x" , prme->m_dwAttribute );
  268. wsprintf( szTmpFile , L"%s" , pszTemp ? pszTemp : L"");
  269. wsprintf( szSrc , L"%s" , pszSrc ? pszSrc : L"");
  270. wsprintf( szDest, L"%s", pszDest ? pszDest : L"");
  271. wsprintf( szAcl, L"%s", prme->m_cbAcl ? (prme->m_fAclInline ? L"Inline" : (LPWSTR) pbAcl) : L"");
  272. ChgLog_Insert(
  273. g_hwndRestMap,
  274. szSeqNo,
  275. szSize,
  276. szOperation,
  277. szAttr,
  278. szTmpFile,
  279. szSrc,
  280. szDest,
  281. szAcl);
  282. }
  283. FreeRestoreMapEntry(prme);
  284. CloseHandle(hFile);
  285. Err:
  286. return TRUE;
  287. }
  288. void
  289. PrintUsage()
  290. {
  291. printf("Usage : testmap <option> <drive> <rpnum> <rstrmappath>\n");
  292. printf(" 1 = both restoremap and changelog\n");
  293. printf(" 2 = only restoremap\n");
  294. printf(" 3 = only changelog\n");
  295. }
  296. int APIENTRY WinMain(HINSTANCE hInstance,
  297. HINSTANCE hPrevInstance,
  298. LPSTR lpCmdLine,
  299. int nCmdShow)
  300. {
  301. // TODO: Place code here.
  302. MSG msg;
  303. HACCEL hAccelTable;
  304. LPWSTR * argv = NULL;
  305. int argc;
  306. HGLOBAL hMem = NULL;
  307. InitAsyncTrace();
  308. #if !NOTRACE
  309. InitAsyncTrace();
  310. #endif
  311. argv = CommandLineToArgvW(GetCommandLine(), &argc);
  312. if (argc < 4)
  313. {
  314. PrintUsage();
  315. goto Exit;
  316. }
  317. g_nOption = _wtoi(argv[1]);
  318. lstrcpy(g_szDrive, argv[2]);
  319. g_nRPNum = _wtoi(argv[3]);
  320. if (argc >= 5)
  321. lstrcpy(g_szRstrmap, argv[4]);
  322. // Initialize global strings
  323. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  324. LoadString(hInstance, IDC_VXDAPP, szWindowClass, MAX_LOADSTRING);
  325. RegisterRestoreMapClass(hInstance);
  326. // Perform application initialization:
  327. if (!InitInstance (hInstance, nCmdShow))
  328. {
  329. return FALSE;
  330. }
  331. hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_VXDAPP);
  332. // Main message loop:
  333. while (GetMessage(&msg, NULL, 0, 0))
  334. {
  335. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  336. {
  337. TranslateMessage(&msg);
  338. DispatchMessage(&msg);
  339. }
  340. }
  341. Exit:
  342. if (argv) hMem = GlobalHandle(argv);
  343. if (hMem) GlobalFree(hMem);
  344. TermAsyncTrace();
  345. return msg.wParam;
  346. }
  347. //
  348. // FUNCTION: RegisterRestoreMapClass()
  349. //
  350. ATOM RegisterRestoreMapClass(HINSTANCE hInstance)
  351. {
  352. WNDCLASSEX wcex;
  353. wcex.cbSize = sizeof(WNDCLASSEX);
  354. wcex.style = CS_HREDRAW | CS_VREDRAW;
  355. wcex.lpfnWndProc = (WNDPROC)WndProc;
  356. wcex.cbClsExtra = 0;
  357. wcex.cbWndExtra = 0;
  358. wcex.hInstance = hInstance;
  359. wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_VXDAPP);
  360. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  361. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  362. wcex.lpszMenuName = (LPCWSTR)IDC_VXDAPP;
  363. wcex.lpszClassName = szWindowClass;
  364. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  365. return RegisterClassEx(&wcex);
  366. }
  367. //
  368. // FUNCTION: InitInstance(HANDLE, int)
  369. //
  370. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  371. {
  372. HWND hWnd;
  373. hInst = hInstance;
  374. // Force the common controls DLL to be loaded.
  375. InitCommonControls();
  376. if (g_nOption == 1)
  377. lstrcpy(szTitle, L"changelog - restoremap");
  378. else if (g_nOption == 2)
  379. lstrcpy(szTitle, L"restoremap");
  380. else if (g_nOption == 3)
  381. lstrcpy(szTitle, L"changelog");
  382. hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  383. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  384. if (!hWnd)
  385. {
  386. return FALSE;
  387. }
  388. ShowWindow(hWnd, nCmdShow);
  389. UpdateWindow(hWnd);
  390. g_hwndMain = hWnd;
  391. return TRUE;
  392. }
  393. //
  394. // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
  395. //
  396. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  397. {
  398. int wmId, wmEvent;
  399. PAINTSTRUCT ps;
  400. HDC hdc;
  401. WCHAR szHello[MAX_LOADSTRING];
  402. LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
  403. switch (message & 0xffff)
  404. {
  405. case WM_CREATE:
  406. {
  407. // Create the list view window.
  408. if (g_nOption == 1 || g_nOption == 3)
  409. {
  410. g_hwndChgLog = CreateWindow( WC_LISTVIEW, L"ListView_Window",
  411. WS_CHILD | LVS_REPORT | WS_VISIBLE,
  412. 0, 0, 300, 300,
  413. hWnd, NULL, hInst, NULL);
  414. if (g_hwndChgLog == NULL)
  415. {
  416. MessageBox(GetFocus(), L"List view cannot create", L"Error", MB_ICONHAND | MB_OK);
  417. return -1;
  418. }
  419. else
  420. {
  421. RECT rc;
  422. GetClientRect(hWnd, &rc);
  423. MoveWindow(g_hwndChgLog, 0, 0, rc.right, rc.bottom, TRUE);
  424. }
  425. ChgLog_InitColumns(g_hwndChgLog);
  426. ChgLog_FillWindow();
  427. }
  428. // Create the list view window.
  429. if (g_nOption == 1 || g_nOption == 2)
  430. {
  431. g_hwndRestMap = CreateWindow(WC_LISTVIEW, L"",
  432. WS_CHILD | LVS_REPORT | WS_VISIBLE,
  433. 0, 0, (g_nOption == 1) ? CW_USEDEFAULT : 300, (g_nOption == 1) ? CW_USEDEFAULT : 300,
  434. hWnd, NULL, hInst, NULL);
  435. if (g_hwndRestMap == NULL)
  436. { MessageBox(GetFocus(), L"Can't create RestMap View", L"Error", MB_ICONHAND | MB_OK);
  437. return -1;
  438. }
  439. else
  440. {
  441. RECT rc;
  442. GetClientRect(hWnd, &rc);
  443. MoveWindow(g_hwndRestMap, 0, (g_nOption == 1) ? (rc.bottom-rc.top)/2 : 0, rc.right, rc.bottom, TRUE);
  444. }
  445. ChgLog_InitColumns(g_hwndRestMap);
  446. RestMap_FillWindow();
  447. }
  448. break;
  449. }
  450. case WM_SIZE:
  451. if (g_hwndChgLog)
  452. { // resize list control
  453. RECT rc;
  454. GetClientRect(hWnd, &rc);
  455. MoveWindow(g_hwndChgLog, 0, 0, rc.right, rc.bottom/2, TRUE);
  456. } // resize list control
  457. if (g_hwndRestMap)
  458. { // resize list control
  459. RECT rc;
  460. GetClientRect(hWnd, &rc);
  461. MoveWindow(g_hwndRestMap, 0, (g_nOption == 1) ? rc.bottom/2 : 0, rc.right, rc.bottom/2, TRUE);
  462. }
  463. return 0;
  464. case WM_COMMAND:
  465. wmId = LOWORD(wParam);
  466. wmEvent = HIWORD(wParam);
  467. switch (wmId)
  468. {
  469. case IDM_ABOUT:
  470. DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
  471. break;
  472. case IDM_EXIT:
  473. DestroyWindow(hWnd);
  474. break;
  475. default:
  476. return DefWindowProc(hWnd, message, wParam, lParam);
  477. }
  478. break;
  479. case WM_PAINT:
  480. hdc = BeginPaint(hWnd, &ps);
  481. // TODO: Add any drawing code here...
  482. RECT rt;
  483. GetClientRect(hWnd, &rt);
  484. // DrawText(hdc, szHello, lstrlen(szHello), &rt, DT_CENTER);
  485. EndPaint(hWnd, &ps);
  486. break;
  487. case WM_DESTROY:
  488. PostQuitMessage(0);
  489. break;
  490. // Parse the menu selections:
  491. case WM_NOTIFY:
  492. if(((LPNMHDR) lParam)->hwndFrom == g_hwndChgLog)
  493. {
  494. switch (((LPNMHDR) lParam)->code)
  495. {
  496. case LVN_GETDISPINFO:
  497. ChgLog_OnGetDispInfo((NMLVDISPINFO*)lParam);
  498. break;
  499. }
  500. }
  501. if(((LPNMHDR) lParam)->hwndFrom == g_hwndRestMap)
  502. {
  503. switch (((LPNMHDR) lParam)->code)
  504. {
  505. case LVN_GETDISPINFO:
  506. ChgLog_OnGetDispInfo((NMLVDISPINFO*)lParam);
  507. break;
  508. }
  509. }
  510. return 0;
  511. default:
  512. return DefWindowProc(hWnd, message, wParam, lParam);
  513. }
  514. return 0;
  515. }
  516. // Mesage handler for about box.
  517. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  518. {
  519. switch (message)
  520. {
  521. case WM_INITDIALOG:
  522. return TRUE;
  523. case WM_COMMAND:
  524. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  525. {
  526. EndDialog(hDlg, LOWORD(wParam));
  527. return TRUE;
  528. }
  529. break;
  530. }
  531. return FALSE;
  532. }