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.

2530 lines
68 KiB

  1. //
  2. // Implementation file for the CListViews Class
  3. //
  4. #include <Windows.h>
  5. #include "stdafx.h"
  6. #include "CListViews.h"
  7. #include "resource.h"
  8. #include <wbemidl.h>
  9. #include <comdef.h>
  10. #include <Commctrl.h>
  11. #include <io.h>
  12. #include <Math.h>
  13. #include <commdlg.h>
  14. #define FILENAME_FIELD_WIDTH 10
  15. #define VERSION_FIELD_WIDTH 13
  16. #define DATE_FIELD_WIDTH 9
  17. #define CURRENT_FIELD_WIDTH 8
  18. #define PATH_FIELD_WIDTH 13
  19. BOOL bUserAbort;
  20. BOOL bSuccess;
  21. HWND hDlgPrint;
  22. #define BUFFER_SIZE 255
  23. LRESULT CListViews::OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled,HWND m_hWnd)
  24. {
  25. LPNMHDR lpnmh = (LPNMHDR) lParam;
  26. NM_LISTVIEW *pnm = (NM_LISTVIEW *)lParam;
  27. LPNMITEMACTIVATE lpnmia;
  28. HWND hwndListView = ::GetDlgItem(m_hWnd, 1001);
  29. _TCHAR ItemName[255];
  30. _TCHAR FileName[255];
  31. _TCHAR TempProduct[255];
  32. if ( lpnmh->idFrom != 1001)
  33. {
  34. return 0;
  35. }
  36. switch(lpnmh->code)
  37. {
  38. case LVN_ITEMCHANGED:
  39. lpnmia = (LPNMITEMACTIVATE)lParam;
  40. switch (m_CurrentView)
  41. {
  42. case VIEW_ALL_FILE:
  43. ListView_GetItemText(hwndListView, lpnmia->iItem,0,TempProduct,255);
  44. ListView_GetItemText(hwndListView, lpnmia->iItem,1,ItemName, 255);
  45. _tcscpy(CurrentProductName,TempProduct);
  46. _tcscpy(m_CurrentHotfix, ItemName);
  47. _tcscpy (m_ProductName,_T("\0"));
  48. AddItemsBottom();
  49. break;
  50. case VIEW_ALL_HOTFIX:
  51. ListView_GetItemText(hwndListView, lpnmia->iItem,0,TempProduct,255);
  52. ListView_GetItemText(hwndListView, lpnmia->iItem,1,ItemName, 255);
  53. _tcscpy(CurrentProductName,TempProduct);
  54. _tcscpy(m_CurrentHotfix, ItemName);
  55. _tcscpy (m_ProductName,_T("\0"));
  56. AddItemsBottom();
  57. break;
  58. case VIEW_BY_FILE:
  59. ListView_GetItemText(hwndListView, lpnmia->iItem,0,ItemName, 255);
  60. ListView_GetItemText(hwndListView, lpnmia->iItem,0,FileName, 255);
  61. _tcscpy(CurrentFile, FileName);
  62. _tcscpy(m_CurrentHotfix, ItemName);
  63. AddItemsBottom();
  64. break;
  65. case VIEW_BY_HOTFIX:
  66. ListView_GetItemText(hwndListView, lpnmia->iItem,0,ItemName, 255);
  67. _tcscpy(m_CurrentHotfix, ItemName);
  68. AddItemsBottom();
  69. break;
  70. } // end switch
  71. //_tcscpy(m_CurrentHotfix, ItemName);
  72. // Process LVN_COLUMNCLICK to sort items by column.
  73. break;
  74. case LVN_COLUMNCLICK:
  75. {
  76. //Message(TEXT("NotifyListView: LVN_COLUMNCLICK"), -1, NULL);
  77. ListView_SortItemsEx(
  78. lpnmh->hwndFrom,
  79. CompareFunc,
  80. pnm->iSubItem);
  81. m_SortOrder = !m_SortOrder;
  82. break;
  83. }
  84. break;
  85. } // end switch
  86. DWORD Status = GetState();
  87. ::EnableWindow(m_WebButton,FALSE);
  88. ::EnableWindow(m_UninstButton,FALSE);
  89. ::EnableWindow(m_RptButton,FALSE);
  90. if (Status & UNINSTALL_OK)
  91. ::EnableWindow(m_UninstButton,TRUE);
  92. if (Status & HOTFIX_SELECTED)
  93. ::EnableWindow(m_WebButton,TRUE);
  94. if (Status & OK_TO_PRINT)
  95. ::EnableWindow(m_RptButton,TRUE);
  96. // SetFocus(m_WebButton);
  97. bHandled = TRUE;
  98. return 0;
  99. }
  100. BOOL CListViews::Initialize( _TCHAR * ComputerName)
  101. {
  102. LVCOLUMN Col;
  103. _TCHAR TempComputer[255];
  104. _tcscpy(m_ProductName,_T("\0"));
  105. EnableWindow(m_WebButton, FALSE);
  106. EnableWindow(m_UninstButton,FALSE);
  107. for (DWORD i = 0; i< 3000000;i++) ;
  108. _tcscpy ( m_ComputerName, ComputerName);
  109. if (DataBase)
  110. FreeDatabase();
  111. DataBase = NULL;
  112. Col.mask = LVCF_WIDTH;
  113. SendMessage(TopList, LVM_DELETEALLITEMS, 0, 0);
  114. SendMessage(TopList, WM_SETREDRAW, FALSE, 0);
  115. while (ListView_GetColumn(TopList,0,&Col))
  116. ListView_DeleteColumn(TopList,0);
  117. // Clear the bottom list
  118. SendMessage(BottomList, LVM_DELETEALLITEMS, 0, 0);
  119. SendMessage(BottomList, WM_SETREDRAW, FALSE, 0);
  120. while (ListView_GetColumn(BottomList,0,&Col))
  121. ListView_DeleteColumn(BottomList,0);
  122. SendMessage(BottomList, WM_SETREDRAW,TRUE, 0);
  123. Col.mask = LVCF_FMT | LVCF_TEXT;
  124. Col.fmt = LVCFMT_LEFT;
  125. Col.pszText = _T("Hotfix Manager");
  126. ListView_InsertColumn(TopList,0,&Col);
  127. LVITEM LvItem;
  128. LvItem.mask = LVIF_TEXT;
  129. LvItem.iItem = 0;
  130. _TCHAR Message[255];
  131. _tcscpy(Message,_T("\0"));
  132. LoadString(m_hInst,IDS_RETRIEVE_DATA,Message,255);
  133. LvItem.pszText = Message;
  134. LvItem.iSubItem = 0;
  135. ListView_InsertItem(TopList,&LvItem);
  136. SendMessage(TopList, WM_SETREDRAW,TRUE, 0);
  137. DataBase = BuildDatabase (ComputerName);
  138. DWORD dwLength = 255;
  139. GetComputerName(TempComputer, &dwLength);
  140. if (_tcscmp(ComputerName, TempComputer))
  141. m_bRemoted = TRUE;
  142. else
  143. m_bRemoted = FALSE;
  144. _tcscpy (m_ProductName,_T("\0"));
  145. _tcscpy(m_CurrentHotfix, _T("\0"));
  146. AddItemsTop();
  147. AddItemsBottom();
  148. return TRUE;
  149. }
  150. BOOL CListViews::Initialize( HWND ParentWnd, HINSTANCE hInst,_TCHAR * ComputerName,
  151. HWND WebButton, HWND UninstButton, HWND RptButton)
  152. {
  153. m_bRemoted = FALSE;
  154. m_WebButton = WebButton;
  155. m_UninstButton = UninstButton;
  156. m_RptButton = RptButton;
  157. m_hInst = hInst;
  158. m_CurrentView = VIEW_ALL_HOTFIX;
  159. _tcscpy (m_ProductName,_T("\0"));
  160. DWORD dwStyle =
  161. WS_CHILD |
  162. WS_BORDER |
  163. LVS_AUTOARRANGE |
  164. // LVS_SORTDESCENDING|
  165. LVS_REPORT |
  166. LVS_SHAREIMAGELISTS |
  167. WS_VISIBLE | LVS_SHOWSELALWAYS ;
  168. TopList = CreateWindowEx( WS_EX_CLIENTEDGE, // ex style
  169. WC_LISTVIEW, // class name - defined in commctrl.h
  170. NULL, // window text
  171. dwStyle, // style
  172. 0, // x position
  173. 0, // y position
  174. 0, // width
  175. 0, // height
  176. ParentWnd, // parent
  177. (HMENU)1001, // ID
  178. hInst, // instance
  179. NULL); // no extra data
  180. dwStyle |= LVS_NOSORTHEADER;
  181. BottomList = CreateWindowEx( WS_EX_CLIENTEDGE, // ex style
  182. WC_LISTVIEW, // class name - defined in commctrl.h
  183. NULL, // window text
  184. dwStyle, // style
  185. 0, // x position
  186. 0, // y position
  187. 0, // width
  188. 0, // height
  189. ParentWnd, // parent
  190. NULL, // ID
  191. hInst, // instance
  192. NULL); // no extra data
  193. ListView_SetExtendedListViewStyle(TopList, LVS_EX_FULLROWSELECT);
  194. ListView_SetExtendedListViewStyle(BottomList, LVS_EX_FULLROWSELECT);
  195. _tcscpy (m_ProductName,_T("\0"));
  196. _tcscpy (m_CurrentHotfix,_T("\0"));
  197. return TRUE;
  198. }
  199. BOOL CListViews::Resize(RECT *rc)
  200. {
  201. MoveWindow( TopList,
  202. rc->left,
  203. rc->top,
  204. rc->right - rc->left,
  205. (rc->bottom -50) /2 - 2,
  206. TRUE);
  207. MoveWindow( BottomList,
  208. rc->left,
  209. ( rc->bottom-50) / 2 ,
  210. rc->right - rc->left,
  211. rc->bottom-50 - (rc->bottom -50) /2,
  212. TRUE);
  213. return TRUE;
  214. }
  215. BOOL CListViews::ShowLists(RECT * rc)
  216. {
  217. ShowWindow(TopList,TRUE);
  218. ShowWindow(BottomList, TRUE);
  219. Resize(rc);
  220. return TRUE;
  221. }
  222. BOOL CListViews::AddItemsTop()
  223. {
  224. // Top View First
  225. LVITEM LvItem;
  226. LVCOLUMN Col;
  227. _TCHAR szBuffer[255];
  228. PHOTFIXLIST CurrentHotfix;
  229. PFILELIST CurrentFile;
  230. int itemnum = 0;
  231. // int iSubItem = 0;
  232. PPRODUCT CurrentEntry;
  233. LvItem.iItem = itemnum;
  234. LvItem.mask = LVIF_TEXT ;
  235. Col.mask = LVCF_WIDTH;
  236. SendMessage(TopList, LVM_DELETEALLITEMS, 0, 0);
  237. SendMessage(TopList, WM_SETREDRAW, FALSE, 0);
  238. while (ListView_GetColumn(TopList,0,&Col))
  239. ListView_DeleteColumn(TopList,0);
  240. Col.cx =100;
  241. Col.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
  242. Col.fmt = LVCFMT_LEFT;
  243. switch (m_CurrentView )
  244. {
  245. case VIEW_ALL_HOTFIX: // default for primary node.
  246. {
  247. CurrentEntry = DataBase;
  248. LoadString(m_hInst,IDS_PRODUCT_NAME,szBuffer ,255);
  249. Col.pszText = _T("Product Name");
  250. ListView_InsertColumn(TopList,0,&Col);
  251. LoadString(m_hInst,IDS_ARTICLE_NUMBER,szBuffer ,255);
  252. Col.pszText = szBuffer;
  253. ListView_InsertColumn(TopList,1,&Col);
  254. LoadString(m_hInst,IDS_DESCRIPTION,szBuffer ,255);
  255. Col.pszText = szBuffer;
  256. ListView_InsertColumn(TopList,2,&Col);
  257. LoadString(m_hInst,IDS_SERVICE_PACK,szBuffer ,255);
  258. Col.pszText = szBuffer;
  259. ListView_InsertColumn(TopList,3,&Col);
  260. LoadString(m_hInst,IDS_INSTALLED_BY,szBuffer ,255);
  261. Col.pszText = szBuffer;
  262. ListView_InsertColumn(TopList,4,&Col);
  263. LoadString(m_hInst,IDS_INSTALL_DATE,szBuffer ,255);
  264. Col.pszText = szBuffer;
  265. ListView_InsertColumn(TopList,5,&Col);
  266. LoadString(m_hInst,IDS_UPDATE_TYPE,szBuffer ,255);
  267. Col.pszText = szBuffer;
  268. ListView_InsertColumn(TopList,6,&Col);
  269. LvItem.mask = LVIF_TEXT ;
  270. if (CurrentEntry == NULL)
  271. {
  272. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  273. LvItem.iSubItem = 0;
  274. LvItem.pszText = szBuffer;
  275. ListView_InsertItem(TopList,&LvItem);
  276. SendMessage(TopList, WM_SETREDRAW, TRUE, 0);
  277. return FALSE;
  278. }
  279. while (CurrentEntry != NULL)
  280. {
  281. // first insert the product name
  282. // Now walk down the hotfix list.
  283. CurrentHotfix = CurrentEntry->HotfixList;
  284. while (CurrentHotfix != NULL)
  285. {
  286. LvItem.mask |= LVIF_PARAM;
  287. LvItem.iItem = itemnum;
  288. LvItem.pszText = CurrentEntry->ProductName;
  289. LvItem.iSubItem = 0;
  290. ListView_InsertItem(TopList,&LvItem);
  291. ListView_SetItemText(TopList, itemnum, 1, CurrentHotfix->HotfixName);
  292. ListView_SetItemText(TopList, itemnum, 2 , CurrentHotfix->Description);
  293. ListView_SetItemText(TopList, itemnum, 3, CurrentHotfix->ServicePack);
  294. ListView_SetItemText(TopList, itemnum, 4, CurrentHotfix->InstalledBy);
  295. ListView_SetItemText(TopList, itemnum, 5, CurrentHotfix->InstalledDate);
  296. ListView_SetItemText(TopList, itemnum, 6, CurrentHotfix->Type);
  297. if (itemnum == 0)
  298. {
  299. // MessageBox(NULL,CurrentEntry->ProductName, _T("Selecting Product"),MB_OK);
  300. _tcscpy(CurrentProductName,CurrentEntry->ProductName);
  301. _tcscpy(m_CurrentHotfix, CurrentEntry->HotfixList->HotfixName );
  302. ListView_SetItemState(TopList, 0,LVIS_SELECTED,LVIS_STATEIMAGEMASK | LVIS_SELECTED);
  303. ::EnableWindow(m_WebButton,FALSE);
  304. ::EnableWindow(m_UninstButton,FALSE);
  305. ::EnableWindow(m_RptButton,FALSE);
  306. DWORD Status = GetState();
  307. if (Status & UNINSTALL_OK)
  308. ::EnableWindow(m_UninstButton,TRUE);
  309. if (Status & HOTFIX_SELECTED)
  310. ::EnableWindow(m_WebButton,TRUE);
  311. if (Status & OK_TO_PRINT)
  312. ::EnableWindow(m_RptButton,TRUE);
  313. SetFocus(m_WebButton);
  314. }
  315. itemnum++;
  316. CurrentHotfix = CurrentHotfix->pNext;
  317. }
  318. CurrentEntry = CurrentEntry->pNext;
  319. }
  320. }
  321. break;
  322. case VIEW_ALL_FILE: // View all of the files updated by all products.
  323. CurrentEntry = DataBase;
  324. // MessageBox(NULL,_T("Viewing all by file"),NULL,MB_OK);
  325. LoadString(m_hInst,IDS_PRODUCT_NAME,szBuffer ,255);
  326. Col.pszText = szBuffer;
  327. ListView_InsertColumn(TopList,0,&Col);
  328. LoadString(m_hInst,IDS_ARTICLE_NUMBER,szBuffer ,255);
  329. Col.pszText = szBuffer;
  330. ListView_InsertColumn(TopList,1,&Col);
  331. LoadString(m_hInst,IDS_FILE_NAME,szBuffer ,255);
  332. Col.pszText = szBuffer;
  333. ListView_InsertColumn(TopList,2,&Col);
  334. LoadString(m_hInst,IDS_FILE_DATE,szBuffer ,255);
  335. Col.pszText = szBuffer;
  336. ListView_InsertColumn(TopList,3,&Col);
  337. LoadString(m_hInst,IDS_FILE_CURRENT,szBuffer ,255);
  338. Col.pszText = szBuffer;
  339. ListView_InsertColumn(TopList,4,&Col);
  340. LoadString(m_hInst,IDS_FILE_VERSION,szBuffer ,255);
  341. Col.pszText = szBuffer;
  342. ListView_InsertColumn(TopList,5,&Col);
  343. LoadString(m_hInst,IDS_FILE_LOCATION,szBuffer ,255);
  344. Col.pszText = szBuffer;
  345. ListView_InsertColumn(TopList,6,&Col);
  346. if (CurrentEntry == NULL)
  347. {
  348. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  349. LvItem.iSubItem = 0;
  350. LvItem.pszText = szBuffer;
  351. ListView_InsertItem(TopList,&LvItem);
  352. SendMessage(TopList, WM_SETREDRAW, TRUE, 0);
  353. // MessageBox(NULL,_T("No Database"),NULL,MB_OK);
  354. return FALSE;
  355. }
  356. LvItem.mask = LVIF_TEXT;
  357. while (CurrentEntry != NULL)
  358. {
  359. // first insert the product name
  360. // Now walk down the hotfix list.
  361. CurrentHotfix = CurrentEntry->HotfixList;
  362. while (CurrentHotfix != NULL)
  363. {
  364. CurrentFile = CurrentHotfix->FileList;
  365. LvItem.iItem = itemnum;
  366. while (CurrentFile != NULL)
  367. {
  368. LvItem.pszText = CurrentEntry->ProductName;
  369. LvItem.iSubItem = 0;
  370. ListView_InsertItem(TopList,&LvItem);
  371. ListView_SetItemText(TopList, itemnum, 1, CurrentHotfix->HotfixName);
  372. ListView_SetItemText(TopList, itemnum, 2 , CurrentFile->FileName);
  373. ListView_SetItemText(TopList, itemnum, 3, CurrentFile->FileDate);
  374. ListView_SetItemText(TopList, itemnum, 4, CurrentFile->IsCurrent);
  375. ListView_SetItemText(TopList, itemnum, 5, CurrentFile->FileVersion);
  376. ListView_SetItemText(TopList, itemnum, 6, CurrentFile->InstallPath);
  377. itemnum++;
  378. CurrentFile = CurrentFile->pNext;
  379. LvItem.iItem = itemnum;
  380. }
  381. CurrentHotfix = CurrentHotfix->pNext;
  382. }
  383. CurrentEntry = CurrentEntry->pNext;
  384. }
  385. break;
  386. case VIEW_BY_HOTFIX:
  387. CurrentEntry = DataBase;
  388. if (CurrentEntry == NULL)
  389. {
  390. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  391. LvItem.iSubItem = 0;
  392. LvItem.pszText = szBuffer;
  393. ListView_InsertItem(TopList,&LvItem);
  394. SendMessage(TopList, WM_SETREDRAW, TRUE, 0);
  395. return FALSE;
  396. }
  397. LoadString(m_hInst,IDS_ARTICLE_NUMBER,szBuffer ,255);
  398. Col.pszText = szBuffer;
  399. ListView_InsertColumn(TopList,0,&Col);
  400. LoadString(m_hInst,IDS_DESCRIPTION,szBuffer ,255);
  401. Col.pszText = szBuffer;
  402. ListView_InsertColumn(TopList,1,&Col);
  403. LoadString(m_hInst,IDS_SERVICE_PACK,szBuffer ,255);
  404. Col.pszText = szBuffer;
  405. ListView_InsertColumn(TopList,2,&Col);
  406. LoadString(m_hInst,IDS_INSTALLED_BY,szBuffer ,255);
  407. Col.pszText = szBuffer;
  408. ListView_InsertColumn(TopList,3,&Col);
  409. LoadString(m_hInst,IDS_INSTALL_DATE,szBuffer ,255);
  410. Col.pszText = szBuffer;
  411. ListView_InsertColumn(TopList,4,&Col);
  412. LoadString(m_hInst,IDS_UPDATE_TYPE,szBuffer ,255);
  413. Col.pszText = szBuffer;
  414. ListView_InsertColumn(TopList,5,&Col);
  415. LvItem.mask = LVIF_TEXT;
  416. while ( _tcscmp(CurrentEntry->ProductName, m_ProductName) && (CurrentEntry != NULL))
  417. CurrentEntry = CurrentEntry->pNext;
  418. // first insert the product name
  419. // Now walk down the hotfix list.
  420. if (CurrentEntry == NULL)
  421. {
  422. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  423. LvItem.iSubItem = 0;
  424. LvItem.pszText = szBuffer;
  425. ListView_InsertItem(TopList,&LvItem);
  426. SendMessage(TopList, WM_SETREDRAW, TRUE, 0);
  427. return FALSE;
  428. }
  429. CurrentHotfix = CurrentEntry->HotfixList;
  430. while (CurrentHotfix != NULL)
  431. {
  432. LvItem.iItem = itemnum;
  433. LvItem.pszText = CurrentHotfix->HotfixName;
  434. LvItem.iSubItem = 0;
  435. ListView_InsertItem(TopList,&LvItem);
  436. ListView_SetItemText(TopList, itemnum, 1 , CurrentHotfix->Description);
  437. ListView_SetItemText(TopList, itemnum, 2, CurrentHotfix->ServicePack);
  438. ListView_SetItemText(TopList, itemnum, 4, CurrentHotfix->InstalledDate);
  439. ListView_SetItemText(TopList, itemnum, 3, CurrentHotfix->InstalledBy);
  440. ListView_SetItemText(TopList, itemnum, 5, CurrentHotfix->Type);
  441. if (itemnum == 0)
  442. {
  443. // MessageBox(NULL,CurrentEntry->ProductName, _T("Selecting Product"),MB_OK);
  444. _tcscpy(CurrentProductName,CurrentEntry->ProductName);
  445. _tcscpy(m_CurrentHotfix, CurrentEntry->HotfixList->HotfixName );
  446. ListView_SetItemState(TopList, 0,LVIS_SELECTED,LVIS_STATEIMAGEMASK | LVIS_SELECTED);
  447. ::EnableWindow(m_WebButton,FALSE);
  448. ::EnableWindow(m_UninstButton,FALSE);
  449. ::EnableWindow(m_RptButton,FALSE);
  450. DWORD Status = GetState();
  451. if (Status & UNINSTALL_OK)
  452. ::EnableWindow(m_UninstButton,TRUE);
  453. if (Status & HOTFIX_SELECTED)
  454. ::EnableWindow(m_WebButton,TRUE);
  455. if (Status & OK_TO_PRINT)
  456. ::EnableWindow(m_RptButton,TRUE);
  457. SetFocus(m_WebButton);
  458. }
  459. itemnum++;
  460. CurrentHotfix = CurrentHotfix->pNext;
  461. }
  462. break;
  463. case VIEW_BY_FILE: // Displays all files modified by all updates for the current product.
  464. CurrentEntry = DataBase;
  465. LoadString(m_hInst,IDS_ARTICLE_NUMBER,szBuffer ,255);
  466. Col.pszText = szBuffer;
  467. ListView_InsertColumn(TopList,1,&Col);
  468. LoadString(m_hInst,IDS_FILE_NAME,szBuffer ,255);
  469. Col.pszText = szBuffer;
  470. ListView_InsertColumn(TopList,2,&Col);
  471. LoadString(m_hInst,IDS_FILE_DATE,szBuffer ,255);
  472. Col.pszText = szBuffer;
  473. ListView_InsertColumn(TopList,3,&Col);
  474. LoadString(m_hInst,IDS_FILE_CURRENT,szBuffer ,255);
  475. Col.pszText = szBuffer;
  476. ListView_InsertColumn(TopList,4,&Col);
  477. LoadString(m_hInst,IDS_FILE_VERSION,szBuffer ,255);
  478. Col.pszText = szBuffer;
  479. ListView_InsertColumn(TopList,5,&Col);
  480. LoadString(m_hInst,IDS_FILE_LOCATION,szBuffer ,255);
  481. Col.pszText = szBuffer;
  482. ListView_InsertColumn(TopList,6,&Col);
  483. if (CurrentEntry == FALSE)
  484. {
  485. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  486. LvItem.iSubItem = 0;
  487. LvItem.pszText = szBuffer;
  488. ListView_InsertItem(TopList,&LvItem);
  489. SendMessage(TopList, WM_SETREDRAW, TRUE, 0);
  490. return FALSE;
  491. }
  492. LvItem.mask = LVIF_TEXT;
  493. // first insert locate the product name
  494. while ( (_tcscmp(CurrentEntry->ProductName,m_ProductName) )&& (CurrentEntry != NULL))
  495. CurrentEntry = CurrentEntry->pNext;
  496. // Now walk down the hotfix list.
  497. if (CurrentEntry == NULL)
  498. {
  499. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  500. LvItem.iSubItem = 0;
  501. LvItem.pszText = szBuffer;
  502. ListView_InsertItem(TopList,&LvItem);
  503. SendMessage(TopList, WM_SETREDRAW, TRUE, 0);
  504. return FALSE;
  505. }
  506. CurrentHotfix = CurrentEntry->HotfixList;
  507. while (CurrentHotfix != NULL)
  508. {
  509. LvItem.iItem = itemnum;
  510. CurrentFile = CurrentHotfix->FileList;
  511. while (CurrentFile != NULL)
  512. {
  513. LvItem.pszText = CurrentHotfix->HotfixName;
  514. LvItem.iSubItem = 0;
  515. ListView_InsertItem(TopList,&LvItem);
  516. ListView_SetItemText(TopList, itemnum, 1 , CurrentFile->FileName);
  517. ListView_SetItemText(TopList, itemnum, 2, CurrentFile->FileDate);
  518. ListView_SetItemText(TopList, itemnum, 3, CurrentFile->IsCurrent);
  519. ListView_SetItemText(TopList, itemnum, 4, CurrentFile->FileVersion);
  520. ListView_SetItemText(TopList, itemnum, 5, CurrentFile->InstallPath);
  521. if (itemnum == 0)
  522. {
  523. // MessageBox(NULL,CurrentEntry->ProductName, _T("Selecting Product"),MB_OK);
  524. _tcscpy(CurrentProductName,CurrentEntry->ProductName);
  525. _tcscpy(m_CurrentHotfix, CurrentEntry->HotfixList->HotfixName );
  526. ListView_SetItemState(TopList, 0,LVIS_SELECTED,LVIS_STATEIMAGEMASK | LVIS_SELECTED);
  527. ::EnableWindow(m_WebButton,FALSE);
  528. ::EnableWindow(m_UninstButton,FALSE);
  529. ::EnableWindow(m_RptButton,FALSE);
  530. DWORD Status = GetState();
  531. if (Status & UNINSTALL_OK)
  532. ::EnableWindow(m_UninstButton,TRUE);
  533. if (Status & HOTFIX_SELECTED)
  534. ::EnableWindow(m_WebButton,TRUE);
  535. if (Status & OK_TO_PRINT)
  536. ::EnableWindow(m_RptButton,TRUE);
  537. SetFocus(m_WebButton);
  538. }
  539. itemnum++;
  540. LvItem.iItem = itemnum;
  541. CurrentFile = CurrentFile->pNext;
  542. }
  543. CurrentHotfix = CurrentHotfix->pNext;
  544. }
  545. break;
  546. } // end switch
  547. SendMessage(TopList, WM_SETREDRAW, TRUE, 0);
  548. return TRUE;
  549. }
  550. BOOL CListViews::AddItemsBottom ()
  551. {
  552. LVITEM LvItem;
  553. LVCOLUMN Col;
  554. _TCHAR szBuffer[255];
  555. PHOTFIXLIST CurrentHotfix;
  556. PFILELIST CurrentFile;
  557. int itemnum = 0;
  558. // int iSubItem = 0;
  559. // int ItemCount = 0;
  560. BOOL Done = FALSE;
  561. LvItem.mask = LVIF_TEXT;
  562. LvItem.iItem = itemnum;
  563. PPRODUCT CurrentEntry;
  564. // Clear the List View and prepare it for updating....
  565. SendMessage(BottomList, LVM_DELETEALLITEMS, 0, 0);
  566. SendMessage(BottomList, WM_SETREDRAW, FALSE, 0);
  567. Col.mask =LVCF_WIDTH;
  568. while (ListView_GetColumn(BottomList,0,&Col))
  569. ListView_DeleteColumn(BottomList,0);
  570. Col.mask = LVCF_TEXT | LVCF_WIDTH;
  571. Col.cx = 100;
  572. switch (m_CurrentView)
  573. {
  574. case VIEW_ALL_FILE:
  575. case VIEW_BY_FILE:
  576. CurrentEntry = DataBase;
  577. LoadString(m_hInst,IDS_ARTICLE_NUMBER,szBuffer ,255);
  578. Col.pszText = szBuffer;
  579. ListView_InsertColumn(BottomList,0,&Col);
  580. LoadString(m_hInst,IDS_DESCRIPTION,szBuffer ,255);
  581. Col.pszText = szBuffer;
  582. ListView_InsertColumn(BottomList,1,&Col);
  583. LoadString(m_hInst,IDS_SERVICE_PACK,szBuffer ,255);
  584. Col.pszText = szBuffer;
  585. ListView_InsertColumn(BottomList,2,&Col);
  586. LoadString(m_hInst,IDS_INSTALLED_BY,szBuffer ,255);
  587. Col.pszText = szBuffer;
  588. ListView_InsertColumn(BottomList,3,&Col);
  589. LoadString(m_hInst,IDS_INSTALL_DATE,szBuffer ,255);
  590. Col.pszText = szBuffer;
  591. ListView_InsertColumn(BottomList,4,&Col);
  592. LoadString(m_hInst,IDS_UPDATE_TYPE,szBuffer ,255);
  593. Col.pszText = szBuffer;
  594. ListView_InsertColumn(BottomList,5,&Col);
  595. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  596. LvItem.mask = LVIF_TEXT;
  597. if (CurrentEntry == NULL)
  598. {
  599. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  600. LvItem.iSubItem = 0;
  601. LvItem.pszText = szBuffer;
  602. ListView_InsertItem(BottomList,&LvItem);
  603. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  604. // MessageBox(NULL, _T("Database is NULL"),_T("No Items"), MB_OK);
  605. return FALSE;
  606. }
  607. Done = FALSE;
  608. if (_tcscmp (m_ProductName,_T("\0")))
  609. {
  610. while ( (!Done) && (CurrentEntry != NULL))
  611. {
  612. if (!_tcscmp(CurrentEntry->ProductName, m_ProductName))
  613. Done = TRUE;
  614. else
  615. CurrentEntry = CurrentEntry->pNext;
  616. }
  617. }
  618. else
  619. {
  620. while ( (!Done) && (CurrentEntry != NULL))
  621. {
  622. if (!_tcscmp(CurrentEntry->ProductName, CurrentProductName))
  623. Done = TRUE;
  624. else
  625. CurrentEntry = CurrentEntry->pNext;
  626. }
  627. }
  628. // Now walk down the hotfix list.
  629. if (CurrentEntry == NULL)
  630. {
  631. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  632. LvItem.iSubItem = 0;
  633. LvItem.pszText = szBuffer;
  634. ListView_InsertItem(BottomList,&LvItem);
  635. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  636. // MessageBox(NULL, _T("Product Not found or not selected"), _T("No Items"),MB_OK);
  637. return FALSE;
  638. }
  639. CurrentHotfix = CurrentEntry->HotfixList;
  640. while ( (CurrentHotfix != NULL) && (_tcscmp(CurrentHotfix->HotfixName, m_CurrentHotfix)))
  641. CurrentHotfix = CurrentHotfix->pNext;
  642. if (CurrentHotfix != NULL)
  643. {
  644. LvItem.iItem = itemnum;
  645. LvItem.pszText = CurrentHotfix->HotfixName,
  646. LvItem.iSubItem = 0;
  647. ListView_InsertItem(BottomList,&LvItem);
  648. ListView_SetItemText(BottomList, itemnum, 1 , CurrentHotfix->Description);
  649. ListView_SetItemText(BottomList, itemnum, 2, CurrentHotfix->ServicePack);
  650. ListView_SetItemText(BottomList, itemnum, 3, CurrentHotfix->InstalledBy);
  651. ListView_SetItemText(BottomList, itemnum, 4, CurrentHotfix->InstalledDate);
  652. ListView_SetItemText(BottomList, itemnum, 5, CurrentHotfix->Type);
  653. itemnum++;
  654. CurrentHotfix = CurrentHotfix->pNext;
  655. }
  656. else
  657. {
  658. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  659. LvItem.iSubItem = 0;
  660. LvItem.pszText = szBuffer;
  661. ListView_InsertItem(BottomList,&LvItem);
  662. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  663. // MessageBox(NULL, _T("No Hotfix Found"), _T("No Items"),MB_OK);
  664. return FALSE;
  665. }
  666. break;
  667. case VIEW_ALL_HOTFIX:
  668. case VIEW_BY_HOTFIX:
  669. CurrentEntry = DataBase;
  670. LoadString(m_hInst,IDS_ARTICLE_NUMBER,szBuffer ,255);
  671. Col.pszText = szBuffer;
  672. ListView_InsertColumn(BottomList,1,&Col);
  673. LoadString(m_hInst,IDS_FILE_NAME,szBuffer ,255);
  674. Col.pszText = szBuffer;
  675. ListView_InsertColumn(BottomList,2,&Col);
  676. LoadString(m_hInst,IDS_FILE_DATE,szBuffer ,255);
  677. Col.pszText = szBuffer;
  678. ListView_InsertColumn(BottomList,3,&Col);
  679. LoadString(m_hInst,IDS_FILE_CURRENT,szBuffer ,255);
  680. Col.pszText = szBuffer;
  681. ListView_InsertColumn(BottomList,4,&Col);
  682. LoadString(m_hInst,IDS_FILE_VERSION,szBuffer ,255);
  683. Col.pszText = szBuffer;
  684. ListView_InsertColumn(BottomList,5,&Col);
  685. LoadString(m_hInst,IDS_FILE_LOCATION,szBuffer ,255);
  686. Col.pszText = szBuffer;
  687. ListView_InsertColumn(BottomList,6,&Col);
  688. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  689. LvItem.mask = LVIF_TEXT ;
  690. // first insert locate the product name
  691. /* if (!_tcscmp(m_ProductName,_T("\0")))
  692. { LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  693. LvItem.iSubItem = 0;
  694. LvItem.pszText = szBuffer;
  695. ListView_InsertItem(BottomList,&LvItem);
  696. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  697. return FALSE;
  698. }
  699. */
  700. if (CurrentEntry == NULL)
  701. {
  702. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  703. LvItem.iSubItem = 0;
  704. LvItem.pszText = szBuffer;
  705. LvItem.lParam = NULL;
  706. ListView_InsertItem(BottomList,&LvItem);
  707. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  708. // MessageBox(NULL, _T("No Database"), _T("No Items"),MB_OK);
  709. return FALSE;
  710. }
  711. if (_tcscmp (m_ProductName,_T("\0")))
  712. {
  713. while ( (!Done) && (CurrentEntry != NULL))
  714. {
  715. if (!_tcscmp(CurrentEntry->ProductName, m_ProductName))
  716. Done = TRUE;
  717. else
  718. CurrentEntry = CurrentEntry->pNext;
  719. }
  720. }
  721. else
  722. {
  723. while ( (!Done) && (CurrentEntry != NULL))
  724. {
  725. if (!_tcscmp(CurrentEntry->ProductName, CurrentProductName))
  726. Done = TRUE;
  727. else
  728. CurrentEntry = CurrentEntry->pNext;
  729. }
  730. }
  731. // Now walk down the hotfix list.
  732. if (CurrentEntry == NULL)
  733. {
  734. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  735. LvItem.iSubItem = 0;
  736. LvItem.pszText = szBuffer;
  737. LvItem. lParam = NULL;
  738. ListView_InsertItem(BottomList,&LvItem);
  739. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  740. // MessageBox(NULL, _T("Product Not found or not selected"), _T("No Items"),MB_OK);
  741. return FALSE;
  742. }
  743. CurrentHotfix = CurrentEntry->HotfixList;
  744. while ((CurrentHotfix != NULL) && (_tcscmp(CurrentHotfix->HotfixName, m_CurrentHotfix)))
  745. CurrentHotfix = CurrentHotfix->pNext;
  746. if ( CurrentHotfix == NULL)
  747. {
  748. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  749. LvItem.iSubItem = 0;
  750. LvItem.pszText = szBuffer;
  751. LvItem.lParam = NULL;
  752. ListView_InsertItem(BottomList,&LvItem);
  753. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  754. // MessageBox(NULL,_T("No Hotfix Found"), _T("No Items"), MB_OK);
  755. return FALSE;
  756. }
  757. if (CurrentHotfix != NULL)
  758. {
  759. LvItem.iItem = itemnum;
  760. CurrentFile = CurrentHotfix->FileList;
  761. if (CurrentFile == NULL)
  762. {
  763. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  764. LvItem.iSubItem = 0;
  765. LvItem.pszText = szBuffer;
  766. LvItem.lParam = NULL;
  767. ListView_InsertItem(BottomList,&LvItem);
  768. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  769. // MessageBox (NULL, _T("No Files Found"), _T("No Items"), MB_OK);
  770. return FALSE;
  771. }
  772. while (CurrentFile != NULL)
  773. {
  774. LvItem.pszText = CurrentHotfix->HotfixName;
  775. LvItem.iSubItem = 0;
  776. ListView_InsertItem(BottomList,&LvItem);
  777. ListView_SetItemText(BottomList, itemnum, 1 , CurrentFile->FileName);
  778. ListView_SetItemText(BottomList, itemnum, 2, CurrentFile->FileDate);
  779. ListView_SetItemText(BottomList, itemnum, 3, CurrentFile->IsCurrent);
  780. ListView_SetItemText(BottomList, itemnum, 4, CurrentFile->FileVersion);
  781. ListView_SetItemText(BottomList, itemnum, 5, CurrentFile->InstallPath);
  782. itemnum++;
  783. LvItem.iItem = itemnum;
  784. CurrentFile = CurrentFile->pNext;
  785. }
  786. CurrentHotfix = CurrentHotfix->pNext;
  787. }
  788. else
  789. {
  790. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  791. LvItem.iSubItem = 0;
  792. LvItem.pszText = szBuffer;
  793. ListView_InsertItem(BottomList,&LvItem);
  794. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  795. return FALSE;
  796. }
  797. break;
  798. default:
  799. LoadString(m_hInst,IDS_NO_ITEMS,szBuffer, 255);
  800. LvItem.iSubItem = 0;
  801. LvItem.pszText = szBuffer;
  802. ListView_InsertItem(BottomList,&LvItem);
  803. return FALSE;
  804. } // end switch
  805. SendMessage(BottomList, WM_SETREDRAW, TRUE, 0);
  806. return TRUE;
  807. }
  808. PPRODUCT CListViews::BuildDatabase(_TCHAR * lpszComputerName)
  809. {
  810. HKEY hPrimaryKey; // Handle of the target system HKLM
  811. // _TCHAR szPrimaryPath; // Path to the update key;
  812. HKEY hUpdatesKey; // Handle to the updates key.
  813. _TCHAR szUpdatesPath[BUFFER_SIZE]; // Path to the udates key
  814. DWORD dwUpdatesIndex; // index of current updates subkey
  815. DWORD dwBufferSize; // Size of the product name buffer.
  816. _TCHAR szProductPath[BUFFER_SIZE]; // Path of the current product key
  817. _TCHAR szProductName[BUFFER_SIZE]; // Name of product; also path to product key
  818. PPRODUCT pProductList = NULL; // Pointer to the head of the product list.
  819. PPRODUCT pNewProdNode; // Pointer used to allocate new nodes in the product list.
  820. PPRODUCT pCurrProdNode; // Used to walk the Products List;
  821. // Connect to the target registry
  822. RegConnectRegistry(lpszComputerName,HKEY_LOCAL_MACHINE, &hPrimaryKey);
  823. // insert error handling here......
  824. if (hPrimaryKey != NULL)
  825. {
  826. // Initialize the primary path not localized since registry keys are not localized.
  827. _tcscpy (szUpdatesPath, _T("SOFTWARE\\Microsoft\\Updates"));
  828. // open the udates key
  829. RegOpenKeyEx(hPrimaryKey,szUpdatesPath, 0, KEY_READ ,&hUpdatesKey);
  830. if (hUpdatesKey != NULL)
  831. {
  832. // Enumerate the Updates key.
  833. dwUpdatesIndex = 0;
  834. while ( RegEnumKeyEx(hUpdatesKey,dwUpdatesIndex,szProductName, &dwBufferSize,0,NULL,NULL,NULL) != ERROR_NO_MORE_ITEMS)
  835. {
  836. // Create a node for the current product
  837. pNewProdNode = (PPRODUCT) malloc(sizeof(PRODUCTLIST));
  838. _tcscpy(pNewProdNode->ProductName,szProductName);
  839. _tcscpy (szProductPath, szProductName);
  840. // now get the hotfix for the current product.
  841. pNewProdNode->HotfixList = GetHotfixInfo(szProductName, &hUpdatesKey);
  842. // Insert the new node into the list.
  843. pCurrProdNode=pProductList;
  844. if (pCurrProdNode == NULL) // Head of the list
  845. {
  846. pProductList = pNewProdNode;
  847. pProductList->pPrev = NULL;
  848. pProductList->pNext = NULL;
  849. }
  850. else
  851. {
  852. //Find the end of the list.
  853. while (pCurrProdNode->pNext != NULL)
  854. pCurrProdNode = pCurrProdNode->pNext;
  855. // Now insert the new node at the end of the list.
  856. pCurrProdNode->pNext = pNewProdNode;
  857. pNewProdNode->pPrev = pCurrProdNode;
  858. pNewProdNode->pNext = NULL;
  859. }
  860. // increment index and clear the szProducts name string for the next pass.
  861. dwUpdatesIndex++;
  862. _tcscpy (szProductName,_T("\0"));
  863. _tcscpy(szProductPath, _T("\0"));
  864. dwBufferSize = 255;
  865. }
  866. }
  867. // close the open keys
  868. RegCloseKey(hUpdatesKey);
  869. RegCloseKey(hPrimaryKey);
  870. }
  871. // return a pointer to the head of our database.
  872. VerifyFiles(pProductList);
  873. return pProductList;
  874. }
  875. void BuildQuery (_TCHAR * Path, _TCHAR * FileName, _TCHAR * Result)
  876. {
  877. _TCHAR * src;
  878. _TCHAR * dest;
  879. _TCHAR Temp[255];
  880. src = Path;
  881. dest = Temp;
  882. while (*src != _T('\0'))
  883. {
  884. if (*src == _T('\\')) // if we hit a \ character we need to insert four of them in the dest string.
  885. {
  886. for (int i = 0; i < 4; i++)
  887. {
  888. *dest = *src;
  889. ++dest;
  890. }
  891. ++src;
  892. }
  893. else
  894. {
  895. *dest = *src;
  896. ++src;
  897. ++dest;
  898. }
  899. }
  900. *dest = _T('\0');
  901. _stprintf(Result,_T("SELECT * from CIM_DataFile WHERE Name = '%s\\\\\\\\%s'"), Temp, FileName);
  902. }
  903. BOOL VerifyVersion(_TCHAR * Ver1, _TCHAR * Ver2)
  904. {
  905. _TCHAR *src1;
  906. _TCHAR *src2;
  907. _TCHAR *dest1, *dest2;
  908. _TCHAR temp[20];
  909. _TCHAR temp2[20];
  910. BOOL Done = FALSE;
  911. BOOL Status = TRUE;
  912. src1 = Ver1;
  913. src2 = Ver2;
  914. dest1 = temp;
  915. dest2 = temp2;
  916. if ((!src1) || (!src2))
  917. return FALSE;
  918. if (!_tcscmp (src1, src2))
  919. return TRUE;
  920. while ( (*src1 != _T('\0')) && (!Done) )
  921. {
  922. _tcscpy (temp, _T("\0"));
  923. _tcscpy (temp2, _T("\0"));
  924. dest1 = temp;
  925. dest2 = temp2;
  926. // Get the next field of the registry string
  927. while( (*src1 != _T('.')) && (*src1 != _T('\0')))
  928. {
  929. *dest1 = *src1;
  930. ++dest1;
  931. ++src1;
  932. }
  933. if ( *src1 != _T('\0'))
  934. ++src1; // skip the .
  935. *dest1 = _T('\0');
  936. ++dest1;
  937. *dest1= _T('\0');
  938. // Now get the next field from the WMI returned version.
  939. while ( (*src2 != _T('.') ) && (*src2 != _T('\0')) )
  940. {
  941. *dest2= *src2;
  942. ++dest2;
  943. ++src2;
  944. }
  945. if ( *src2 != _T('\0'))
  946. ++src2; // skip the .
  947. *dest2 = _T('\0');
  948. ++dest2;
  949. *dest2= _T('\0');
  950. // Now convert the strings to integers.
  951. if ( _ttol (temp) != _ttol (temp2) )
  952. {
  953. Status = FALSE;
  954. Done = TRUE;
  955. }
  956. if ( (*src1 == _T('\0')) && (*src2 != _T('\0')) )
  957. {
  958. Done = TRUE;
  959. Status = FALSE;
  960. }
  961. if ( ( *src1 != _T('\0')) && (*src2 == _T('\0')) )
  962. {
  963. Done = TRUE;
  964. Status = FALSE;
  965. }
  966. }
  967. return Status;
  968. }
  969. VOID CListViews::VerifyFiles(PPRODUCT Database)
  970. {
  971. PPRODUCT CurrentProduct = NULL;
  972. PHOTFIXLIST CurrentHotfix = NULL;
  973. PFILELIST CurrentFile = NULL;
  974. HRESULT hres;
  975. _TCHAR ConnectString[255];
  976. _TCHAR TempBuffer[255];
  977. IWbemLocator *pLoc = 0;
  978. hres = CoCreateInstance(CLSID_WbemLocator, 0,CLSCTX_INPROC_SERVER,IID_IWbemLocator, (LPVOID *) &pLoc);
  979. if ( FAILED (hres))
  980. {
  981. // MessageBox(NULL, _T("Failed to create IWebmLocator Object"),NULL,MB_OK);
  982. }
  983. else
  984. {
  985. IWbemServices *pSvc = NULL;
  986. // Build the connection string.
  987. if (!_tcscmp(m_ComputerName,_T("\0")))
  988. _stprintf(ConnectString,_T("ROOT\\CIMV2"));
  989. else
  990. _stprintf(ConnectString,_T("\\\\%s\\ROOT\\CIMV2"), m_ComputerName);
  991. _TCHAR * ConnectString1;
  992. ConnectString1 = SysAllocString(ConnectString);
  993. // Connect to the default namespace
  994. hres = pLoc->ConnectServer(
  995. ConnectString1,
  996. NULL,NULL,0,NULL,0,0,&pSvc);
  997. SysFreeString(ConnectString1);
  998. if ( FAILED (hres))
  999. {
  1000. ;
  1001. }
  1002. else
  1003. {
  1004. CoSetProxyBlanket(pSvc, RPC_C_AUTHN_WINNT,RPC_C_AUTHZ_NONE,
  1005. NULL,
  1006. RPC_C_AUTHN_LEVEL_CALL,
  1007. RPC_C_IMP_LEVEL_IMPERSONATE,
  1008. NULL,
  1009. EOAC_NONE);
  1010. IEnumWbemClassObject *pEnum = NULL;
  1011. IWbemClassObject *pObj = NULL;
  1012. // Now Update the Current field of all of the File Entries.
  1013. CurrentProduct = Database;
  1014. _TCHAR Query[255];
  1015. while (CurrentProduct != NULL)
  1016. {
  1017. CurrentHotfix = CurrentProduct->HotfixList;
  1018. while (CurrentHotfix != NULL)
  1019. {
  1020. CurrentFile = CurrentHotfix->FileList;
  1021. while (CurrentFile != NULL)
  1022. {
  1023. _tcscpy (Query,_T("\0"));
  1024. BuildQuery(CurrentFile->InstallPath, CurrentFile->FileName, Query);
  1025. _TCHAR * bstrQuery = SysAllocString(Query);
  1026. _TCHAR * bstrType = SysAllocString(_T("WQL"));
  1027. hres = pSvc->ExecQuery(bstrType,
  1028. bstrQuery,
  1029. WBEM_FLAG_FORWARD_ONLY,
  1030. NULL,
  1031. &pEnum);
  1032. SysFreeString (bstrQuery);
  1033. SysFreeString(bstrType);
  1034. if (hres == WBEM_S_NO_ERROR)
  1035. {
  1036. ULONG uReturned = 1;
  1037. while (uReturned == 1)
  1038. {
  1039. hres = pEnum->Next(WBEM_INFINITE ,1,&pObj, &uReturned);
  1040. if ( (SUCCEEDED (hres)) && (uReturned == 1))
  1041. {
  1042. VARIANT pVal;
  1043. VariantClear (&pVal);
  1044. BSTR propName = SysAllocString(L"Version");
  1045. hres = pObj->Get(propName,
  1046. 0L,
  1047. &pVal,
  1048. NULL,
  1049. NULL);
  1050. if (pVal.vt == VT_NULL)
  1051. ;
  1052. else if (pVal.vt == VT_BSTR)
  1053. {
  1054. TCHAR NewVal[255];
  1055. _tcscpy (NewVal, pVal.bstrVal);
  1056. //_bstr_t NewVal(pVal.bstrVal,FALSE);
  1057. if (! _tcscmp(CurrentFile->FileVersion, _T("\0")))
  1058. _tcscpy (CurrentFile->IsCurrent, _T("N\\A"));
  1059. else
  1060. {
  1061. if (VerifyVersion ( CurrentFile->FileVersion, NewVal) )
  1062. {
  1063. LoadString(m_hInst, IDS_YES, TempBuffer, 255);
  1064. _tcscpy(CurrentFile->IsCurrent, TempBuffer);
  1065. }
  1066. else
  1067. {
  1068. LoadString(m_hInst, IDS_NO, TempBuffer, 255);
  1069. _tcscpy(CurrentFile->IsCurrent,_T("\0"));
  1070. }
  1071. }
  1072. }
  1073. if (pObj) pObj->Release();
  1074. }
  1075. else
  1076. ;
  1077. } // end while uReturned
  1078. }
  1079. // Done with this enumerator
  1080. if (pEnum) pEnum->Release();
  1081. CurrentFile = CurrentFile->pNext;
  1082. }// end while CurrentFile != NULL
  1083. CurrentHotfix = CurrentHotfix->pNext;
  1084. }// end while hotfix != NULL
  1085. CurrentProduct = CurrentProduct->pNext;
  1086. } // end while product != NULL
  1087. }//end else
  1088. } // end else
  1089. } // end
  1090. PHOTFIXLIST CListViews::GetHotfixInfo( _TCHAR * pszProductName, HKEY* hUpdateKey )
  1091. {
  1092. HKEY hHotfixKey = NULL; // Handle of the hotfix key being processed.
  1093. HKEY hProduct = NULL ; // Handle to the current product key
  1094. HKEY hSPKey = NULL;
  1095. _TCHAR szHotfixName[BUFFER_SIZE]; // Name of the current hotfix.
  1096. _TCHAR szValueName[BUFFER_SIZE];
  1097. _TCHAR szSPName[BUFFER_SIZE];
  1098. PHOTFIXLIST pHotfixList = NULL; // Pointer to the head of the hotfix list.
  1099. PHOTFIXLIST pCurrNode = NULL; // Used to walk the list of hotfixes
  1100. PHOTFIXLIST pNewNode = NULL; // Used to create nodes to be added to the list.
  1101. DWORD dwBufferSize; // Size of the product name buffer.
  1102. DWORD dwValIndex; // index of current value.
  1103. DWORD dwHotfixIndex = 0;
  1104. BYTE *Data = NULL;
  1105. DWORD dwDataSize = BUFFER_SIZE;
  1106. DWORD dwValType;
  1107. DWORD dwSPIndex = 0;
  1108. Data = (BYTE *) malloc(BUFFER_SIZE);
  1109. if (Data == NULL)
  1110. return NULL;
  1111. // Open the current product key
  1112. if (*hUpdateKey != NULL)
  1113. {
  1114. RegOpenKeyEx(*hUpdateKey,pszProductName,0 , KEY_READ, &hProduct);
  1115. if (hProduct != NULL)
  1116. {
  1117. dwHotfixIndex = 0;
  1118. dwBufferSize = BUFFER_SIZE;
  1119. dwSPIndex = 0;
  1120. while (RegEnumKeyEx(hProduct,dwSPIndex, szSPName,&dwBufferSize, 0, NULL,NULL,NULL) != ERROR_NO_MORE_ITEMS)
  1121. {
  1122. // Open the Service pack Key
  1123. RegOpenKeyEx(hProduct,szSPName,0,KEY_READ,&hSPKey);
  1124. if (hSPKey != NULL)
  1125. {
  1126. // Enumerate the Service Pack key to get the hotfix keys.
  1127. dwBufferSize = BUFFER_SIZE;
  1128. dwHotfixIndex = 0;
  1129. while (RegEnumKeyEx(hSPKey,dwHotfixIndex, szHotfixName, &dwBufferSize,0,NULL,NULL,NULL) != ERROR_NO_MORE_ITEMS)
  1130. {
  1131. // now create a new node
  1132. pNewNode = (PHOTFIXLIST) malloc (sizeof(HOTFIXLIST));
  1133. pNewNode->pNext = NULL;
  1134. pNewNode->FileList = NULL;
  1135. _tcscpy(pNewNode->HotfixName,szHotfixName);
  1136. _tcscpy(pNewNode->ServicePack,szSPName);
  1137. _tcscpy(pNewNode->Uninstall,_T("\0"));
  1138. // Open the Hotfix Key
  1139. RegOpenKeyEx(hSPKey,szHotfixName, 0, KEY_READ,&hHotfixKey);
  1140. if (hHotfixKey != NULL)
  1141. {
  1142. // Now enumerate the values of the current hotfix.
  1143. dwValIndex = 0;
  1144. dwBufferSize =BUFFER_SIZE;
  1145. dwDataSize = BUFFER_SIZE;
  1146. while (RegEnumValue(hHotfixKey,dwValIndex, szValueName,&dwBufferSize, 0,&dwValType, Data, &dwDataSize) != ERROR_NO_MORE_ITEMS)
  1147. {
  1148. // Fill in the hotfix data members.
  1149. _tcslwr(szValueName);
  1150. if (!_tcscmp(szValueName,_T("description")))
  1151. _tcscpy(pNewNode->Description,(_TCHAR *) Data);
  1152. if (!_tcscmp(szValueName,_T("installeddate")))
  1153. _tcscpy(pNewNode->InstalledDate,(_TCHAR *) Data);
  1154. if (!_tcscmp(szValueName,_T("type")))
  1155. _tcscpy(pNewNode->Type,(_TCHAR*) Data);
  1156. if (!_tcscmp(szValueName,_T("installedby")))
  1157. _tcscpy(pNewNode->InstalledBy , (_TCHAR*) Data);
  1158. if (!_tcscmp(szValueName,_T("uninstallcommand")))
  1159. _tcscpy(pNewNode->Uninstall, (_TCHAR*)Data);
  1160. ++ dwValIndex;
  1161. _tcscpy (szValueName, _T("\0"));
  1162. ZeroMemory(Data,BUFFER_SIZE);
  1163. dwValType = 0;
  1164. dwBufferSize =BUFFER_SIZE;
  1165. dwDataSize = BUFFER_SIZE;
  1166. }
  1167. // Get the file list for the current hotfix.
  1168. pNewNode->FileList = GetFileInfo(&hHotfixKey);
  1169. //insert the new node at the end of the hotfix list.
  1170. pCurrNode = pHotfixList;
  1171. if (pCurrNode == NULL)
  1172. {
  1173. pHotfixList = pNewNode;
  1174. pHotfixList->pPrev = NULL;
  1175. pHotfixList->pNext = NULL;
  1176. }
  1177. else
  1178. {
  1179. pCurrNode = pHotfixList;
  1180. while (pCurrNode->pNext != NULL)
  1181. pCurrNode = pCurrNode->pNext;
  1182. pCurrNode->pNext = pNewNode;
  1183. pNewNode->pPrev = pCurrNode;
  1184. pNewNode->pNext = NULL;
  1185. }
  1186. // Close the current Hotfix Key
  1187. RegCloseKey(hHotfixKey);
  1188. // Clear the strings.
  1189. _tcscpy(szHotfixName,_T("\0"));
  1190. // increment the current index
  1191. ++dwHotfixIndex;
  1192. dwBufferSize = BUFFER_SIZE;
  1193. }
  1194. }
  1195. RegCloseKey(hSPKey);
  1196. _tcscpy (szSPName,_T("\0"));
  1197. dwBufferSize = BUFFER_SIZE;
  1198. dwSPIndex++;
  1199. }
  1200. }// end enum SP keys.
  1201. // Close all open keys
  1202. RegCloseKey(hProduct);
  1203. }
  1204. if (Data != NULL)
  1205. free (Data);
  1206. }
  1207. return pHotfixList;
  1208. }
  1209. PFILELIST CListViews::GetFileInfo(HKEY* hHotfixKey)
  1210. {
  1211. PFILELIST pFileList = NULL; // Pointer to the head of the file list.
  1212. // _TCHAR szFilePath; // Path to the files subkey.
  1213. PFILELIST pNewNode = NULL;
  1214. PFILELIST pCurrNode = NULL;;
  1215. BYTE * Data;
  1216. DWORD dwBufferSize = BUFFER_SIZE;
  1217. DWORD dwDataSize = BUFFER_SIZE;
  1218. DWORD dwFileIndex = 0;
  1219. DWORD dwPrimeIndex = 0;
  1220. DWORD dwValType = 0;
  1221. HKEY hPrimaryFile;
  1222. HKEY hFileKey;
  1223. _TCHAR szFileSubKey[BUFFER_SIZE];
  1224. _TCHAR szValueName[BUFFER_SIZE];
  1225. Data = (BYTE *) malloc(BUFFER_SIZE);
  1226. ZeroMemory(Data,BUFFER_SIZE);
  1227. // Open the files subkey of the current hotfix
  1228. if (RegOpenKeyEx(*hHotfixKey, _T("FileList"),0,KEY_READ,&hPrimaryFile) != ERROR_SUCCESS)
  1229. {
  1230. return NULL;
  1231. }
  1232. _tcscpy(szValueName,_T("\0"));
  1233. while (RegEnumKeyEx(hPrimaryFile,dwPrimeIndex,szFileSubKey, &dwBufferSize,0,NULL,NULL,NULL) != ERROR_NO_MORE_ITEMS)
  1234. {
  1235. // open the subfile key
  1236. RegOpenKeyEx(hPrimaryFile,szFileSubKey,0,KEY_READ,&hFileKey);
  1237. dwFileIndex = 0;
  1238. // Enumerate the file(x) subkeys of the file subkey
  1239. dwDataSize = BUFFER_SIZE;
  1240. dwBufferSize = BUFFER_SIZE;
  1241. pNewNode = (PFILELIST) malloc (sizeof(FILELIST));
  1242. pNewNode->pNext = NULL;
  1243. pNewNode->pPrev = NULL;
  1244. _tcscpy (pNewNode->IsCurrent,_T("\0"));
  1245. _tcscpy(pNewNode->FileDate,_T("\0"));
  1246. while (RegEnumValue(hFileKey,dwFileIndex,szValueName,&dwBufferSize,0,&dwValType,Data,&dwDataSize) != ERROR_NO_MORE_ITEMS)
  1247. {
  1248. _tcslwr(szValueName);
  1249. // now find out which value we have and insert it into the node
  1250. if (! _tcscmp(szValueName,_T("filename")))
  1251. {
  1252. _tcscpy(pNewNode->FileName,(_TCHAR *) Data);
  1253. }
  1254. if (! _tcscmp(szValueName,_T("version")))
  1255. {
  1256. _tcscpy(pNewNode->FileVersion,(_TCHAR*)Data);
  1257. }
  1258. if (!_tcscmp(szValueName,_T("builddate")))
  1259. {
  1260. _tcscpy(pNewNode->FileDate,(_TCHAR*) Data);
  1261. }
  1262. if (! _tcscmp(szValueName, _T("location")))
  1263. {
  1264. _tcscpy(pNewNode->InstallPath, (_TCHAR*) Data);
  1265. }
  1266. dwFileIndex ++;
  1267. _tcscpy(szValueName,_T("\0"));
  1268. ZeroMemory(Data,BUFFER_SIZE);
  1269. dwValType = 0;
  1270. dwBufferSize = BUFFER_SIZE;
  1271. dwDataSize = BUFFER_SIZE;
  1272. }
  1273. RegCloseKey(hFileKey);
  1274. // add the current node to the list if not stored in dll cache
  1275. _TCHAR TempString[255];
  1276. _tcscpy (TempString, pNewNode->InstallPath);
  1277. _tcslwr(TempString);
  1278. if ( (_tcsstr (TempString, _T("dllcache")) == NULL ) && (_tcsstr (TempString, _T("driver cache") )== NULL))
  1279. {
  1280. pCurrNode = pFileList;
  1281. if (pNewNode != NULL)
  1282. {
  1283. if (pFileList == NULL)
  1284. {
  1285. pFileList = pNewNode;
  1286. }
  1287. else
  1288. {
  1289. while (pCurrNode->pNext != NULL)
  1290. pCurrNode = pCurrNode->pNext;
  1291. pCurrNode->pNext = pNewNode;
  1292. pNewNode->pPrev = pCurrNode;
  1293. }
  1294. }
  1295. }
  1296. else // otherwise free the node.
  1297. free (pNewNode);
  1298. ++dwPrimeIndex;
  1299. } // end enum of primary file key
  1300. RegCloseKey(hPrimaryFile);
  1301. if (Data != NULL)
  1302. free (Data);
  1303. return pFileList;
  1304. }
  1305. _TCHAR * CListViews::GetCurrentHotfix()
  1306. {
  1307. return m_CurrentHotfix;
  1308. }
  1309. void CListViews::SetViewMode(DWORD ViewType)
  1310. {
  1311. m_CurrentView = ViewType;
  1312. _tcscpy (m_CurrentHotfix,_T("\0"));
  1313. EnableWindow(m_UninstButton,FALSE);
  1314. EnableWindow(m_WebButton,FALSE);
  1315. switch (ViewType)
  1316. {
  1317. case VIEW_BY_FILE:
  1318. if (! _tcscmp(m_ProductName,_T("\0")))
  1319. m_CurrentView = VIEW_ALL_FILE;
  1320. else
  1321. m_CurrentView = VIEW_BY_FILE;
  1322. break;
  1323. case VIEW_BY_HOTFIX:
  1324. if (! _tcscmp(m_ProductName,_T("\0")))
  1325. m_CurrentView =VIEW_ALL_HOTFIX;
  1326. else
  1327. m_CurrentView = VIEW_BY_HOTFIX;
  1328. break;
  1329. }
  1330. AddItemsTop();
  1331. AddItemsBottom();
  1332. }
  1333. void CListViews::SetProductName(_TCHAR * NewName)
  1334. {
  1335. _tcscpy (m_ProductName,NewName);
  1336. _tcscpy(m_ProductName, NewName);
  1337. EnableWindow(m_WebButton, FALSE);
  1338. EnableWindow(m_UninstButton,FALSE);
  1339. _tcscpy(m_CurrentHotfix, _T("\0"));
  1340. if (_tcscmp(NewName, _T("\0")))
  1341. {
  1342. switch (m_CurrentView)
  1343. {
  1344. case VIEW_ALL_FILE:
  1345. m_CurrentView = VIEW_BY_FILE;
  1346. break;
  1347. case VIEW_ALL_HOTFIX:
  1348. m_CurrentView = VIEW_BY_HOTFIX;
  1349. break;
  1350. }
  1351. }
  1352. if (!_tcscmp(NewName, _T("\0")))
  1353. {
  1354. switch (m_CurrentView)
  1355. {
  1356. case VIEW_BY_FILE:
  1357. m_CurrentView = VIEW_ALL_FILE;
  1358. break;
  1359. case VIEW_BY_HOTFIX:
  1360. m_CurrentView = VIEW_ALL_HOTFIX;
  1361. break;
  1362. default:
  1363. m_CurrentView = VIEW_ALL_HOTFIX;
  1364. }
  1365. _tcscpy(m_ProductName,_T("\0"));
  1366. _tcscpy(m_CurrentHotfix,_T("\0"));
  1367. }
  1368. AddItemsTop();
  1369. AddItemsBottom();
  1370. }
  1371. BOOL CListViews::FreeFileList(PFILELIST CurrentFile)
  1372. {
  1373. while (CurrentFile->pNext->pNext != NULL)
  1374. CurrentFile = CurrentFile->pNext;
  1375. //Remove the file list
  1376. while ( (CurrentFile->pPrev != NULL) && (CurrentFile->pNext != NULL) )
  1377. {
  1378. free ( CurrentFile->pNext );
  1379. CurrentFile = CurrentFile->pPrev ;
  1380. }
  1381. if (CurrentFile != NULL)
  1382. free (CurrentFile);
  1383. CurrentFile = NULL;
  1384. return TRUE;
  1385. }
  1386. BOOL CListViews::FreeHotfixList (PHOTFIXLIST CurrentHotfix)
  1387. {
  1388. PFILELIST CurrentFile;
  1389. while (CurrentHotfix->pNext != NULL)
  1390. CurrentHotfix = CurrentHotfix->pNext;
  1391. if (CurrentHotfix->pPrev != NULL)
  1392. CurrentHotfix = CurrentHotfix->pPrev;
  1393. //Remove the Hotfix list
  1394. while ( (CurrentHotfix->pPrev != NULL) && (CurrentHotfix->pNext != NULL) )
  1395. {
  1396. CurrentFile = CurrentHotfix->pNext->FileList ;
  1397. FreeFileList (CurrentFile);
  1398. free ( CurrentHotfix->pNext );
  1399. CurrentHotfix = CurrentHotfix->pPrev ;
  1400. }
  1401. if (CurrentHotfix != NULL)
  1402. free (CurrentHotfix);
  1403. return TRUE;
  1404. }
  1405. BOOL CListViews::FreeDatabase()
  1406. {
  1407. PPRODUCT CurrentProduct = DataBase;
  1408. PHOTFIXLIST CurrentHotfix;
  1409. PFILELIST CurrentFile;
  1410. while (CurrentProduct->pNext->pNext != NULL)
  1411. CurrentProduct = CurrentProduct->pNext;
  1412. while (CurrentProduct->pPrev != NULL)
  1413. {
  1414. CurrentHotfix = CurrentProduct->HotfixList;
  1415. FreeHotfixList(CurrentHotfix);
  1416. CurrentProduct = CurrentProduct->pPrev ;
  1417. }
  1418. if (CurrentProduct != NULL)
  1419. free(CurrentProduct);
  1420. DataBase = NULL;
  1421. return TRUE;
  1422. }
  1423. BOOL CListViews::Uninstall()
  1424. {
  1425. char temp[255];
  1426. PPRODUCT pProduct = NULL;
  1427. PHOTFIXLIST pHotfix = NULL;
  1428. pProduct = DataBase;
  1429. BOOL Done = FALSE;
  1430. if (_tcscmp (m_ProductName,_T("\0")))
  1431. {
  1432. while ( (!Done) && (pProduct != NULL))
  1433. {
  1434. if (!_tcscmp(pProduct->ProductName, m_ProductName))
  1435. Done = TRUE;
  1436. else
  1437. pProduct = pProduct->pNext;
  1438. }
  1439. }
  1440. else
  1441. {
  1442. while ( (!Done) && (pProduct != NULL))
  1443. {
  1444. if (!_tcscmp(pProduct->ProductName, CurrentProductName))
  1445. Done = TRUE;
  1446. else
  1447. pProduct = pProduct->pNext;
  1448. }
  1449. }
  1450. if (pProduct != NULL)
  1451. pHotfix = pProduct->HotfixList;
  1452. if (pHotfix != NULL)
  1453. {
  1454. Done = FALSE;
  1455. while( (!Done) && (pHotfix != NULL) )
  1456. {
  1457. if ( ! _tcscmp(pHotfix->HotfixName,m_CurrentHotfix))
  1458. Done = TRUE;
  1459. else
  1460. pHotfix = pHotfix->pNext;
  1461. }
  1462. if (pHotfix != NULL)
  1463. {
  1464. if (_tcscmp(pHotfix->Uninstall, _T("\0")))
  1465. {
  1466. _TCHAR TempString[255];
  1467. _TCHAR TempString2[255];
  1468. LoadString(m_hInst,IDS_UNINSTAL_WRN,TempString,255);
  1469. _tcscat (TempString, pHotfix->HotfixName);
  1470. LoadString(m_hInst,IDS_UNINSTAL_WRN_TITLE,TempString2,255);
  1471. if (::MessageBox(NULL,TempString,TempString2, MB_OKCANCEL) != IDCANCEL)
  1472. {
  1473. wcstombs(temp,pHotfix->Uninstall,255);
  1474. WinExec( (char*)temp, SW_SHOWNORMAL);
  1475. // Free the database
  1476. FreeDatabase();
  1477. DataBase = NULL;
  1478. BuildDatabase( m_ComputerName);
  1479. }
  1480. }
  1481. }
  1482. }
  1483. return TRUE;
  1484. }
  1485. void InitializeOfn(OPENFILENAME *ofn)
  1486. {
  1487. static _TCHAR szFilter[] = _T("Text (Comma Delimited) (*.csv)\0*.csv\0\0") ;
  1488. ofn->lStructSize = sizeof (OPENFILENAME);
  1489. ofn->hwndOwner = NULL;
  1490. ofn->hInstance = NULL;
  1491. ofn->lpstrFilter = szFilter;
  1492. ofn->lpstrCustomFilter = NULL;
  1493. ofn->nMaxCustFilter = 0;
  1494. ofn->lpstrFile = NULL;
  1495. ofn->nMaxFile = MAX_PATH;
  1496. ofn->lpstrFileTitle = NULL;
  1497. ofn->Flags = OFN_OVERWRITEPROMPT;
  1498. ofn->nFileOffset = 0;
  1499. ofn->nFileExtension = 0;
  1500. ofn->lpstrDefExt = _T("csv");
  1501. ofn->lCustData = 0L;
  1502. ofn->lpfnHook = NULL;
  1503. ofn->lpTemplateName = NULL;
  1504. }
  1505. void CListViews::SaveToCSV()
  1506. {
  1507. PPRODUCT pProduct = NULL;
  1508. PHOTFIXLIST pHotfix = NULL;
  1509. PFILELIST pFileList = NULL;
  1510. _TCHAR *Buffer;
  1511. DWORD LineLength = 0;
  1512. HANDLE hFile = NULL;
  1513. DWORD BytesWritten = 0;
  1514. DWORD LineSize = 0;
  1515. char *Buffer2;
  1516. static OPENFILENAME ofn;
  1517. _TCHAR FileName[MAX_PATH];
  1518. _tcscpy (FileName,_T("\0"));
  1519. InitializeOfn (&ofn);
  1520. ofn.lpstrFile = FileName;
  1521. if ( !GetSaveFileName(&ofn) )
  1522. {
  1523. return;
  1524. }
  1525. // open the file
  1526. hFile = CreateFile( FileName, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  1527. if ( hFile == INVALID_HANDLE_VALUE)
  1528. {
  1529. LPVOID lpMsgBuf;
  1530. FormatMessage(
  1531. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  1532. FORMAT_MESSAGE_FROM_SYSTEM |
  1533. FORMAT_MESSAGE_IGNORE_INSERTS,
  1534. NULL,
  1535. GetLastError(),
  1536. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  1537. (LPTSTR) &lpMsgBuf,
  1538. 0,
  1539. NULL
  1540. );
  1541. // Process any inserts in lpMsgBuf.
  1542. // ...
  1543. // Display the string.
  1544. // MessageBox( NULL, (LPCTSTR)lpMsgBuf,_T(" Error"), MB_OK | MB_ICONINFORMATION );
  1545. // Free the buffer.
  1546. LocalFree( lpMsgBuf );
  1547. return;
  1548. }
  1549. // Store Headers
  1550. Buffer = (_TCHAR *) malloc (2000);
  1551. Buffer2 = (char*) malloc(2000);
  1552. LoadString(m_hInst,IDS_CSV_HEADER,Buffer,1000);
  1553. //_stprintf(Buffer, _T("Product,Service Pack,Article,InstalledBy,InstalledDate,FileName,FileVersion,FileDate,InstallPath,Current\r"));
  1554. wcstombs(Buffer2,Buffer, _msize(Buffer2) );
  1555. WriteFile(hFile,Buffer2, strlen(Buffer2), &BytesWritten, NULL);
  1556. if (Buffer)
  1557. free (Buffer);
  1558. if (Buffer2)
  1559. free (Buffer2);
  1560. Buffer = NULL;
  1561. Buffer2 = NULL;
  1562. // Run through the Data base and write the info to the file.
  1563. pProduct = DataBase;
  1564. while (pProduct != NULL)
  1565. {
  1566. pHotfix = pProduct->HotfixList;
  1567. while (pHotfix != NULL)
  1568. {
  1569. pFileList = pHotfix->FileList;
  1570. while (pFileList != NULL)
  1571. {
  1572. // Build the CSV output string
  1573. // Product,Article,Description, ServicePack, By, Date, Type, FileName, Version, Date,Current,InstallPath
  1574. // Add up the string lengths and allocata a large enough buffer.
  1575. LineLength = _tcslen(pProduct->ProductName) + _tcslen(pHotfix->ServicePack)+
  1576. _tcslen(pHotfix->HotfixName) + _tcslen(pHotfix->Description )+ _tcslen(pHotfix->InstalledBy ) +
  1577. _tcslen(pHotfix->InstalledDate) + _tcslen(pHotfix->Type) +
  1578. _tcslen(pFileList->FileName ) + _tcslen(pFileList->FileVersion ) +
  1579. _tcslen(pFileList->FileDate ) + _tcslen(pFileList->InstallPath )+
  1580. _tcslen(pFileList->IsCurrent );
  1581. Buffer = (_TCHAR *) malloc ( LineLength * sizeof (_TCHAR ) *2) ;
  1582. Buffer2 = (char *) malloc (LineLength *2);
  1583. //ZeroMemory(Buffer, (LineLength * sizeof (_TCHAR)) +2);
  1584. _tcscpy (Buffer,_T("\0"));
  1585. strcpy(Buffer2,"\0");
  1586. if (!Buffer)
  1587. MessageBox (NULL,_T("NO Memory"),NULL, MB_OK);
  1588. else
  1589. {
  1590. _stprintf(Buffer,_T("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\r\0\0"),pProduct->ProductName,
  1591. pHotfix->ServicePack,pHotfix->HotfixName,pHotfix->Description ,pHotfix->InstalledBy, pHotfix->InstalledDate,
  1592. pHotfix->Type,pFileList->FileName,pFileList->FileVersion,pFileList->FileDate ,
  1593. pFileList->InstallPath,pFileList->IsCurrent);
  1594. // Write the line to the file
  1595. LineSize = 0;
  1596. LineSize = wcstombs(Buffer2,Buffer, _msize (Buffer2) );
  1597. strcat(Buffer2,"\0");
  1598. WriteFile(hFile, Buffer2, LineSize, &BytesWritten, NULL);
  1599. }
  1600. // Free the buffer and zero the line length for next pass.
  1601. if (Buffer)
  1602. {
  1603. free (Buffer);
  1604. free (Buffer2);
  1605. }
  1606. Buffer = NULL;
  1607. Buffer2 = NULL;
  1608. LineLength = 0;
  1609. pFileList = pFileList->pNext;
  1610. }
  1611. pHotfix = pHotfix->pNext;
  1612. }
  1613. pProduct = pProduct->pNext;
  1614. }
  1615. CloseHandle(hFile);
  1616. }
  1617. DWORD CListViews::GetState()
  1618. {
  1619. DWORD dwStatus =0;
  1620. PPRODUCT CurrentProduct;
  1621. PHOTFIXLIST CurrentHotfix;
  1622. BOOL Done = FALSE;;
  1623. switch (m_CurrentView)
  1624. {
  1625. case VIEW_ALL_FILE:
  1626. case VIEW_BY_FILE:
  1627. dwStatus |= STATE_VIEW_FILE;
  1628. break;
  1629. case VIEW_ALL_HOTFIX:
  1630. case VIEW_BY_HOTFIX:
  1631. dwStatus |= STATE_VIEW_HOTFIX;
  1632. break;
  1633. }
  1634. // Do we have a database.
  1635. if (DataBase == NULL)
  1636. return dwStatus;
  1637. // Does the database contain any data...
  1638. // A case can arise if a hotfix is installed and then uninstalled where the Registry keys
  1639. // for the Product and Service Pack are not removed. We need to have at least 1 hotfix list.
  1640. CurrentProduct = DataBase;
  1641. while ( (CurrentProduct != NULL) && (!Done))
  1642. {
  1643. if (CurrentProduct ->HotfixList != NULL)
  1644. Done = TRUE;
  1645. CurrentProduct = CurrentProduct->pNext;
  1646. }
  1647. if (!Done)
  1648. {
  1649. //dwStatus = 0;
  1650. return dwStatus;
  1651. }
  1652. else
  1653. {
  1654. // We do have data in the database so we can enable the Export list and Print options.
  1655. dwStatus |= DATA_TO_SAVE;
  1656. dwStatus |= OK_TO_PRINT;
  1657. }
  1658. // Do we have a hotfix selected
  1659. if (_tcscmp(m_CurrentHotfix,_T("\0")))
  1660. dwStatus |= HOTFIX_SELECTED;
  1661. else
  1662. {
  1663. // If we don't have a selected hotfix we cant view the web or uninstall so
  1664. // Just return the current status
  1665. return dwStatus;
  1666. }
  1667. // Now we need to see if we have an uninstall string for the current hotfix
  1668. CurrentProduct = DataBase;
  1669. // Find the selected product
  1670. Done = FALSE;
  1671. while ( (CurrentProduct != NULL) && (!Done))
  1672. {
  1673. if (!_tcscmp(CurrentProduct->ProductName ,m_ProductName))
  1674. {
  1675. // Find the selected hotfix
  1676. CurrentHotfix = CurrentProduct->HotfixList;
  1677. while ((CurrentHotfix != NULL) && (!Done))
  1678. {
  1679. if (! _tcscmp (CurrentHotfix->HotfixName, m_CurrentHotfix))
  1680. {
  1681. // Now verify the uninstall string exists
  1682. if (_tcscmp(CurrentHotfix->Uninstall, _T("\0")))
  1683. {
  1684. // Now verify the directory still exists
  1685. _TCHAR TempString[255];
  1686. _tcscpy (TempString,CurrentHotfix->Uninstall);
  1687. PathRemoveArgs(TempString);
  1688. if ( PathFileExists( TempString ))
  1689. {
  1690. // Yes it does we can enable uninstall
  1691. dwStatus |=UNINSTALL_OK;
  1692. }
  1693. }
  1694. Done = TRUE;
  1695. }
  1696. CurrentHotfix = CurrentHotfix->pNext;
  1697. }
  1698. }
  1699. CurrentProduct = CurrentProduct->pNext;
  1700. }
  1701. return dwStatus;
  1702. }
  1703. _TCHAR * BuildDocument()
  1704. {
  1705. // _TCHAR Document;
  1706. return NULL;
  1707. }
  1708. BOOL CALLBACK AbortProc(HDC hPrinterDC, int iCode)
  1709. {
  1710. MSG msg;
  1711. while (!bUserAbort && PeekMessage (&msg, NULL,0,0,PM_REMOVE))
  1712. {
  1713. if (!hDlgPrint || !IsDialogMessage (hDlgPrint, &msg))
  1714. {
  1715. TranslateMessage (&msg);
  1716. DispatchMessage (&msg);
  1717. }
  1718. }
  1719. return !bUserAbort;
  1720. }
  1721. BOOL CALLBACK PrintDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  1722. {
  1723. switch (msg)
  1724. {
  1725. case WM_INITDIALOG :
  1726. EnableMenuItem (GetSystemMenu (hDlg,FALSE), SC_CLOSE, MF_GRAYED);
  1727. return TRUE;
  1728. case WM_COMMAND:
  1729. bUserAbort = TRUE;
  1730. EnableWindow (GetParent (hDlg), TRUE);
  1731. DestroyWindow (hDlg);
  1732. hDlgPrint = NULL;
  1733. return TRUE;
  1734. }
  1735. return FALSE;
  1736. }
  1737. BOOL JustifyString( _TCHAR* String, int FieldLength, BOOL Left)
  1738. {
  1739. _TCHAR TempString[255];
  1740. int i= 0;
  1741. int NumSpaces = 0;
  1742. _TCHAR Message[100];
  1743. _TCHAR *src, *dest;
  1744. if (String == NULL)
  1745. {
  1746. return FALSE;
  1747. }
  1748. if (Left)
  1749. {
  1750. // String leading spaces.
  1751. src = String;
  1752. dest = TempString;
  1753. while (*src == _T(' '))
  1754. ++src;
  1755. while (*src != _T('\0'))
  1756. {
  1757. *dest = *src;
  1758. ++src;
  1759. ++dest;
  1760. }
  1761. *dest = _T('\0');
  1762. ++dest;
  1763. *dest = _T('\0');
  1764. NumSpaces = (FieldLength - _tcslen(TempString) );
  1765. _stprintf(Message,_T("FieldSize: %d, String Length: %d"),FieldLength, _tcslen(TempString));
  1766. // MessageBox(NULL,Message,_T("Justify"),MB_OK);
  1767. while (NumSpaces >0)
  1768. {
  1769. _tcscat(TempString,_T(" "));
  1770. --NumSpaces;
  1771. }
  1772. _tcscpy (String, TempString);
  1773. _stprintf(Message,_T("NewString Length: %d"),_tcslen(String));
  1774. // MessageBox(NULL,Message,_T("New String Length"),MB_OK);
  1775. }
  1776. else
  1777. {
  1778. _tcscpy(TempString,_T("\0"));
  1779. NumSpaces = FieldLength - _tcslen(String);
  1780. if (NumSpaces > 0 )
  1781. {
  1782. for (i = 0 ; i < NumSpaces;i++)
  1783. TempString[i] = _T(' ');
  1784. TempString[i] = _T('\0');
  1785. _tcscat(TempString,String);
  1786. _tcscpy(String,TempString);
  1787. }
  1788. }
  1789. return TRUE;
  1790. }
  1791. void GetFont ( int PointSize, BOOL Bold, BOOL Underlined, LOGFONT * lf, HDC hDC)
  1792. {
  1793. POINT pt;
  1794. lf->lfHeight = PointSize * 10;
  1795. pt.y = GetDeviceCaps(hDC, LOGPIXELSY) * lf->lfHeight;
  1796. pt.y /= 720; // 72 points/inch, 10 decipoints/point
  1797. DPtoLP(hDC, &pt, 1);
  1798. POINT ptOrg = { 0, 0 };
  1799. DPtoLP(hDC, &ptOrg, 1);
  1800. lf->lfHeight = -abs(pt.y - ptOrg.y);
  1801. if (Underlined)
  1802. lf->lfUnderline = TRUE;
  1803. else
  1804. lf->lfUnderline = FALSE;
  1805. if (Bold)
  1806. lf->lfWeight = FW_BOLD;
  1807. else
  1808. lf->lfWeight = FW_NORMAL;
  1809. }
  1810. void NewPage (HDC hDC, _TCHAR *Header1, _TCHAR * Header2, DWORD * CurrentLine, LOGFONT * lf)
  1811. {
  1812. TEXTMETRIC tm;
  1813. SIZE size;
  1814. DWORD xStart;
  1815. DWORD yChar;
  1816. RECT rect;
  1817. rect.left = (LONG) (0 + GetDeviceCaps(hDC, LOGPIXELSX) * 0.5);
  1818. rect.right = (LONG) (GetDeviceCaps(hDC, PHYSICALWIDTH) -(1+ (GetDeviceCaps(hDC, LOGPIXELSX) / 2)));
  1819. rect.top = (LONG) (1 + GetDeviceCaps(hDC, LOGPIXELSY) * 0.5);
  1820. rect.bottom = (LONG) (GetDeviceCaps(hDC, PHYSICALHEIGHT) - GetDeviceCaps(hDC, LOGPIXELSX) * 0.5);
  1821. if (StartPage(hDC) > 0)
  1822. {
  1823. *CurrentLine = 1;
  1824. GetFont (12,TRUE,TRUE,lf,hDC);
  1825. SelectObject(hDC, CreateFontIndirect(lf));
  1826. GetTextMetrics(hDC,&tm);
  1827. yChar = tm.tmHeight + tm.tmExternalLeading ;
  1828. GetTextExtentPoint32(hDC, Header1,_tcslen(Header1),&size);
  1829. xStart = (rect.right - rect.left)/2 - size.cx/2 ;
  1830. TextOut (hDC, xStart,(*CurrentLine)* yChar ,Header1, _tcslen(Header1) );
  1831. GetFont (10,FALSE, FALSE, lf, hDC);
  1832. SelectObject(hDC, CreateFontIndirect (lf));
  1833. GetTextMetrics (hDC, &tm);
  1834. yChar = tm.tmHeight + tm.tmExternalLeading ;
  1835. xStart = rect.right - ((_tcslen(Header2) +2) * tm.tmAveCharWidth);
  1836. TextOut(hDC, xStart,(*CurrentLine) * yChar, Header2, _tcslen(Header2));
  1837. (*CurrentLine) += 4;
  1838. }
  1839. }
  1840. void CListViews::PrintReport()
  1841. {
  1842. static DOCINFO di = {sizeof (DOCINFO) } ;
  1843. static PRINTDLG pd;
  1844. BOOL bSuccess;
  1845. int yChar, iCharsPerLine, iLinesPerPage;
  1846. _TCHAR Header1[255];
  1847. _TCHAR Header2[255];
  1848. TEXTMETRIC tm;
  1849. _TCHAR Line [255];
  1850. PPRODUCT CurrentProduct;
  1851. PHOTFIXLIST CurrentHotfix;
  1852. PFILELIST CurrentFile;
  1853. DWORD CurrentLine = 0;
  1854. DWORD yStart = 0;
  1855. _TCHAR TempBuffer[255];
  1856. RECT rect;
  1857. SIZE size;
  1858. _TCHAR * src;
  1859. DWORD xStart;
  1860. static LOGFONT lf;
  1861. SYSTEMTIME systime;
  1862. BOOL Done = FALSE;
  1863. _TCHAR SystemDate[255];
  1864. _TCHAR SystemTime[255];
  1865. _TCHAR TempBuffer1[255];
  1866. _TCHAR TempBuffer2[255];
  1867. // invoke Print common dialog box
  1868. GetLocalTime(&systime);
  1869. GetDateFormatW (LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systime,NULL, SystemDate,255);
  1870. GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systime,NULL,SystemTime,255);
  1871. CurrentProduct = DataBase;
  1872. pd.lStructSize = sizeof (PRINTDLG);
  1873. pd.hwndOwner = TopList; //m_hWnd;
  1874. pd.hDevMode = NULL;
  1875. pd.hDevNames= NULL;
  1876. pd.hDC= NULL;
  1877. pd.Flags = PD_ALLPAGES | PD_COLLATE |
  1878. PD_RETURNDC | PD_NOSELECTION ;
  1879. pd.nFromPage = 0;
  1880. pd.nToPage = 0;
  1881. pd.nMinPage = 0;
  1882. pd.nMaxPage = 0;
  1883. pd.nCopies = 1;
  1884. pd.hInstance = NULL;
  1885. pd.lCustData = 0L;
  1886. pd.lpfnPrintHook = NULL;
  1887. pd.lpfnSetupHook = NULL;
  1888. pd.lpPrintTemplateName = NULL;
  1889. pd.lpSetupTemplateName = NULL;
  1890. pd.hPrintTemplate = NULL;
  1891. pd.hSetupTemplate = NULL;
  1892. if (!PrintDlg (&pd) )
  1893. return; //TRUE;
  1894. else
  1895. {
  1896. // Setup the printer dimensions.
  1897. rect.left = (LONG) (0 + GetDeviceCaps(pd.hDC, LOGPIXELSX) * 0.5);
  1898. rect.right = (LONG) (GetDeviceCaps(pd.hDC, PHYSICALWIDTH) - GetDeviceCaps(pd.hDC, LOGPIXELSX) * 0.5);
  1899. rect.top = (LONG) (1 + GetDeviceCaps(pd.hDC, LOGPIXELSY) * 0.5);
  1900. rect.bottom = (LONG) ( GetDeviceCaps(pd.hDC, PHYSICALHEIGHT) - GetDeviceCaps(pd.hDC, LOGPIXELSX) * 0.5);
  1901. rect.bottom -= 100;
  1902. bSuccess = TRUE;
  1903. bUserAbort = TRUE;
  1904. hDlgPrint = CreateDialog(m_hInst, _T("PrintDlgBox"),
  1905. TopList, PrintDlgProc );
  1906. di.lpszDocName = _T("Hotfix Manager");
  1907. SetAbortProc(pd.hDC, AbortProc);
  1908. LOGFONT logFont;
  1909. memset(&logFont, 0, sizeof(LOGFONT));
  1910. logFont.lfCharSet = DEFAULT_CHARSET;
  1911. _tcscpy(logFont.lfFaceName, _T("Dlg Shell Font"));
  1912. LoadString(m_hInst, IDS_UPDATE_REPORT, TempBuffer, 255);
  1913. _stprintf(Header1,_T("%s %s"), TempBuffer,m_ComputerName);
  1914. _stprintf(Header2, _T("%s %s"),SystemDate,SystemTime);
  1915. StartDoc(pd.hDC,&di);
  1916. _tcscpy (Line,_T("\0"));
  1917. NewPage (pd.hDC, Header1,Header2, &CurrentLine, &logFont);
  1918. GetTextMetrics(pd.hDC,&tm);
  1919. yChar = tm.tmHeight + tm.tmExternalLeading ;
  1920. iCharsPerLine = GetDeviceCaps (pd.hDC, HORZRES) / tm.tmAveCharWidth ;
  1921. iLinesPerPage = GetDeviceCaps (pd.hDC, VERTRES) / yChar ;
  1922. _tcscpy (Line,_T("\0"));
  1923. xStart = rect.left;
  1924. while ( (CurrentProduct != NULL) && (!Done))
  1925. {
  1926. _tcscpy (Line,_T("\0"));
  1927. LoadString(m_hInst,IDS_PRODUCT_NAME, TempBuffer,255);
  1928. logFont.lfWeight = FW_BOLD;
  1929. SelectObject(pd.hDC,CreateFontIndirect (&logFont));
  1930. GetTextMetrics (pd.hDC, &tm);
  1931. _stprintf (Line, _T("%s: "), TempBuffer);
  1932. yStart = CurrentLine * yChar;
  1933. if (yStart >= (UINT) rect.bottom)
  1934. {
  1935. EndPage(pd.hDC);
  1936. NewPage(pd.hDC, Header1,Header2, &CurrentLine, &logFont);
  1937. yStart = CurrentLine * yChar;
  1938. }
  1939. TextOut (pd.hDC, xStart,yStart ,Line, _tcslen(Line) );
  1940. xStart = rect.left + ((_tcslen(Line) + 4 )* tm.tmAveCharWidth);
  1941. logFont.lfWeight = FW_NORMAL;
  1942. SelectObject(pd.hDC,CreateFontIndirect (&logFont));
  1943. GetTextMetrics (pd.hDC, &tm);
  1944. _tcscpy (Line, CurrentProduct->ProductName);
  1945. TextOut(pd.hDC, xStart, yStart , Line, _tcslen(Line) );
  1946. CurrentLine ++;
  1947. yStart = CurrentLine * yChar;
  1948. if (yStart >= (UINT)rect.bottom)
  1949. {
  1950. EndPage(pd.hDC);
  1951. NewPage(pd.hDC, Header1,Header2, &CurrentLine, &logFont);
  1952. yStart = CurrentLine * yChar;
  1953. }
  1954. xStart = rect.left;
  1955. CurrentHotfix = CurrentProduct->HotfixList;
  1956. while ( (CurrentHotfix != NULL ) && (!Done))
  1957. {
  1958. _stprintf (Line, _T("%s \t%s"),CurrentHotfix->HotfixName,CurrentHotfix->Description );
  1959. TabbedTextOut (pd.hDC, xStart,yStart ,Line, _tcslen(Line),0,NULL,0 );
  1960. ++CurrentLine;
  1961. yStart = CurrentLine * yChar;
  1962. if (yStart >= (UINT)rect.bottom)
  1963. {
  1964. EndPage(pd.hDC);
  1965. NewPage(pd.hDC, Header1,Header2, &CurrentLine, &logFont);
  1966. yStart = CurrentLine * yChar;
  1967. }
  1968. LoadString (m_hInst,IDS_SERVICE_PACK, TempBuffer, 255);
  1969. LoadString (m_hInst,IDS_INSTALL_DATE, TempBuffer1, 255);
  1970. LoadString (m_hInst,IDS_INSTALLED_BY, TempBuffer2, 255);
  1971. _stprintf(Line, _T("\t\t%s: %s \t%s: %s \t%s: %s"), TempBuffer, CurrentHotfix->ServicePack,
  1972. TempBuffer1, CurrentHotfix->InstalledDate,
  1973. TempBuffer2, CurrentHotfix->InstalledBy);
  1974. // _stprintf (Line, _T("\t\tService Pack: %s\tInstall Date: %s\tInstalled By %s"),
  1975. // CurrentHotfix->ServicePack,CurrentHotfix->InstalledDate, CurrentHotfix->InstalledBy);
  1976. TabbedTextOut (pd.hDC, xStart,yStart ,Line, _tcslen(Line),0,NULL,0 );
  1977. CurrentLine +=2;
  1978. yStart = CurrentLine * yChar;
  1979. if (yStart >= (UINT)rect.bottom)
  1980. {
  1981. EndPage(pd.hDC);
  1982. NewPage(pd.hDC, Header1,Header2, &CurrentLine, &logFont);
  1983. yStart = CurrentLine * yChar;
  1984. }
  1985. CurrentFile = CurrentHotfix->FileList ;
  1986. if (CurrentFile == NULL)
  1987. {
  1988. _tcscpy (Line, _T("\0"));
  1989. LoadString(m_hInst,IDS_NO_FILES,Line,255);
  1990. TextOut (pd.hDC, xStart,yStart ,Line, _tcslen(Line) );
  1991. CurrentLine += 2;
  1992. if (yStart >= (UINT) rect.bottom)
  1993. {
  1994. EndPage(pd.hDC);
  1995. NewPage(pd.hDC, Header1,Header2, &CurrentLine, &logFont);
  1996. yStart = CurrentLine * yChar;
  1997. }
  1998. }
  1999. else
  2000. {
  2001. logFont.lfUnderline = TRUE;
  2002. logFont.lfWeight = FW_BOLD;
  2003. SelectObject(pd.hDC, CreateFontIndirect (&logFont));
  2004. _tcscpy (Line, _T("\0"));
  2005. LoadString (m_hInst, IDS_FILE,TempBuffer,255);
  2006. JustifyString(TempBuffer,FILENAME_FIELD_WIDTH,TRUE);
  2007. TextOut( pd.hDC, xStart,yStart ,TempBuffer, _tcslen(TempBuffer) );
  2008. LoadString (m_hInst, IDS_FILEDATE,TempBuffer,255);
  2009. JustifyString(TempBuffer,DATE_FIELD_WIDTH,TRUE);
  2010. TextOut( pd.hDC, xStart + 29 * tm.tmAveCharWidth ,yStart ,TempBuffer, _tcslen(TempBuffer) );
  2011. LoadString (m_hInst, IDS_FILEVERSION,TempBuffer,255);
  2012. JustifyString(TempBuffer,VERSION_FIELD_WIDTH,TRUE);
  2013. TextOut( pd.hDC, xStart + 45 * tm.tmAveCharWidth ,yStart ,TempBuffer, _tcslen(TempBuffer) );
  2014. LoadString (m_hInst, IDS_FILECURRENT,TempBuffer,255);
  2015. JustifyString(TempBuffer,CURRENT_FIELD_WIDTH,TRUE);
  2016. TextOut( pd.hDC, xStart + 61* tm.tmAveCharWidth,yStart ,TempBuffer, _tcslen(TempBuffer) );
  2017. LoadString (m_hInst, IDS_FILEPATH,TempBuffer,255);
  2018. JustifyString(TempBuffer,PATH_FIELD_WIDTH,TRUE);
  2019. TextOut( pd.hDC, xStart+72 * tm.tmAveCharWidth ,yStart ,TempBuffer, _tcslen(TempBuffer) );
  2020. ++ CurrentLine;
  2021. yStart = CurrentLine * yChar;
  2022. if (yStart >= (UINT)rect.bottom)
  2023. {
  2024. EndPage(pd.hDC);
  2025. NewPage(pd.hDC, Header1,Header2, &CurrentLine, &logFont);
  2026. yStart = CurrentLine * yChar;
  2027. }
  2028. }
  2029. while ( (CurrentFile != NULL) && (!Done) )
  2030. {
  2031. logFont.lfWeight = FW_NORMAL;
  2032. logFont.lfUnderline = FALSE;
  2033. SelectObject(pd.hDC, CreateFontIndirect (&logFont));
  2034. _tcscpy (Line, _T("\0"));
  2035. _tcscpy (Line, CurrentFile->FileName);
  2036. // JustifyString(Line,40, TRUE);
  2037. TextOut (pd.hDC, xStart,yStart ,Line, _tcslen(Line) );
  2038. //_tcscat (Line,TempBuffer);
  2039. _tcscpy (Line, CurrentFile->FileDate);
  2040. // JustifyString(Line,20, TRUE);
  2041. TextOut (pd.hDC, xStart + 29 * tm.tmAveCharWidth,yStart ,Line, _tcslen(Line) );
  2042. _tcscpy (Line, CurrentFile->FileVersion );
  2043. // JustifyString(Line,18, TRUE);
  2044. TextOut (pd.hDC, xStart + 45 * tm.tmAveCharWidth,yStart ,Line, _tcslen(Line) );
  2045. _tcscpy (Line, CurrentFile->IsCurrent);
  2046. // JustifyString(Line,12, TRUE);
  2047. TextOut (pd.hDC, xStart + 61 * tm.tmAveCharWidth,yStart ,Line, _tcslen(Line) );
  2048. _tcscpy (Line,CurrentFile->InstallPath);
  2049. TextOut (pd.hDC, xStart + 72 * tm.tmAveCharWidth,yStart ,Line, _tcslen(Line) );
  2050. ++CurrentLine;
  2051. yStart = CurrentLine * yChar;
  2052. if (yStart >= (UINT)rect.bottom)
  2053. {
  2054. // MessageBox (NULL,_T("Hit Page Break Code"),NULL,MB_OK);
  2055. EndPage(pd.hDC);
  2056. NewPage(pd.hDC, Header1,Header2, &CurrentLine, &logFont);
  2057. yStart = CurrentLine * yChar;
  2058. }
  2059. CurrentFile = CurrentFile->pNext;
  2060. if (!bUserAbort)
  2061. Done = TRUE;
  2062. } // End While Current File
  2063. ++CurrentLine;
  2064. yStart = CurrentLine * yChar;
  2065. if (yStart >= (UINT)rect.bottom)
  2066. {
  2067. EndPage(pd.hDC);
  2068. NewPage(pd.hDC, Header1,Header2, &CurrentLine, &logFont);
  2069. yStart = CurrentLine * yChar;
  2070. }
  2071. CurrentHotfix = CurrentHotfix->pNext;
  2072. if (!bUserAbort)
  2073. Done = TRUE;
  2074. }
  2075. ++CurrentLine;
  2076. yStart = CurrentLine * yChar;
  2077. if (yStart >= (UINT)rect.bottom)
  2078. {
  2079. EndPage(pd.hDC);
  2080. NewPage(pd.hDC, Header1,Header2, &CurrentLine, &logFont);
  2081. yStart = CurrentLine * yChar;
  2082. }
  2083. CurrentProduct = CurrentProduct->pNext;
  2084. if (!bUserAbort)
  2085. Done = TRUE;
  2086. }
  2087. if (EndPage(pd.hDC) > 0)
  2088. EndDoc(pd.hDC);
  2089. DeleteDC(pd.hDC);
  2090. DestroyWindow(hDlgPrint);
  2091. }
  2092. return; //FALSE;
  2093. }
  2094. int CALLBACK CListViews::CompareFunc (LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  2095. {
  2096. int Result = -1;
  2097. int SubItemIndex = (INT) lParamSort;
  2098. _TCHAR String1[1000];
  2099. _TCHAR String2 [1000];
  2100. ListView_GetItemText( TopList, lParam1, SubItemIndex, String1, 1000);
  2101. ListView_GetItemText( TopList, lParam2, SubItemIndex, String2, 1000);
  2102. if (! (String1 && String2) )
  2103. return 1;
  2104. if (m_SortOrder) // Sort Acending
  2105. {
  2106. Result = _tcscmp(String1,String2);
  2107. }
  2108. else // Sort Decending
  2109. {
  2110. Result = -_tcscmp(String1,String2);
  2111. }
  2112. if (Result == 0)
  2113. Result = -1;
  2114. return Result;
  2115. }