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.

369 lines
13 KiB

  1. #include "precomp.h"
  2. extern TCHAR g_szTitle[];
  3. extern TCHAR g_szBuildTemp[];
  4. extern TCHAR g_szBaseURL[];
  5. extern TCHAR g_szWizRoot[];
  6. extern HWND g_hWait;
  7. extern BOOL g_fLocalMode, g_fOCW;
  8. extern int s_iType;
  9. extern DWORD GetRootFree(LPCTSTR pcszPath);
  10. extern HRESULT DownloadCab(HWND hDlg, LPTSTR szUrl, LPTSTR szFilename,
  11. LPCTSTR pcszDisplayname, int sComponent, BOOL &fIgnore);
  12. void UpdateIni(LPCTSTR pcszCurrentIni, CCifComponent_t * pCifComponent_t)
  13. {
  14. TCHAR szNew[INTERNET_MAX_URL_LENGTH];
  15. if (SUCCEEDED(pCifComponent_t->GetCustomData(TEXT("Win32"), szNew, countof(szNew))))
  16. WritePrivateProfileString(TEXT("IEAK"), TEXT("Win32"), szNew, pcszCurrentIni);
  17. if (SUCCEEDED(pCifComponent_t->GetCustomData(TEXT("Ini"), szNew, countof(szNew))))
  18. WritePrivateProfileString(VERSION, IK_INI, szNew, pcszCurrentIni);
  19. }
  20. BOOL CheckIniVersion(LPTSTR pszId, LPCTSTR pcszCurrentIni, CCifComponent_t * pCifComponent_t)
  21. {
  22. TCHAR szCurrentVer[64];
  23. TCHAR szNewVer[64];
  24. BOOL fRet = TRUE;
  25. GetPrivateProfileString(VERSION, pszId, TEXT(""), szCurrentVer, countof(szCurrentVer), pcszCurrentIni);
  26. fRet = SUCCEEDED(pCifComponent_t->GetCustomData(pszId, szNewVer, countof(szNewVer)));
  27. return (fRet && (CheckVer(szCurrentVer, szNewVer) < 0));
  28. }
  29. DWORD DownloadUpdateThreadProc(LPVOID lpvUrl)
  30. {
  31. TCHAR szDest[MAX_PATH];
  32. TCHAR szMsg[MAX_PATH];
  33. LPTSTR pFile;
  34. DWORD dwRet = 0;
  35. GetTempPath(countof(szDest), szDest);
  36. pFile = StrRChr((LPTSTR)lpvUrl, NULL, TEXT('/'));
  37. if (pFile != NULL)
  38. pFile++;
  39. if (StrCmpI(StrRChr((LPTSTR)lpvUrl, NULL, TEXT('.')), TEXT(".EXE")) == 0)
  40. {
  41. BOOL fIgnore = FALSE;
  42. PathAppend(szDest, pFile);
  43. if (DownloadCab(g_hWait, (LPTSTR)lpvUrl, szDest, NULL, 0, fIgnore) != NOERROR)
  44. {
  45. LoadString(g_rvInfo.hInst, IDS_UPDATEERROR, szMsg, countof(szMsg));
  46. MessageBox(g_hWizard, szMsg, g_szTitle, MB_OK);
  47. return (DWORD)-1;
  48. }
  49. }
  50. else
  51. {
  52. BOOL fSuccess = TRUE;
  53. BOOL fIgnore = FALSE;
  54. PathCombine(szDest, g_szBuildTemp, pFile);
  55. if (DownloadCab(g_hWait, (LPTSTR)lpvUrl, szDest, NULL, 0, fIgnore) == NOERROR)
  56. {
  57. TCHAR szTempDir[MAX_PATH];
  58. PathCombine(szTempDir, g_szBuildTemp, TEXT("update"));
  59. PathCreatePath(szTempDir);
  60. if (ExtractFilesWrap(szDest, szTempDir, 0, NULL, NULL, 0) == ERROR_SUCCESS)
  61. {
  62. TCHAR szInf[MAX_PATH];
  63. PathCombine(szInf, szTempDir, TEXT("ieak6.inf"));
  64. dwRet = RunSetupCommandWrap(g_hWizard, szInf, NULL, szTempDir, NULL,
  65. NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
  66. PathRemovePath(szTempDir);
  67. DeleteFile(szDest);
  68. }
  69. else
  70. fSuccess = FALSE;
  71. }
  72. else
  73. fSuccess = FALSE;
  74. SendMessage(g_hWait, WM_CLOSE, 0, 0);
  75. if (!fSuccess)
  76. {
  77. LoadString(g_rvInfo.hInst, IDS_UPDATEERROR, szMsg, countof(szMsg));
  78. MessageBox(g_hWizard, szMsg, g_szTitle, MB_OK);
  79. return (DWORD)-1;
  80. }
  81. }
  82. return dwRet;
  83. }
  84. void UpdateIEAK(HWND hDlg)
  85. {
  86. TCHAR szCurrentIni[MAX_PATH];
  87. TCHAR szMsg[MAX_PATH];
  88. TCHAR szUpdateUrl[INTERNET_MAX_URL_LENGTH];
  89. TCHAR szCifLang[8];
  90. TCHAR szWizLang[8];
  91. ICifComponent * pCifComponent;
  92. CCifComponent_t * pCifComponent_t;
  93. DWORD dwTid;
  94. DWORD dwRet = ERROR_SUCCESS;
  95. BOOL fNo = FALSE;
  96. HWND hWait;
  97. if (!g_lpCifFileNew || !(SUCCEEDED(g_lpCifFileNew->FindComponent(TEXT("ieak6OPT"), &pCifComponent))))
  98. return;
  99. pCifComponent_t = new CCifComponent_t((ICifRWComponent *)pCifComponent);
  100. pCifComponent_t->GetCustomData(TEXT("Lang"), szCifLang, countof(szCifLang));
  101. StrCpy(szUpdateUrl, g_szBaseURL);
  102. if (*(CharPrev(szUpdateUrl, szUpdateUrl + StrLen(szUpdateUrl))) != TEXT('/'))
  103. StrCat(szUpdateUrl, TEXT("/"));
  104. PathCombine(szCurrentIni, g_szWizRoot, TEXT("ieak.ini"));
  105. GetPrivateProfileString(VERSION, TEXT("Lang"), TEXT(""), szWizLang, countof(szWizLang), szCurrentIni);
  106. // only allow self-update for same language as the current wizard
  107. if (StrCmpI(szCifLang, szWizLang) != 0)
  108. goto exit;
  109. if (CheckIniVersion(IK_FULL, szCurrentIni, pCifComponent_t))
  110. {
  111. pCifComponent_t->GetCustomData(TEXT("FullText"), szMsg, countof(szMsg));
  112. if (MessageBox(g_hWizard, szMsg, g_szTitle, MB_YESNO | MB_DEFBUTTON2) == IDYES)
  113. {
  114. HANDLE hThread;
  115. TCHAR szExeName[MAX_PATH];
  116. DWORD dwFlags;
  117. ICifComponent * pCifExeComponent;
  118. CCifComponent_t * pCifExeComponent_t;
  119. if (SUCCEEDED(g_lpCifFileNew->FindComponent(TEXT("ieak6EXE"), &pCifExeComponent)))
  120. {
  121. pCifExeComponent_t = new CCifComponent_t((ICifRWComponent *)pCifExeComponent);
  122. if (SUCCEEDED(pCifExeComponent_t->GetUrl(0, szExeName, countof(szExeName), &dwFlags)))
  123. {
  124. // do not allow self-update to continue if not enough size (size of Exe +
  125. // extract size approximated by twice the size of the exe)
  126. if (((dwFlags = pCifExeComponent_t->GetDownloadSize() * 3) > GetRootFree(g_szBuildTemp)) &&
  127. dwFlags)
  128. {
  129. TCHAR szMsg[MAX_PATH];
  130. TCHAR szMsgTemplate[MAX_PATH];
  131. LoadString(g_rvInfo.hInst, IDS_ERROR_UPDATESPACE, szMsgTemplate, countof(szMsgTemplate));
  132. wnsprintf(szMsg, countof(szMsg), szMsgTemplate, pCifExeComponent_t->GetDownloadSize() * 3);
  133. dwRet = (DWORD)-1;
  134. MessageBox(hDlg, szMsg, g_szTitle, MB_OK | MB_ICONEXCLAMATION);
  135. }
  136. else
  137. {
  138. StrCat(szUpdateUrl, szExeName);
  139. hWait = CreateDialog(g_rvInfo.hInst, MAKEINTRESOURCE(IDD_UPDATE), hDlg,
  140. DownloadStatusDlgProc);
  141. ShowWindow( hWait, SW_SHOWNORMAL );
  142. hThread = CreateThread(NULL, 4096, DownloadUpdateThreadProc, (LPVOID)szUpdateUrl, 0, &dwTid);
  143. while (MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT) != WAIT_OBJECT_0)
  144. {
  145. MSG msg;
  146. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  147. {
  148. TranslateMessage(&msg);
  149. DispatchMessage(&msg);
  150. }
  151. }
  152. GetExitCodeThread(hThread, &dwRet);
  153. CloseHandle(hThread);
  154. SendMessage(hWait, WM_CLOSE, 0, 0);
  155. }
  156. }
  157. else
  158. dwRet = (DWORD)-1;
  159. delete pCifExeComponent_t;
  160. }
  161. else
  162. dwRet = (DWORD)-1;
  163. if (dwRet == -1)
  164. {
  165. g_fLocalMode = TRUE;
  166. goto exit;
  167. }
  168. else
  169. {
  170. SHELLEXECUTEINFO shInfo;
  171. DWORD dwPID;
  172. TCHAR szTempBuf[MAX_PATH + 32];
  173. TCHAR szTempPath[MAX_PATH];
  174. PathCombine(szTempBuf, g_szWizRoot, TEXT("update.exe"));
  175. GetTempPath(countof(szTempPath), szTempPath);
  176. CopyFileToDir(szTempBuf, szTempPath);
  177. ZeroMemory(&shInfo, sizeof(shInfo));
  178. shInfo.cbSize = sizeof(shInfo);
  179. shInfo.hwnd = GetDesktopWindow();
  180. shInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  181. shInfo.lpVerb = TEXT("open");
  182. shInfo.lpFile = TEXT("update.exe");
  183. dwPID = GetCurrentProcessId();
  184. WCHAR wcType;
  185. switch (s_iType)
  186. {
  187. case BRANDED:
  188. wcType = TEXT('B');
  189. break;
  190. case REDIST:
  191. wcType = TEXT('R');
  192. break;
  193. case INTRANET:
  194. default:
  195. wcType = TEXT('I');
  196. break;
  197. }
  198. if (g_fOCW)
  199. wnsprintf(szTempBuf, countof(szTempBuf), TEXT("/o /p:%lu /m:%c"), dwPID,wcType);
  200. else
  201. wnsprintf(szTempBuf, countof(szTempBuf), TEXT("/p:%lu /m:%c"), dwPID,wcType);
  202. shInfo.lpParameters = szTempBuf;
  203. shInfo.lpDirectory = szTempPath;
  204. shInfo.nShow = SW_SHOWNORMAL;
  205. ShellExecuteEx(&shInfo);
  206. CloseHandle(shInfo.hProcess);
  207. DoCancel();
  208. goto exit;
  209. }
  210. }
  211. else
  212. fNo = TRUE;
  213. }
  214. if (!fNo && (CheckIniVersion(IK_CAB, szCurrentIni, pCifComponent_t)))
  215. {
  216. pCifComponent_t->GetCustomData(TEXT("CabText"), szMsg, countof(szMsg));
  217. if (MessageBox(g_hWizard, szMsg, g_szTitle, MB_YESNO | MB_DEFBUTTON2) == IDYES)
  218. {
  219. TCHAR szNewVer[MAX_PATH];
  220. TCHAR szCabName[32];
  221. DWORD dwFlags;
  222. HANDLE hThread;
  223. ICifComponent * pCifCabComponent;
  224. CCifComponent_t * pCifCabComponent_t;
  225. if (SUCCEEDED(g_lpCifFileNew->FindComponent(TEXT("ieak6CAB"), &pCifCabComponent)))
  226. {
  227. pCifCabComponent_t = new CCifComponent_t((ICifRWComponent *)pCifCabComponent);
  228. if (SUCCEEDED(pCifCabComponent_t->GetUrl(0, szCabName, countof(szCabName), &dwFlags)))
  229. {
  230. // do not allow self-update to continue if not enough size (size of Cab +
  231. // extract size approximated by twice the size of the cab)
  232. if (((dwFlags = pCifCabComponent_t->GetDownloadSize() * 3) > GetRootFree(g_szBuildTemp)) &&
  233. dwFlags)
  234. {
  235. TCHAR szMsg[MAX_PATH];
  236. TCHAR szMsgTemplate[MAX_PATH];
  237. LoadString(g_rvInfo.hInst, IDS_ERROR_UPDATESPACE, szMsgTemplate, countof(szMsgTemplate));
  238. wnsprintf(szMsg, countof(szMsg), szMsgTemplate, pCifCabComponent_t->GetDownloadSize() * 3);
  239. dwRet = (DWORD)-1;
  240. MessageBox(hDlg, szMsg, g_szTitle, MB_OK | MB_ICONEXCLAMATION);
  241. }
  242. else
  243. {
  244. StrCat(szUpdateUrl, szCabName);
  245. hWait = CreateDialog(g_rvInfo.hInst, MAKEINTRESOURCE(IDD_UPDATE), hDlg,
  246. DownloadStatusDlgProc);
  247. ShowWindow( hWait, SW_SHOWNORMAL );
  248. hThread = CreateThread(NULL, 4096, DownloadUpdateThreadProc, (LPVOID)szUpdateUrl, 0, &dwTid);
  249. while (MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT) != WAIT_OBJECT_0)
  250. {
  251. MSG msg;
  252. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  253. {
  254. TranslateMessage(&msg);
  255. DispatchMessage(&msg);
  256. }
  257. }
  258. GetExitCodeThread(hThread, &dwRet);
  259. CloseHandle(hThread);
  260. SendMessage(hWait, WM_CLOSE, 0, 0);
  261. }
  262. }
  263. else
  264. dwRet = (DWORD)-1;
  265. delete pCifCabComponent_t;
  266. }
  267. else
  268. dwRet = (DWORD)-1;
  269. if (dwRet == (DWORD)-1)
  270. {
  271. g_fLocalMode = TRUE;
  272. goto exit;
  273. }
  274. if (CheckIniVersion(IK_INI, szCurrentIni, pCifComponent_t))
  275. UpdateIni(szCurrentIni, pCifComponent_t);
  276. if (SUCCEEDED(pCifComponent_t->GetCustomData(TEXT("Cab"), szNewVer, countof(szNewVer))))
  277. WritePrivateProfileString(VERSION, IK_CAB, szNewVer, szCurrentIni);
  278. }
  279. else
  280. fNo = TRUE;
  281. }
  282. if (!fNo && (CheckIniVersion(IK_INI, szCurrentIni, pCifComponent_t)))
  283. {
  284. pCifComponent_t->GetCustomData(TEXT("IniText"), szMsg, countof(szMsg));
  285. if (MessageBox(g_hWizard, szMsg, g_szTitle, MB_YESNO | MB_DEFBUTTON2) == IDYES)
  286. {
  287. UpdateIni(szCurrentIni, pCifComponent_t);
  288. }
  289. else
  290. fNo = TRUE;
  291. }
  292. if (dwRet == ERROR_SUCCESS_REBOOT_REQUIRED)
  293. DoReboot(g_hWizard);
  294. if (fNo)
  295. g_fLocalMode = TRUE;
  296. exit:
  297. delete pCifComponent_t;
  298. }