Leaked source code of windows server 2003
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.

960 lines
32 KiB

  1. #include "precomp.h"
  2. #include "ie4comp.h"
  3. #include "updates.h"
  4. extern PCOMP_VERSION g_rgCompVer;
  5. void InsertCommas(LPTSTR pszIn)
  6. { //---- Puts commas into numbered strings ending in " KB" ----
  7. TCHAR szTemp[30], szTemp2[30];
  8. int i, j, z;
  9. for (j=0; pszIn[j+3]; j++);
  10. for (i=j-1; i>=0; i--)
  11. szTemp[j-i-1]=pszIn[i];
  12. szTemp[j]='\0';
  13. z=0;
  14. for (i=0; szTemp[i]; i++, z++) {
  15. szTemp2[z] = szTemp[i];
  16. if (i % 3 == 2) {
  17. z++;
  18. szTemp2[z] = ',';
  19. }
  20. }
  21. if (',' == szTemp2[z-1])
  22. z--;
  23. szTemp2[z]='\0';
  24. for (i=z-1; i>=0; i--)
  25. pszIn[z-i-1] = szTemp2[i];
  26. pszIn[z]='\0';
  27. StrCat(pszIn, TEXT(" KB"));
  28. }
  29. ATOM CreateIEAKUrl()
  30. {
  31. WNDCLASS wc;
  32. wc.style = 0;
  33. wc.lpfnWndProc = HyperLinkWndProc;
  34. wc.cbClsExtra = 0;
  35. wc.cbWndExtra = 0;
  36. wc.hInstance = g_rvInfo.hInst;
  37. wc.hIcon = NULL;
  38. wc.hCursor = LoadCursor(g_rvInfo.hInst, MAKEINTRESOURCE(IDC_LINK));
  39. wc.hbrBackground = (HBRUSH) GetStockObject(GetSysColor(COLOR_MENU));
  40. wc.lpszMenuName = TEXT("Link Window");
  41. wc.lpszClassName = TEXT("Link Window");
  42. return RegisterClass(&wc);
  43. }
  44. HRESULT CifComponentToPComponent(PCOMPONENT pComp, CCifComponent_t * pCifComponent_t)
  45. {
  46. TCHAR szCustData[MAX_PATH], szID[128], szMode[MAX_PATH];
  47. DWORD dwPlatform, dwType, dwVer, dwBuild;
  48. UINT uiIndex = 0;
  49. ICifComponent* pCifComponentTemp;
  50. pComp->fVisible = (pCifComponent_t->IsUIVisible() == S_FALSE) ? FALSE : TRUE;
  51. dwPlatform = pCifComponent_t->GetPlatform();
  52. if (dwPlatform & PLATFORM_WIN98)
  53. {
  54. if (dwPlatform & PLATFORM_NT4)
  55. pComp->iPlatform = PLAT_I386;
  56. else
  57. pComp->iPlatform = PLAT_W98;
  58. }
  59. else
  60. pComp->iPlatform = PLAT_NTx86;
  61. pCifComponent_t->GetID(szID, countof(szID));
  62. if ((SUCCEEDED(pCifComponent_t->GetCustomData(TEXT("AddOnOnly"), szCustData, countof(szCustData))))
  63. && (szCustData[0] == TEXT('1')))
  64. {
  65. pComp->fAddOnOnly = TRUE;
  66. pComp->fVisible = TRUE;
  67. }
  68. if ((SUCCEEDED(pCifComponent_t->GetCustomData(TEXT("IEAKVisible"), szCustData, countof(szCustData))))
  69. && (szCustData[0] == TEXT('1')))
  70. pComp->fVisible = TRUE;
  71. szMode[0] = TEXT('\0');
  72. if (SUCCEEDED(g_lpCifRWFile->FindComponent(szID, &pCifComponentTemp)))
  73. {
  74. CCifComponent_t * pCifComponentTemp_t =
  75. new CCifComponent_t((ICifRWComponent *)pCifComponentTemp);
  76. while (SUCCEEDED(pCifComponentTemp_t->GetMode(uiIndex, szMode, countof(szMode))))
  77. {
  78. pComp->szModes[uiIndex] = szMode[0];
  79. pComp->afInstall[szMode[0] - TEXT('0')] = TRUE;
  80. uiIndex++;
  81. }
  82. delete pCifComponentTemp_t;
  83. }
  84. else
  85. {
  86. while (SUCCEEDED(pCifComponent_t->GetMode(uiIndex, szMode, countof(szMode))))
  87. {
  88. pComp->szModes[uiIndex] = szMode[0];
  89. pComp->afInstall[szMode[0] - TEXT('0')] = TRUE;
  90. uiIndex++;
  91. }
  92. }
  93. pComp->szModes[uiIndex] = TEXT('\0');
  94. ZeroMemory(pComp->szVersion, sizeof(pComp->szVersion));
  95. pCifComponent_t->GetVersion(&dwVer, &dwBuild);
  96. ConvertDwordsToVersionStr(pComp->szVersion, dwVer, dwBuild);
  97. if ((SUCCEEDED(pCifComponent_t->GetCustomData(TEXT("IEAKCore"), szCustData, countof(szCustData))))
  98. && (szCustData[0] == TEXT('1')))
  99. {
  100. pComp->iCompType = COMP_CORE;
  101. pComp->fVisible = FALSE;
  102. }
  103. // pick up special core comps for OCW
  104. if (g_fOCW && (SUCCEEDED(pCifComponent_t->GetCustomData(TEXT("IEAKOCWCore"), szCustData, countof(szCustData))))
  105. && (szCustData[0] == TEXT('1')))
  106. {
  107. pComp->iCompType = COMP_CORE;
  108. pComp->fVisible = FALSE;
  109. }
  110. if ((SUCCEEDED(pCifComponent_t->GetCustomData(TEXT("IEAKServer"), szCustData, countof(szCustData))))
  111. && (szCustData[0] == TEXT('1')))
  112. pComp->iCompType = COMP_SERVER;
  113. // IEAK should ignore these components since they point to the same cabs as
  114. // another section
  115. if ((SUCCEEDED(pCifComponent_t->GetCustomData(TEXT("IEAKAVSIgnore"), szCustData, countof(szCustData))))
  116. && (szCustData[0] == TEXT('1')))
  117. {
  118. pComp->fAVSDupe = TRUE;
  119. pComp->fVisible = FALSE;
  120. }
  121. // pick up components which point to the same cabs as this section
  122. if ((SUCCEEDED(pCifComponent_t->GetCustomData(TEXT("IEAKAVSLinks"), szCustData, countof(szCustData))))
  123. && ISNONNULL(szCustData))
  124. {
  125. StrRemoveWhitespace(szCustData);
  126. if ((pComp->pszAVSDupeSections =
  127. (LPTSTR)CoTaskMemAlloc((StrLen(szCustData)+1) * sizeof(TCHAR))) != NULL)
  128. StrCpy(pComp->pszAVSDupeSections, szCustData);
  129. }
  130. else
  131. pComp->pszAVSDupeSections = NULL;
  132. StrCpy(pComp->szSection, szID);
  133. /*bug 14679 - don't change these pointers in updates.cpp or this will get clobbered when updates.cpp frees
  134. all this memory!!
  135. if (StrCmpI(szID, TEXT("MAILNEWS")) == 0)
  136. g_pMNComp = pComp;
  137. */
  138. pCifComponent_t->GetGUID(pComp->szGUID, countof(pComp->szGUID));
  139. pCifComponent_t->GetDescription(pComp->szDisplayName, countof(pComp->szDisplayName));
  140. pCifComponent_t->GetUrl(0, pComp->szUrl, countof(pComp->szUrl), &dwType);
  141. if (!(dwType & URLF_RELATIVEURL))
  142. {
  143. LPTSTR pUrl;
  144. TCHAR szTempUrl[MAX_PATH];
  145. pUrl = StrRChr(pComp->szUrl, NULL, TEXT('/'));
  146. if (pUrl)
  147. pUrl++;
  148. else
  149. pUrl = pComp->szUrl;
  150. StrCpy(szTempUrl, pUrl);
  151. StrCpy(pComp->szUrl, szTempUrl);
  152. }
  153. pComp->dwSize = pCifComponent_t->GetDownloadSize();
  154. return TRUE;
  155. }
  156. void UpdateBlueIcon(HWND hCompList, PCOMPONENT pComp)
  157. {
  158. PCOMPONENT pCompTemp = FindComp(pComp->szSection, FALSE);
  159. LVITEM lvi;
  160. StrCpy(pCompTemp->szVersion, pComp->szVersion);
  161. pCompTemp->dwSize = pComp->dwSize;
  162. pCompTemp->iImage = BLUE2;
  163. ZeroMemory(&lvi, sizeof(lvi));
  164. lvi.mask = LVIF_IMAGE;
  165. lvi.iItem = pCompTemp->iList;
  166. ListView_GetItem(hCompList, &lvi);
  167. lvi.iImage = BLUE2;
  168. lvi.mask = LVIF_IMAGE;
  169. lvi.iItem = pCompTemp->iList;
  170. ListView_SetItem(hCompList, &lvi);
  171. ListView_SetItemText(hCompList, lvi.iItem, 1, pComp->szVersion);
  172. }
  173. void UpdateBrownIcon(HWND hCompList, PCOMPONENT pNewComp)
  174. {
  175. PCOMPONENT pComp = NULL;
  176. PCOMP_VERSION pCompVer = NULL;
  177. LVITEM lvi;
  178. int nList = ListView_GetItemCount(hCompList);
  179. UINT uiSize;
  180. ZeroMemory(&lvi, sizeof(lvi));
  181. uiSize = (UINT)LocalSize(g_paComp);
  182. if (uiSize < (g_uiNumCabs * sizeof(COMPONENT)))
  183. {
  184. ASSERT(TRUE); //not enough memory for all these components
  185. return;
  186. }
  187. pComp = g_paComp + g_uiNumCabs;
  188. *pComp = *pNewComp;
  189. //we also need to set g_rgCompVer
  190. pCompVer = g_rgCompVer + g_uiNumCabs;
  191. StrCpy(pCompVer->szID,pComp->szCommand);
  192. StrCpy(pCompVer->szVersion,pComp->szVersion);
  193. pComp->iList = nList;
  194. pComp->iImage = BROWN2;
  195. lvi.mask = LVIF_TEXT | LVIF_IMAGE;
  196. lvi.iItem = nList;
  197. lvi.iSubItem = 0;
  198. lvi.iImage = BROWN2;
  199. lvi.pszText = pComp->szDisplayName;
  200. lvi.cchTextMax = countof(pComp->szDisplayName);
  201. ListView_InsertItem(hCompList, &lvi);
  202. //handle our special case globals--per bug 14679, we have to be very careful what these point
  203. //to, that it's something that won't be freed until we are really done. g_paComp will hold
  204. //onto this memory until the end, though having these global pointers is still risky design
  205. if (StrCmpI(pComp->szDisplayName, TEXT("MAILNEWS")) == 0)
  206. g_pMNComp = pComp;
  207. ListView_SetItemText(hCompList, nList, 1, pComp->szVersion);
  208. g_uiNumCabs++;
  209. }
  210. HRESULT ProcessUpdateIcons(HWND hDlg)
  211. { //---- fixes updated component for the main page list view
  212. HWND hCompList = GetDlgItem(hDlg, IDC_COMPLIST);
  213. HRESULT hr = NULL;
  214. TCHAR szUpdateCif[MAX_PATH];
  215. PCOMP_VERSION pCompVer = NULL;
  216. CCifFile_t* pCifFile = NULL;
  217. IEnumCifComponents* pEnumCifComponents = NULL;
  218. PathCombine(szUpdateCif, g_szIEAKProg, TEXT("update\\ieupdate.cif"));
  219. if (!PathFileExists(szUpdateCif))
  220. return DONT_SHOW_UPDATES;
  221. if ((0 == StrCmp(TEXT(""), g_szUpdateData)) || (0 == StrCmp(TEXT(""), g_szUpdateURL)))
  222. GetUpdateSite();
  223. GetICifFileFromFile_t(&pCifFile, szUpdateCif);
  224. hr = pCifFile->EnumComponents(&pEnumCifComponents, PLATFORM_WIN98 | PLATFORM_NT4 |
  225. PLATFORM_NT5 | PLATFORM_MILLEN, NULL);
  226. if (FAILED(hr)) {
  227. delete pCifFile;
  228. return hr;
  229. }
  230. ICifComponent* pCifComponent = NULL;
  231. PCOMPONENT pComp = NULL;
  232. pComp = (PCOMPONENT) LocalAlloc(LPTR, sizeof(COMPONENT) );
  233. while (S_OK == pEnumCifComponents->Next(&pCifComponent))
  234. {
  235. CCifComponent_t* pCifComp;
  236. pCifComp = new CCifComponent_t((ICifRWComponent*)pCifComponent);
  237. if (NULL == pCifComp) {
  238. delete pCifComp;
  239. continue;
  240. }
  241. ZeroMemory(pComp, sizeof(COMPONENT));
  242. CifComponentToPComponent(pComp, pCifComp);
  243. if ((FALSE == pComp->fVisible) || (TRUE == pComp->fAVSDupe)) {
  244. delete pCifComp;
  245. continue;
  246. }
  247. pComp->iImage = AssignComponentIcon(pComp->szSection, 3);
  248. if (DONT_SHOW_UPDATES != pComp->iImage) {
  249. if (BLUE2 == pComp->iImage)
  250. UpdateBlueIcon(hCompList, pComp);
  251. if (BROWN2 == pComp->iImage)
  252. UpdateBrownIcon(hCompList, pComp);
  253. }
  254. delete pCifComp;
  255. }
  256. pEnumCifComponents->Release();
  257. delete pCifFile;
  258. LocalFree(pComp);
  259. return TRUE;
  260. }
  261. HRESULT DownloadUpdate(PCOMPONENT pComp)
  262. {
  263. TCHAR szLocalPath[MAX_PATH], szUrl[INTERNET_MAX_URL_LENGTH];
  264. LPTSTR pCab = NULL;
  265. DWORD dwFreeSpace;
  266. HRESULT hr;
  267. BOOL fIgnore = FALSE;
  268. if (pComp->szDisplayName)
  269. SetDlgItemText( s_hStat, IDC_DOWNCOMPNAMD, pComp->szDisplayName );
  270. PathCombine(szLocalPath, g_szIEAKProg, pComp->szUrl);
  271. StrCpy(szUrl, g_szUpdateURL);
  272. StrCat(szUrl, TEXT("/"));
  273. StrCat(szUrl, pComp->szUrl);
  274. dwFreeSpace = GetRootFree(g_szIEAKProg);
  275. if (dwFreeSpace < pComp->dwSize)
  276. {
  277. TCHAR szTitle[MAX_PATH];
  278. TCHAR szTemplate[MAX_PATH];
  279. TCHAR szMsg[MAX_PATH];
  280. LoadString( g_rvInfo.hInst, IDS_DISKERROR, szTitle, MAX_PATH );
  281. LoadString( g_rvInfo.hInst, IDS_TEMPDISKMSG, szTemplate, MAX_PATH );
  282. wnsprintf(szMsg, countof(szMsg), szTemplate, dwFreeSpace, (pComp->dwSize));
  283. MessageBox(NULL, szMsg, szTitle, MB_OK | MB_SETFOREGROUND);
  284. return FALSE;
  285. }
  286. hr = DownloadCab(s_hStat, szUrl, szLocalPath, pComp->szDisplayName, pComp->dwSize, fIgnore);
  287. if (!PathFileExists(szLocalPath) || (DONT_SHOW_UPDATES == hr))
  288. return DONT_SHOW_UPDATES;
  289. updateCifVersions32(pComp, fIgnore, TRUE);
  290. return S_OK;
  291. }
  292. void InitAVSListView(HWND hCompList)
  293. {
  294. LVCOLUMN lvc;
  295. TCHAR szAux[MAX_PATH];
  296. HICON hBrown, hBrown2, hBlue, hBlue2, hRed, hYellow, hGreen;
  297. //----- Create the image list if it has not already been created -----
  298. if (s_hImgList == 0)
  299. {
  300. s_hImgList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
  301. GetSystemMetrics(SM_CYSMICON), 1, 7, 1);
  302. hBrown = LoadIcon(g_rvInfo.hInst, MAKEINTRESOURCE(IDI_BROWN));
  303. hBrown2 = LoadIcon(g_rvInfo.hInst, MAKEINTRESOURCE(IDI_BROWN2));
  304. hBlue = LoadIcon(g_rvInfo.hInst, MAKEINTRESOURCE(IDI_BLUE));
  305. hBlue2 = LoadIcon(g_rvInfo.hInst, MAKEINTRESOURCE(IDI_BLUE2));
  306. hRed = LoadIcon(g_rvInfo.hInst, MAKEINTRESOURCE(IDI_RED));
  307. hYellow = LoadIcon(g_rvInfo.hInst, MAKEINTRESOURCE(IDI_YELLOW));
  308. hGreen = LoadIcon(g_rvInfo.hInst, MAKEINTRESOURCE(IDI_GREEN));
  309. s_aiIcon[0] = ImageList_AddIcon(s_hImgList, hBrown);
  310. s_aiIcon[1] = ImageList_AddIcon(s_hImgList, hBrown2);
  311. s_aiIcon[2] = ImageList_AddIcon(s_hImgList, hBlue);
  312. s_aiIcon[3] = ImageList_AddIcon(s_hImgList, hBlue2);
  313. s_aiIcon[4] = ImageList_AddIcon(s_hImgList, hRed);
  314. s_aiIcon[5] = ImageList_AddIcon(s_hImgList, hYellow);
  315. s_aiIcon[6] = ImageList_AddIcon(s_hImgList, hGreen);
  316. DestroyIcon(hBrown);
  317. DestroyIcon(hBrown2);
  318. DestroyIcon(hBlue);
  319. DestroyIcon(hBlue2);
  320. DestroyIcon(hRed);
  321. DestroyIcon(hYellow);
  322. DestroyIcon(hGreen);
  323. }
  324. // Assign the image lists to the list view control.
  325. ListView_SetImageList(hCompList, s_hImgList, LVSIL_SMALL);
  326. //----- Initialize columns in a list view -----
  327. LoadString(g_rvInfo.hInst, IDS_COMPNAME, szAux, countof(szAux));
  328. ZeroMemory(&lvc, sizeof(lvc));
  329. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
  330. lvc.fmt = LVCFMT_LEFT;
  331. lvc.cx = 273;
  332. lvc.pszText = szAux;
  333. ListView_InsertColumn(hCompList, 0, &lvc);
  334. LoadString(g_rvInfo.hInst, IDS_VERSION, szAux, countof(szAux));
  335. ZeroMemory(&lvc, sizeof(lvc));
  336. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
  337. lvc.fmt = LVCFMT_LEFT;
  338. lvc.cx = 105;
  339. lvc.pszText = szAux;
  340. ListView_InsertColumn(hCompList, 1, &lvc);
  341. }
  342. HRESULT AssignComponentIcon(LPTSTR szInID, int ipageNumber)
  343. {
  344. //---- returns the icon color, Unless the component update is not shown => returns DONT_SHOW_UPDATE
  345. TCHAR szDiskVer[MAX_PATH], szSetupVer[MAX_PATH], szUpdateVer[MAX_PATH],
  346. szIECifPath[MAX_PATH], szUpdatePath[MAX_PATH];
  347. HRESULT hr = NULL;
  348. DWORD dwVer, dwBuild;
  349. UINT i;
  350. BOOL fOnDisk = TRUE, fInSetupFile = TRUE, fInUpdateFile = TRUE, fInDownload = TRUE;
  351. PCOMP_VERSION pCompVer = NULL;
  352. CCifFile_t * lpDiskFile = NULL, * lpSetupFile = NULL, * lpUpdateFile = NULL;
  353. ICifComponent * pDiskComponent = NULL, * pSetupComponent = NULL, * pUpdateComponent = NULL;
  354. CCifComponent_t * pDiskComp = NULL, * pSetupComp = NULL, * pUpdateComp = NULL;
  355. int iDiskSetup;
  356. PathCombine(szIECifPath, g_szIEAKProg, TEXT("new\\iesetup.cif"));
  357. PathCombine(szUpdatePath, g_szIEAKProg, TEXT("update\\ieupdate.cif"));
  358. if (PathFileExists(g_szCif))
  359. hr = GetICifFileFromFile_t(&lpDiskFile, g_szCif);
  360. else
  361. fOnDisk = FALSE;
  362. pCompVer = g_rgCompVer;
  363. for (i=0; i < g_uiNumCabs; i++, pCompVer++)
  364. if ((NULL != pCompVer->szID) && (0 == StrCmp(pCompVer->szID, szInID))) {
  365. StrCpy(szSetupVer, pCompVer->szVersion);
  366. fInSetupFile = TRUE;
  367. break;
  368. }
  369. if (((NULL == pCompVer->szID) || (i == g_uiNumCabs)) && (0 != StrCmp(pCompVer->szID, szInID)))
  370. fInSetupFile = FALSE;
  371. if (PathFileExists(szUpdatePath))
  372. hr = GetICifFileFromFile_t(&lpUpdateFile, szUpdatePath);
  373. else
  374. fInUpdateFile = FALSE;
  375. if (fOnDisk)
  376. fOnDisk = SUCCEEDED(lpDiskFile->FindComponent(szInID, &pDiskComponent));
  377. if (fOnDisk) //--- Search ID in Builds\...\IEsetup.cif
  378. {
  379. TCHAR szPath[MAX_PATH], szUrl[MAX_PATH];
  380. DWORD dwType;
  381. pDiskComp = new CCifComponent_t((ICifRWComponent *) pDiskComponent);
  382. StrCpy(szPath, g_szIEAKProg);
  383. pDiskComp->GetUrl(0, szUrl, countof(szUrl), &dwType); //--- Check to see if it the cab is downloaded
  384. if (!(dwType & URLF_RELATIVEURL))
  385. {
  386. LPTSTR pUrl;
  387. TCHAR szTempUrl[MAX_PATH];
  388. pUrl = StrRChr(szUrl, NULL, TEXT('/'));
  389. if (pUrl)
  390. pUrl++;
  391. else
  392. pUrl = szUrl;
  393. StrCpy(szTempUrl, pUrl);
  394. StrCpy(szUrl, szTempUrl);
  395. }
  396. PathAppend(szPath, szUrl);
  397. if (!PathFileExists(szPath))
  398. fInDownload = FALSE;
  399. pDiskComp->GetVersion(&dwVer, &dwBuild);
  400. ConvertDwordsToVersionStr(szDiskVer, dwVer, dwBuild);
  401. }
  402. else
  403. fInDownload = FALSE;
  404. if (fInUpdateFile)
  405. fInUpdateFile = SUCCEEDED(lpUpdateFile->FindComponent(szInID, &pUpdateComponent));
  406. if (fInUpdateFile) //--- Search ID in update\IEsetup.cif
  407. {
  408. pUpdateComp = new CCifComponent_t((ICifRWComponent *) pUpdateComponent);
  409. pUpdateComp->GetVersion(&dwVer, &dwBuild);
  410. ConvertDwordsToVersionStr(szUpdateVer, dwVer, dwBuild);
  411. }
  412. delete pSetupComp;
  413. delete pDiskComp;
  414. delete pUpdateComp;
  415. delete lpDiskFile;
  416. delete lpSetupFile;
  417. delete lpUpdateFile;
  418. if ((ipageNumber == 1) || (ipageNumber == 3))
  419. if ((!fOnDisk) || (!fInDownload))
  420. return RED;
  421. else
  422. {
  423. iDiskSetup = CheckVer(szDiskVer, szSetupVer);
  424. if ((fInSetupFile) && (0 > iDiskSetup))
  425. return YELLOW;
  426. else
  427. if ((fInSetupFile) && (0 == iDiskSetup))
  428. return GREEN;
  429. }
  430. if (fOnDisk)
  431. {
  432. if ((2 == ipageNumber) && (((CheckVer(szDiskVer, szUpdateVer) == 0) && (fInDownload)) ||
  433. (0 == CheckVer(szUpdateVer, szSetupVer))))
  434. return DONT_SHOW_UPDATES;
  435. if (2 == ipageNumber)
  436. if (fInSetupFile)
  437. return BLUE;
  438. else
  439. return BROWN;
  440. if (fInSetupFile)
  441. return BLUE2;
  442. else
  443. return BROWN2;
  444. }
  445. else
  446. if (!fInSetupFile)
  447. return BROWN;
  448. else
  449. return BLUE;
  450. }
  451. HRESULT PreAddListItem(HWND hCompList, int * count, CCifComponent_t * pCifComp)
  452. {
  453. LVITEM lvi;
  454. PCOMPONENT pComp = NULL;
  455. ZeroMemory(&lvi, sizeof(lvi));
  456. pComp = (PCOMPONENT) LocalAlloc(LPTR, sizeof(COMPONENT) );
  457. if (!pComp)
  458. return FALSE;
  459. ZeroMemory(pComp, sizeof(COMPONENT));
  460. CifComponentToPComponent(pComp, pCifComp);
  461. if ((TRUE == pComp->fAVSDupe) || (FALSE == pComp->fVisible))
  462. return FALSE;
  463. else
  464. pComp->iImage = lvi.iImage = AssignComponentIcon(pComp->szSection, 2);
  465. if (DONT_SHOW_UPDATES == lvi.iImage)
  466. return FALSE;
  467. lvi.lParam = (LPARAM) pComp;
  468. lvi.mask = LVIF_STATE | LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  469. lvi.iItem = *count;
  470. lvi.pszText = pComp->szDisplayName;
  471. lvi.cchTextMax = countof(pComp->szDisplayName);
  472. ListView_InsertItem(hCompList, &lvi);
  473. ListView_SetItemText(hCompList, *count, 1, pComp->szVersion);
  474. return TRUE;
  475. }
  476. int FillComponentsListView(HWND hCompList, LPCTSTR szCifPath, FCLV_PREADDLISTITEM pfnPreAddListItem)
  477. {
  478. HRESULT hr;
  479. LPLVITEM plvi = NULL;
  480. int icount = 0;
  481. CCifFile_t* pCifFile = NULL;
  482. InitAVSListView(hCompList); //---- assigns image list and creates columns
  483. if (NULL == pfnPreAddListItem)
  484. return S_FALSE;
  485. hr = GetICifFileFromFile_t(&pCifFile, szCifPath);
  486. if (FAILED(hr))
  487. return hr;
  488. IEnumCifComponents* pEnumCifComponents = NULL;
  489. ICifComponent* pCifComponent = NULL;
  490. hr = pCifFile->EnumComponents(&pEnumCifComponents,
  491. PLATFORM_WIN98 | PLATFORM_NT4 | PLATFORM_NT5 | PLATFORM_MILLEN, NULL);
  492. if (FAILED(hr))
  493. return hr;
  494. while (S_OK == pEnumCifComponents->Next(&pCifComponent))
  495. {
  496. CCifComponent_t* pCifComponent_t;
  497. pCifComponent_t = new CCifComponent_t((ICifRWComponent*)pCifComponent);
  498. if (NULL == pCifComponent_t)
  499. continue;
  500. if (!(*pfnPreAddListItem)(hCompList, &icount, pCifComponent_t))
  501. delete pCifComponent_t;
  502. else
  503. icount++; //----- Don't delete the component if it's in the list view
  504. }
  505. pEnumCifComponents->Release();
  506. delete pCifFile;
  507. return icount;
  508. }
  509. DWORD InitUpdateThreadProc(LPVOID lParam) //----- Downloads cab file, extracts new cif, and sends status -----
  510. {
  511. TCHAR szLocalCab[MAX_PATH], szCabURL[MAX_PATH], szLocalDir[MAX_PATH];
  512. HWND hDlg = (HWND) lParam,
  513. hCompList = GetDlgItem(hDlg, IDC_COMPLIST);
  514. HRESULT hrCom;
  515. int count = 0;
  516. BOOL fIgnore = FALSE;
  517. CCifFile_t * lpUpdateFile = NULL;
  518. hrCom = CoInitialize(NULL);
  519. PathCombine(szLocalDir, g_szIEAKProg, TEXT("update\\"));
  520. TCHAR szMsg[MAX_PATH], szTitle[MAX_PATH];
  521. LoadString(g_rvInfo.hInst, IDS_NOUPDATETITLE, szTitle, countof(szTitle));
  522. LoadString(g_rvInfo.hInst, IDS_ERROR_UPDATEFOLDER, szMsg, countof(szMsg));
  523. if (!PathIsDirectory(szLocalDir))
  524. while ((!CreateDirectory(szLocalDir, NULL)) && (IDRETRY == MessageBox(hDlg, szMsg, szTitle, MB_ICONERROR | MB_RETRYCANCEL)));
  525. if ((0 == StrCmp(TEXT(""), g_szUpdateData)) || (0 == StrCmp(TEXT(""), g_szUpdateURL)))
  526. GetUpdateSite();
  527. ZeroMemory(szCabURL, sizeof(szCabURL));
  528. StrCpy(szCabURL, g_szUpdateURL);
  529. StrCat(szCabURL, TEXT("/IEUPDATE.CAB"));
  530. PathCombine(szLocalCab, szLocalDir, TEXT("IEUPDATE.CAB"));
  531. if (SUCCEEDED(DownloadCab(hDlg, szCabURL, szLocalCab, TEXT("IEUPDATE.CAB"), 0, fIgnore)))
  532. {
  533. if (SUCCEEDED(ExtractFilesWrap(szLocalCab, szLocalDir, 0, NULL, NULL, 0)))
  534. {
  535. TCHAR szLocalCif[MAX_PATH];
  536. FCLV_PREADDLISTITEM pfnPreAddListItem = PreAddListItem;
  537. PathCombine(szLocalCif, szLocalDir, TEXT("ieupdate.cif"));
  538. count = FillComponentsListView(hCompList, szLocalCif, pfnPreAddListItem);
  539. if ((0 < count) && (9 > count))
  540. ListView_SetColumnWidth(hCompList, 1, 128);
  541. else
  542. ListView_SetColumnWidth(hCompList, 1, 113);
  543. }
  544. else
  545. {
  546. LoadString(g_rvInfo.hInst, IDS_ERROR_IEUPDATECIF, szMsg, countof(szMsg));
  547. MessageBox(hDlg, szMsg, szTitle, MB_ICONERROR);
  548. }
  549. }
  550. else
  551. DownloadErrMsg(hDlg, TEXT("IEUPDATE.CAB"), MAKEINTRESOURCE(IDD_DOWNLOADERR));
  552. if (SUCCEEDED(hrCom))
  553. CoUninitialize();
  554. return (0 < count) ? SHOW_UPDATES : DONT_SHOW_UPDATES;
  555. }
  556. INT_PTR CALLBACK FindUpdateDlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
  557. {
  558. UNREFERENCED_PARAMETER(wParam);
  559. HWND* phDlg;
  560. switch (iMsg)
  561. {
  562. case WM_INITDIALOG:
  563. phDlg = (HWND*)lParam;
  564. if (NULL != phDlg) {
  565. ASSERT(NULL == *phDlg);
  566. *phDlg = hDlg;
  567. }
  568. break;
  569. default:
  570. return FALSE;
  571. }
  572. return TRUE;
  573. }
  574. DWORD UpdateDlg_InitDialog(HWND hDlg, LPTSTR ps_szFreeSpace, LPTSTR ps_szTotalSize)
  575. {
  576. HWND hFindUpdateDlg;
  577. HANDLE hAVSThread;
  578. DWORD dwResult, dwThread;
  579. hAVSThread = CreateThread(NULL, 4096, InitUpdateThreadProc, hDlg, 0, &dwThread);
  580. if (NULL == hAVSThread) {
  581. return 0;
  582. }
  583. hFindUpdateDlg = CreateDialog(g_rvInfo.hInst, MAKEINTRESOURCE(IDD_FINDUPDATE), hDlg, FindUpdateDlgProc);
  584. ShowWindow(hFindUpdateDlg, SW_SHOWNORMAL);
  585. while (WAIT_OBJECT_0 != MsgWaitForMultipleObjects(1, &hAVSThread, FALSE, INFINITE, QS_ALLINPUT))
  586. {
  587. MSG msg;
  588. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  589. {
  590. TranslateMessage(&msg);
  591. DispatchMessage(&msg);
  592. }
  593. }
  594. DestroyWindow(hFindUpdateDlg);
  595. GetExitCodeThread(hAVSThread, &dwResult);
  596. if (DONT_SHOW_UPDATES == dwResult) {
  597. TCHAR szMsg[MAX_PATH], szTitle[MAX_PATH];
  598. LoadString(g_rvInfo.hInst, IDS_AVSNOUPDATES, szMsg, countof(szMsg));
  599. LoadString(g_rvInfo.hInst, IDS_NOUPDATETITLE, szTitle, countof(szTitle));
  600. MessageBox(hDlg, szMsg, szTitle, MB_OK);
  601. EndDialog(hDlg, IDCANCEL);
  602. }
  603. //--- Set initial Disk space displays -----
  604. InsertCommas(ps_szFreeSpace);
  605. SetDlgItemText(hDlg, IDC_DISKSPACE, ps_szFreeSpace);
  606. ShowDlgItem(hDlg, IDC_DISKSPACE);
  607. UpdateDlg_GetDownloadSize(GetDlgItem(hDlg, IDC_COMPLIST), GetDlgItem(hDlg, IDC_DISKSPACENEEDED), TRUE);
  608. GetDlgItemText(hDlg, IDC_DISKSPACENEEDED, ps_szTotalSize, MAX_PATH);
  609. ShowDlgItem(hDlg, IDC_DISKSPACENEEDED);
  610. ShowDlgItem(hDlg, IDC_DISKSPACETEXT);
  611. DisableDlgItem(hDlg, IDOK); //---- Can't synchronize with nothing selected.
  612. return 0;
  613. }
  614. PCOMPONENT* UpdateDlg_GetDownloadList(HWND hDlg)
  615. {
  616. HWND hCompList = GetDlgItem(hDlg, IDC_COMPLIST);
  617. PCOMPONENT* rgpComp,
  618. pComp;
  619. UINT cSelected,
  620. i, j;
  621. cSelected = ListView_GetSelectedCount(hCompList);
  622. if (0 == cSelected)
  623. return NULL;
  624. rgpComp = (PCOMPONENT*)LocalAlloc(LPTR, (1 + cSelected) * sizeof(PCOMPONENT));
  625. if (NULL == rgpComp)
  626. return NULL;
  627. ZeroMemory(rgpComp, (1 + cSelected) * sizeof(PCOMPONENT));
  628. for (i = j = 0; i < (UINT) ListView_GetItemCount(hCompList); i++)
  629. {
  630. LVITEM lvi;
  631. ZeroMemory(&lvi, sizeof(lvi));
  632. lvi.mask = LVIF_STATE | LVIF_PARAM;
  633. lvi.stateMask = LVIS_SELECTED;
  634. lvi.iItem = i;
  635. ListView_GetItem(hCompList, &lvi);
  636. pComp = (PCOMPONENT)lvi.lParam;
  637. if (0 != (LVIS_SELECTED & lvi.state))
  638. rgpComp[j++] = pComp;
  639. else
  640. LocalFree(pComp);
  641. }
  642. ASSERT(j == cSelected);
  643. rgpComp[j] = NULL;
  644. return rgpComp;
  645. }
  646. void UpdateDlg_GetDownloadSize(HWND hCompList, HWND hStatusField, BOOL fAll)
  647. {
  648. int i;
  649. DWORD dwSize = 0;
  650. TCHAR szSize[32];
  651. PCOMPONENT pComp;
  652. for (i=0; i < ListView_GetItemCount(hCompList); i++)
  653. {
  654. LVITEM lvi;
  655. ZeroMemory(&lvi, sizeof(lvi));
  656. lvi.mask = LVIF_STATE | LVIF_PARAM;
  657. lvi.stateMask = LVIS_SELECTED;
  658. lvi.iItem = i;
  659. ListView_GetItem(hCompList, &lvi);
  660. if ((!fAll) && ((lvi.state & LVIS_SELECTED) == 0))
  661. continue;
  662. pComp = (PCOMPONENT) lvi.lParam;
  663. dwSize += pComp->dwSize;
  664. }
  665. wnsprintf(szSize, countof(szSize), TEXT("%lu KB"), dwSize);
  666. InsertCommas(szSize);
  667. SetWindowText(hStatusField, szSize);
  668. }
  669. LRESULT CALLBACK HyperLinkWndProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
  670. {
  671. TCHAR szText[30];
  672. PAINTSTRUCT ps;
  673. HDC hdc;
  674. LOGFONT lfNew, lf;
  675. HFONT hfCurrent, hfLink;
  676. int len;
  677. switch (iMsg)
  678. {
  679. case WM_PAINT:
  680. ZeroMemory(szText, sizeof(szText));
  681. GetWindowText(hDlg, szText, sizeof(szText));
  682. hdc = BeginPaint(hDlg, &ps);
  683. hfCurrent = (HFONT) GetCurrentObject(hdc, OBJ_FONT);
  684. ASSERT(hfCurrent != NULL);
  685. len = GetObject(hfCurrent, sizeof(lf), &lf);
  686. ASSERT(len == sizeof(lf));
  687. ZeroMemory(&lfNew, sizeof(lfNew));
  688. lfNew.lfHeight = (LONG) 13;
  689. lfNew.lfUnderline = TRUE;
  690. lfNew.lfWeight = FW_NORMAL;
  691. StrCpy(lfNew.lfFaceName, TEXT("Tahoma"));
  692. hfLink = CreateFontIndirect(&lfNew);
  693. SelectObject(hdc, hfLink);
  694. SetBkColor(hdc, GetSysColor(COLOR_MENU));
  695. SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
  696. TextOut(hdc, 0, 0, szText, StrLen(szText));
  697. DeleteObject(SelectObject(hdc, GetStockObject(OBJ_FONT)));
  698. DeleteDC(hdc);
  699. EndPaint(hDlg, &ps);
  700. return 0;
  701. case WM_KEYUP:
  702. if (wParam != VK_SPACE)
  703. break;
  704. case WM_LBUTTONUP:
  705. SendMessage(GetParent(hDlg), WM_COMMAND, GetWindowLong(hDlg, GWL_ID), (LPARAM) hDlg);
  706. return 0;
  707. }
  708. return DefWindowProc(hDlg, iMsg, wParam, lParam);
  709. }
  710. INT_PTR CALLBACK UpdateDlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
  711. {
  712. static PCOMPONENT** s_ppCompList; /*= NULL*/
  713. HWND hCompList;
  714. static TCHAR s_szFreeSpace[MAX_PATH];
  715. static TCHAR s_szTotalSize[MAX_PATH];
  716. static HFONT hfLink;
  717. switch (iMsg)
  718. {
  719. case WM_INITDIALOG:
  720. wnsprintf(s_szFreeSpace, countof(s_szFreeSpace), TEXT("%lu KB"), GetRootFree(g_szIEAKProg));
  721. UpdateDlg_InitDialog(hDlg, s_szFreeSpace, s_szTotalSize);
  722. s_ppCompList = (PCOMPONENT**)lParam; //--- Keep pointer to download list
  723. ASSERT(NULL != s_ppCompList);
  724. break;
  725. case IDM_INITIALIZE:
  726. break;
  727. case WM_COMMAND:
  728. if (BN_CLICKED != GET_WM_COMMAND_CMD(wParam, lParam))
  729. return FALSE;
  730. switch (GET_WM_COMMAND_ID(wParam, lParam))
  731. {
  732. case IDOK:
  733. *s_ppCompList = UpdateDlg_GetDownloadList(hDlg); //--- Set download list
  734. case IDCANCEL:
  735. EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  736. break;
  737. case IDHELP:
  738. ListView_SetItemState(GetDlgItem(hDlg, IDC_COMPLIST), -1, 0, LVIS_SELECTED);
  739. IeakPageHelp(hDlg, MAKEINTRESOURCE(IDD_OPTUPDATE));
  740. break;
  741. case IDC_DOWNLOADALL:
  742. hCompList = GetDlgItem(hDlg, IDC_COMPLIST);
  743. SetFocus(hCompList);
  744. ListView_SetItemState(hCompList, -1, LVIS_SELECTED, LVIS_SELECTED);
  745. break;
  746. //----------------- IEAK Site here Take out link for now since it doesn't work with build lab------------
  747. //----------------- also need to uncomment CreateIEAKUrl in ie4comp.cpp and the comments ------------
  748. //----------------- for the control in ieakui\wizard.rc (IDD_OPTUPDATE) to activate ------------
  749. // case IDC_DIALOGLINK:
  750. // ShellExecute(hDlg, TEXT("open"), TEXT("http://www.microsoft.com/isapi/Redir.dll?prd=ieak&ar=ieak"),
  751. // NULL, NULL, SW_SHOWNORMAL);
  752. break;
  753. default:
  754. return FALSE;
  755. }
  756. break;
  757. case WM_NOTIFY:
  758. switch (((NMHDR FAR *)lParam)->code)
  759. {
  760. case LVN_ITEMCHANGED:
  761. hCompList = GetDlgItem(hDlg, IDC_COMPLIST);
  762. if (0 < ListView_GetSelectedCount(hCompList))
  763. {
  764. HideDlgItem(hDlg, IDC_DISKSPACETEXT);
  765. UpdateDlg_GetDownloadSize(hCompList, GetDlgItem(hDlg, IDC_DISKSPACENEEDED), FALSE);
  766. ShowDlgItem(hDlg, IDC_DISKSPACETEXT2);
  767. EnableDlgItem(hDlg, IDOK);
  768. }
  769. else
  770. {
  771. ShowDlgItem(hDlg, IDC_DISKSPACETEXT);
  772. HideDlgItem(hDlg, IDC_DISKSPACETEXT2);
  773. SetDlgItemText(hDlg, IDC_DISKSPACENEEDED, s_szTotalSize);
  774. DisableDlgItem(hDlg, IDOK);
  775. }
  776. break;
  777. default:
  778. return FALSE;
  779. }
  780. break;
  781. case WM_HELP:
  782. ListView_SetItemState(GetDlgItem(hDlg, IDC_COMPLIST), -1, 0, LVIS_SELECTED);
  783. IeakPageHelp(hDlg, MAKEINTRESOURCE(IDD_OPTUPDATE));
  784. break;
  785. default:
  786. return FALSE;
  787. }
  788. return TRUE;
  789. }