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.

2690 lines
81 KiB

  1. #include "inspch.h"
  2. #include "inseng.h"
  3. #include "insobj.h"
  4. #include "util2.h"
  5. #define MAX_VALUE_LEN 256
  6. #define MAX_SMALL_BUF 64
  7. #define NO_ENTRY ""
  8. #define UNINSTALL_BRANCH "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
  9. char g_pBuffer[BUFFERSIZE];
  10. #define NUM_RETRIES 2
  11. HINSTANCE CCifComponent::_hDetLib = NULL;
  12. char CCifComponent::_szDetDllName[] = "";
  13. const char c_gszSRLiteOffset[] = "patch/";
  14. char gszIsPatchable[] = "IsPatchable";
  15. //=--------------------------------------------------------------------------=
  16. // Function name here
  17. //=--------------------------------------------------------------------------=
  18. // Function description
  19. //
  20. // Parameters:
  21. //
  22. // Returns:
  23. //
  24. // Notes:
  25. //
  26. CCifComponent::CCifComponent(LPCSTR pszCompID, CCifFile *pCif) : CCifEntry(pszCompID, pCif)
  27. {
  28. _dwPlatform = 0xffffffff;
  29. _uInstallStatus = 0xffffffff;
  30. _uInstallCount = 0;
  31. _fDependenciesQueued = FALSE;
  32. _fUseSRLite = FALSE;
  33. _fBeforeInstall = TRUE;
  34. SetDownloadDir("");
  35. }
  36. //=--------------------------------------------------------------------------=
  37. // Function name here
  38. //=--------------------------------------------------------------------------=
  39. // Function description
  40. //
  41. // Parameters:
  42. //
  43. // Returns:
  44. //
  45. // Notes:
  46. //
  47. CCifComponent::~CCifComponent()
  48. {
  49. if(_hDetLib)
  50. {
  51. FreeLibrary(_hDetLib);
  52. _hDetLib = NULL;
  53. }
  54. }
  55. STDMETHODIMP CCifComponent::GetID(LPSTR pszID, DWORD dwSize)
  56. {
  57. lstrcpyn(pszID, _szID, dwSize);
  58. return NOERROR;
  59. }
  60. STDMETHODIMP CCifComponent::GetGUID(LPSTR pszGUID, DWORD dwSize)
  61. {
  62. return(GetPrivateProfileString(_szID, GUID_KEY, "", pszGUID, dwSize, _pCif->GetCifPath()) ? NOERROR : E_FAIL);
  63. }
  64. STDMETHODIMP CCifComponent::GetDescription(LPSTR pszDesc, DWORD dwSize)
  65. {
  66. return(MyTranslateString(_pCif->GetCifPath(), _szID, DISPLAYNAME_KEY, pszDesc, dwSize));
  67. }
  68. STDMETHODIMP CCifComponent::GetDetails(LPSTR pszDetails, DWORD dwSize)
  69. {
  70. return(MyTranslateString(_pCif->GetCifPath(), _szID, DETAILS_KEY, pszDetails, dwSize));
  71. }
  72. STDMETHODIMP CCifComponent::GetUrl(UINT uUrlNum, LPSTR pszUrl, DWORD dwSize, LPDWORD pdwUrlFlags)
  73. {
  74. char szKey[16];
  75. char szBuf[MAX_VALUE_LEN];
  76. HRESULT hr = E_FAIL;
  77. // in cif, these things start at 1. we want to start at 0 when handing them out
  78. uUrlNum++;
  79. // Build up the key
  80. wsprintf(szKey, "%s%lu", URL_KEY, uUrlNum);
  81. GetPrivateProfileString(_szID, szKey, NO_ENTRY, szBuf, sizeof(szBuf), _pCif->GetCifPath());
  82. // See if there is any such entry
  83. if(lstrcmp(szBuf, NO_ENTRY) != 0)
  84. {
  85. // snatch the url name
  86. if(GetStringField(szBuf, 0, pszUrl, dwSize) != 0)
  87. {
  88. // This url looks ok
  89. hr = NOERROR;
  90. *pdwUrlFlags = GetIntField(szBuf, 1, URLF_DEFAULT);
  91. }
  92. }
  93. return hr;
  94. }
  95. STDMETHODIMP CCifComponent::GetFileExtractList(UINT uUrlNum, LPSTR pszExtract, DWORD dwSize)
  96. {
  97. char szKey[16];
  98. char szBuf[MAX_VALUE_LEN];
  99. HRESULT hr = E_FAIL;
  100. uUrlNum++;
  101. // Build up the key
  102. wsprintf(szKey, "%s%lu", URL_KEY, uUrlNum);
  103. GetPrivateProfileString(_szID, szKey, NO_ENTRY, szBuf, sizeof(szBuf), _pCif->GetCifPath());
  104. // See if there is any such entry
  105. if(lstrcmp(szBuf, NO_ENTRY) != 0)
  106. {
  107. // snatch the extract list
  108. if(GetStringField(szBuf, 2, pszExtract, dwSize))
  109. hr = NOERROR;
  110. }
  111. return hr;
  112. }
  113. STDMETHODIMP CCifComponent::GetUrlCheckRange(UINT uUrlNum, LPDWORD pdwMin, LPDWORD pdwMax)
  114. {
  115. char szKey[16];
  116. char szBuf[MAX_VALUE_LEN];
  117. HRESULT hr = E_FAIL;
  118. uUrlNum++;
  119. *pdwMin = *pdwMax = 0;
  120. // Build up the key
  121. wsprintf(szKey, "%s%lu", URLSIZE_KEY, uUrlNum);
  122. GetPrivateProfileString(_szID, szKey, NO_ENTRY, szBuf, sizeof(szBuf), _pCif->GetCifPath());
  123. // See if there is any such entry
  124. if(lstrcmp(szBuf, NO_ENTRY) != 0)
  125. {
  126. // snatch the extract list
  127. *pdwMin = GetIntField(szBuf, 0, 0);
  128. *pdwMax = GetIntField(szBuf, 1, *pdwMin);
  129. }
  130. return hr;
  131. }
  132. STDMETHODIMP CCifComponent::GetCommand(UINT uCmdNum, LPSTR pszCmd, DWORD dwCmdSize,
  133. LPSTR pszSwitches, DWORD dwSwitchSize, LPDWORD pdwType)
  134. {
  135. char szKey[16];
  136. HRESULT hr = E_FAIL;
  137. uCmdNum++;
  138. // Build up the key
  139. wsprintf(szKey, "%s%lu", CMD_KEY, uCmdNum);
  140. GetPrivateProfileString(_szID, szKey, NO_ENTRY, pszCmd, dwCmdSize, _pCif->GetCifPath());
  141. if(lstrcmp(pszCmd, NO_ENTRY) != 0)
  142. {
  143. // Build up the key
  144. wsprintf(szKey, "%s%d", ARGS_KEY, uCmdNum);
  145. GetPrivateProfileString(_szID, szKey, NO_ENTRY, pszSwitches, dwSwitchSize, _pCif->GetCifPath());
  146. // expand #W (or #w) to windows directory
  147. ExpandString( pszSwitches, dwSwitchSize );
  148. // Build up the key
  149. wsprintf(szKey, "%s%d", TYPE_KEY, uCmdNum);
  150. *pdwType = GetPrivateProfileInt(_szID, szKey, CMDF_DEFAULT, _pCif->GetCifPath());
  151. hr = NOERROR;
  152. }
  153. return hr;
  154. }
  155. STDMETHODIMP CCifComponent::GetVersion(LPDWORD pdwVersion, LPDWORD pdwBuild)
  156. {
  157. char szBuf[MAX_VALUE_LEN];
  158. szBuf[0] = '\0';
  159. // Version
  160. GetPrivateProfileString(_szID, VERSION_KEY, "", szBuf, sizeof(szBuf), _pCif->GetCifPath());
  161. ConvertVersionStrToDwords(szBuf, pdwVersion, pdwBuild);
  162. return NOERROR;
  163. }
  164. STDMETHODIMP CCifComponent::GetLocale(LPSTR pszLocale, DWORD dwSize)
  165. {
  166. if(FAILED(MyTranslateString(_pCif->GetCifPath(), _szID, LOCALE_KEY, pszLocale, dwSize)))
  167. lstrcpyn(pszLocale, DEFAULT_LOCALE, dwSize);
  168. return NOERROR;
  169. }
  170. STDMETHODIMP CCifComponent::GetUninstallKey(LPSTR pszKey, DWORD dwSize)
  171. {
  172. return(GetPrivateProfileString(_szID, UNINSTALLSTRING_KEY, "", pszKey, dwSize, _pCif->GetCifPath()) ? NOERROR : E_FAIL);
  173. }
  174. STDMETHODIMP CCifComponent::GetInstalledSize(LPDWORD pdwWin, LPDWORD pdwApp)
  175. {
  176. char szBuf[MAX_VALUE_LEN];
  177. if(GetPrivateProfileString(_szID, INSTALLSIZE_KEY, "", szBuf, sizeof(szBuf), _pCif->GetCifPath()))
  178. {
  179. *pdwApp = GetIntField(szBuf, 0, 0);
  180. *pdwWin = GetIntField(szBuf, 1, 0);
  181. }
  182. else
  183. {
  184. *pdwWin = 0;
  185. *pdwApp = 2 * GetDownloadSize();
  186. }
  187. return NOERROR;
  188. }
  189. STDMETHODIMP_(DWORD) CCifComponent::GetDownloadSize()
  190. {
  191. char szBuf[MAX_VALUE_LEN];
  192. szBuf[0] = '\0';
  193. // Read in size
  194. GetPrivateProfileString(_szID, SIZE_KEY, "0,0", szBuf, sizeof(szBuf), _pCif->GetCifPath());
  195. return(GetIntField(szBuf, 0, 0));
  196. }
  197. STDMETHODIMP_(DWORD) CCifComponent::GetExtractSize()
  198. {
  199. char szBuf[MAX_VALUE_LEN];
  200. DWORD dwSize;
  201. szBuf[0] = '\0';
  202. // Read in size
  203. GetPrivateProfileString(_szID, SIZE_KEY, "0,0", szBuf, sizeof(szBuf), _pCif->GetCifPath());
  204. dwSize = GetIntField(szBuf, 1, 2 * GetIntField(szBuf, 0, 0));
  205. return dwSize;
  206. }
  207. STDMETHODIMP CCifComponent::GetSuccessKey(LPSTR pszKey, DWORD dwSize)
  208. {
  209. return(GetPrivateProfileString(_szID, SUCCESS_KEY, "", pszKey, dwSize, _pCif->GetCifPath()) ? NOERROR : E_FAIL);
  210. }
  211. STDMETHODIMP CCifComponent::GetProgressKeys(LPSTR pszProgress, DWORD dwProgSize, LPSTR pszCancel, DWORD dwCancelSize)
  212. {
  213. GetPrivateProfileString(_szID, PROGRESS_KEY, "", pszProgress, dwProgSize, _pCif->GetCifPath());
  214. GetPrivateProfileString(_szID, MUTEX_KEY, "", pszCancel, dwCancelSize, _pCif->GetCifPath());
  215. if(*pszProgress != 0 || *pszCancel != 0)
  216. return NOERROR;
  217. else
  218. return E_FAIL;
  219. }
  220. STDMETHODIMP CCifComponent::IsActiveSetupAware()
  221. {
  222. return(GetPrivateProfileInt(_szID, ACTSETUPAWARE_KEY, 0, _pCif->GetCifPath()) ? S_OK : S_FALSE);
  223. }
  224. STDMETHODIMP CCifComponent::IsRebootRequired()
  225. {
  226. return(GetPrivateProfileInt(_szID, REBOOT_KEY, 0, _pCif->GetCifPath()) ? S_OK : S_FALSE);
  227. }
  228. STDMETHODIMP CCifComponent::RequiresAdminRights()
  229. {
  230. return(GetPrivateProfileInt(_szID, ADMIN_KEY, 0, _pCif->GetCifPath()) ? S_OK : S_FALSE);
  231. }
  232. STDMETHODIMP_(DWORD) CCifComponent::GetPriority()
  233. {
  234. return(GetPrivateProfileInt(_szID, PRIORITY, 0, _pCif->GetCifPath()));
  235. }
  236. STDMETHODIMP CCifComponent::GetDependency(UINT uDepNum, LPSTR pszID, DWORD dwBuf, char *pchType, LPDWORD pdwVer, LPDWORD pdwBuild)
  237. {
  238. char szBuf[MAX_VALUE_LEN];
  239. char szBuf2[MAX_VALUE_LEN];
  240. HRESULT hr = E_FAIL;
  241. DWORD dwLen;
  242. LPSTR pszTemp;
  243. DWORD dwV, dwBld;
  244. dwV = dwBld = 0xffffffff;
  245. if(GetPrivateProfileString(_szID, DEPENDENCY_KEY, NO_ENTRY, szBuf2, sizeof(szBuf2), _pCif->GetCifPath()))
  246. {
  247. if(GetStringField(szBuf2, uDepNum, szBuf, sizeof(szBuf)))
  248. {
  249. // Do some funky parsing
  250. dwLen = lstrlen(szBuf);
  251. *pchType = DEP_INSTALL;
  252. pszTemp = FindChar(szBuf, ':');
  253. if(*pszTemp)
  254. {
  255. *pszTemp = 0;
  256. lstrcpyn(pszID, szBuf, dwBuf);
  257. pszTemp++;
  258. *pchType = *pszTemp;
  259. // see if we have a version
  260. pszTemp = FindChar(pszTemp, ':');
  261. if(*pszTemp)
  262. {
  263. pszTemp++;
  264. // wierdness - scan the string, convert . to , for parsing
  265. LPSTR pszTemp2 = pszTemp;
  266. while(*pszTemp2 != 0)
  267. {
  268. if(*pszTemp2 == '.')
  269. *pszTemp2 = ',';
  270. pszTemp2++;
  271. }
  272. ConvertVersionStrToDwords(pszTemp, &dwV, &dwBld);
  273. }
  274. }
  275. else
  276. lstrcpyn(pszID, szBuf, dwBuf);
  277. if(dwV == 0xffffffff && dwBld == 0xffffffff)
  278. {
  279. // get version of dependency from cif
  280. ICifComponent *pcomp;
  281. if(SUCCEEDED(_pCif->FindComponent(pszID, &pcomp)))
  282. pcomp->GetVersion(&dwV, &dwBld);
  283. }
  284. hr = NOERROR;
  285. }
  286. }
  287. if(pdwVer)
  288. *pdwVer = dwV;
  289. if(pdwBuild)
  290. *pdwBuild = dwBld;
  291. return hr;
  292. }
  293. LPSTR g_pszComp[] = { "Branding.cab",
  294. "desktop.cab",
  295. "custom0",
  296. "custom1",
  297. "custom2",
  298. "custom3",
  299. "custom4",
  300. "custom5",
  301. "custom6",
  302. "custom7",
  303. "custom8",
  304. "custom9",
  305. "CustIcmPro",
  306. NULL};
  307. STDMETHODIMP_(DWORD) CCifComponent::GetPlatform()
  308. {
  309. if(_dwPlatform == 0xffffffff)
  310. {
  311. char *rszPlatforms[7] = { STR_WIN95, STR_WIN98, STR_NT4, STR_NT5, STR_NT4ALPHA, STR_NT5ALPHA,STR_MILLEN };
  312. DWORD rdwPlatforms[] = { PLATFORM_WIN95, PLATFORM_WIN98, PLATFORM_NT4, PLATFORM_NT5,
  313. PLATFORM_NT4ALPHA, PLATFORM_NT5ALPHA, PLATFORM_MILLEN };
  314. char szBuf[MAX_VALUE_LEN];
  315. char szPlatBuf[MAX_VALUE_LEN];
  316. BOOL bFound = FALSE;
  317. int i = 0;
  318. while (!bFound && g_pszComp[i])
  319. {
  320. bFound = (lstrcmpi(g_pszComp[i], _szID) == 0);
  321. i++;
  322. }
  323. _dwPlatform = 0;
  324. if(!bFound && GetPrivateProfileString(_szID, PLATFORM_KEY, NO_ENTRY, szBuf, sizeof(szBuf), _pCif->GetCifPath()))
  325. {
  326. int j = 0;
  327. while(GetStringField(szBuf, j++, szPlatBuf, sizeof(szPlatBuf)))
  328. {
  329. for(int i = 0; i < 7; i++)
  330. {
  331. if(lstrcmpi(szPlatBuf, rszPlatforms[i]) == 0)
  332. {
  333. // check if we should add this platform for this component.
  334. if ((GetCurrentPlatform() != rdwPlatforms[i]) ||
  335. !DisableComponent())
  336. _dwPlatform |= rdwPlatforms[i];
  337. }
  338. }
  339. }
  340. }
  341. else
  342. _dwPlatform = PLATFORM_WIN95 | PLATFORM_WIN98 | PLATFORM_NT4 | PLATFORM_NT5 | PLATFORM_NT4ALPHA | PLATFORM_NT5ALPHA | PLATFORM_MILLEN;
  343. }
  344. return _dwPlatform;
  345. }
  346. STDMETHODIMP_(BOOL) CCifComponent::DisableComponent()
  347. {
  348. BOOL bDisableComp = FALSE;
  349. BOOL bGuidMatch = FALSE;
  350. HKEY hKey;
  351. DWORD dwIndex = 0;
  352. CHAR szGUIDComp[MAX_VALUE_LEN];
  353. CHAR szGUID[MAX_VALUE_LEN];
  354. DWORD dwGUIDSize = sizeof(szGUID);
  355. CHAR szData[MAX_VALUE_LEN];
  356. DWORD dwDataSize = sizeof(szData);
  357. LPSTR pTmp;
  358. DWORD dwVersion , dwBuild;
  359. DWORD dwInstallVer, dwInstallBuild;
  360. if(RegOpenKeyExA(HKEY_LOCAL_MACHINE, COMPONENTBLOCK_KEY, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  361. {
  362. while (!bDisableComp &&
  363. (RegEnumValue(hKey, dwIndex, szGUID, &dwGUIDSize, NULL, NULL,
  364. (LPBYTE)szData, &dwDataSize) == ERROR_SUCCESS) )
  365. {
  366. GetGUID(szGUIDComp, sizeof(szGUIDComp));
  367. pTmp = ANSIStrChr( szGUID, '*' );
  368. if (pTmp)
  369. {
  370. // If there is a * assume it is at the end
  371. *pTmp = '\0';
  372. szGUIDComp[lstrlen(szGUID)] = '\0';
  373. }
  374. bGuidMatch = (lstrcmpi(szGUID, szGUIDComp) == 0);
  375. // Did the Guids match?
  376. if (bGuidMatch)
  377. {
  378. // now see if we have version info.
  379. if (dwDataSize == 0)
  380. bDisableComp = TRUE;
  381. else
  382. {
  383. // Convert the versin number for the registry
  384. ConvertVersionStrToDwords(szData, &dwVersion, &dwBuild);
  385. if (dwVersion == 0)
  386. bDisableComp = TRUE;
  387. else
  388. {
  389. // Get the versin we would install.
  390. GetVersion(&dwInstallVer, &dwInstallBuild);
  391. // If the version we would install is equal or less, disable the component.
  392. if ((dwInstallVer < dwVersion) ||
  393. ((dwInstallVer == dwVersion) && (dwInstallBuild <= dwBuild)) )
  394. bDisableComp = TRUE;
  395. }
  396. }
  397. }
  398. dwGUIDSize = sizeof(szGUID);
  399. dwDataSize = sizeof(szData);
  400. dwIndex++;
  401. }
  402. RegCloseKey(hKey);
  403. }
  404. return bDisableComp;
  405. }
  406. STDMETHODIMP CCifComponent::GetMode(UINT uModeNum, LPSTR pszMode, DWORD dwSize)
  407. {
  408. char szBuf[MAX_VALUE_LEN];
  409. if(FAILED(MyTranslateString(_pCif->GetCifPath(), _szID, MODES_KEY, szBuf, sizeof(szBuf))))
  410. return E_FAIL;
  411. return(GetStringField(szBuf, uModeNum, pszMode, dwSize) ? NOERROR : E_FAIL);
  412. }
  413. STDMETHODIMP CCifComponent::GetGroup(LPSTR pszID, DWORD dwSize)
  414. {
  415. return(GetPrivateProfileString(_szID, GROUP_KEY, "", pszID, dwSize, _pCif->GetCifPath()) ? NOERROR : E_FAIL);
  416. }
  417. STDMETHODIMP CCifComponent::IsUIVisible()
  418. {
  419. return(GetPrivateProfileInt(_szID, UIVISIBLE_KEY, 1, _pCif->GetCifPath()) ? S_OK : S_FALSE);
  420. }
  421. STDMETHODIMP CCifComponent::GetPatchID(LPSTR pszID, DWORD dwSize)
  422. {
  423. return(GetPrivateProfileString(_szID, PATCHID_KEY, "", pszID, dwSize, _pCif->GetCifPath()) ? NOERROR : E_FAIL);
  424. }
  425. STDMETHODIMP CCifComponent::GetTreatAsOneComponents(UINT uNum, LPSTR pszID, DWORD dwBuf)
  426. {
  427. char szBuf[MAX_VALUE_LEN];
  428. szBuf[0] = '\0';
  429. GetPrivateProfileString(_szID, TREATAS_KEY, "", szBuf, sizeof(szBuf), _pCif->GetCifPath());
  430. return(GetStringField(szBuf, uNum, pszID, dwBuf) ? NOERROR : E_FAIL);
  431. }
  432. STDMETHODIMP CCifComponent::GetCustomData(LPSTR pszKey, LPSTR pszData, DWORD dwSize)
  433. {
  434. char szNewKey[MAX_VALUE_LEN];
  435. wsprintf(szNewKey, "_%s", pszKey);
  436. return(MyTranslateString(_pCif->GetCifPath(), _szID, szNewKey, pszData, dwSize));
  437. }
  438. STDMETHODIMP_(DWORD) CCifComponent::IsComponentInstalled()
  439. {
  440. CHAR szCifBuf[512];
  441. CHAR szCompBuf[512];
  442. CHAR szGUID[MAX_VALUE_LEN];
  443. CHAR szLocale[8];
  444. HKEY hComponentKey = NULL;
  445. DETECTION_STRUCT Det;
  446. DWORD dwCifVer, dwCifBuild, dwInstalledVer, dwInstalledBuild;
  447. DWORD dwUnused, dwType, dwIsInstalled;
  448. BOOL bVersionFound = FALSE;
  449. if(_uInstallStatus != ICI_NOTINITIALIZED)
  450. return _uInstallStatus;
  451. _uInstallStatus = ICI_NOTINSTALLED;
  452. // use detection dll first if it is available
  453. if ( SUCCEEDED(GetDetVersion(szCifBuf, sizeof(szCifBuf), szCompBuf, sizeof(szCompBuf))))
  454. {
  455. GetVersion(&dwCifVer, &dwCifBuild);
  456. Det.dwSize = sizeof(DETECTION_STRUCT);
  457. Det.pdwInstalledVer = &dwInstalledVer;
  458. Det.pdwInstalledBuild = &dwInstalledBuild;
  459. GetLocale(szLocale, sizeof(szLocale));
  460. Det.pszLocale = szLocale;
  461. GetGUID(szGUID, sizeof(szGUID));
  462. Det.pszGUID = szGUID;
  463. Det.dwAskVer = dwCifVer;
  464. Det.dwAskBuild = dwCifBuild;
  465. Det.pCifFile = (ICifFile *) _pCif;
  466. Det.pCifComp = (ICifComponent *) this;
  467. if (SUCCEEDED(_GetDetVerResult(szCifBuf, szCompBuf, &Det, &_uInstallStatus)))
  468. {
  469. // only wizard want to know this status, if the newer version is installed, means Installed.
  470. if (_uInstallStatus == ICI_OLDVERSIONAVAILABLE)
  471. _uInstallStatus = ICI_INSTALLED;
  472. return _uInstallStatus;
  473. }
  474. }
  475. // Build GUID Key
  476. lstrcpy(szCompBuf, COMPONENT_KEY);
  477. lstrcat(szCompBuf, "\\");
  478. GetGUID(szCifBuf, sizeof(szCifBuf));
  479. lstrcat(szCompBuf, szCifBuf);
  480. if(RegOpenKeyExA(HKEY_LOCAL_MACHINE, szCompBuf, 0, KEY_READ, &hComponentKey) == ERROR_SUCCESS)
  481. {
  482. // first check for the IsInstalled valuename
  483. // if the valuename is there AND equals zero, we say not installed.
  484. // otherwise continue.
  485. // NOTE: We default to ISINSTALLED_YES if valuename not present to be Back-compatible
  486. // with when we didn't write this valuename at all.....
  487. dwUnused = sizeof(dwIsInstalled);
  488. if(RegQueryValueEx(hComponentKey, ISINSTALLED_KEY, 0, NULL, (LPBYTE) (&dwIsInstalled), &dwUnused) != ERROR_SUCCESS)
  489. dwIsInstalled = ISINSTALLED_YES;
  490. if(dwIsInstalled == ISINSTALLED_YES)
  491. {
  492. // next check for a locale match (no locale entry use default)
  493. dwUnused = sizeof(szCompBuf);
  494. if(RegQueryValueEx(hComponentKey, LOCALE_KEY, 0, NULL, (LPBYTE) szCompBuf, &dwUnused) != ERROR_SUCCESS)
  495. lstrcpy(szCompBuf, DEFAULT_LOCALE);
  496. GetLocale(szCifBuf, sizeof(szCifBuf));
  497. if(_fBeforeInstall || (CompareLocales(szCompBuf, szCifBuf) == 0))
  498. {
  499. // locales match so go check the version
  500. // first check for updated version key
  501. dwUnused = sizeof(szCompBuf);
  502. bVersionFound = (RegQueryValueEx(hComponentKey, QFE_VERSION_KEY,
  503. 0, &dwType, (LPBYTE) szCompBuf, &dwUnused) == ERROR_SUCCESS);
  504. // if QFEVersion doesn't exist, look for version
  505. if(!bVersionFound)
  506. {
  507. dwUnused = sizeof(szCompBuf);
  508. bVersionFound = (RegQueryValueEx(hComponentKey, VERSION_KEY,
  509. 0, &dwType, (LPBYTE) szCompBuf, &dwUnused) == ERROR_SUCCESS);
  510. }
  511. // figure out if we have REG_STR
  512. if(bVersionFound)
  513. {
  514. // if we have a string convert to ver, if we have binary directly copy into version struct
  515. if(dwType == REG_SZ)
  516. {
  517. ConvertVersionStrToDwords(szCompBuf, &dwInstalledVer, &dwInstalledBuild);
  518. GetVersion(&dwCifVer, &dwCifBuild);
  519. if( (dwInstalledVer > dwCifVer) ||
  520. ((dwInstalledVer == dwCifVer) && (dwInstalledBuild >= dwCifBuild)) )
  521. {
  522. _uInstallStatus = ICI_INSTALLED;
  523. }
  524. else
  525. {
  526. _uInstallStatus = ICI_NEWVERSIONAVAILABLE;
  527. }
  528. }
  529. else
  530. _uInstallStatus = ICI_NEWVERSIONAVAILABLE;
  531. }
  532. }
  533. }
  534. }
  535. if(hComponentKey)
  536. RegCloseKey(hComponentKey);
  537. // We think its installed, now check
  538. if(_uInstallStatus != ICI_NOTINSTALLED)
  539. {
  540. // if there is an uninstall key to check do it
  541. if(SUCCEEDED(GetUninstallKey(szCompBuf, sizeof(szCompBuf))))
  542. {
  543. if(!UninstallKeyExists(szCompBuf))
  544. {
  545. _uInstallStatus = ICI_NOTINSTALLED;
  546. }
  547. else
  548. {
  549. // if there is a success key to check do it
  550. if(SUCCEEDED(GetSuccessKey(szCompBuf, sizeof(szCompBuf))))
  551. {
  552. if(!SuccessCheck(szCompBuf))
  553. {
  554. _uInstallStatus = ICI_NOTINSTALLED;
  555. }
  556. }
  557. }
  558. }
  559. }
  560. return _uInstallStatus;
  561. }
  562. STDMETHODIMP CCifComponent::IsComponentDownloaded()
  563. {
  564. if(GetActualDownloadSize() == 0)
  565. return S_OK;
  566. else
  567. return S_FALSE;
  568. }
  569. STDMETHODIMP_(DWORD) CCifComponent::IsThisVersionInstalled(DWORD dwAskVer, DWORD dwAskBld, LPDWORD pdwVersion, LPDWORD pdwBuild)
  570. {
  571. CHAR szCifBuf[512];
  572. CHAR szCompBuf[512];
  573. CHAR szLocale[8];
  574. CHAR szGUID[MAX_VALUE_LEN];
  575. DETECTION_STRUCT Det;
  576. HKEY hComponentKey = NULL;
  577. UINT uStatus = ICI_NOTINSTALLED;
  578. *pdwVersion = 0;
  579. *pdwBuild = 0;
  580. // use detection dll first if it is available
  581. if ( SUCCEEDED(GetDetVersion(szCifBuf, sizeof(szCifBuf), szCompBuf, sizeof(szCompBuf))))
  582. {
  583. Det.dwSize = sizeof(DETECTION_STRUCT);
  584. Det.pdwInstalledVer = pdwVersion;
  585. Det.pdwInstalledBuild = pdwBuild;
  586. GetLocale(szLocale, sizeof(szLocale));
  587. Det.pszLocale = szLocale;
  588. GetGUID(szGUID, sizeof(szGUID));
  589. Det.pszGUID = szGUID;
  590. Det.dwAskVer = dwAskVer;
  591. Det.dwAskBuild = dwAskBld;
  592. Det.pCifFile = (ICifFile *) _pCif;
  593. Det.pCifComp = (ICifComponent *) this;
  594. if (SUCCEEDED(_GetDetVerResult(szCifBuf, szCompBuf, &Det, &uStatus)))
  595. {
  596. return uStatus;
  597. }
  598. }
  599. if(IsComponentInstalled() == ICI_NOTINSTALLED)
  600. return uStatus;
  601. DWORD dwUnused, dwType;
  602. BOOL bVersionFound = FALSE;
  603. // Build GUID Key
  604. lstrcpy(szCompBuf, COMPONENT_KEY);
  605. lstrcat(szCompBuf, "\\");
  606. GetGUID(szCifBuf, sizeof(szCifBuf));
  607. lstrcat(szCompBuf, szCifBuf);
  608. if(RegOpenKeyExA(HKEY_LOCAL_MACHINE, szCompBuf, 0, KEY_READ, &hComponentKey) == ERROR_SUCCESS)
  609. {
  610. // first check for updated version key
  611. dwUnused = sizeof(szCompBuf);
  612. bVersionFound = (RegQueryValueEx(hComponentKey, QFE_VERSION_KEY,
  613. 0, &dwType, (LPBYTE) szCompBuf, &dwUnused) == ERROR_SUCCESS);
  614. // if QFEVersion doesn't exist, look for version
  615. if(!bVersionFound)
  616. {
  617. dwUnused = sizeof(szCompBuf);
  618. bVersionFound = (RegQueryValueEx(hComponentKey, VERSION_KEY,
  619. 0, &dwType, (LPBYTE) szCompBuf, &dwUnused) == ERROR_SUCCESS);
  620. }
  621. //figure out if we have REG_STR
  622. if(bVersionFound)
  623. {
  624. // if we have a string convert to ver, if we have binary directly copy into version struct
  625. if(dwType == REG_SZ)
  626. {
  627. ConvertVersionStrToDwords(szCompBuf, pdwVersion, pdwBuild);
  628. if((*pdwVersion == dwAskVer) && (*pdwBuild == dwAskBld) )
  629. {
  630. uStatus = ICI_INSTALLED;
  631. }
  632. else if ((*pdwVersion > dwAskVer) ||
  633. (*pdwVersion == dwAskVer) && (*pdwBuild > dwAskBld) )
  634. {
  635. uStatus = ICI_OLDVERSIONAVAILABLE;
  636. }
  637. else
  638. {
  639. uStatus = ICI_NEWVERSIONAVAILABLE;
  640. }
  641. }
  642. else
  643. uStatus = ICI_NEWVERSIONAVAILABLE;
  644. }
  645. RegCloseKey(hComponentKey);
  646. }
  647. return uStatus;
  648. }
  649. STDMETHODIMP_(DWORD) CCifComponent::GetInstallQueueState()
  650. {
  651. if(_uInstallCount)
  652. return SETACTION_INSTALL;
  653. else
  654. return SETACTION_NONE;
  655. }
  656. STDMETHODIMP CCifComponent::SetInstallQueueState(DWORD dwState)
  657. {
  658. HRESULT hr = NOERROR;
  659. DWORD uDependencyAction;
  660. char szCompBuf[MAX_ID_LENGTH];
  661. char chType;
  662. ICifComponent *pcomp;
  663. BOOL fProcessDependencies = TRUE;
  664. // check to see if we allow install on this platform
  665. if((dwState != SETACTION_NONE) && (dwState != SETACTION_DEPENDENCYNONE) &&
  666. !_pCif->GetInstallEngine()->AllowCrossPlatform())
  667. {
  668. if(!(GetPlatform() & GetCurrentPlatform()))
  669. return S_FALSE;
  670. }
  671. switch(dwState)
  672. {
  673. case SETACTION_INSTALL:
  674. // check if it was already on. If so, don't process dependencies
  675. if(_uInstallCount & 0x80000000)
  676. fProcessDependencies = FALSE;
  677. _uInstallCount |= 0x80000000;
  678. uDependencyAction = SETACTION_DEPENDENCYINSTALL;
  679. break;
  680. case SETACTION_DEPENDENCYINSTALL:
  681. _uInstallCount++;
  682. uDependencyAction = SETACTION_DEPENDENCYINSTALL;
  683. break;
  684. case SETACTION_NONE:
  685. // check if it was not on to begin with. If not, don't process dependencies
  686. if(!(_uInstallCount & 0x80000000))
  687. fProcessDependencies = FALSE;
  688. _uInstallCount &= 0x7fffffff;
  689. uDependencyAction = SETACTION_DEPENDENCYNONE;
  690. break;
  691. case SETACTION_DEPENDENCYNONE:
  692. // if our depdency refcount is greater than zero, decrement it.
  693. // this allows us to unconditionally call this when an item is "unqueued"
  694. if(_uInstallCount & 0x7fffffff) _uInstallCount--;
  695. uDependencyAction = SETACTION_DEPENDENCYNONE;
  696. break;
  697. default:
  698. hr = E_INVALIDARG;
  699. break;
  700. }
  701. // now set each dependency, if needed
  702. if(SUCCEEDED(hr) && fProcessDependencies)
  703. {
  704. if(!_fDependenciesQueued)
  705. {
  706. _fDependenciesQueued = TRUE;
  707. DWORD dwNeedVer, dwNeedBuild, dwInsVer, dwInsBuild;
  708. for(int i = 0; SUCCEEDED(GetDependency(i, szCompBuf, sizeof(szCompBuf), &chType, &dwNeedVer, &dwNeedBuild)); i++)
  709. {
  710. if(chType == DEP_INSTALL || chType == DEP_BUDDY)
  711. {
  712. if(SUCCEEDED(_pCif->FindComponent(szCompBuf, &pcomp)))
  713. {
  714. // queue for install if
  715. // 1. Not installed
  716. // 2. Not a good enough version
  717. // 3. FORCEDEPENDIECIES is set
  718. UINT uStatus = pcomp->IsThisVersionInstalled(dwNeedVer, dwNeedBuild, &dwInsVer, &dwInsBuild);
  719. if( (uStatus == ICI_NOTINSTALLED) ||
  720. (uStatus == ICI_NEWVERSIONAVAILABLE) ||
  721. (_pCif->GetInstallEngine()->ForceDependencies()) )
  722. pcomp->SetInstallQueueState(uDependencyAction);
  723. }
  724. }
  725. }
  726. _fDependenciesQueued = FALSE;
  727. }
  728. }
  729. return hr;
  730. }
  731. STDMETHODIMP_(DWORD) CCifComponent::GetActualDownloadSize()
  732. {
  733. char szCompBuf[MAX_PATH];
  734. LPSTR pszFilename = NULL;
  735. LPSTR pszPathEnd = NULL;
  736. DWORD dwUrlSize, dwFlags;
  737. DWORD dwTotalSize = 0;
  738. BOOL alldownloaded = TRUE;
  739. if (_fUseSRLite)
  740. {
  741. // Let the patching engine determine the correct value
  742. dwTotalSize = 0;
  743. }
  744. else
  745. {
  746. if(_CompareDownloadInfo())
  747. {
  748. // so our versions match correctly, check each file
  749. for(UINT i = 0; SUCCEEDED(GetUrl(i, szCompBuf, sizeof(szCompBuf), &dwFlags)); i++)
  750. {
  751. pszFilename = ParseURLA(szCompBuf);
  752. if(_FileIsDownloaded(pszFilename, i, &dwUrlSize))
  753. dwTotalSize += dwUrlSize;
  754. else
  755. alldownloaded = FALSE;
  756. }
  757. }
  758. else
  759. alldownloaded = FALSE;
  760. if(alldownloaded)
  761. dwTotalSize = 0;
  762. else
  763. dwTotalSize = GetDownloadSize() - (dwTotalSize >> 10);
  764. }
  765. return dwTotalSize;
  766. }
  767. HRESULT CCifComponent::OnProgress(ULONG uProgSoFar, LPCSTR pszStatus)
  768. {
  769. _uIndivProgress = uProgSoFar;
  770. if(_uTotalProgress + _uIndivProgress > _uTotalGoal)
  771. _uIndivProgress = _uTotalGoal - _uTotalProgress;
  772. _pCif->GetInstallEngine()->OnComponentProgress(_szID, _uPhase, _szDesc,
  773. pszStatus, _uTotalProgress + _uIndivProgress, _uTotalGoal);
  774. return NOERROR;
  775. }
  776. STDMETHODIMP_(DWORD) CCifComponent::GetCurrentPriority()
  777. {
  778. if(_uPriority == 0xffffffff)
  779. {
  780. char szID[MAX_ID_LENGTH];
  781. ICifGroup *pgrp;
  782. _uPriority = 0;
  783. GetGroup(szID, sizeof(szID));
  784. if(SUCCEEDED(_pCif->FindGroup(szID, &pgrp)))
  785. {
  786. _uPriority = pgrp->GetCurrentPriority();
  787. }
  788. _uPriority += GetPriority();
  789. }
  790. return _uPriority;
  791. }
  792. STDMETHODIMP CCifComponent::SetCurrentPriority(DWORD dwPriority)
  793. {
  794. _uPriority = dwPriority;
  795. // priorities may have changed need to resort
  796. _pCif->ReinsertComponent(this);
  797. return NOERROR;
  798. }
  799. HRESULT CCifComponent::Download()
  800. {
  801. char szBuf[INTERNET_MAX_URL_LENGTH];
  802. HRESULT hr = NOERROR;
  803. DWORD uType;
  804. GetDescription(_szDesc, sizeof(_szDesc));
  805. // BUGBUG: Download size isn't accurate for SR lite and patching
  806. _uTotalGoal = GetActualDownloadSize();
  807. // Engage SR lite behavior only if we're going to install the component,
  808. // and the new advpack extension is available.
  809. DWORD dwOptions = 0;
  810. BOOL fRetryClassic = TRUE;
  811. CHAR szCompBuf[MAX_VALUE_LEN];
  812. CHAR szDir[MAX_PATH];
  813. LPSTR pszSubDir = NULL;
  814. CHAR szCanPatch[MAX_VALUE_LEN];
  815. lstrcpyn(szDir, _pCif->GetDownloadDir(), sizeof(szDir));
  816. SetDownloadDir(szDir);
  817. if (IsPatchableIEVersion() &&
  818. SUCCEEDED(_pCif->GetInstallEngine()->GetInstallOptions(&dwOptions)) &&
  819. (dwOptions & INSTALLOPTIONS_INSTALL) &&
  820. (dwOptions & INSTALLOPTIONS_DOWNLOAD) &&
  821. _pCif->GetInstallEngine()->IsAdvpackExtAvailable() &&
  822. _pCif->GetInstallEngine()->GetPatchDownloader()->IsEnabled() &&
  823. SUCCEEDED(GetCustomData(gszIsPatchable, szCanPatch, sizeof(szCanPatch))) &&
  824. lstrcmp(szCanPatch, "1") == 0)
  825. {
  826. _fUseSRLite = TRUE;
  827. // Adjust the download directory
  828. // The idea here is that the download directory will contain
  829. // subdirectories which will contain the empty cabs + inf +
  830. // the downloaded files.
  831. //
  832. GetID(szCompBuf, sizeof(szCompBuf));
  833. wsprintf(szLogBuf, "Attempting to download empty cabs for %s\r\n", szCompBuf);
  834. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  835. AddPath(szDir, szCompBuf);
  836. SetDownloadDir(szDir);
  837. if (GetFileAttributes(szDir) == 0xFFFFFFFF)
  838. CreateDirectory(szDir, NULL);
  839. }
  840. _pCif->GetInstallEngine()->OnStartComponent(_szID, _uTotalGoal, 0 , _szDesc);
  841. _MarkDownloadStarted();
  842. // check for disk space
  843. _uPhase = INSTALLSTATUS_INITIALIZING;
  844. _pCif->GetInstallEngine()->OnComponentProgress(_szID, _uPhase, _szDesc, NULL, 0, 0);
  845. if(!IsEnoughSpace(GetDownloadDir(), _uTotalGoal))
  846. hr = E_FAIL;
  847. _uTotalProgress = 0;
  848. for(int i = 0; SUCCEEDED(hr) && SUCCEEDED(GetUrl(i, szBuf, sizeof(szBuf), &uType)); i++)
  849. {
  850. // Change the download loc to point to the special
  851. // "empty cab" location, so we can download the empty
  852. // cabs + the INF that will contain instructions for
  853. // generating the file list for this type of installation.
  854. //
  855. // Assume the new download loc to be in the "patch" subdirectory
  856. // relative to the passed in URL
  857. //
  858. // BUGBUG... only handle the case for relative URLs
  859. if (_fUseSRLite && (uType & URLF_RELATIVEURL) && lstrlen(c_gszSRLiteOffset) + lstrlen(szBuf) < INTERNET_MAX_URL_LENGTH)
  860. {
  861. char szBuf2[INTERNET_MAX_URL_LENGTH];
  862. lstrcpy(szBuf2, c_gszSRLiteOffset);
  863. lstrcat(szBuf2, szBuf);
  864. hr = _DownloadUrl(i, szBuf2, uType);
  865. wsprintf(szLogBuf, "Empty cab download of %s returned 0x%lx\r\n", szBuf2, hr);
  866. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  867. }
  868. else
  869. {
  870. wsprintf(szLogBuf, "Initial download attempt will be tried as a full download.\r\n");
  871. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  872. // No need to retry because the first attempt will be the old way...
  873. fRetryClassic = FALSE;
  874. // Restore the download dir to the same state as a normal
  875. // full download.
  876. if (_fUseSRLite)
  877. {
  878. SetDownloadDir(_pCif->GetDownloadDir());
  879. // Ensure we're set to false...just in case there was a problem
  880. // with obtaining the URL for the SR Lite download.
  881. _fUseSRLite = FALSE;
  882. }
  883. hr = _DownloadUrl(i, szBuf, uType);
  884. }
  885. }
  886. if (_fUseSRLite && SUCCEEDED(hr))
  887. {
  888. // Ok...time for the real action of using advpext.dll to
  889. // download the needed files.
  890. hr = _SRLiteDownloadFiles();
  891. }
  892. if (_fUseSRLite && !SUCCEEDED(hr))
  893. {
  894. DelNode(szDir, 0);
  895. // Restore the download dir
  896. SetDownloadDir(_pCif->GetDownloadDir());
  897. }
  898. if(SUCCEEDED(hr))
  899. _uPhase = INSTALLSTATUS_DOWNLOADFINISHED;
  900. else if (_fUseSRLite && fRetryClassic)
  901. {
  902. // Fall back to downloading the full cabs.
  903. _fUseSRLite = FALSE;
  904. _pCif->GetInstallEngine()->WriteToLog("Retrying via full download\r\n", FALSE);
  905. hr = S_OK;
  906. // this re-sets the progress for the retry
  907. _uPhase = INSTALLSTATUS_DOWNLOADING;
  908. _pCif->GetInstallEngine()->OnComponentProgress(_szID, _uPhase, _szDesc, NULL, 0, 0);
  909. _uTotalProgress = 0;
  910. for(int i = 0; SUCCEEDED(hr) && SUCCEEDED(GetUrl(i, szBuf, sizeof(szBuf), &uType)); i++)
  911. {
  912. hr = _DownloadUrl(i, szBuf, uType);
  913. }
  914. if(SUCCEEDED(hr))
  915. _uPhase = INSTALLSTATUS_DOWNLOADFINISHED;
  916. }
  917. _pCif->GetInstallEngine()->OnStopComponent(_szID, hr, _uPhase, _szDesc, 0);
  918. return hr;
  919. }
  920. HRESULT CCifComponent::_DownloadUrl(UINT uUrlNum, LPCSTR pszUrl, UINT uType)
  921. {
  922. // call the downloader
  923. // check the file
  924. // if good
  925. // move to download dir
  926. // else
  927. // redo
  928. HRESULT hr;
  929. char szTempfile[MAX_PATH];
  930. char szFullUrl[INTERNET_MAX_URL_LENGTH];
  931. UINT uStartProgress;
  932. char szDest[MAX_PATH];
  933. char szTimeStamp[MAX_PATH*2];
  934. _uPhase = INSTALLSTATUS_DOWNLOADING;
  935. if(_FileIsDownloaded(ParseURLA(pszUrl), uUrlNum, NULL))
  936. return NOERROR;
  937. CDownloader *pDL = _pCif->GetInstallEngine()->GetDownloader();
  938. uStartProgress = _uTotalProgress;
  939. // retry until success
  940. // save starting progress in case we retry
  941. hr = E_FAIL;
  942. for(int i = 1; i <= NUM_RETRIES && FAILED(hr) && (hr != E_ABORT); i++)
  943. {
  944. _uTotalProgress = uStartProgress;
  945. if(uType & URLF_RELATIVEURL)
  946. {
  947. lstrcpyn(szFullUrl, _pCif->GetInstallEngine()->GetBaseUrl(),
  948. INTERNET_MAX_URL_LENGTH - (lstrlen(pszUrl) + 2));
  949. lstrcat(szFullUrl, "/");
  950. lstrcat(szFullUrl, pszUrl);
  951. }
  952. else
  953. lstrcpy(szFullUrl, pszUrl);
  954. if(SUCCEEDED(_pCif->GetInstallEngine()->CheckForContinue()))
  955. {
  956. DWORD dwFlags = 0;
  957. if(_pCif->GetInstallEngine()->UseCache())
  958. dwFlags |= DOWNLOADFLAGS_USEWRITECACHE;
  959. hr = pDL->SetupDownload(szFullUrl, (IMyDownloadCallback *) this, dwFlags, NULL);
  960. szTempfile[0] = 0;
  961. if(SUCCEEDED(hr))
  962. {
  963. // Log the start time.
  964. wsprintf(szLogBuf, " Downloading : %s\r\n", szFullUrl);
  965. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  966. GetTimeDateStamp(szTimeStamp);
  967. wsprintf(szLogBuf, " Start : %s\r\n", szTimeStamp);
  968. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  969. hr = pDL->DoDownload(szTempfile, sizeof(szTempfile));
  970. // Log the stop time.
  971. GetTimeDateStamp(szTimeStamp);
  972. wsprintf(szLogBuf, " Stop : %s\r\n", szTimeStamp);
  973. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  974. wsprintf(szLogBuf, " Result: %x (%s)\r\n", hr, SUCCEEDED(hr) ? STR_OK : STR_FAILED);
  975. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  976. }
  977. }
  978. else
  979. hr = E_ABORT;
  980. if(SUCCEEDED(hr))
  981. {
  982. // Check if it is save to download from this URL
  983. _uPhase = INSTALLSTATUS_CHECKINGTRUST;
  984. hr = _pCif->GetInstallEngine()->CheckForContinue();
  985. if(SUCCEEDED(hr))
  986. hr = _CheckForTrust(szFullUrl, szTempfile);
  987. if(SUCCEEDED(hr) && (hr == S_FALSE) )
  988. {
  989. DWORD dwMin, dwMax;
  990. DWORD dwFileSize = 0;
  991. dwFileSize = MyGetFileSize(szTempfile);
  992. dwFileSize = dwFileSize >> 10;
  993. /*
  994. // Open the file
  995. HANDLE h = CreateFile(szTempfile, GENERIC_READ, 0, NULL,
  996. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  997. if(h != INVALID_HANDLE_VALUE)
  998. {
  999. dwFileSize = GetFileSize(h, NULL);
  1000. CloseHandle(h);
  1001. }
  1002. */
  1003. GetUrlCheckRange(uUrlNum, &dwMin, &dwMax);
  1004. if(dwMin != 0)
  1005. {
  1006. if(dwMin > dwFileSize || dwMax < dwFileSize)
  1007. hr = E_FAIL;
  1008. else
  1009. hr = S_OK;
  1010. }
  1011. }
  1012. if(SUCCEEDED(hr))
  1013. hr = _pCif->GetInstallEngine()->CheckForContinue();
  1014. // so now we downloaded and checked
  1015. // if it is OK, move to download dir
  1016. if(SUCCEEDED(hr))
  1017. {
  1018. lstrcpy(szDest, GetDownloadDir());
  1019. AddPath(szDest, ParseURLA(pszUrl));
  1020. if(!CopyFile(szTempfile, szDest, FALSE))
  1021. {
  1022. wsprintf(szLogBuf, "CopyFile FAILED, szTempfile=%s, szDest=%s\r\n", szTempfile, szDest);
  1023. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  1024. hr = E_FAIL;
  1025. }
  1026. _uTotalProgress += _uIndivProgress;
  1027. }
  1028. // delete the temp download copy
  1029. if(szTempfile[0] != 0)
  1030. {
  1031. GetParentDir(szTempfile);
  1032. DelNode(szTempfile, 0);
  1033. }
  1034. }
  1035. if(FAILED(hr) && (hr != E_ABORT))
  1036. {
  1037. // we failed
  1038. // if this is last retry, call EngineProblem
  1039. // else just retry
  1040. if(i == NUM_RETRIES)
  1041. {
  1042. HRESULT hEngProb;
  1043. DWORD dwResult = 0;
  1044. hEngProb = _pCif->GetInstallEngine()->OnEngineProblem(ENGINEPROBLEM_DOWNLOADFAIL, &dwResult);
  1045. if(hEngProb == S_OK)
  1046. {
  1047. if(dwResult == DOWNLOADFAIL_RETRY)
  1048. i = 0;
  1049. }
  1050. }
  1051. }
  1052. }
  1053. if(SUCCEEDED(hr))
  1054. _MarkFileDownloadFinished(szDest, uUrlNum, ParseURLA(pszUrl));
  1055. return hr;
  1056. }
  1057. HRESULT CCifComponent::Install()
  1058. {
  1059. CHAR szCompBuf[MAX_PATH];
  1060. HKEY hKey;
  1061. DWORD dwWin, dwApp;
  1062. HRESULT hr = NOERROR;
  1063. DWORD dwStatus = 0;
  1064. GetTimeDateStamp(szCompBuf);
  1065. wsprintf(szLogBuf, " Start : %s\r\n", szCompBuf);
  1066. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  1067. szCompBuf[0] = 0;
  1068. _uInstallStatus = ICI_NOTINITIALIZED;
  1069. GetDescription(_szDesc, sizeof(_szDesc));
  1070. GetInstalledSize(&dwWin, &dwApp);
  1071. _uTotalGoal = dwWin + dwApp;
  1072. _pCif->GetInstallEngine()->OnStartComponent(_szID, 0, _uTotalGoal, _szDesc);
  1073. _uPhase = INSTALLSTATUS_DEPENDENCY;
  1074. hr = _CheckForDependencies();
  1075. // check for disk space here
  1076. if(SUCCEEDED(hr))
  1077. {
  1078. _uPhase = INSTALLSTATUS_INITIALIZING;
  1079. _pCif->GetInstallEngine()->OnComponentProgress(_szID, _uPhase, _szDesc, NULL, 0, 0);
  1080. hr = CreateTempDir(GetDownloadSize(), GetExtractSize(), _pCif->GetInstallEngine()->GetInstallDrive(),
  1081. dwApp, dwWin, szCompBuf, sizeof(szCompBuf), 0);
  1082. }
  1083. if(SUCCEEDED(hr))
  1084. {
  1085. if( IsNT() && (RequiresAdminRights() == S_OK) && !IsNTAdmin(0,NULL))
  1086. {
  1087. hr = E_ACCESSDENIED;
  1088. _pCif->GetInstallEngine()->WriteToLog("Admin Check failed\n", TRUE);
  1089. }
  1090. }
  1091. _uTotalProgress = 0;
  1092. // BUGBUG: ie6wzd sets the download directory for non web-based
  1093. // installs at a later time. Make sure it's set here
  1094. // if we weren't successful with installing via SR Lite.
  1095. if (lstrlen(GetDownloadDir()) == 0)
  1096. {
  1097. SetDownloadDir(_pCif->GetDownloadDir());
  1098. }
  1099. if(SUCCEEDED(hr))
  1100. {
  1101. hr = _CopyAllUrls(szCompBuf);
  1102. if(SUCCEEDED(hr))
  1103. {
  1104. // The new PerUser method requires to leave the IsInstalled flag & StubPath as it was
  1105. //_MarkComponentInstallStarted();
  1106. _pCif->GetInstallEngine()->GetInstaller()->StartClock();
  1107. hr = _RunAllCommands(szCompBuf, &dwStatus);
  1108. }
  1109. }
  1110. if(szCompBuf[0] != 0)
  1111. DelNode(szCompBuf, 0);
  1112. if(SUCCEEDED(hr))
  1113. {
  1114. _fBeforeInstall = FALSE;
  1115. // we think it made it, now double check
  1116. if(IsActiveSetupAware() == S_OK)
  1117. {
  1118. if(IsComponentInstalled() != ICI_INSTALLED)
  1119. {
  1120. // we think they made it but they didn't write their key ...
  1121. _pCif->GetInstallEngine()->WriteToLog("Component did not write to InstalledComponent branch\r\n", TRUE);
  1122. hr = E_FAIL;
  1123. }
  1124. }
  1125. else
  1126. {
  1127. char szCompBuf[MAX_VALUE_LEN];
  1128. // if there is an uninstall key to check do it
  1129. if(SUCCEEDED(GetUninstallKey(szCompBuf, sizeof(szCompBuf))))
  1130. {
  1131. if(!UninstallKeyExists(szCompBuf))
  1132. {
  1133. _pCif->GetInstallEngine()->WriteToLog("UninstallKey check failed\r\n", TRUE);
  1134. hr = E_FAIL;
  1135. }
  1136. else
  1137. {
  1138. // if there is a success key to check do it
  1139. if(SUCCEEDED(GetSuccessKey(szCompBuf, sizeof(szCompBuf))))
  1140. {
  1141. if(!SuccessCheck(szCompBuf))
  1142. {
  1143. _pCif->GetInstallEngine()->WriteToLog("Success key check failed\r\n", TRUE);
  1144. hr = E_FAIL;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. }
  1150. }
  1151. _pCif->RemoveFromCriticalComponents(this);
  1152. if(SUCCEEDED(hr))
  1153. {
  1154. _MarkAsInstalled();
  1155. _pCif->MarkCriticalComponents(this);
  1156. _uPhase = INSTALLSTATUS_FINISHED;
  1157. _pCif->GetInstallEngine()->GetInstaller()->SetBytes((dwWin + dwApp) << 10, TRUE);
  1158. if(IsRebootRequired() == S_OK)
  1159. {
  1160. dwStatus |= STOPINSTALL_REBOOTNEEDED;
  1161. }
  1162. _pCif->GetInstallEngine()->SetStatus(dwStatus);
  1163. }
  1164. _pCif->GetInstallEngine()->GetInstaller()->StopClock();
  1165. _pCif->GetInstallEngine()->OnStopComponent(_szID, hr, _uPhase, _szDesc, dwStatus);
  1166. GetTimeDateStamp(szCompBuf);
  1167. wsprintf(szLogBuf, " Stop : %s\r\n", szCompBuf);
  1168. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  1169. return hr;
  1170. }
  1171. HRESULT CCifComponent::_RunAllCommands(LPCSTR pszDir, DWORD *pdwStatus)
  1172. {
  1173. char szCmd[MAX_PATH];
  1174. char szArg[MAX_VALUE_LEN];
  1175. char szProg[MAX_VALUE_LEN];
  1176. char szCancel[MAX_VALUE_LEN];
  1177. char szPath[] = "X:\\";
  1178. DWORD dwWinSpace, dwInstallSpace;
  1179. DWORD dwType;
  1180. HRESULT hr = NOERROR;
  1181. // Save the widows space and install drive space
  1182. szPath[0] = g_szWindowsDir[0];
  1183. dwWinSpace = GetSpace(szPath);
  1184. if(szPath[0] != _pCif->GetInstallEngine()->GetInstallDrive())
  1185. {
  1186. szPath[0] = _pCif->GetInstallEngine()->GetInstallDrive();
  1187. dwInstallSpace = GetSpace(szPath);
  1188. }
  1189. else
  1190. {
  1191. dwInstallSpace = 0;
  1192. }
  1193. _uTotalProgress = 0;
  1194. _uPhase = INSTALLSTATUS_RUNNING;
  1195. _pCif->GetInstallEngine()->OnComponentProgress(_szID, INSTALLSTATUS_RUNNING,
  1196. _szDesc, NULL, _uTotalProgress, _uTotalGoal);
  1197. hr = _pCif->GetInstallEngine()->CheckForContinue();
  1198. for(UINT i = 0; SUCCEEDED(hr) && SUCCEEDED(GetCommand(i, szCmd, sizeof(szCmd), szArg, sizeof(szArg), &dwType)); i++)
  1199. {
  1200. _uIndivProgress = 0;
  1201. GetProgressKeys(szProg, sizeof(szProg), szCancel, sizeof(szCancel));
  1202. hr = _pCif->GetInstallEngine()->GetInstaller()->DoInstall(pszDir, szCmd, szArg,
  1203. lstrlen(szProg) ? szProg : NULL, lstrlen(szCancel) ? szCancel : NULL,
  1204. dwType, pdwStatus, (IMyDownloadCallback *) this) ;
  1205. _uTotalProgress += _uIndivProgress;
  1206. }
  1207. _pCif->GetInstallEngine()->OnComponentProgress(_szID, _uPhase, _szDesc, NULL, _uTotalGoal,_uTotalGoal);
  1208. // figure how much we used, and log it
  1209. szPath[0] = g_szWindowsDir[0];
  1210. dwWinSpace = dwWinSpace - GetSpace(szPath);
  1211. if(szPath[0] != _pCif->GetInstallEngine()->GetInstallDrive())
  1212. {
  1213. szPath[0] = _pCif->GetInstallEngine()->GetInstallDrive();
  1214. dwInstallSpace = dwInstallSpace - GetSpace(szPath);
  1215. }
  1216. // log the space used
  1217. wsprintf(szCmd, "SpaceUsed: Windows drive: %d InstallDrive: %d\r\n", dwWinSpace, dwInstallSpace);
  1218. _pCif->GetInstallEngine()->WriteToLog(szCmd, FALSE);
  1219. return hr;
  1220. }
  1221. HRESULT CCifComponent::_CopyAllUrls(LPCSTR pszTemp)
  1222. {
  1223. char szCompBuf[MAX_VALUE_LEN];
  1224. char szDest[MAX_PATH];
  1225. char szSource[MAX_PATH];
  1226. DWORD dwType;
  1227. HRESULT hr = NOERROR;
  1228. HANDLE hFind;
  1229. WIN32_FIND_DATA ffd;
  1230. char szBuf[MAX_PATH];
  1231. for(UINT i = 0; SUCCEEDED(hr) && SUCCEEDED(GetUrl(i, szCompBuf, sizeof(szCompBuf), &dwType)) ; i++)
  1232. {
  1233. _uPhase = INSTALLSTATUS_COPYING;
  1234. _pCif->GetInstallEngine()->OnComponentProgress(_szID, _uPhase, _szDesc, NULL, 0, 0);
  1235. lstrcpy(szSource, GetDownloadDir());
  1236. AddPath(szSource, ParseURLA(szCompBuf));
  1237. lstrcpy(szDest, pszTemp);
  1238. AddPath(szDest, ParseURLA(szCompBuf));
  1239. // Copy the file
  1240. if(!CopyFile(szSource, szDest, FALSE))
  1241. {
  1242. wsprintf(szLogBuf, "CopyFile failed for szSource=%s, szDest=%s, DLDir=%s\r\n", szSource, szDest, GetDownloadDir());
  1243. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  1244. hr = E_FILESMISSING;
  1245. }
  1246. if(SUCCEEDED(hr))
  1247. hr = _pCif->GetInstallEngine()->CheckForContinue();
  1248. if(SUCCEEDED(hr))
  1249. {
  1250. _uPhase = INSTALLSTATUS_CHECKINGTRUST;
  1251. hr = _CheckForTrust(szSource, szDest);
  1252. if (hr == S_FALSE && !_pCif->GetInstallEngine()->IgnoreTrustCheck())
  1253. hr = TRUST_E_FAIL;
  1254. if(FAILED(hr))
  1255. {
  1256. DeleteFile(szSource);
  1257. }
  1258. }
  1259. if(SUCCEEDED(hr))
  1260. hr = _pCif->GetInstallEngine()->CheckForContinue();
  1261. if(SUCCEEDED(hr))
  1262. hr = _ExtractFiles(i, szDest, dwType);
  1263. if(SUCCEEDED(hr))
  1264. hr = _pCif->GetInstallEngine()->CheckForContinue();
  1265. }
  1266. // Now, if we're attempting an SR Lite install, then after
  1267. // extracting cab files to the temp directory...copy all of
  1268. // downloaded files to the temp directory.
  1269. if (_fUseSRLite)
  1270. {
  1271. lstrcpy(szSource, GetDownloadDir());
  1272. AddPath(szSource, "*.*");
  1273. if ( (hFind = FindFirstFile(szSource, &ffd)) != INVALID_HANDLE_VALUE)
  1274. {
  1275. do
  1276. {
  1277. if (ffd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
  1278. {
  1279. lstrcpyn(szSource, GetDownloadDir(), sizeof(szSource));
  1280. SafeAddPath(szSource, ffd.cFileName, sizeof(szSource) - lstrlen(szSource));
  1281. lstrcpy(szDest, pszTemp);
  1282. AddPath(szDest, ffd.cFileName);
  1283. MoveFile(szSource, szDest);
  1284. }
  1285. } while (SUCCEEDED(hr) && FindNextFile(hFind, &ffd));
  1286. FindClose(hFind);
  1287. }
  1288. }
  1289. return hr;
  1290. }
  1291. STDMETHODIMP CCifComponent::GetDetVersion(LPSTR pszDll, DWORD dwdllSize, LPSTR pszEntry, DWORD dwentSize)
  1292. {
  1293. char szBuf[MAX_VALUE_LEN];
  1294. HRESULT hr = E_FAIL;
  1295. if(pszDll && pszEntry)
  1296. *pszDll = *pszEntry = 0;
  1297. else
  1298. return hr;
  1299. if(GetPrivateProfileString(_szID, DETVERSION_KEY, "", szBuf, sizeof(szBuf), _pCif->GetCifPath()))
  1300. {
  1301. if((GetStringField(szBuf, 0, pszDll, dwdllSize) != 0) && (GetStringField(szBuf, 1, pszEntry, dwentSize) != 0))
  1302. {
  1303. hr = NOERROR;
  1304. }
  1305. }
  1306. return hr;
  1307. }
  1308. HRESULT CCifComponent::_GetDetVerResult(LPCSTR pszDll, LPCSTR pszEntry, DETECTION_STRUCT *pDet, UINT *puStatus)
  1309. {
  1310. char szBuf[MAX_PATH];
  1311. HRESULT hr = E_FAIL;
  1312. HINSTANCE hLib;
  1313. DETECTVERSION fpDetVer;
  1314. *puStatus = ICI_NOTINSTALLED;
  1315. if (pszDll && pszEntry)
  1316. {
  1317. if(_hDetLib && (lstrcmpi(pszDll, _szDetDllName) == 0))
  1318. {
  1319. hLib = _hDetLib;
  1320. }
  1321. else
  1322. {
  1323. lstrcpy(szBuf, _pCif->GetCifPath());
  1324. GetParentDir(szBuf);
  1325. AddPath(szBuf, pszDll);
  1326. hLib = LoadLibrary(szBuf);
  1327. if (hLib == NULL)
  1328. {
  1329. // if Cif folder failed try IE folder before using searching path
  1330. if (SUCCEEDED(GetIEPath(szBuf, sizeof(szBuf))))
  1331. {
  1332. AddPath(szBuf, pszDll);
  1333. hLib = LoadLibrary(szBuf);
  1334. }
  1335. }
  1336. if(hLib)
  1337. {
  1338. lstrcpy(_szDetDllName, pszDll);
  1339. _hDetLib = hLib;
  1340. }
  1341. }
  1342. if (hLib)
  1343. {
  1344. fpDetVer = (DETECTVERSION)GetProcAddress(hLib, pszEntry);
  1345. if (fpDetVer)
  1346. {
  1347. switch(fpDetVer(pDet))
  1348. {
  1349. case DET_NOTINSTALLED:
  1350. *puStatus = ICI_NOTINSTALLED;
  1351. break;
  1352. case DET_INSTALLED:
  1353. *puStatus = ICI_INSTALLED;
  1354. break;
  1355. case DET_NEWVERSIONINSTALLED:
  1356. *puStatus = ICI_OLDVERSIONAVAILABLE;
  1357. break;
  1358. case DET_OLDVERSIONINSTALLED:
  1359. *puStatus = ICI_NEWVERSIONAVAILABLE;
  1360. break;
  1361. }
  1362. hr = NOERROR;
  1363. }
  1364. }
  1365. }
  1366. return hr;
  1367. }
  1368. //=--------------------------------------------------------------------------=
  1369. // Function name here
  1370. //=--------------------------------------------------------------------------=
  1371. // Function description
  1372. //
  1373. // Parameters:
  1374. //
  1375. // Returns:
  1376. //
  1377. // Notes:
  1378. //
  1379. HRESULT CCifComponent::_CheckForTrust(LPCSTR pszURL, LPCSTR pszFilename)
  1380. {
  1381. HRESULT hr = S_FALSE;
  1382. // BUGBUG: Our internal workaround for non signed stuff
  1383. // if(rdwUrlFlags[i] & URLF_NOCHECKTRUST)
  1384. // return S_OK;
  1385. _uPhase = INSTALLSTATUS_CHECKINGTRUST;
  1386. _pCif->GetInstallEngine()->OnComponentProgress(_szID, _uPhase, _szDesc, NULL, 0, 0);
  1387. if(!_pCif->GetInstallEngine()->IgnoreTrustCheck())
  1388. hr = ::CheckTrustEx(pszURL, pszFilename, _pCif->GetInstallEngine()->GetHWND(), FALSE, NULL);
  1389. wsprintf(szLogBuf, " CheckTrust: %s, Result: %x (%s)\r\n", pszFilename, hr, SUCCEEDED(hr) ? STR_OK : STR_FAILED);
  1390. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, TRUE);
  1391. return hr;
  1392. }
  1393. //=--------------------------------------------------------------------------=
  1394. // Function name here
  1395. //=--------------------------------------------------------------------------=
  1396. // Function description
  1397. //
  1398. // Parameters:
  1399. //
  1400. // Returns:
  1401. //
  1402. // Notes:
  1403. //
  1404. HRESULT CCifComponent::_ExtractFiles(UINT i, LPCSTR pszFile, DWORD dwType)
  1405. {
  1406. HRESULT hr = NOERROR;
  1407. char szPath[MAX_PATH];
  1408. char szExtractList[MAX_VALUE_LEN];
  1409. // Need to pay attention to rdwUrlFlags[i] to see if there is anything to do
  1410. if(dwType & URLF_EXTRACT)
  1411. {
  1412. _uPhase = INSTALLSTATUS_EXTRACTING;
  1413. _pCif->GetInstallEngine()->OnComponentProgress(_szID, _uPhase, _szDesc, NULL, 0, 0);
  1414. lstrcpy(szPath, pszFile);
  1415. GetParentDir(szPath);
  1416. GetFileExtractList(i, szExtractList, sizeof(szExtractList));
  1417. hr=ExtractFiles(pszFile, szPath, 0, lstrlen(szExtractList) ? szExtractList : NULL, NULL, 0);
  1418. wsprintf(szLogBuf, "File extraction: %s, Result: %x (%s)\r\n", pszFile, hr, SUCCEEDED(hr) ? STR_OK : STR_FAILED);
  1419. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, TRUE);
  1420. // if the flag is set to delte the cab after an extract, do it
  1421. // I don't really care too much if this fails, at least not
  1422. // enough to fail this component
  1423. if(dwType & URLF_DELETE_AFTER_EXTRACT)
  1424. DeleteFile(pszFile);
  1425. }
  1426. return hr;
  1427. }
  1428. void CCifComponent::_MarkComponentInstallStarted()
  1429. {
  1430. char szReg[MAX_PATH];
  1431. char szCompBuf[MAX_DISPLAYNAME_LENGTH];
  1432. HKEY hKey;
  1433. DWORD dwDumb;
  1434. lstrcpy(szReg, COMPONENT_KEY);
  1435. lstrcat(szReg, "\\");
  1436. GetGUID(szCompBuf, sizeof(szCompBuf));
  1437. lstrcat(szReg, szCompBuf);
  1438. if(RegOpenKeyEx( HKEY_LOCAL_MACHINE, szReg, 0,
  1439. KEY_READ | KEY_WRITE, &hKey) == ERROR_SUCCESS)
  1440. {
  1441. // Set IsInstalled=0
  1442. dwDumb = ISINSTALLED_NO;
  1443. RegSetValueExA(hKey, ISINSTALLED_KEY, 0, REG_DWORD,
  1444. (BYTE *) &dwDumb , sizeof(dwDumb));
  1445. // Delete StubPath so peruser isn't confused
  1446. RegDeleteValue(hKey, STUBPATH_KEY);
  1447. RegCloseKey(hKey);
  1448. }
  1449. }
  1450. BOOL CCifComponent::_CompareDownloadInfo()
  1451. {
  1452. char szCompBuf[MAX_VALUE_LEN];
  1453. char szInfoBuf[128];
  1454. DWORD dwCompVer, dwCompBuild, dwDLVer, dwDLBuild;
  1455. // first check this is the same language
  1456. GetPrivateProfileString(_szID, LOCALE_KEY, "", szInfoBuf, sizeof(szInfoBuf), _pCif->GetFilelist());
  1457. GetLocale(szCompBuf, sizeof(szCompBuf));
  1458. if(CompareLocales(szInfoBuf, szCompBuf) == 0)
  1459. {
  1460. // compare guids
  1461. GetPrivateProfileString(_szID, GUID_KEY, "", szInfoBuf, sizeof(szInfoBuf), _pCif->GetFilelist());
  1462. GetGUID(szCompBuf, sizeof(szCompBuf));
  1463. // intentionally let blank guid match to be backward compatible
  1464. if(lstrcmpi(szCompBuf, szInfoBuf) == 0)
  1465. {
  1466. GetPrivateProfileString(_szID, VERSION_KEY,"",szInfoBuf,
  1467. sizeof(szInfoBuf), _pCif->GetFilelist());
  1468. ConvertVersionStrToDwords(szInfoBuf, &dwDLVer, &dwDLBuild);
  1469. GetVersion(&dwCompVer, &dwCompBuild);
  1470. if((dwDLVer == dwCompVer) && (dwDLBuild == dwCompBuild))
  1471. return TRUE;
  1472. }
  1473. }
  1474. return FALSE;
  1475. }
  1476. BOOL CCifComponent::_FileIsDownloaded(LPCSTR pszFile, UINT i, DWORD *pdwSize)
  1477. {
  1478. HANDLE h;
  1479. DWORD dwSize, dwFileSize;
  1480. char szKey[16];
  1481. char szBuf[MAX_PATH];
  1482. szBuf[0] = '\0';
  1483. if(pdwSize)
  1484. *pdwSize = 0;
  1485. wsprintf(szKey, "URL%d", i);
  1486. GetPrivateProfileString(_szID, szKey,"0",szBuf,
  1487. sizeof(szBuf), _pCif->GetFilelist());
  1488. dwSize = GetIntField(szBuf, 0, 0);
  1489. if(dwSize == 0)
  1490. return FALSE;
  1491. if (_fUseSRLite && lstrlen(GetDownloadDir()) != 0)
  1492. lstrcpy(szBuf, GetDownloadDir());
  1493. else
  1494. lstrcpy(szBuf, _pCif->GetDownloadDir());
  1495. AddPath(szBuf, pszFile);
  1496. dwFileSize = MyGetFileSize(szBuf);
  1497. /*
  1498. // Open the file
  1499. h = CreateFile(pszFile, GENERIC_READ, 0, NULL,
  1500. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  1501. if(h == INVALID_HANDLE_VALUE)
  1502. return FALSE;
  1503. // dont worry about files over 4 gig
  1504. dwFileSize = GetFileSize(h, NULL);
  1505. CloseHandle(h);
  1506. */
  1507. if(dwFileSize == dwSize)
  1508. {
  1509. if(pdwSize)
  1510. *pdwSize = dwFileSize;
  1511. return TRUE;
  1512. }
  1513. return FALSE;
  1514. }
  1515. //=--------------------------------------------------------------------------=
  1516. // Function name here
  1517. //=--------------------------------------------------------------------------=
  1518. // Function description
  1519. //
  1520. // Parameters:
  1521. //
  1522. // Returns:
  1523. //
  1524. // Notes:
  1525. //
  1526. void CCifComponent::_MarkAsInstalled()
  1527. {
  1528. CHAR szCompBuf[MAX_VALUE_LEN];
  1529. HKEY hComponentKey = NULL;
  1530. HKEY hGUIDKey = NULL;
  1531. DWORD dwDumb, dwVer, dwBuild;
  1532. LPSTR psz;
  1533. if(RegCreateKeyExA(HKEY_LOCAL_MACHINE, COMPONENT_KEY, 0, 0, 0,
  1534. KEY_WRITE, NULL, &hComponentKey, &dwDumb) == ERROR_SUCCESS)
  1535. {
  1536. GetGUID(szCompBuf, sizeof(szCompBuf));
  1537. if(RegCreateKeyExA(hComponentKey, szCompBuf, 0, 0, 0, KEY_WRITE, NULL, &hGUIDKey, &dwDumb) == ERROR_SUCCESS)
  1538. {
  1539. // we only write to the key if this guy is NOT active setup aware
  1540. if(IsActiveSetupAware() == S_FALSE)
  1541. {
  1542. // write Display name to Default
  1543. GetDescription(szCompBuf, sizeof(szCompBuf));
  1544. RegSetValueExA(hGUIDKey, NULL, 0, REG_SZ, (BYTE *)szCompBuf , lstrlen(szCompBuf) + 1 );
  1545. // write component ID
  1546. GetID(szCompBuf, sizeof(szCompBuf));
  1547. RegSetValueExA(hGUIDKey, "ComponentID", 0, REG_SZ, (BYTE *)szCompBuf , lstrlen(szCompBuf) + 1 );
  1548. // write out version
  1549. GetVersion(&dwVer, &dwBuild);
  1550. wsprintf(szCompBuf, "%d,%d,%d,%d", HIWORD(dwVer),LOWORD(dwVer),HIWORD(dwBuild),LOWORD(dwBuild));
  1551. RegSetValueExA(hGUIDKey, VERSION_KEY, 0, REG_SZ, (BYTE *)szCompBuf , lstrlen(szCompBuf) + 1);
  1552. // write out locale
  1553. GetLocale(szCompBuf, sizeof(szCompBuf));
  1554. RegSetValueExA(hGUIDKey, LOCALE_KEY, 0, REG_SZ, (BYTE *)szCompBuf , lstrlen(szCompBuf) + 1);
  1555. // Write out "IsInstalled=1"
  1556. dwDumb = ISINSTALLED_YES;
  1557. RegSetValueExA(hGUIDKey, ISINSTALLED_KEY, 0, REG_DWORD, (BYTE *) &dwDumb , sizeof(dwDumb));
  1558. }
  1559. }
  1560. }
  1561. if(hComponentKey)
  1562. RegCloseKey(hComponentKey);
  1563. if(hGUIDKey)
  1564. RegCloseKey(hGUIDKey);
  1565. }
  1566. void CCifComponent::_MarkFileDownloadFinished(LPCSTR pszFilePath, UINT i, LPCSTR pszFilename)
  1567. {
  1568. char szSize[MAX_PATH];
  1569. char szKey[16];
  1570. DWORD dwFileSize;
  1571. HANDLE h;
  1572. // put any entry in filelist.dat
  1573. // [CompID]
  1574. // URLi=Filesize
  1575. dwFileSize = MyGetFileSize(pszFilePath);
  1576. /*
  1577. // Create the file
  1578. h = CreateFile(pszFilePath, GENERIC_READ, 0, NULL,
  1579. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  1580. if(h == INVALID_HANDLE_VALUE)
  1581. return;
  1582. // dont worry about files over 4 gig
  1583. dwFileSize = GetFileSize(h, NULL);
  1584. CloseHandle(h);
  1585. */
  1586. if(dwFileSize != 0xffffffff)
  1587. {
  1588. wsprintf(szKey, "URL%d", i);
  1589. wsprintf(szSize, "%d,%s", dwFileSize, pszFilename);
  1590. WritePrivateProfileString(_szID, szKey, szSize, _pCif->GetFilelist());
  1591. // need to flush the pszFileList file; otherwise, with Stacker installed,
  1592. // it GPFs when trying to open the file in another thread (bug #13041)
  1593. WritePrivateProfileString(NULL, NULL, NULL, _pCif->GetFilelist());
  1594. }
  1595. }
  1596. void CCifComponent::_MarkFileDownloadStarted(UINT i)
  1597. {
  1598. char szKey[10];
  1599. wsprintf(szKey, "URL%d", i);
  1600. WritePrivateProfileString(_szID, szKey, NULL, _pCif->GetFilelist());
  1601. // flush -- fixes the Stacker bug #13041
  1602. WritePrivateProfileString(NULL, NULL, NULL, _pCif->GetFilelist());
  1603. }
  1604. void CCifComponent::_MarkDownloadStarted()
  1605. {
  1606. char szCompBuf[MAX_VALUE_LEN];
  1607. DWORD dwVer, dwBuild;
  1608. // if the section doesn't match what we expect, we kill
  1609. // section so we will redownload everything
  1610. if(!_CompareDownloadInfo())
  1611. WritePrivateProfileSection(_szID, NULL, _pCif->GetFilelist());
  1612. // write the version
  1613. GetVersion(&dwVer, &dwBuild);
  1614. wsprintf(szCompBuf, "%d,%d,%d,%d", HIWORD(dwVer),LOWORD(dwVer),HIWORD(dwBuild),LOWORD(dwBuild));
  1615. WritePrivateProfileString(_szID, VERSION_KEY, szCompBuf, _pCif->GetFilelist());
  1616. // write locale
  1617. GetLocale(szCompBuf, sizeof(szCompBuf));
  1618. WritePrivateProfileString(_szID, LOCALE_KEY, szCompBuf, _pCif->GetFilelist());
  1619. // write the guid
  1620. GetGUID(szCompBuf, sizeof(szCompBuf));
  1621. WritePrivateProfileString(_szID, GUID_KEY, szCompBuf, _pCif->GetFilelist());
  1622. // flush -- fixes the Stacker bug #13041
  1623. WritePrivateProfileString(NULL, NULL, NULL, _pCif->GetFilelist());
  1624. }
  1625. HRESULT CCifComponent::_CheckForDependencies()
  1626. {
  1627. char szCompBuf[MAX_ID_LENGTH];
  1628. char chType;
  1629. ICifComponent *pcomp;
  1630. HRESULT hr = NOERROR;
  1631. DWORD dwNeedVer, dwNeedBuild, dwInsVer, dwInsBuild;
  1632. for(int i = 0; SUCCEEDED(GetDependency(i, szCompBuf, sizeof(szCompBuf), &chType, &dwNeedVer, &dwNeedBuild)); i++)
  1633. {
  1634. if(SUCCEEDED(_pCif->FindComponent(szCompBuf, &pcomp)))
  1635. {
  1636. if(chType != DEP_BUDDY)
  1637. {
  1638. UINT uStatus = pcomp->IsThisVersionInstalled(dwNeedVer, dwNeedBuild, &dwInsVer, &dwInsBuild);
  1639. if( (uStatus == ICI_NOTINSTALLED) || (uStatus == ICI_NEWVERSIONAVAILABLE) )
  1640. {
  1641. hr = E_FAIL;
  1642. break;
  1643. }
  1644. }
  1645. }
  1646. }
  1647. return hr;
  1648. }
  1649. HRESULT CCifComponent::_SRLiteDownloadFiles()
  1650. {
  1651. HANDLE hFile;
  1652. WIN32_FIND_DATA ffd = {0};
  1653. CHAR szFile[MAX_PATH];
  1654. LPSTR pszFile = NULL;
  1655. HRESULT hr = S_OK;
  1656. CHAR szCompBuf[INTERNET_MAX_URL_LENGTH];
  1657. DWORD dwType;
  1658. BOOL fRet;
  1659. UINT uPatchCount = 0;
  1660. _uPhase = INSTALLSTATUS_DOWNLOADING;
  1661. // Look for presence of [DownloadFileSection] in a single
  1662. // .inf file extracted from the cabs.
  1663. for(UINT i = 0; SUCCEEDED(hr) && SUCCEEDED(GetUrl(i, szCompBuf, sizeof(szCompBuf), &dwType)) ; i++)
  1664. {
  1665. TCHAR szShortPath[MAX_PATH] = "";
  1666. GetShortPathName(GetDownloadDir(), szShortPath, sizeof(szShortPath));
  1667. // If all goes well, we should just get a single INF file extracted
  1668. lstrcpyn(szFile, GetDownloadDir(), sizeof(szFile));
  1669. SafeAddPath(szFile, szCompBuf, sizeof(szCompBuf));
  1670. hr = ExtractFiles(szFile, szShortPath, 0, NULL, NULL, 0);
  1671. wsprintf(szLogBuf, "Extracting empty cabs for %s in %s returned 0x%lx\r\n", szCompBuf, szShortPath, hr);
  1672. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  1673. }
  1674. lstrcpyn(szFile, GetDownloadDir(), sizeof(szFile));
  1675. SafeAddPath(szFile, "*.inf", sizeof(szFile));
  1676. // Get the file count because we're going to hack the
  1677. // progress bar UI since we don't know the real download sizes
  1678. // for the patch INFs upfront.
  1679. hFile = FindFirstFile(szFile, &ffd);
  1680. if (hFile != INVALID_HANDLE_VALUE)
  1681. {
  1682. do
  1683. {
  1684. // Strip filename from path
  1685. lstrcpyn(szFile, GetDownloadDir(), sizeof(szFile));
  1686. SafeAddPath(szFile, ffd.cFileName, sizeof(szFile) - lstrlen(szFile));
  1687. if (IsPatchableINF(szFile))
  1688. {
  1689. uPatchCount++;
  1690. }
  1691. } while (FindNextFile(hFile, &ffd));
  1692. FindClose(hFile);
  1693. }
  1694. lstrcpyn(szFile, GetDownloadDir(), sizeof(szFile));
  1695. SafeAddPath(szFile, "*.inf", sizeof(szFile));
  1696. hFile = FindFirstFile(szFile, &ffd);
  1697. // No need to keep the grep pattern...
  1698. lstrcpyn(szFile, GetDownloadDir(), sizeof(szFile));
  1699. pszFile = szFile + lstrlen(szFile);
  1700. if (hFile != INVALID_HANDLE_VALUE)
  1701. {
  1702. do
  1703. {
  1704. // Strip filename from path
  1705. lstrcpyn(szFile, GetDownloadDir(), sizeof(szFile));
  1706. SafeAddPath(szFile, ffd.cFileName, sizeof(szFile) - lstrlen(szFile));
  1707. if (IsPatchableINF(szFile))
  1708. {
  1709. fRet = TRUE;
  1710. // Found an inf that supports SR Lite. Try downloading the patch files.
  1711. // Use our downloader wrapper for the advpack extension to do the
  1712. // downloading.
  1713. hr = _pCif->GetInstallEngine()->GetPatchDownloader()->SetupDownload(_uTotalGoal, uPatchCount, (IMyDownloadCallback *) this, GetDownloadDir());
  1714. hr = _pCif->GetInstallEngine()->GetPatchDownloader()->DoDownload(szFile);
  1715. }
  1716. else
  1717. {
  1718. wsprintf(szLogBuf, "%s INF found with no DownloadFileSection\r\n", szFile);
  1719. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  1720. }
  1721. _uTotalProgress += _uIndivProgress;
  1722. } while (SUCCEEDED(hr) && FindNextFile(hFile, &ffd));
  1723. FindClose(hFile);
  1724. }
  1725. if (!fRet || !SUCCEEDED(hr))
  1726. {
  1727. wsprintf(szLogBuf, "Either no INF was found with a DownloadFileSection or an error occured during processing\r\n");
  1728. _pCif->GetInstallEngine()->WriteToLog(szLogBuf, FALSE);
  1729. return E_FAIL;
  1730. }
  1731. return hr;
  1732. }
  1733. void CCifComponent::SetDownloadDir(LPCSTR pszDownloadDir)
  1734. {
  1735. if (pszDownloadDir)
  1736. lstrcpyn(_szDLDir, pszDownloadDir, MAX_PATH);
  1737. }
  1738. //========= ICifRWComponent implementation ================================================
  1739. //
  1740. CCifRWComponent::CCifRWComponent(LPCSTR pszID, CCifFile *pCif) : CCifComponent(pszID, pCif)
  1741. {
  1742. }
  1743. CCifRWComponent::~CCifRWComponent()
  1744. {
  1745. }
  1746. STDMETHODIMP CCifRWComponent::GetID(LPSTR pszID, DWORD dwSize)
  1747. {
  1748. return(CCifComponent::GetID(pszID, dwSize));
  1749. }
  1750. STDMETHODIMP CCifRWComponent::GetGUID(LPSTR pszGUID, DWORD dwSize)
  1751. {
  1752. return(CCifComponent::GetGUID(pszGUID, dwSize));
  1753. }
  1754. STDMETHODIMP CCifRWComponent::GetDescription(LPSTR pszDesc, DWORD dwSize)
  1755. {
  1756. return(CCifComponent::GetDescription(pszDesc, dwSize));
  1757. }
  1758. STDMETHODIMP CCifRWComponent::GetDetails(LPSTR pszDetails, DWORD dwSize)
  1759. {
  1760. return(CCifComponent::GetDetails(pszDetails, dwSize));
  1761. }
  1762. STDMETHODIMP CCifRWComponent::GetUrl(UINT uUrlNum, LPSTR pszUrl, DWORD dwSize, LPDWORD pdwUrlFlags)
  1763. {
  1764. return(CCifComponent::GetUrl(uUrlNum, pszUrl, dwSize, pdwUrlFlags));
  1765. }
  1766. STDMETHODIMP CCifRWComponent::GetFileExtractList(UINT uUrlNum, LPSTR pszExtract, DWORD dwSize)
  1767. {
  1768. return(CCifComponent::GetFileExtractList(uUrlNum, pszExtract, dwSize));
  1769. }
  1770. STDMETHODIMP CCifRWComponent::GetUrlCheckRange(UINT uUrlNum, LPDWORD pdwMin, LPDWORD pdwMax)
  1771. {
  1772. return(CCifComponent::GetUrlCheckRange(uUrlNum, pdwMin, pdwMax));
  1773. }
  1774. STDMETHODIMP CCifRWComponent::GetCommand(UINT uCmdNum, LPSTR pszCmd, DWORD dwCmdSize, LPSTR pszSwitches,
  1775. DWORD dwSwitchSize, LPDWORD pdwType)
  1776. {
  1777. return(CCifComponent::GetCommand(uCmdNum, pszCmd, dwCmdSize, pszSwitches, dwSwitchSize, pdwType));
  1778. }
  1779. STDMETHODIMP CCifRWComponent::GetVersion(LPDWORD pdwVersion, LPDWORD pdwBuild)
  1780. {
  1781. return(CCifComponent::GetVersion(pdwVersion, pdwBuild));
  1782. }
  1783. STDMETHODIMP CCifRWComponent::GetLocale(LPSTR pszLocale, DWORD dwSize)
  1784. {
  1785. return(CCifComponent::GetLocale(pszLocale, dwSize));
  1786. }
  1787. STDMETHODIMP CCifRWComponent::GetUninstallKey(LPSTR pszKey, DWORD dwSize)
  1788. {
  1789. return(CCifComponent::GetUninstallKey(pszKey, dwSize));
  1790. }
  1791. STDMETHODIMP CCifRWComponent::GetInstalledSize(LPDWORD pdwWin, LPDWORD pdwApp)
  1792. {
  1793. return(CCifComponent::GetInstalledSize(pdwWin, pdwApp));
  1794. }
  1795. STDMETHODIMP_(DWORD) CCifRWComponent::GetDownloadSize()
  1796. {
  1797. return(CCifComponent::GetDownloadSize());
  1798. }
  1799. STDMETHODIMP_(DWORD) CCifRWComponent::GetExtractSize()
  1800. {
  1801. return(CCifComponent::GetExtractSize());
  1802. }
  1803. STDMETHODIMP CCifRWComponent::GetSuccessKey(LPSTR pszKey, DWORD dwSize)
  1804. {
  1805. return(CCifComponent::GetSuccessKey(pszKey, dwSize));
  1806. }
  1807. STDMETHODIMP CCifRWComponent::GetProgressKeys(LPSTR pszProgress, DWORD dwProgSize,
  1808. LPSTR pszCancel, DWORD dwCancelSize)
  1809. {
  1810. return(CCifComponent::GetProgressKeys(pszProgress, dwProgSize, pszCancel, dwCancelSize));
  1811. }
  1812. STDMETHODIMP CCifRWComponent::IsActiveSetupAware()
  1813. {
  1814. return(CCifComponent::IsActiveSetupAware());
  1815. }
  1816. STDMETHODIMP CCifRWComponent::IsRebootRequired()
  1817. {
  1818. return(CCifComponent::IsActiveSetupAware());
  1819. }
  1820. STDMETHODIMP CCifRWComponent::RequiresAdminRights()
  1821. {
  1822. return(CCifComponent::RequiresAdminRights());
  1823. }
  1824. STDMETHODIMP_(DWORD) CCifRWComponent::GetPriority()
  1825. {
  1826. return(CCifComponent::GetPriority());
  1827. }
  1828. STDMETHODIMP CCifRWComponent::GetDependency(UINT uDepNum, LPSTR pszID, DWORD dwBuf, char *pchType, LPDWORD pdwVer, LPDWORD pdwBuild)
  1829. {
  1830. return(CCifComponent::GetDependency(uDepNum, pszID, dwBuf, pchType, pdwVer, pdwBuild));
  1831. }
  1832. STDMETHODIMP_(DWORD) CCifRWComponent::GetPlatform()
  1833. {
  1834. return(CCifComponent::GetPlatform());
  1835. }
  1836. STDMETHODIMP CCifRWComponent::GetMode(UINT uModeNum, LPSTR pszModes, DWORD dwSize)
  1837. {
  1838. return(CCifComponent::GetMode(uModeNum, pszModes, dwSize));
  1839. }
  1840. STDMETHODIMP CCifRWComponent::GetTreatAsOneComponents(UINT uNum, LPSTR pszID, DWORD dwBuf)
  1841. {
  1842. return(CCifComponent::GetTreatAsOneComponents(uNum, pszID, dwBuf));
  1843. }
  1844. STDMETHODIMP CCifRWComponent::GetCustomData(LPSTR pszKey, LPSTR pszData, DWORD dwSize)
  1845. {
  1846. return(CCifComponent::GetCustomData(pszKey, pszData, dwSize));
  1847. }
  1848. STDMETHODIMP CCifRWComponent::GetGroup(LPSTR pszID, DWORD dwSize)
  1849. {
  1850. return(CCifComponent::GetGroup(pszID, dwSize));
  1851. }
  1852. STDMETHODIMP CCifRWComponent::IsUIVisible()
  1853. {
  1854. return(CCifComponent::IsUIVisible());
  1855. }
  1856. STDMETHODIMP CCifRWComponent::GetPatchID(LPSTR pszID, DWORD dwSize)
  1857. {
  1858. return(CCifComponent::GetPatchID(pszID, dwSize));
  1859. }
  1860. STDMETHODIMP_(DWORD) CCifRWComponent::IsComponentInstalled()
  1861. {
  1862. return(CCifComponent::IsComponentInstalled());
  1863. }
  1864. STDMETHODIMP CCifRWComponent::IsComponentDownloaded()
  1865. {
  1866. return(CCifComponent::IsComponentDownloaded());
  1867. }
  1868. STDMETHODIMP_(DWORD) CCifRWComponent::IsThisVersionInstalled(DWORD dwAskVer, DWORD dwAskBld, LPDWORD pdwVersion, LPDWORD pdwBuild)
  1869. {
  1870. return(CCifComponent::IsThisVersionInstalled(dwAskVer, dwAskBld, pdwVersion, pdwBuild));
  1871. }
  1872. STDMETHODIMP_(DWORD) CCifRWComponent::GetInstallQueueState()
  1873. {
  1874. return(CCifComponent::GetInstallQueueState());
  1875. }
  1876. STDMETHODIMP CCifRWComponent::SetInstallQueueState(DWORD dwState)
  1877. {
  1878. return(CCifComponent::SetInstallQueueState(dwState));
  1879. }
  1880. STDMETHODIMP_(DWORD) CCifRWComponent::GetActualDownloadSize()
  1881. {
  1882. return(CCifComponent::GetActualDownloadSize());
  1883. }
  1884. STDMETHODIMP_(DWORD) CCifRWComponent::GetCurrentPriority()
  1885. {
  1886. return(CCifComponent::GetCurrentPriority());
  1887. }
  1888. STDMETHODIMP CCifRWComponent::SetCurrentPriority(DWORD dwPriority)
  1889. {
  1890. return(CCifComponent::SetCurrentPriority(dwPriority));
  1891. }
  1892. STDMETHODIMP CCifRWComponent:: GetDetVersion(LPSTR pszDLL, DWORD dwdllSize, LPSTR pszEntry, DWORD dwentSize)
  1893. {
  1894. return(CCifComponent::GetDetVersion(pszDLL, dwdllSize, pszEntry, dwentSize));
  1895. }
  1896. STDMETHODIMP CCifRWComponent::SetGUID(LPCSTR pszGUID)
  1897. {
  1898. return (WritePrivateProfileString(_szID, GUID_KEY, pszGUID, _pCif->GetCifPath())? NOERROR:E_FAIL);
  1899. }
  1900. STDMETHODIMP CCifRWComponent::SetDescription(LPCSTR pszDesc)
  1901. {
  1902. return (WriteTokenizeString(_pCif->GetCifPath(), _szID, DISPLAYNAME_KEY, pszDesc));
  1903. }
  1904. STDMETHODIMP CCifRWComponent::SetDetails(LPCSTR pszDesc)
  1905. {
  1906. return (WriteTokenizeString(_pCif->GetCifPath(), _szID, DETAILS_KEY, pszDesc));
  1907. }
  1908. STDMETHODIMP CCifRWComponent::SetVersion(LPCSTR pszVersion)
  1909. {
  1910. return (WritePrivateProfileString(_szID, VERSION_KEY, pszVersion, _pCif->GetCifPath())? NOERROR:E_FAIL);
  1911. }
  1912. STDMETHODIMP CCifRWComponent::SetUninstallKey(LPCSTR pszKey)
  1913. {
  1914. return (MyWritePrivateProfileString(_szID, UNINSTALLSTRING_KEY, pszKey, _pCif->GetCifPath())? NOERROR:E_FAIL);
  1915. }
  1916. STDMETHODIMP CCifRWComponent::SetInstalledSize(DWORD dwWin, DWORD dwApp)
  1917. {
  1918. char szBuf[50];
  1919. wsprintf(szBuf,"%d,%d", dwWin, dwApp);
  1920. return (WritePrivateProfileString(_szID, INSTALLSIZE_KEY, szBuf, _pCif->GetCifPath())? NOERROR:E_FAIL);
  1921. }
  1922. STDMETHODIMP CCifRWComponent::SetDownloadSize(DWORD dwSize)
  1923. {
  1924. char szBuf1[MAX_VALUE_LEN];
  1925. char szBuf2[MAX_VALUE_LEN];
  1926. DWORD dwExtractSize;
  1927. szBuf1[0] = '\0';
  1928. // Read in size
  1929. GetPrivateProfileString(_szID, SIZE_KEY, "0", szBuf1, sizeof(szBuf1), _pCif->GetCifPath());
  1930. dwExtractSize = GetIntField(szBuf1, 1, (DWORD)-1);
  1931. if (dwExtractSize == (DWORD)-1)
  1932. wsprintf(szBuf2,"%d", dwSize);
  1933. else
  1934. wsprintf(szBuf2,"%d,%d", dwSize, dwExtractSize);
  1935. return (WritePrivateProfileString(_szID, SIZE_KEY, szBuf2, _pCif->GetCifPath())? NOERROR:E_FAIL);
  1936. }
  1937. STDMETHODIMP CCifRWComponent::SetExtractSize(DWORD dwSize)
  1938. {
  1939. char szBuf1[MAX_VALUE_LEN];
  1940. char szBuf2[MAX_VALUE_LEN];
  1941. szBuf1[0] = '\0';
  1942. // Read in size
  1943. GetPrivateProfileString(_szID, SIZE_KEY, "0,0", szBuf1, sizeof(szBuf1), _pCif->GetCifPath());
  1944. wsprintf(szBuf2,"%d,%d", GetIntField(szBuf1, 0, 0), dwSize);
  1945. return (WritePrivateProfileString(_szID, SIZE_KEY, szBuf2, _pCif->GetCifPath())? NOERROR:E_FAIL);
  1946. }
  1947. STDMETHODIMP CCifRWComponent::DeleteDependency(LPCSTR pszID, char chType)
  1948. {
  1949. HRESULT hr;
  1950. if (pszID == NULL) //delete all from all modes
  1951. hr = WritePrivateProfileString(_szID, DEPENDENCY_KEY, NULL, _pCif->GetCifPath())?NOERROR:E_FAIL;
  1952. else
  1953. {
  1954. // delete only the given ones
  1955. char szBuf[MAX_VALUE_LEN];
  1956. char szBufIn[MAX_VALUE_LEN];
  1957. char szBufOut[MAX_VALUE_LEN];
  1958. char szOne[MAX_ID_LENGTH];
  1959. LPSTR pszTmp;
  1960. UINT i = 0;
  1961. szBufOut[0] =0;
  1962. wsprintf( szBuf, "%s:%c", pszID, chType);
  1963. if (GetPrivateProfileString(_szID, DEPENDENCY_KEY, "", szBufIn, sizeof(szBufIn), _pCif->GetCifPath()))
  1964. {
  1965. pszTmp = szBufOut;
  1966. while(GetStringField(szBufIn, i++, szOne, sizeof(szOne)))
  1967. {
  1968. if (lstrcmpi(szOne, szBuf))
  1969. {
  1970. if ( i != 1)
  1971. {
  1972. lstrcpy(pszTmp,",");
  1973. pszTmp++;
  1974. }
  1975. lstrcpy(pszTmp, szOne);
  1976. pszTmp = pszTmp + lstrlen(szOne);
  1977. }
  1978. }
  1979. hr = WritePrivateProfileString(_szID, DEPENDENCY_KEY, szBufOut, _pCif->GetCifPath())? NOERROR:E_FAIL;
  1980. }
  1981. }
  1982. return hr;
  1983. }
  1984. STDMETHODIMP CCifRWComponent::AddDependency(LPCSTR pszID, char chType)
  1985. {
  1986. char szBuf[MAX_VALUE_LEN];
  1987. char szBuf1[MAX_VALUE_LEN];
  1988. char szOne[MAX_ID_LENGTH];
  1989. LPSTR pszTmp;
  1990. UINT i = 0;
  1991. BOOL bFound = FALSE;
  1992. HRESULT hr = NOERROR;
  1993. if (pszID==NULL)
  1994. return hr;
  1995. if (chType == '\\')
  1996. wsprintf( szBuf1, "%s:N:6.0.0.0", pszID, chType);
  1997. else
  1998. wsprintf( szBuf1, "%s:%c", pszID, chType);
  1999. if (GetPrivateProfileString(_szID, DEPENDENCY_KEY, "", szBuf, sizeof(szBuf), _pCif->GetCifPath()))
  2000. {
  2001. while(GetStringField(szBuf, i++, szOne, sizeof(szOne)))
  2002. {
  2003. if (lstrcmpi(szOne, szBuf1) == 0)
  2004. {
  2005. // found it, no need to add
  2006. bFound = TRUE;
  2007. break;
  2008. }
  2009. }
  2010. if (!bFound)
  2011. {
  2012. LPSTR pszTmp = szBuf + lstrlen(szBuf);
  2013. lstrcpy(pszTmp, ",");
  2014. pszTmp++;
  2015. lstrcpy(pszTmp, szBuf1);
  2016. hr = WritePrivateProfileString(_szID, DEPENDENCY_KEY, szBuf, _pCif->GetCifPath())? NOERROR:E_FAIL;
  2017. }
  2018. }
  2019. else
  2020. hr = WritePrivateProfileString(_szID, DEPENDENCY_KEY, szBuf1, _pCif->GetCifPath())? NOERROR:E_FAIL;
  2021. return hr;
  2022. }
  2023. STDMETHODIMP CCifRWComponent::SetUIVisible(BOOL bFlag)
  2024. {
  2025. return (WritePrivateProfileString(_szID, UIVISIBLE_KEY, bFlag? "1" : "0", _pCif->GetCifPath())? NOERROR:E_FAIL);
  2026. }
  2027. STDMETHODIMP CCifRWComponent::SetGroup(LPCSTR pszID)
  2028. {
  2029. return (WritePrivateProfileString(_szID, GROUP_KEY, pszID, _pCif->GetCifPath())? NOERROR:E_FAIL);
  2030. }
  2031. STDMETHODIMP CCifRWComponent::SetPlatform(DWORD dwPlatform)
  2032. {
  2033. char szBuf[MAX_VALUE_LEN];
  2034. char *rszPlatforms[7] = { STR_WIN95, STR_WIN98, STR_NT4, STR_NT5, STR_NT4ALPHA, STR_NT5ALPHA, STR_MILLEN };
  2035. DWORD rdwPlatforms[] = { PLATFORM_WIN95, PLATFORM_WIN98, PLATFORM_NT4, PLATFORM_NT5,
  2036. PLATFORM_NT4ALPHA, PLATFORM_NT5ALPHA, PLATFORM_MILLEN };
  2037. _dwPlatform = dwPlatform;
  2038. szBuf[0] = 0;
  2039. for(int i = 0; i < 7; i++)
  2040. {
  2041. if(dwPlatform & rdwPlatforms[i])
  2042. {
  2043. lstrcat(szBuf, rszPlatforms[i]);
  2044. lstrcat(szBuf, ",");
  2045. }
  2046. }
  2047. return (WritePrivateProfileString(_szID, PLATFORM_KEY, szBuf, _pCif->GetCifPath())? NOERROR:E_FAIL);
  2048. }
  2049. STDMETHODIMP CCifRWComponent::SetPriority(DWORD dwPri)
  2050. {
  2051. char szBuf[MAX_SMALL_BUF];
  2052. wsprintf(szBuf, "%d", dwPri);
  2053. return (WritePrivateProfileString(_szID, PRIORITY, szBuf, _pCif->GetCifPath())? NOERROR:E_FAIL);
  2054. }
  2055. STDMETHODIMP CCifRWComponent::SetReboot(BOOL bReboot)
  2056. {
  2057. return (WritePrivateProfileString(_szID, REBOOT_KEY, bReboot? "1":"0", _pCif->GetCifPath())? NOERROR:E_FAIL);
  2058. }
  2059. STDMETHODIMP CCifRWComponent::SetCommand(UINT uCmdNum, LPCSTR pszCmd, LPCSTR pszSwitches, DWORD dwType)
  2060. {
  2061. char szKey[16];
  2062. char szType[10];
  2063. HRESULT hr = NOERROR;
  2064. uCmdNum++;
  2065. wsprintf(szKey, "%s%lu", CMD_KEY, uCmdNum);
  2066. if (!MyWritePrivateProfileString(_szID, szKey, pszCmd, _pCif->GetCifPath()))
  2067. hr = E_FAIL;
  2068. wsprintf(szKey, "%s%lu", ARGS_KEY, uCmdNum);
  2069. if(!MyWritePrivateProfileString(_szID, szKey, (pszCmd==NULL)?NULL:pszSwitches, _pCif->GetCifPath()))
  2070. hr = E_FAIL;
  2071. wsprintf(szKey, "%s%lu", TYPE_KEY, uCmdNum);
  2072. wsprintf(szType,"%d", dwType);
  2073. if(!WritePrivateProfileString(_szID, szKey, (pszCmd==NULL)? NULL:szType, _pCif->GetCifPath()))
  2074. hr = E_FAIL;
  2075. return hr;
  2076. }
  2077. STDMETHODIMP CCifRWComponent::SetUrl(UINT uUrlNum, LPCSTR pszUrl, DWORD dwUrlFlags)
  2078. {
  2079. char szKey[16];
  2080. char szBuf[MAX_VALUE_LEN];
  2081. HRESULT hr = NOERROR;
  2082. uUrlNum++;
  2083. wsprintf(szKey, "%s%lu", URL_KEY, uUrlNum);
  2084. wsprintf(szBuf, "\"%s\",%d", pszUrl, dwUrlFlags);
  2085. if (!WritePrivateProfileString(_szID, szKey, szBuf, _pCif->GetCifPath()))
  2086. hr = E_FAIL;
  2087. wsprintf(szKey, "%s%lu", SIZE_KEY, uUrlNum);
  2088. if(!WritePrivateProfileString(_szID, szKey, NULL, _pCif->GetCifPath()))
  2089. hr = E_FAIL;
  2090. return hr;
  2091. }
  2092. STDMETHODIMP CCifRWComponent::DeleteFromModes(LPCSTR pszMode)
  2093. {
  2094. HRESULT hr;
  2095. if (pszMode == NULL) //delete all from all modes
  2096. hr = WritePrivateProfileString(_szID, MODES_KEY, pszMode, _pCif->GetCifPath())?NOERROR:E_FAIL;
  2097. else
  2098. {
  2099. // delete only the given ones
  2100. char szBufIn[MAX_VALUE_LEN];
  2101. char szBufOut[MAX_VALUE_LEN];
  2102. char szOneMode[MAX_ID_LENGTH];
  2103. LPSTR pszTmp;
  2104. UINT i = 0;
  2105. szBufOut[0] =0;
  2106. if (SUCCEEDED(MyTranslateString(_pCif->GetCifPath(), _szID, MODES_KEY, szBufIn, sizeof(szBufIn))))
  2107. {
  2108. pszTmp = szBufOut;
  2109. while(GetStringField(szBufIn, i++, szOneMode, sizeof(szOneMode)))
  2110. {
  2111. if (lstrcmpi(szOneMode, pszMode))
  2112. {
  2113. if ( i != 1)
  2114. {
  2115. lstrcpy(pszTmp,",");
  2116. pszTmp++;
  2117. }
  2118. lstrcpy(pszTmp, szOneMode);
  2119. pszTmp = pszTmp + lstrlen(szOneMode);
  2120. }
  2121. }
  2122. hr = WriteTokenizeString(_pCif->GetCifPath(), _szID, MODES_KEY, szBufOut);
  2123. }
  2124. }
  2125. return hr;
  2126. }
  2127. STDMETHODIMP CCifRWComponent::AddToMode(LPCSTR pszMode)
  2128. {
  2129. char szBuf[MAX_VALUE_LEN];
  2130. char szOneMode[MAX_ID_LENGTH];
  2131. LPSTR pszTmp;
  2132. UINT i = 0;
  2133. BOOL bFound = FALSE;
  2134. HRESULT hr = NOERROR;
  2135. if (SUCCEEDED(MyTranslateString(_pCif->GetCifPath(), _szID, MODES_KEY, szBuf, sizeof(szBuf))))
  2136. {
  2137. while(GetStringField(szBuf, i++, szOneMode, sizeof(szOneMode)))
  2138. {
  2139. if (lstrcmpi(szOneMode, pszMode) == 0)
  2140. {
  2141. // found it, no need to add
  2142. bFound = TRUE;
  2143. break;
  2144. }
  2145. }
  2146. if (!bFound)
  2147. {
  2148. LPSTR pszTmp = szBuf + lstrlen(szBuf);
  2149. lstrcpy(pszTmp, ",");
  2150. pszTmp++;
  2151. lstrcpy(pszTmp, pszMode);
  2152. hr = WriteTokenizeString(_pCif->GetCifPath(), _szID, MODES_KEY, szBuf);
  2153. }
  2154. }
  2155. else
  2156. hr = WritePrivateProfileString(_szID, MODES_KEY, pszMode, _pCif->GetCifPath()) ? NOERROR : E_FAIL;
  2157. return hr;
  2158. }
  2159. STDMETHODIMP CCifRWComponent::SetModes(LPCSTR pszMode)
  2160. {
  2161. return (WriteTokenizeString(_pCif->GetCifPath(), _szID, MODES_KEY, pszMode)?NOERROR:E_FAIL);
  2162. }
  2163. STDMETHODIMP CCifRWComponent::CopyComponent(LPCSTR pszCifFile)
  2164. {
  2165. LPSTR pszSec;
  2166. DWORD dwSize;
  2167. HRESULT hr = NOERROR;
  2168. dwSize = MAX_VALUE_LEN*4*4;
  2169. pszSec = (LPSTR)LocalAlloc(LPTR, dwSize); //allocate 4K buffer to read section
  2170. while(pszSec && GetPrivateProfileSection(_szID, pszSec, dwSize, pszCifFile)==(dwSize-2))
  2171. {
  2172. LocalFree(pszSec);
  2173. dwSize = dwSize*2;
  2174. pszSec = (LPSTR)LocalAlloc(LPTR, dwSize);
  2175. }
  2176. if (pszSec)
  2177. {
  2178. // first clean the Old section if there
  2179. WritePrivateProfileString(_szID, NULL, NULL, _pCif->GetCifPath());
  2180. // write out the copied section
  2181. WritePrivateProfileSection(_szID, pszSec, _pCif->GetCifPath());
  2182. LocalFree(pszSec);
  2183. }
  2184. else
  2185. hr = E_OUTOFMEMORY;
  2186. // need to check to see if we need to get strings out of the Strings section
  2187. CopyCifString(_szID, DISPLAYNAME_KEY, pszCifFile, _pCif->GetCifPath());
  2188. CopyCifString(_szID, DETAILS_KEY, pszCifFile, _pCif->GetCifPath());
  2189. CopyCifString(_szID, MODES_KEY, pszCifFile, _pCif->GetCifPath());
  2190. CopyCifString(_szID, LOCALE_KEY, pszCifFile, _pCif->GetCifPath());
  2191. return hr;
  2192. }
  2193. STDMETHODIMP CCifRWComponent::AddToTreatAsOne(LPCSTR pszCompID)
  2194. {
  2195. char szBuf[MAX_VALUE_LEN];
  2196. char szOneID[MAX_ID_LENGTH];
  2197. LPSTR pszTmp;
  2198. UINT i = 0;
  2199. BOOL bFound = FALSE;
  2200. HRESULT hr = NOERROR;
  2201. if (SUCCEEDED(MyTranslateString(_pCif->GetCifPath(), _szID, TREATAS_KEY, szBuf, sizeof(szBuf))))
  2202. {
  2203. while(GetStringField(szBuf, i++, szOneID, sizeof(szOneID)))
  2204. {
  2205. if (lstrcmpi(szOneID, pszCompID) == 0)
  2206. {
  2207. // found it, no need to add
  2208. bFound = TRUE;
  2209. break;
  2210. }
  2211. }
  2212. if (!bFound)
  2213. {
  2214. LPSTR pszTmp = szBuf + lstrlen(szBuf);
  2215. lstrcpy(pszTmp, ",");
  2216. pszTmp++;
  2217. lstrcpy(pszTmp, pszCompID);
  2218. hr = WriteTokenizeString(_pCif->GetCifPath(), _szID, TREATAS_KEY, szBuf);
  2219. }
  2220. }
  2221. else
  2222. hr = WritePrivateProfileString(_szID, TREATAS_KEY, pszCompID, _pCif->GetCifPath()) ? NOERROR : E_FAIL;
  2223. return hr;
  2224. }