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.

3240 lines
116 KiB

  1. //-------------------------------------------------------------------------------------------------
  2. // <copyright file="WixStandardBootstrapperApplication.cpp" company="Outercurve Foundation">
  3. // Copyright (c) 2004, Outercurve Foundation.
  4. // This software is released under Microsoft Reciprocal License (MS-RL).
  5. // The license and further copyright text can be found in the file
  6. // LICENSE.TXT at the root directory of the distribution.
  7. // </copyright>
  8. //-------------------------------------------------------------------------------------------------
  9. #include "pch.h"
  10. static const LPCWSTR PYBA_WINDOW_CLASS = L"PythonBA";
  11. static const DWORD PYBA_ACQUIRE_PERCENTAGE = 30;
  12. static const LPCWSTR PYBA_VARIABLE_BUNDLE_FILE_VERSION = L"WixBundleFileVersion";
  13. enum PYBA_STATE {
  14. PYBA_STATE_INITIALIZING,
  15. PYBA_STATE_INITIALIZED,
  16. PYBA_STATE_HELP,
  17. PYBA_STATE_DETECTING,
  18. PYBA_STATE_DETECTED,
  19. PYBA_STATE_PLANNING,
  20. PYBA_STATE_PLANNED,
  21. PYBA_STATE_APPLYING,
  22. PYBA_STATE_CACHING,
  23. PYBA_STATE_CACHED,
  24. PYBA_STATE_EXECUTING,
  25. PYBA_STATE_EXECUTED,
  26. PYBA_STATE_APPLIED,
  27. PYBA_STATE_FAILED,
  28. };
  29. static const int WM_PYBA_SHOW_HELP = WM_APP + 100;
  30. static const int WM_PYBA_DETECT_PACKAGES = WM_APP + 101;
  31. static const int WM_PYBA_PLAN_PACKAGES = WM_APP + 102;
  32. static const int WM_PYBA_APPLY_PACKAGES = WM_APP + 103;
  33. static const int WM_PYBA_CHANGE_STATE = WM_APP + 104;
  34. static const int WM_PYBA_SHOW_FAILURE = WM_APP + 105;
  35. // This enum must be kept in the same order as the PAGE_NAMES array.
  36. enum PAGE {
  37. PAGE_LOADING,
  38. PAGE_HELP,
  39. PAGE_INSTALL,
  40. PAGE_UPGRADE,
  41. PAGE_SIMPLE_INSTALL,
  42. PAGE_CUSTOM1,
  43. PAGE_CUSTOM2,
  44. PAGE_MODIFY,
  45. PAGE_PROGRESS,
  46. PAGE_PROGRESS_PASSIVE,
  47. PAGE_SUCCESS,
  48. PAGE_FAILURE,
  49. COUNT_PAGE,
  50. };
  51. // This array must be kept in the same order as the PAGE enum.
  52. static LPCWSTR PAGE_NAMES[] = {
  53. L"Loading",
  54. L"Help",
  55. L"Install",
  56. L"Upgrade",
  57. L"SimpleInstall",
  58. L"Custom1",
  59. L"Custom2",
  60. L"Modify",
  61. L"Progress",
  62. L"ProgressPassive",
  63. L"Success",
  64. L"Failure",
  65. };
  66. enum CONTROL_ID {
  67. // Non-paged controls
  68. ID_CLOSE_BUTTON = THEME_FIRST_ASSIGN_CONTROL_ID,
  69. ID_MINIMIZE_BUTTON,
  70. // Welcome page
  71. ID_INSTALL_BUTTON,
  72. ID_INSTALL_CUSTOM_BUTTON,
  73. ID_INSTALL_SIMPLE_BUTTON,
  74. ID_INSTALL_UPGRADE_BUTTON,
  75. ID_INSTALL_UPGRADE_CUSTOM_BUTTON,
  76. ID_INSTALL_CANCEL_BUTTON,
  77. ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX,
  78. // Customize Page
  79. ID_TARGETDIR_EDITBOX,
  80. ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX,
  81. ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX,
  82. ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX,
  83. ID_CUSTOM_INCLUDE_LAUNCHER_HELP_LABEL,
  84. ID_CUSTOM_COMPILE_ALL_CHECKBOX,
  85. ID_CUSTOM_BROWSE_BUTTON,
  86. ID_CUSTOM_BROWSE_BUTTON_LABEL,
  87. ID_CUSTOM_INSTALL_BUTTON,
  88. ID_CUSTOM_NEXT_BUTTON,
  89. ID_CUSTOM1_BACK_BUTTON,
  90. ID_CUSTOM2_BACK_BUTTON,
  91. ID_CUSTOM1_CANCEL_BUTTON,
  92. ID_CUSTOM2_CANCEL_BUTTON,
  93. // Modify page
  94. ID_MODIFY_BUTTON,
  95. ID_REPAIR_BUTTON,
  96. ID_UNINSTALL_BUTTON,
  97. ID_MODIFY_CANCEL_BUTTON,
  98. // Progress page
  99. ID_CACHE_PROGRESS_PACKAGE_TEXT,
  100. ID_CACHE_PROGRESS_BAR,
  101. ID_CACHE_PROGRESS_TEXT,
  102. ID_EXECUTE_PROGRESS_PACKAGE_TEXT,
  103. ID_EXECUTE_PROGRESS_BAR,
  104. ID_EXECUTE_PROGRESS_TEXT,
  105. ID_EXECUTE_PROGRESS_ACTIONDATA_TEXT,
  106. ID_OVERALL_PROGRESS_PACKAGE_TEXT,
  107. ID_OVERALL_PROGRESS_BAR,
  108. ID_OVERALL_CALCULATED_PROGRESS_BAR,
  109. ID_OVERALL_PROGRESS_TEXT,
  110. ID_PROGRESS_CANCEL_BUTTON,
  111. // Success page
  112. ID_SUCCESS_TEXT,
  113. ID_SUCCESS_RESTART_TEXT,
  114. ID_SUCCESS_RESTART_BUTTON,
  115. ID_SUCCESS_CANCEL_BUTTON,
  116. ID_SUCCESS_MAX_PATH_BUTTON,
  117. // Failure page
  118. ID_FAILURE_LOGFILE_LINK,
  119. ID_FAILURE_MESSAGE_TEXT,
  120. ID_FAILURE_RESTART_TEXT,
  121. ID_FAILURE_RESTART_BUTTON,
  122. ID_FAILURE_CANCEL_BUTTON
  123. };
  124. static THEME_ASSIGN_CONTROL_ID CONTROL_ID_NAMES[] = {
  125. { ID_CLOSE_BUTTON, L"CloseButton" },
  126. { ID_MINIMIZE_BUTTON, L"MinimizeButton" },
  127. { ID_INSTALL_BUTTON, L"InstallButton" },
  128. { ID_INSTALL_CUSTOM_BUTTON, L"InstallCustomButton" },
  129. { ID_INSTALL_SIMPLE_BUTTON, L"InstallSimpleButton" },
  130. { ID_INSTALL_UPGRADE_BUTTON, L"InstallUpgradeButton" },
  131. { ID_INSTALL_UPGRADE_CUSTOM_BUTTON, L"InstallUpgradeCustomButton" },
  132. { ID_INSTALL_CANCEL_BUTTON, L"InstallCancelButton" },
  133. { ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, L"InstallLauncherAllUsers" },
  134. { ID_TARGETDIR_EDITBOX, L"TargetDir" },
  135. { ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, L"AssociateFiles" },
  136. { ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX, L"InstallAllUsers" },
  137. { ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, L"CustomInstallLauncherAllUsers" },
  138. { ID_CUSTOM_INCLUDE_LAUNCHER_HELP_LABEL, L"Include_launcherHelp" },
  139. { ID_CUSTOM_COMPILE_ALL_CHECKBOX, L"CompileAll" },
  140. { ID_CUSTOM_BROWSE_BUTTON, L"CustomBrowseButton" },
  141. { ID_CUSTOM_BROWSE_BUTTON_LABEL, L"CustomBrowseButtonLabel" },
  142. { ID_CUSTOM_INSTALL_BUTTON, L"CustomInstallButton" },
  143. { ID_CUSTOM_NEXT_BUTTON, L"CustomNextButton" },
  144. { ID_CUSTOM1_BACK_BUTTON, L"Custom1BackButton" },
  145. { ID_CUSTOM2_BACK_BUTTON, L"Custom2BackButton" },
  146. { ID_CUSTOM1_CANCEL_BUTTON, L"Custom1CancelButton" },
  147. { ID_CUSTOM2_CANCEL_BUTTON, L"Custom2CancelButton" },
  148. { ID_MODIFY_BUTTON, L"ModifyButton" },
  149. { ID_REPAIR_BUTTON, L"RepairButton" },
  150. { ID_UNINSTALL_BUTTON, L"UninstallButton" },
  151. { ID_MODIFY_CANCEL_BUTTON, L"ModifyCancelButton" },
  152. { ID_CACHE_PROGRESS_PACKAGE_TEXT, L"CacheProgressPackageText" },
  153. { ID_CACHE_PROGRESS_BAR, L"CacheProgressbar" },
  154. { ID_CACHE_PROGRESS_TEXT, L"CacheProgressText" },
  155. { ID_EXECUTE_PROGRESS_PACKAGE_TEXT, L"ExecuteProgressPackageText" },
  156. { ID_EXECUTE_PROGRESS_BAR, L"ExecuteProgressbar" },
  157. { ID_EXECUTE_PROGRESS_TEXT, L"ExecuteProgressText" },
  158. { ID_EXECUTE_PROGRESS_ACTIONDATA_TEXT, L"ExecuteProgressActionDataText" },
  159. { ID_OVERALL_PROGRESS_PACKAGE_TEXT, L"OverallProgressPackageText" },
  160. { ID_OVERALL_PROGRESS_BAR, L"OverallProgressbar" },
  161. { ID_OVERALL_CALCULATED_PROGRESS_BAR, L"OverallCalculatedProgressbar" },
  162. { ID_OVERALL_PROGRESS_TEXT, L"OverallProgressText" },
  163. { ID_PROGRESS_CANCEL_BUTTON, L"ProgressCancelButton" },
  164. { ID_SUCCESS_TEXT, L"SuccessText" },
  165. { ID_SUCCESS_RESTART_TEXT, L"SuccessRestartText" },
  166. { ID_SUCCESS_RESTART_BUTTON, L"SuccessRestartButton" },
  167. { ID_SUCCESS_CANCEL_BUTTON, L"SuccessCancelButton" },
  168. { ID_SUCCESS_MAX_PATH_BUTTON, L"SuccessMaxPathButton" },
  169. { ID_FAILURE_LOGFILE_LINK, L"FailureLogFileLink" },
  170. { ID_FAILURE_MESSAGE_TEXT, L"FailureMessageText" },
  171. { ID_FAILURE_RESTART_TEXT, L"FailureRestartText" },
  172. { ID_FAILURE_RESTART_BUTTON, L"FailureRestartButton" },
  173. { ID_FAILURE_CANCEL_BUTTON, L"FailureCancelButton" },
  174. };
  175. static struct { LPCWSTR regName; LPCWSTR variableName; } OPTIONAL_FEATURES[] = {
  176. { L"core_d", L"Include_debug" },
  177. { L"core_pdb", L"Include_symbols" },
  178. { L"dev", L"Include_dev" },
  179. { L"doc", L"Include_doc" },
  180. { L"exe", L"Include_exe" },
  181. { L"lib", L"Include_lib" },
  182. { L"path", L"PrependPath" },
  183. { L"pip", L"Include_pip" },
  184. { L"tcltk", L"Include_tcltk" },
  185. { L"test", L"Include_test" },
  186. { L"tools", L"Include_tools" },
  187. { L"Shortcuts", L"Shortcuts" },
  188. // Include_launcher and AssociateFiles are handled separately and so do
  189. // not need to be included in this list.
  190. { nullptr, nullptr }
  191. };
  192. class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
  193. void ShowPage(DWORD newPageId) {
  194. // Process each control for special handling in the new page.
  195. ProcessPageControls(ThemeGetPage(_theme, newPageId));
  196. // Enable disable controls per-page.
  197. if (_pageIds[PAGE_INSTALL] == newPageId ||
  198. _pageIds[PAGE_SIMPLE_INSTALL] == newPageId ||
  199. _pageIds[PAGE_UPGRADE] == newPageId) {
  200. InstallPage_Show();
  201. } else if (_pageIds[PAGE_CUSTOM1] == newPageId) {
  202. Custom1Page_Show();
  203. } else if (_pageIds[PAGE_CUSTOM2] == newPageId) {
  204. Custom2Page_Show();
  205. } else if (_pageIds[PAGE_MODIFY] == newPageId) {
  206. ModifyPage_Show();
  207. } else if (_pageIds[PAGE_SUCCESS] == newPageId) {
  208. SuccessPage_Show();
  209. } else if (_pageIds[PAGE_FAILURE] == newPageId) {
  210. FailurePage_Show();
  211. }
  212. // Prevent repainting while switching page to avoid ugly flickering
  213. _suppressPaint = TRUE;
  214. ThemeShowPage(_theme, newPageId, SW_SHOW);
  215. ThemeShowPage(_theme, _visiblePageId, SW_HIDE);
  216. _suppressPaint = FALSE;
  217. InvalidateRect(_theme->hwndParent, nullptr, TRUE);
  218. _visiblePageId = newPageId;
  219. // On the install page set the focus to the install button or
  220. // the next enabled control if install is disabled
  221. if (_pageIds[PAGE_INSTALL] == newPageId) {
  222. ThemeSetFocus(_theme, ID_INSTALL_BUTTON);
  223. } else if (_pageIds[PAGE_SIMPLE_INSTALL] == newPageId) {
  224. ThemeSetFocus(_theme, ID_INSTALL_SIMPLE_BUTTON);
  225. }
  226. }
  227. //
  228. // Handles control clicks
  229. //
  230. void OnCommand(CONTROL_ID id) {
  231. LPWSTR defaultDir = nullptr;
  232. LPWSTR targetDir = nullptr;
  233. LONGLONG elevated, crtInstalled, installAllUsers;
  234. BOOL checked, launcherChecked;
  235. WCHAR wzPath[MAX_PATH] = { };
  236. BROWSEINFOW browseInfo = { };
  237. PIDLIST_ABSOLUTE pidl = nullptr;
  238. DWORD pageId;
  239. HRESULT hr = S_OK;
  240. switch(id) {
  241. case ID_CLOSE_BUTTON:
  242. OnClickCloseButton();
  243. break;
  244. // Install commands
  245. case ID_INSTALL_SIMPLE_BUTTON: __fallthrough;
  246. case ID_INSTALL_UPGRADE_BUTTON: __fallthrough;
  247. case ID_INSTALL_BUTTON:
  248. SavePageSettings();
  249. if (!WillElevate() && !QueryElevateForCrtInstall()) {
  250. break;
  251. }
  252. hr = BalGetNumericVariable(L"InstallAllUsers", &installAllUsers);
  253. ExitOnFailure(hr, L"Failed to get install scope");
  254. hr = _engine->SetVariableNumeric(L"CompileAll", installAllUsers);
  255. ExitOnFailure(hr, L"Failed to update CompileAll");
  256. hr = EnsureTargetDir();
  257. ExitOnFailure(hr, L"Failed to set TargetDir");
  258. OnPlan(BOOTSTRAPPER_ACTION_INSTALL);
  259. break;
  260. case ID_CUSTOM1_BACK_BUTTON:
  261. SavePageSettings();
  262. if (_modifying) {
  263. GoToPage(PAGE_MODIFY);
  264. } else if (_upgrading) {
  265. GoToPage(PAGE_UPGRADE);
  266. } else {
  267. GoToPage(PAGE_INSTALL);
  268. }
  269. break;
  270. case ID_INSTALL_CUSTOM_BUTTON: __fallthrough;
  271. case ID_INSTALL_UPGRADE_CUSTOM_BUTTON: __fallthrough;
  272. case ID_CUSTOM2_BACK_BUTTON:
  273. SavePageSettings();
  274. GoToPage(PAGE_CUSTOM1);
  275. break;
  276. case ID_CUSTOM_NEXT_BUTTON:
  277. SavePageSettings();
  278. GoToPage(PAGE_CUSTOM2);
  279. break;
  280. case ID_CUSTOM_INSTALL_BUTTON:
  281. SavePageSettings();
  282. hr = BalGetStringVariable(L"TargetDir", &targetDir);
  283. if (SUCCEEDED(hr)) {
  284. // TODO: Check whether directory exists and contains another installation
  285. ReleaseStr(targetDir);
  286. }
  287. if (!WillElevate() && !QueryElevateForCrtInstall()) {
  288. break;
  289. }
  290. OnPlan(_command.action);
  291. break;
  292. case ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX:
  293. checked = ThemeIsControlChecked(_theme, ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX);
  294. _engine->SetVariableNumeric(L"InstallLauncherAllUsers", checked);
  295. ThemeControlElevates(_theme, ID_INSTALL_BUTTON, WillElevate());
  296. break;
  297. case ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX:
  298. checked = ThemeIsControlChecked(_theme, ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX);
  299. _engine->SetVariableNumeric(L"InstallLauncherAllUsers", checked);
  300. ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, WillElevate());
  301. break;
  302. case ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX:
  303. checked = ThemeIsControlChecked(_theme, ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX);
  304. _engine->SetVariableNumeric(L"InstallAllUsers", checked);
  305. ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, WillElevate());
  306. ThemeControlEnable(_theme, ID_CUSTOM_BROWSE_BUTTON_LABEL, !checked);
  307. if (checked) {
  308. _engine->SetVariableNumeric(L"CompileAll", 1);
  309. ThemeSendControlMessage(_theme, ID_CUSTOM_COMPILE_ALL_CHECKBOX, BM_SETCHECK, BST_CHECKED, 0);
  310. }
  311. ThemeGetTextControl(_theme, ID_TARGETDIR_EDITBOX, &targetDir);
  312. if (targetDir) {
  313. // Check the current value against the default to see
  314. // if we should switch it automatically.
  315. hr = BalGetStringVariable(
  316. checked ? L"DefaultJustForMeTargetDir" : L"DefaultAllUsersTargetDir",
  317. &defaultDir
  318. );
  319. if (SUCCEEDED(hr) && defaultDir) {
  320. LPWSTR formatted = nullptr;
  321. if (defaultDir[0] && SUCCEEDED(BalFormatString(defaultDir, &formatted))) {
  322. if (wcscmp(formatted, targetDir) == 0) {
  323. ReleaseStr(defaultDir);
  324. defaultDir = nullptr;
  325. ReleaseStr(formatted);
  326. formatted = nullptr;
  327. hr = BalGetStringVariable(
  328. checked ? L"DefaultAllUsersTargetDir" : L"DefaultJustForMeTargetDir",
  329. &defaultDir
  330. );
  331. if (SUCCEEDED(hr) && defaultDir && defaultDir[0] && SUCCEEDED(BalFormatString(defaultDir, &formatted))) {
  332. ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, formatted);
  333. ReleaseStr(formatted);
  334. }
  335. } else {
  336. ReleaseStr(formatted);
  337. }
  338. }
  339. ReleaseStr(defaultDir);
  340. }
  341. }
  342. break;
  343. case ID_CUSTOM_BROWSE_BUTTON:
  344. browseInfo.hwndOwner = _hWnd;
  345. browseInfo.pszDisplayName = wzPath;
  346. browseInfo.lpszTitle = _theme->sczCaption;
  347. browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI;
  348. pidl = ::SHBrowseForFolderW(&browseInfo);
  349. if (pidl && ::SHGetPathFromIDListW(pidl, wzPath)) {
  350. ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, wzPath);
  351. }
  352. if (pidl) {
  353. ::CoTaskMemFree(pidl);
  354. }
  355. break;
  356. // Modify commands
  357. case ID_MODIFY_BUTTON:
  358. // Some variables cannot be modified
  359. _engine->SetVariableString(L"InstallAllUsersState", L"disable");
  360. _engine->SetVariableString(L"InstallLauncherAllUsersState", L"disable");
  361. _engine->SetVariableString(L"TargetDirState", L"disable");
  362. _engine->SetVariableString(L"CustomBrowseButtonState", L"disable");
  363. _modifying = TRUE;
  364. GoToPage(PAGE_CUSTOM1);
  365. break;
  366. case ID_REPAIR_BUTTON:
  367. OnPlan(BOOTSTRAPPER_ACTION_REPAIR);
  368. break;
  369. case ID_UNINSTALL_BUTTON:
  370. OnPlan(BOOTSTRAPPER_ACTION_UNINSTALL);
  371. break;
  372. case ID_SUCCESS_MAX_PATH_BUTTON:
  373. EnableMaxPathSupport();
  374. ThemeControlEnable(_theme, ID_SUCCESS_MAX_PATH_BUTTON, FALSE);
  375. break;
  376. }
  377. LExit:
  378. return;
  379. }
  380. void InstallPage_Show() {
  381. // Ensure the All Users install button has a UAC shield
  382. BOOL elevated = WillElevate();
  383. ThemeControlElevates(_theme, ID_INSTALL_BUTTON, elevated);
  384. ThemeControlElevates(_theme, ID_INSTALL_SIMPLE_BUTTON, elevated);
  385. ThemeControlElevates(_theme, ID_INSTALL_UPGRADE_BUTTON, elevated);
  386. }
  387. void Custom1Page_Show() {
  388. LONGLONG installLauncherAllUsers;
  389. if (FAILED(BalGetNumericVariable(L"InstallLauncherAllUsers", &installLauncherAllUsers))) {
  390. installLauncherAllUsers = 0;
  391. }
  392. ThemeSendControlMessage(_theme, ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, BM_SETCHECK,
  393. installLauncherAllUsers ? BST_CHECKED : BST_UNCHECKED, 0);
  394. LOC_STRING *pLocString = nullptr;
  395. LPCWSTR locKey = L"#(loc.Include_launcherHelp)";
  396. LONGLONG detectedLauncher;
  397. if (SUCCEEDED(BalGetNumericVariable(L"DetectedLauncher", &detectedLauncher)) && detectedLauncher) {
  398. locKey = L"#(loc.Include_launcherRemove)";
  399. } else if (SUCCEEDED(BalGetNumericVariable(L"DetectedOldLauncher", &detectedLauncher)) && detectedLauncher) {
  400. locKey = L"#(loc.Include_launcherUpgrade)";
  401. }
  402. if (SUCCEEDED(LocGetString(_wixLoc, locKey, &pLocString)) && pLocString) {
  403. ThemeSetTextControl(_theme, ID_CUSTOM_INCLUDE_LAUNCHER_HELP_LABEL, pLocString->wzText);
  404. }
  405. }
  406. void Custom2Page_Show() {
  407. HRESULT hr;
  408. LONGLONG installAll, includeLauncher;
  409. if (FAILED(BalGetNumericVariable(L"InstallAllUsers", &installAll))) {
  410. installAll = 0;
  411. }
  412. if (WillElevate()) {
  413. ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, TRUE);
  414. ThemeShowControl(_theme, ID_CUSTOM_BROWSE_BUTTON_LABEL, SW_HIDE);
  415. } else {
  416. ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, FALSE);
  417. ThemeShowControl(_theme, ID_CUSTOM_BROWSE_BUTTON_LABEL, SW_SHOW);
  418. }
  419. if (SUCCEEDED(BalGetNumericVariable(L"Include_launcher", &includeLauncher)) && includeLauncher) {
  420. ThemeControlEnable(_theme, ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, TRUE);
  421. } else {
  422. ThemeSendControlMessage(_theme, ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, BM_SETCHECK, BST_UNCHECKED, 0);
  423. ThemeControlEnable(_theme, ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, FALSE);
  424. }
  425. LPWSTR targetDir = nullptr;
  426. hr = BalGetStringVariable(L"TargetDir", &targetDir);
  427. if (SUCCEEDED(hr) && targetDir && targetDir[0]) {
  428. ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, targetDir);
  429. StrFree(targetDir);
  430. } else if (SUCCEEDED(hr)) {
  431. StrFree(targetDir);
  432. targetDir = nullptr;
  433. LPWSTR defaultTargetDir = nullptr;
  434. hr = BalGetStringVariable(L"DefaultCustomTargetDir", &defaultTargetDir);
  435. if (SUCCEEDED(hr) && defaultTargetDir && !defaultTargetDir[0]) {
  436. StrFree(defaultTargetDir);
  437. defaultTargetDir = nullptr;
  438. hr = BalGetStringVariable(
  439. installAll ? L"DefaultAllUsersTargetDir" : L"DefaultJustForMeTargetDir",
  440. &defaultTargetDir
  441. );
  442. }
  443. if (SUCCEEDED(hr) && defaultTargetDir) {
  444. if (defaultTargetDir[0] && SUCCEEDED(BalFormatString(defaultTargetDir, &targetDir))) {
  445. ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, targetDir);
  446. StrFree(targetDir);
  447. }
  448. StrFree(defaultTargetDir);
  449. }
  450. }
  451. }
  452. void ModifyPage_Show() {
  453. ThemeControlEnable(_theme, ID_REPAIR_BUTTON, !_suppressRepair);
  454. }
  455. void SuccessPage_Show() {
  456. // on the "Success" page, check if the restart button should be enabled.
  457. BOOL showRestartButton = FALSE;
  458. LOC_STRING *successText = nullptr;
  459. HRESULT hr = S_OK;
  460. if (_restartRequired) {
  461. if (BOOTSTRAPPER_RESTART_PROMPT == _command.restart) {
  462. showRestartButton = TRUE;
  463. }
  464. }
  465. switch (_plannedAction) {
  466. case BOOTSTRAPPER_ACTION_INSTALL:
  467. hr = LocGetString(_wixLoc, L"#(loc.SuccessInstallMessage)", &successText);
  468. break;
  469. case BOOTSTRAPPER_ACTION_MODIFY:
  470. hr = LocGetString(_wixLoc, L"#(loc.SuccessModifyMessage)", &successText);
  471. break;
  472. case BOOTSTRAPPER_ACTION_REPAIR:
  473. hr = LocGetString(_wixLoc, L"#(loc.SuccessRepairMessage)", &successText);
  474. break;
  475. case BOOTSTRAPPER_ACTION_UNINSTALL:
  476. hr = LocGetString(_wixLoc, L"#(loc.SuccessRemoveMessage)", &successText);
  477. break;
  478. }
  479. if (successText) {
  480. LPWSTR formattedString = nullptr;
  481. BalFormatString(successText->wzText, &formattedString);
  482. if (formattedString) {
  483. ThemeSetTextControl(_theme, ID_SUCCESS_TEXT, formattedString);
  484. StrFree(formattedString);
  485. }
  486. }
  487. ThemeControlEnable(_theme, ID_SUCCESS_RESTART_TEXT, showRestartButton);
  488. ThemeControlEnable(_theme, ID_SUCCESS_RESTART_BUTTON, showRestartButton);
  489. if (_command.action != BOOTSTRAPPER_ACTION_INSTALL ||
  490. !IsWindowsVersionOrGreater(10, 0, 0)) {
  491. ThemeControlEnable(_theme, ID_SUCCESS_MAX_PATH_BUTTON, FALSE);
  492. } else {
  493. DWORD dataType = 0, buffer = 0, bufferLen = sizeof(buffer);
  494. HKEY hKey;
  495. LRESULT res = RegOpenKeyExW(
  496. HKEY_LOCAL_MACHINE,
  497. L"SYSTEM\\CurrentControlSet\\Control\\FileSystem",
  498. 0,
  499. KEY_READ,
  500. &hKey
  501. );
  502. if (res == ERROR_SUCCESS) {
  503. res = RegQueryValueExW(hKey, L"LongPathsEnabled", nullptr, &dataType,
  504. (LPBYTE)&buffer, &bufferLen);
  505. RegCloseKey(hKey);
  506. }
  507. else {
  508. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Failed to open SYSTEM\\CurrentControlSet\\Control\\FileSystem: error code %d", res);
  509. }
  510. if (res == ERROR_SUCCESS && dataType == REG_DWORD && buffer == 0) {
  511. ThemeControlElevates(_theme, ID_SUCCESS_MAX_PATH_BUTTON, TRUE);
  512. }
  513. else {
  514. if (res == ERROR_SUCCESS)
  515. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Failed to read LongPathsEnabled value: error code %d", res);
  516. else
  517. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Hiding MAX_PATH button because it is already enabled");
  518. ThemeControlEnable(_theme, ID_SUCCESS_MAX_PATH_BUTTON, FALSE);
  519. }
  520. }
  521. }
  522. void FailurePage_Show() {
  523. // on the "Failure" page, show error message and check if the restart button should be enabled.
  524. // if there is a log file variable then we'll assume the log file exists.
  525. BOOL showLogLink = (_bundle.sczLogVariable && *_bundle.sczLogVariable);
  526. BOOL showErrorMessage = FALSE;
  527. BOOL showRestartButton = FALSE;
  528. if (FAILED(_hrFinal)) {
  529. LPWSTR unformattedText = nullptr;
  530. LPWSTR text = nullptr;
  531. // If we know the failure message, use that.
  532. if (_failedMessage && *_failedMessage) {
  533. StrAllocString(&unformattedText, _failedMessage, 0);
  534. } else {
  535. // try to get the error message from the error code.
  536. StrAllocFromError(&unformattedText, _hrFinal, nullptr);
  537. if (!unformattedText || !*unformattedText) {
  538. StrAllocFromError(&unformattedText, E_FAIL, nullptr);
  539. }
  540. }
  541. if (E_WIXSTDBA_CONDITION_FAILED == _hrFinal) {
  542. if (unformattedText) {
  543. StrAllocString(&text, unformattedText, 0);
  544. }
  545. } else {
  546. StrAllocFormatted(&text, L"0x%08x - %ls", _hrFinal, unformattedText);
  547. }
  548. if (text) {
  549. ThemeSetTextControl(_theme, ID_FAILURE_MESSAGE_TEXT, text);
  550. showErrorMessage = TRUE;
  551. }
  552. ReleaseStr(text);
  553. ReleaseStr(unformattedText);
  554. }
  555. if (_restartRequired && BOOTSTRAPPER_RESTART_PROMPT == _command.restart) {
  556. showRestartButton = TRUE;
  557. }
  558. ThemeControlEnable(_theme, ID_FAILURE_LOGFILE_LINK, showLogLink);
  559. ThemeControlEnable(_theme, ID_FAILURE_MESSAGE_TEXT, showErrorMessage);
  560. ThemeControlEnable(_theme, ID_FAILURE_RESTART_TEXT, showRestartButton);
  561. ThemeControlEnable(_theme, ID_FAILURE_RESTART_BUTTON, showRestartButton);
  562. }
  563. static void EnableMaxPathSupport() {
  564. LPWSTR targetDir = nullptr, defaultDir = nullptr;
  565. HRESULT hr = BalGetStringVariable(L"TargetDir", &targetDir);
  566. if (FAILED(hr) || !targetDir || !targetDir[0]) {
  567. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to get TargetDir");
  568. return;
  569. }
  570. LPWSTR pythonw = nullptr;
  571. StrAllocFormatted(&pythonw, L"%ls\\pythonw.exe", targetDir);
  572. if (!pythonw || !pythonw[0]) {
  573. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to construct pythonw.exe path");
  574. return;
  575. }
  576. LPCWSTR arguments = L"-c \"import winreg; "
  577. "winreg.SetValueEx("
  578. "winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, "
  579. "r'SYSTEM\\CurrentControlSet\\Control\\FileSystem'), "
  580. "'LongPathsEnabled', "
  581. "None, "
  582. "winreg.REG_DWORD, "
  583. "1"
  584. ")\"";
  585. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Executing %ls %ls", pythonw, arguments);
  586. HINSTANCE res = ShellExecuteW(0, L"runas", pythonw, arguments, NULL, SW_HIDE);
  587. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "return code 0x%08x", res);
  588. }
  589. public: // IBootstrapperApplication
  590. virtual STDMETHODIMP OnStartup() {
  591. HRESULT hr = S_OK;
  592. DWORD dwUIThreadId = 0;
  593. // create UI thread
  594. _hUiThread = ::CreateThread(nullptr, 0, UiThreadProc, this, 0, &dwUIThreadId);
  595. if (!_hUiThread) {
  596. ExitWithLastError(hr, "Failed to create UI thread.");
  597. }
  598. LExit:
  599. return hr;
  600. }
  601. virtual STDMETHODIMP_(int) OnShutdown() {
  602. int nResult = IDNOACTION;
  603. // wait for UI thread to terminate
  604. if (_hUiThread) {
  605. ::WaitForSingleObject(_hUiThread, INFINITE);
  606. ReleaseHandle(_hUiThread);
  607. }
  608. // If a restart was required.
  609. if (_restartRequired && _allowRestart) {
  610. nResult = IDRESTART;
  611. }
  612. return nResult;
  613. }
  614. virtual STDMETHODIMP_(int) OnDetectRelatedMsiPackage(
  615. __in_z LPCWSTR wzPackageId,
  616. __in_z LPCWSTR /*wzProductCode*/,
  617. __in BOOL fPerMachine,
  618. __in DWORD64 /*dw64Version*/,
  619. __in BOOTSTRAPPER_RELATED_OPERATION operation
  620. ) {
  621. if (BOOTSTRAPPER_RELATED_OPERATION_MAJOR_UPGRADE == operation &&
  622. (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, L"launcher_AllUsers", -1) ||
  623. CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, L"launcher_JustForMe", -1))) {
  624. auto hr = LoadAssociateFilesStateFromKey(_engine, fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER);
  625. if (hr == S_OK) {
  626. _engine->SetVariableNumeric(L"AssociateFiles", 1);
  627. } else if (FAILED(hr)) {
  628. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to load AssociateFiles state: error code 0x%08X", hr);
  629. }
  630. _engine->SetVariableNumeric(L"Include_launcher", 1);
  631. _engine->SetVariableNumeric(L"DetectedOldLauncher", 1);
  632. _engine->SetVariableNumeric(L"InstallLauncherAllUsers", fPerMachine ? 1 : 0);
  633. }
  634. return CheckCanceled() ? IDCANCEL : IDNOACTION;
  635. }
  636. virtual STDMETHODIMP_(int) OnDetectRelatedBundle(
  637. __in LPCWSTR wzBundleId,
  638. __in BOOTSTRAPPER_RELATION_TYPE relationType,
  639. __in LPCWSTR /*wzBundleTag*/,
  640. __in BOOL fPerMachine,
  641. __in DWORD64 /*dw64Version*/,
  642. __in BOOTSTRAPPER_RELATED_OPERATION operation
  643. ) {
  644. BalInfoAddRelatedBundleAsPackage(&_bundle.packages, wzBundleId, relationType, fPerMachine);
  645. // Remember when our bundle would cause a downgrade.
  646. if (BOOTSTRAPPER_RELATED_OPERATION_DOWNGRADE == operation) {
  647. _downgradingOtherVersion = TRUE;
  648. } else if (BOOTSTRAPPER_RELATED_OPERATION_MAJOR_UPGRADE == operation) {
  649. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Detected previous version - planning upgrade");
  650. _upgrading = TRUE;
  651. LoadOptionalFeatureStates(_engine);
  652. } else if (BOOTSTRAPPER_RELATED_OPERATION_NONE == operation) {
  653. if (_command.action == BOOTSTRAPPER_ACTION_INSTALL) {
  654. LOC_STRING *pLocString = nullptr;
  655. if (SUCCEEDED(LocGetString(_wixLoc, L"#(loc.FailureExistingInstall)", &pLocString)) && pLocString) {
  656. BalFormatString(pLocString->wzText, &_failedMessage);
  657. } else {
  658. BalFormatString(L"Cannot install [WixBundleName] because it is already installed.", &_failedMessage);
  659. }
  660. BalLog(
  661. BOOTSTRAPPER_LOG_LEVEL_ERROR,
  662. "Related bundle %ls is preventing install",
  663. wzBundleId
  664. );
  665. SetState(PYBA_STATE_FAILED, E_WIXSTDBA_CONDITION_FAILED);
  666. }
  667. }
  668. return CheckCanceled() ? IDCANCEL : IDOK;
  669. }
  670. virtual STDMETHODIMP_(void) OnDetectPackageComplete(
  671. __in LPCWSTR wzPackageId,
  672. __in HRESULT hrStatus,
  673. __in BOOTSTRAPPER_PACKAGE_STATE state
  674. ) {
  675. if (FAILED(hrStatus)) {
  676. return;
  677. }
  678. BOOL detectedLauncher = FALSE;
  679. HKEY hkey = HKEY_LOCAL_MACHINE;
  680. if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, L"launcher_AllUsers", -1)) {
  681. if (BOOTSTRAPPER_PACKAGE_STATE_PRESENT == state || BOOTSTRAPPER_PACKAGE_STATE_OBSOLETE == state) {
  682. detectedLauncher = TRUE;
  683. _engine->SetVariableNumeric(L"InstallLauncherAllUsers", 1);
  684. }
  685. } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, L"launcher_JustForMe", -1)) {
  686. if (BOOTSTRAPPER_PACKAGE_STATE_PRESENT == state || BOOTSTRAPPER_PACKAGE_STATE_OBSOLETE == state) {
  687. detectedLauncher = TRUE;
  688. _engine->SetVariableNumeric(L"InstallLauncherAllUsers", 0);
  689. }
  690. }
  691. if (detectedLauncher) {
  692. /* When we detect the current version of the launcher. */
  693. _engine->SetVariableNumeric(L"Include_launcher", 1);
  694. _engine->SetVariableNumeric(L"DetectedLauncher", 1);
  695. _engine->SetVariableString(L"Include_launcherState", L"disable");
  696. _engine->SetVariableString(L"InstallLauncherAllUsersState", L"disable");
  697. auto hr = LoadAssociateFilesStateFromKey(_engine, hkey);
  698. if (hr == S_OK) {
  699. _engine->SetVariableNumeric(L"AssociateFiles", 1);
  700. } else if (FAILED(hr)) {
  701. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to load AssociateFiles state: error code 0x%08X", hr);
  702. }
  703. }
  704. }
  705. virtual STDMETHODIMP_(void) OnDetectComplete(__in HRESULT hrStatus) {
  706. if (SUCCEEDED(hrStatus) && _baFunction) {
  707. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running detect complete BA function");
  708. _baFunction->OnDetectComplete();
  709. }
  710. if (SUCCEEDED(hrStatus)) {
  711. hrStatus = EvaluateConditions();
  712. }
  713. if (SUCCEEDED(hrStatus)) {
  714. // Ensure the default path has been set
  715. hrStatus = EnsureTargetDir();
  716. }
  717. SetState(PYBA_STATE_DETECTED, hrStatus);
  718. // If we're not interacting with the user or we're doing a layout or we're just after a force restart
  719. // then automatically start planning.
  720. if (BOOTSTRAPPER_DISPLAY_FULL > _command.display ||
  721. BOOTSTRAPPER_ACTION_LAYOUT == _command.action ||
  722. BOOTSTRAPPER_ACTION_UNINSTALL == _command.action ||
  723. BOOTSTRAPPER_RESUME_TYPE_REBOOT == _command.resumeType) {
  724. if (SUCCEEDED(hrStatus)) {
  725. ::PostMessageW(_hWnd, WM_PYBA_PLAN_PACKAGES, 0, _command.action);
  726. }
  727. }
  728. }
  729. virtual STDMETHODIMP_(int) OnPlanRelatedBundle(
  730. __in_z LPCWSTR /*wzBundleId*/,
  731. __inout_z BOOTSTRAPPER_REQUEST_STATE* pRequestedState
  732. ) {
  733. return CheckCanceled() ? IDCANCEL : IDOK;
  734. }
  735. virtual STDMETHODIMP_(int) OnPlanPackageBegin(
  736. __in_z LPCWSTR wzPackageId,
  737. __inout BOOTSTRAPPER_REQUEST_STATE *pRequestState
  738. ) {
  739. HRESULT hr = S_OK;
  740. BAL_INFO_PACKAGE* pPackage = nullptr;
  741. if (_nextPackageAfterRestart) {
  742. // After restart we need to finish the dependency registration for our package so allow the package
  743. // to go present.
  744. if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, _nextPackageAfterRestart, -1)) {
  745. // Do not allow a repair because that could put us in a perpetual restart loop.
  746. if (BOOTSTRAPPER_REQUEST_STATE_REPAIR == *pRequestState) {
  747. *pRequestState = BOOTSTRAPPER_REQUEST_STATE_PRESENT;
  748. }
  749. ReleaseNullStr(_nextPackageAfterRestart); // no more skipping now.
  750. } else {
  751. // not the matching package, so skip it.
  752. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Skipping package: %ls, after restart because it was applied before the restart.", wzPackageId);
  753. *pRequestState = BOOTSTRAPPER_REQUEST_STATE_NONE;
  754. }
  755. } else if ((_plannedAction == BOOTSTRAPPER_ACTION_INSTALL || _plannedAction == BOOTSTRAPPER_ACTION_MODIFY) &&
  756. SUCCEEDED(BalInfoFindPackageById(&_bundle.packages, wzPackageId, &pPackage))) {
  757. BOOL f = FALSE;
  758. if (SUCCEEDED(_engine->EvaluateCondition(pPackage->sczInstallCondition, &f)) && f) {
  759. *pRequestState = BOOTSTRAPPER_REQUEST_STATE_PRESENT;
  760. }
  761. }
  762. return CheckCanceled() ? IDCANCEL : IDOK;
  763. }
  764. virtual STDMETHODIMP_(int) OnPlanMsiFeature(
  765. __in_z LPCWSTR wzPackageId,
  766. __in_z LPCWSTR wzFeatureId,
  767. __inout BOOTSTRAPPER_FEATURE_STATE* pRequestedState
  768. ) {
  769. LONGLONG install;
  770. if (wcscmp(wzFeatureId, L"AssociateFiles") == 0 || wcscmp(wzFeatureId, L"Shortcuts") == 0) {
  771. if (SUCCEEDED(_engine->GetVariableNumeric(wzFeatureId, &install)) && install) {
  772. *pRequestedState = BOOTSTRAPPER_FEATURE_STATE_LOCAL;
  773. } else {
  774. *pRequestedState = BOOTSTRAPPER_FEATURE_STATE_ABSENT;
  775. }
  776. } else {
  777. *pRequestedState = BOOTSTRAPPER_FEATURE_STATE_LOCAL;
  778. }
  779. return CheckCanceled() ? IDCANCEL : IDNOACTION;
  780. }
  781. virtual STDMETHODIMP_(void) OnPlanComplete(__in HRESULT hrStatus) {
  782. if (SUCCEEDED(hrStatus) && _baFunction) {
  783. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running plan complete BA function");
  784. _baFunction->OnPlanComplete();
  785. }
  786. SetState(PYBA_STATE_PLANNED, hrStatus);
  787. if (SUCCEEDED(hrStatus)) {
  788. ::PostMessageW(_hWnd, WM_PYBA_APPLY_PACKAGES, 0, 0);
  789. }
  790. _startedExecution = FALSE;
  791. _calculatedCacheProgress = 0;
  792. _calculatedExecuteProgress = 0;
  793. }
  794. virtual STDMETHODIMP_(int) OnCachePackageBegin(
  795. __in_z LPCWSTR wzPackageId,
  796. __in DWORD cCachePayloads,
  797. __in DWORD64 dw64PackageCacheSize
  798. ) {
  799. if (wzPackageId && *wzPackageId) {
  800. BAL_INFO_PACKAGE* pPackage = nullptr;
  801. HRESULT hr = BalInfoFindPackageById(&_bundle.packages, wzPackageId, &pPackage);
  802. LPCWSTR wz = (SUCCEEDED(hr) && pPackage->sczDisplayName) ? pPackage->sczDisplayName : wzPackageId;
  803. ThemeSetTextControl(_theme, ID_CACHE_PROGRESS_PACKAGE_TEXT, wz);
  804. // If something started executing, leave it in the overall progress text.
  805. if (!_startedExecution) {
  806. ThemeSetTextControl(_theme, ID_OVERALL_PROGRESS_PACKAGE_TEXT, wz);
  807. }
  808. }
  809. return __super::OnCachePackageBegin(wzPackageId, cCachePayloads, dw64PackageCacheSize);
  810. }
  811. virtual STDMETHODIMP_(int) OnCacheAcquireProgress(
  812. __in_z LPCWSTR wzPackageOrContainerId,
  813. __in_z_opt LPCWSTR wzPayloadId,
  814. __in DWORD64 dw64Progress,
  815. __in DWORD64 dw64Total,
  816. __in DWORD dwOverallPercentage
  817. ) {
  818. WCHAR wzProgress[5] = { };
  819. #ifdef DEBUG
  820. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "PYBA: OnCacheAcquireProgress() - container/package: %ls, payload: %ls, progress: %I64u, total: %I64u, overall progress: %u%%", wzPackageOrContainerId, wzPayloadId, dw64Progress, dw64Total, dwOverallPercentage);
  821. #endif
  822. ::StringCchPrintfW(wzProgress, countof(wzProgress), L"%u%%", dwOverallPercentage);
  823. ThemeSetTextControl(_theme, ID_CACHE_PROGRESS_TEXT, wzProgress);
  824. ThemeSetProgressControl(_theme, ID_CACHE_PROGRESS_BAR, dwOverallPercentage);
  825. _calculatedCacheProgress = dwOverallPercentage * PYBA_ACQUIRE_PERCENTAGE / 100;
  826. ThemeSetProgressControl(_theme, ID_OVERALL_CALCULATED_PROGRESS_BAR, _calculatedCacheProgress + _calculatedExecuteProgress);
  827. SetTaskbarButtonProgress(_calculatedCacheProgress + _calculatedExecuteProgress);
  828. return __super::OnCacheAcquireProgress(wzPackageOrContainerId, wzPayloadId, dw64Progress, dw64Total, dwOverallPercentage);
  829. }
  830. virtual STDMETHODIMP_(int) OnCacheAcquireComplete(
  831. __in_z LPCWSTR wzPackageOrContainerId,
  832. __in_z_opt LPCWSTR wzPayloadId,
  833. __in HRESULT hrStatus,
  834. __in int nRecommendation
  835. ) {
  836. SetProgressState(hrStatus);
  837. return __super::OnCacheAcquireComplete(wzPackageOrContainerId, wzPayloadId, hrStatus, nRecommendation);
  838. }
  839. virtual STDMETHODIMP_(int) OnCacheVerifyComplete(
  840. __in_z LPCWSTR wzPackageId,
  841. __in_z LPCWSTR wzPayloadId,
  842. __in HRESULT hrStatus,
  843. __in int nRecommendation
  844. ) {
  845. SetProgressState(hrStatus);
  846. return __super::OnCacheVerifyComplete(wzPackageId, wzPayloadId, hrStatus, nRecommendation);
  847. }
  848. virtual STDMETHODIMP_(void) OnCacheComplete(__in HRESULT /*hrStatus*/) {
  849. ThemeSetTextControl(_theme, ID_CACHE_PROGRESS_PACKAGE_TEXT, L"");
  850. SetState(PYBA_STATE_CACHED, S_OK); // we always return success here and let OnApplyComplete() deal with the error.
  851. }
  852. virtual STDMETHODIMP_(int) OnError(
  853. __in BOOTSTRAPPER_ERROR_TYPE errorType,
  854. __in LPCWSTR wzPackageId,
  855. __in DWORD dwCode,
  856. __in_z LPCWSTR wzError,
  857. __in DWORD dwUIHint,
  858. __in DWORD /*cData*/,
  859. __in_ecount_z_opt(cData) LPCWSTR* /*rgwzData*/,
  860. __in int nRecommendation
  861. ) {
  862. int nResult = nRecommendation;
  863. LPWSTR sczError = nullptr;
  864. if (BOOTSTRAPPER_DISPLAY_EMBEDDED == _command.display) {
  865. HRESULT hr = _engine->SendEmbeddedError(dwCode, wzError, dwUIHint, &nResult);
  866. if (FAILED(hr)) {
  867. nResult = IDERROR;
  868. }
  869. } else if (BOOTSTRAPPER_DISPLAY_FULL == _command.display) {
  870. // If this is an authentication failure, let the engine try to handle it for us.
  871. if (BOOTSTRAPPER_ERROR_TYPE_HTTP_AUTH_SERVER == errorType || BOOTSTRAPPER_ERROR_TYPE_HTTP_AUTH_PROXY == errorType) {
  872. nResult = IDTRYAGAIN;
  873. } else // show a generic error message box.
  874. {
  875. BalRetryErrorOccurred(wzPackageId, dwCode);
  876. if (!_showingInternalUIThisPackage) {
  877. // If no error message was provided, use the error code to try and get an error message.
  878. if (!wzError || !*wzError || BOOTSTRAPPER_ERROR_TYPE_WINDOWS_INSTALLER != errorType) {
  879. HRESULT hr = StrAllocFromError(&sczError, dwCode, nullptr);
  880. if (FAILED(hr) || !sczError || !*sczError) {
  881. StrAllocFormatted(&sczError, L"0x%x", dwCode);
  882. }
  883. }
  884. nResult = ::MessageBoxW(_hWnd, sczError ? sczError : wzError, _theme->sczCaption, dwUIHint);
  885. }
  886. }
  887. SetProgressState(HRESULT_FROM_WIN32(dwCode));
  888. } else {
  889. // just take note of the error code and let things continue.
  890. BalRetryErrorOccurred(wzPackageId, dwCode);
  891. }
  892. ReleaseStr(sczError);
  893. return nResult;
  894. }
  895. virtual STDMETHODIMP_(int) OnExecuteMsiMessage(
  896. __in_z LPCWSTR wzPackageId,
  897. __in INSTALLMESSAGE mt,
  898. __in UINT uiFlags,
  899. __in_z LPCWSTR wzMessage,
  900. __in DWORD cData,
  901. __in_ecount_z_opt(cData) LPCWSTR* rgwzData,
  902. __in int nRecommendation
  903. ) {
  904. #ifdef DEBUG
  905. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "PYBA: OnExecuteMsiMessage() - package: %ls, message: %ls", wzPackageId, wzMessage);
  906. #endif
  907. if (BOOTSTRAPPER_DISPLAY_FULL == _command.display && (INSTALLMESSAGE_WARNING == mt || INSTALLMESSAGE_USER == mt)) {
  908. int nResult = ::MessageBoxW(_hWnd, wzMessage, _theme->sczCaption, uiFlags);
  909. return nResult;
  910. }
  911. if (INSTALLMESSAGE_ACTIONSTART == mt) {
  912. ThemeSetTextControl(_theme, ID_EXECUTE_PROGRESS_ACTIONDATA_TEXT, wzMessage);
  913. }
  914. return __super::OnExecuteMsiMessage(wzPackageId, mt, uiFlags, wzMessage, cData, rgwzData, nRecommendation);
  915. }
  916. virtual STDMETHODIMP_(int) OnProgress(__in DWORD dwProgressPercentage, __in DWORD dwOverallProgressPercentage) {
  917. WCHAR wzProgress[5] = { };
  918. #ifdef DEBUG
  919. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "PYBA: OnProgress() - progress: %u%%, overall progress: %u%%", dwProgressPercentage, dwOverallProgressPercentage);
  920. #endif
  921. ::StringCchPrintfW(wzProgress, countof(wzProgress), L"%u%%", dwOverallProgressPercentage);
  922. ThemeSetTextControl(_theme, ID_OVERALL_PROGRESS_TEXT, wzProgress);
  923. ThemeSetProgressControl(_theme, ID_OVERALL_PROGRESS_BAR, dwOverallProgressPercentage);
  924. SetTaskbarButtonProgress(dwOverallProgressPercentage);
  925. return __super::OnProgress(dwProgressPercentage, dwOverallProgressPercentage);
  926. }
  927. virtual STDMETHODIMP_(int) OnExecutePackageBegin(__in_z LPCWSTR wzPackageId, __in BOOL fExecute) {
  928. LPWSTR sczFormattedString = nullptr;
  929. _startedExecution = TRUE;
  930. if (wzPackageId && *wzPackageId) {
  931. BAL_INFO_PACKAGE* pPackage = nullptr;
  932. BalInfoFindPackageById(&_bundle.packages, wzPackageId, &pPackage);
  933. LPCWSTR wz = wzPackageId;
  934. if (pPackage) {
  935. LOC_STRING* pLocString = nullptr;
  936. switch (pPackage->type) {
  937. case BAL_INFO_PACKAGE_TYPE_BUNDLE_ADDON:
  938. LocGetString(_wixLoc, L"#(loc.ExecuteAddonRelatedBundleMessage)", &pLocString);
  939. break;
  940. case BAL_INFO_PACKAGE_TYPE_BUNDLE_PATCH:
  941. LocGetString(_wixLoc, L"#(loc.ExecutePatchRelatedBundleMessage)", &pLocString);
  942. break;
  943. case BAL_INFO_PACKAGE_TYPE_BUNDLE_UPGRADE:
  944. LocGetString(_wixLoc, L"#(loc.ExecuteUpgradeRelatedBundleMessage)", &pLocString);
  945. break;
  946. }
  947. if (pLocString) {
  948. // If the wix developer is showing a hidden variable in the UI, then obviously they don't care about keeping it safe
  949. // so don't go down the rabbit hole of making sure that this is securely freed.
  950. BalFormatString(pLocString->wzText, &sczFormattedString);
  951. }
  952. wz = sczFormattedString ? sczFormattedString : pPackage->sczDisplayName ? pPackage->sczDisplayName : wzPackageId;
  953. }
  954. _showingInternalUIThisPackage = pPackage && pPackage->fDisplayInternalUI;
  955. ThemeSetTextControl(_theme, ID_EXECUTE_PROGRESS_PACKAGE_TEXT, wz);
  956. ThemeSetTextControl(_theme, ID_OVERALL_PROGRESS_PACKAGE_TEXT, wz);
  957. } else {
  958. _showingInternalUIThisPackage = FALSE;
  959. }
  960. ReleaseStr(sczFormattedString);
  961. return __super::OnExecutePackageBegin(wzPackageId, fExecute);
  962. }
  963. virtual int __stdcall OnExecuteProgress(
  964. __in_z LPCWSTR wzPackageId,
  965. __in DWORD dwProgressPercentage,
  966. __in DWORD dwOverallProgressPercentage
  967. ) {
  968. WCHAR wzProgress[8] = { };
  969. #ifdef DEBUG
  970. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "PYBA: OnExecuteProgress() - package: %ls, progress: %u%%, overall progress: %u%%", wzPackageId, dwProgressPercentage, dwOverallProgressPercentage);
  971. #endif
  972. ::StringCchPrintfW(wzProgress, countof(wzProgress), L"%u%%", dwOverallProgressPercentage);
  973. ThemeSetTextControl(_theme, ID_EXECUTE_PROGRESS_TEXT, wzProgress);
  974. ThemeSetProgressControl(_theme, ID_EXECUTE_PROGRESS_BAR, dwOverallProgressPercentage);
  975. _calculatedExecuteProgress = dwOverallProgressPercentage * (100 - PYBA_ACQUIRE_PERCENTAGE) / 100;
  976. ThemeSetProgressControl(_theme, ID_OVERALL_CALCULATED_PROGRESS_BAR, _calculatedCacheProgress + _calculatedExecuteProgress);
  977. SetTaskbarButtonProgress(_calculatedCacheProgress + _calculatedExecuteProgress);
  978. return __super::OnExecuteProgress(wzPackageId, dwProgressPercentage, dwOverallProgressPercentage);
  979. }
  980. virtual STDMETHODIMP_(int) OnExecutePackageComplete(
  981. __in_z LPCWSTR wzPackageId,
  982. __in HRESULT hrExitCode,
  983. __in BOOTSTRAPPER_APPLY_RESTART restart,
  984. __in int nRecommendation
  985. ) {
  986. SetProgressState(hrExitCode);
  987. if (_wcsnicmp(wzPackageId, L"path_", 5) == 0 && SUCCEEDED(hrExitCode)) {
  988. SendMessageTimeoutW(
  989. HWND_BROADCAST,
  990. WM_SETTINGCHANGE,
  991. 0,
  992. reinterpret_cast<LPARAM>(L"Environment"),
  993. SMTO_ABORTIFHUNG,
  994. 1000,
  995. nullptr
  996. );
  997. }
  998. int nResult = __super::OnExecutePackageComplete(wzPackageId, hrExitCode, restart, nRecommendation);
  999. return nResult;
  1000. }
  1001. virtual STDMETHODIMP_(void) OnExecuteComplete(__in HRESULT hrStatus) {
  1002. ThemeSetTextControl(_theme, ID_EXECUTE_PROGRESS_PACKAGE_TEXT, L"");
  1003. ThemeSetTextControl(_theme, ID_EXECUTE_PROGRESS_ACTIONDATA_TEXT, L"");
  1004. ThemeSetTextControl(_theme, ID_OVERALL_PROGRESS_PACKAGE_TEXT, L"");
  1005. ThemeControlEnable(_theme, ID_PROGRESS_CANCEL_BUTTON, FALSE); // no more cancel.
  1006. SetState(PYBA_STATE_EXECUTED, S_OK); // we always return success here and let OnApplyComplete() deal with the error.
  1007. SetProgressState(hrStatus);
  1008. }
  1009. virtual STDMETHODIMP_(int) OnResolveSource(
  1010. __in_z LPCWSTR wzPackageOrContainerId,
  1011. __in_z_opt LPCWSTR wzPayloadId,
  1012. __in_z LPCWSTR wzLocalSource,
  1013. __in_z_opt LPCWSTR wzDownloadSource
  1014. ) {
  1015. int nResult = IDERROR; // assume we won't resolve source and that is unexpected.
  1016. if (BOOTSTRAPPER_DISPLAY_FULL == _command.display) {
  1017. if (wzDownloadSource) {
  1018. nResult = IDDOWNLOAD;
  1019. } else {
  1020. // prompt to change the source location.
  1021. OPENFILENAMEW ofn = { };
  1022. WCHAR wzFile[MAX_PATH] = { };
  1023. ::StringCchCopyW(wzFile, countof(wzFile), wzLocalSource);
  1024. ofn.lStructSize = sizeof(ofn);
  1025. ofn.hwndOwner = _hWnd;
  1026. ofn.lpstrFile = wzFile;
  1027. ofn.nMaxFile = countof(wzFile);
  1028. ofn.lpstrFilter = L"All Files\0*.*\0";
  1029. ofn.nFilterIndex = 1;
  1030. ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  1031. ofn.lpstrTitle = _theme->sczCaption;
  1032. if (::GetOpenFileNameW(&ofn)) {
  1033. HRESULT hr = _engine->SetLocalSource(wzPackageOrContainerId, wzPayloadId, ofn.lpstrFile);
  1034. nResult = SUCCEEDED(hr) ? IDRETRY : IDERROR;
  1035. } else {
  1036. nResult = IDCANCEL;
  1037. }
  1038. }
  1039. } else if (wzDownloadSource) {
  1040. // If doing a non-interactive install and download source is available, let's try downloading the package silently
  1041. nResult = IDDOWNLOAD;
  1042. }
  1043. // else there's nothing more we can do in non-interactive mode
  1044. return CheckCanceled() ? IDCANCEL : nResult;
  1045. }
  1046. virtual STDMETHODIMP_(int) OnApplyComplete(__in HRESULT hrStatus, __in BOOTSTRAPPER_APPLY_RESTART restart) {
  1047. _restartResult = restart; // remember the restart result so we return the correct error code no matter what the user chooses to do in the UI.
  1048. // If a restart was encountered and we are not suppressing restarts, then restart is required.
  1049. _restartRequired = (BOOTSTRAPPER_APPLY_RESTART_NONE != restart && BOOTSTRAPPER_RESTART_NEVER < _command.restart);
  1050. // If a restart is required and we're not displaying a UI or we are not supposed to prompt for restart then allow the restart.
  1051. _allowRestart = _restartRequired && (BOOTSTRAPPER_DISPLAY_FULL > _command.display || BOOTSTRAPPER_RESTART_PROMPT < _command.restart);
  1052. // If we are showing UI, wait a beat before moving to the final screen.
  1053. if (BOOTSTRAPPER_DISPLAY_NONE < _command.display) {
  1054. ::Sleep(250);
  1055. }
  1056. SetState(PYBA_STATE_APPLIED, hrStatus);
  1057. SetTaskbarButtonProgress(100); // show full progress bar, green, yellow, or red
  1058. return IDNOACTION;
  1059. }
  1060. virtual STDMETHODIMP_(void) OnLaunchApprovedExeComplete(__in HRESULT hrStatus, __in DWORD /*processId*/) {
  1061. }
  1062. private:
  1063. //
  1064. // UiThreadProc - entrypoint for UI thread.
  1065. //
  1066. static DWORD WINAPI UiThreadProc(__in LPVOID pvContext) {
  1067. HRESULT hr = S_OK;
  1068. PythonBootstrapperApplication* pThis = (PythonBootstrapperApplication*)pvContext;
  1069. BOOL comInitialized = FALSE;
  1070. BOOL ret = FALSE;
  1071. MSG msg = { };
  1072. // Initialize COM and theme.
  1073. hr = ::CoInitialize(nullptr);
  1074. BalExitOnFailure(hr, "Failed to initialize COM.");
  1075. comInitialized = TRUE;
  1076. hr = ThemeInitialize(pThis->_hModule);
  1077. BalExitOnFailure(hr, "Failed to initialize theme manager.");
  1078. hr = pThis->InitializeData();
  1079. BalExitOnFailure(hr, "Failed to initialize data in bootstrapper application.");
  1080. // Create main window.
  1081. pThis->InitializeTaskbarButton();
  1082. hr = pThis->CreateMainWindow();
  1083. BalExitOnFailure(hr, "Failed to create main window.");
  1084. pThis->ValidateOperatingSystem();
  1085. if (FAILED(pThis->_hrFinal)) {
  1086. pThis->SetState(PYBA_STATE_FAILED, hr);
  1087. ::PostMessageW(pThis->_hWnd, WM_PYBA_SHOW_FAILURE, 0, 0);
  1088. } else {
  1089. // Okay, we're ready for packages now.
  1090. pThis->SetState(PYBA_STATE_INITIALIZED, hr);
  1091. ::PostMessageW(pThis->_hWnd, BOOTSTRAPPER_ACTION_HELP == pThis->_command.action ? WM_PYBA_SHOW_HELP : WM_PYBA_DETECT_PACKAGES, 0, 0);
  1092. }
  1093. // message pump
  1094. while (0 != (ret = ::GetMessageW(&msg, nullptr, 0, 0))) {
  1095. if (-1 == ret) {
  1096. hr = E_UNEXPECTED;
  1097. BalExitOnFailure(hr, "Unexpected return value from message pump.");
  1098. } else if (!ThemeHandleKeyboardMessage(pThis->_theme, msg.hwnd, &msg)) {
  1099. ::TranslateMessage(&msg);
  1100. ::DispatchMessageW(&msg);
  1101. }
  1102. }
  1103. // Succeeded thus far, check to see if anything went wrong while actually
  1104. // executing changes.
  1105. if (FAILED(pThis->_hrFinal)) {
  1106. hr = pThis->_hrFinal;
  1107. } else if (pThis->CheckCanceled()) {
  1108. hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT);
  1109. }
  1110. LExit:
  1111. // destroy main window
  1112. pThis->DestroyMainWindow();
  1113. // initiate engine shutdown
  1114. DWORD dwQuit = HRESULT_CODE(hr);
  1115. if (BOOTSTRAPPER_APPLY_RESTART_INITIATED == pThis->_restartResult) {
  1116. dwQuit = ERROR_SUCCESS_REBOOT_INITIATED;
  1117. } else if (BOOTSTRAPPER_APPLY_RESTART_REQUIRED == pThis->_restartResult) {
  1118. dwQuit = ERROR_SUCCESS_REBOOT_REQUIRED;
  1119. }
  1120. pThis->_engine->Quit(dwQuit);
  1121. ReleaseTheme(pThis->_theme);
  1122. ThemeUninitialize();
  1123. // uninitialize COM
  1124. if (comInitialized) {
  1125. ::CoUninitialize();
  1126. }
  1127. return hr;
  1128. }
  1129. //
  1130. // ParseVariablesFromUnattendXml - reads options from unattend.xml if it
  1131. // exists
  1132. //
  1133. HRESULT ParseVariablesFromUnattendXml() {
  1134. HRESULT hr = S_OK;
  1135. LPWSTR sczUnattendXmlPath = nullptr;
  1136. IXMLDOMDocument *pixdUnattend = nullptr;
  1137. IXMLDOMNodeList *pNodes = nullptr;
  1138. IXMLDOMNode *pNode = nullptr;
  1139. long cNodes;
  1140. DWORD dwAttr;
  1141. LPWSTR scz = nullptr;
  1142. BOOL bValue;
  1143. int iValue;
  1144. BOOL tryConvert;
  1145. BSTR bstrValue = nullptr;
  1146. hr = BalFormatString(L"[WixBundleOriginalSourceFolder]unattend.xml", &sczUnattendXmlPath);
  1147. BalExitOnFailure(hr, "Failed to calculate path to unattend.xml");
  1148. if (!FileExistsEx(sczUnattendXmlPath, &dwAttr)) {
  1149. BalLog(BOOTSTRAPPER_LOG_LEVEL_VERBOSE, "Did not find %ls", sczUnattendXmlPath);
  1150. hr = S_FALSE;
  1151. goto LExit;
  1152. }
  1153. hr = XmlLoadDocumentFromFile(sczUnattendXmlPath, &pixdUnattend);
  1154. BalExitOnFailure1(hr, "Failed to read %ls", sczUnattendXmlPath);
  1155. // get the list of variables users have overridden
  1156. hr = XmlSelectNodes(pixdUnattend, L"/Options/Option", &pNodes);
  1157. if (S_FALSE == hr) {
  1158. ExitFunction1(hr = S_OK);
  1159. }
  1160. BalExitOnFailure(hr, "Failed to select option nodes.");
  1161. hr = pNodes->get_length((long*)&cNodes);
  1162. BalExitOnFailure(hr, "Failed to get option node count.");
  1163. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Reading settings from %ls", sczUnattendXmlPath);
  1164. for (DWORD i = 0; i < cNodes; ++i) {
  1165. hr = XmlNextElement(pNodes, &pNode, nullptr);
  1166. BalExitOnFailure(hr, "Failed to get next node.");
  1167. // @Name
  1168. hr = XmlGetAttributeEx(pNode, L"Name", &scz);
  1169. BalExitOnFailure(hr, "Failed to get @Name.");
  1170. tryConvert = TRUE;
  1171. hr = XmlGetAttribute(pNode, L"Value", &bstrValue);
  1172. if (FAILED(hr) || !bstrValue || !*bstrValue) {
  1173. hr = XmlGetText(pNode, &bstrValue);
  1174. tryConvert = FALSE;
  1175. }
  1176. BalExitOnFailure(hr, "Failed to get @Value.");
  1177. if (tryConvert &&
  1178. CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, bstrValue, -1, L"yes", -1)) {
  1179. _engine->SetVariableNumeric(scz, 1);
  1180. } else if (tryConvert &&
  1181. CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, bstrValue, -1, L"no", -1)) {
  1182. _engine->SetVariableNumeric(scz, 0);
  1183. } else if (tryConvert && ::StrToIntExW(bstrValue, STIF_DEFAULT, &iValue)) {
  1184. _engine->SetVariableNumeric(scz, iValue);
  1185. } else {
  1186. _engine->SetVariableString(scz, bstrValue);
  1187. }
  1188. ReleaseNullBSTR(bstrValue);
  1189. ReleaseNullStr(scz);
  1190. ReleaseNullObject(pNode);
  1191. }
  1192. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Finished reading from %ls", sczUnattendXmlPath);
  1193. LExit:
  1194. ReleaseObject(pNode);
  1195. ReleaseObject(pNodes);
  1196. ReleaseObject(pixdUnattend);
  1197. ReleaseStr(sczUnattendXmlPath);
  1198. return hr;
  1199. }
  1200. //
  1201. // InitializeData - initializes all the package information.
  1202. //
  1203. HRESULT InitializeData() {
  1204. HRESULT hr = S_OK;
  1205. LPWSTR sczModulePath = nullptr;
  1206. IXMLDOMDocument *pixdManifest = nullptr;
  1207. hr = BalManifestLoad(_hModule, &pixdManifest);
  1208. BalExitOnFailure(hr, "Failed to load bootstrapper application manifest.");
  1209. hr = ParseOverridableVariablesFromXml(pixdManifest);
  1210. BalExitOnFailure(hr, "Failed to read overridable variables.");
  1211. hr = ParseVariablesFromUnattendXml();
  1212. ExitOnFailure(hr, "Failed to read unattend.ini file.");
  1213. hr = ProcessCommandLine(&_language);
  1214. ExitOnFailure(hr, "Unknown commandline parameters.");
  1215. hr = PathRelativeToModule(&sczModulePath, nullptr, _hModule);
  1216. BalExitOnFailure(hr, "Failed to get module path.");
  1217. hr = LoadLocalization(sczModulePath, _language);
  1218. ExitOnFailure(hr, "Failed to load localization.");
  1219. hr = LoadTheme(sczModulePath, _language);
  1220. ExitOnFailure(hr, "Failed to load theme.");
  1221. hr = BalInfoParseFromXml(&_bundle, pixdManifest);
  1222. BalExitOnFailure(hr, "Failed to load bundle information.");
  1223. hr = BalConditionsParseFromXml(&_conditions, pixdManifest, _wixLoc);
  1224. BalExitOnFailure(hr, "Failed to load conditions from XML.");
  1225. hr = LoadBootstrapperBAFunctions();
  1226. BalExitOnFailure(hr, "Failed to load bootstrapper functions.");
  1227. hr = UpdateUIStrings(_command.action);
  1228. BalExitOnFailure(hr, "Failed to load UI strings.");
  1229. if (_command.action == BOOTSTRAPPER_ACTION_MODIFY) {
  1230. LoadOptionalFeatureStates(_engine);
  1231. }
  1232. GetBundleFileVersion();
  1233. // don't fail if we couldn't get the version info; best-effort only
  1234. LExit:
  1235. ReleaseObject(pixdManifest);
  1236. ReleaseStr(sczModulePath);
  1237. return hr;
  1238. }
  1239. //
  1240. // ProcessCommandLine - process the provided command line arguments.
  1241. //
  1242. HRESULT ProcessCommandLine(__inout LPWSTR* psczLanguage) {
  1243. HRESULT hr = S_OK;
  1244. int argc = 0;
  1245. LPWSTR* argv = nullptr;
  1246. LPWSTR sczVariableName = nullptr;
  1247. LPWSTR sczVariableValue = nullptr;
  1248. if (_command.wzCommandLine && *_command.wzCommandLine) {
  1249. argv = ::CommandLineToArgvW(_command.wzCommandLine, &argc);
  1250. ExitOnNullWithLastError(argv, hr, "Failed to get command line.");
  1251. for (int i = 0; i < argc; ++i) {
  1252. if (argv[i][0] == L'-' || argv[i][0] == L'/') {
  1253. if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, L"lang", -1)) {
  1254. if (i + 1 >= argc) {
  1255. hr = E_INVALIDARG;
  1256. BalExitOnFailure(hr, "Must specify a language.");
  1257. }
  1258. ++i;
  1259. hr = StrAllocString(psczLanguage, &argv[i][0], 0);
  1260. BalExitOnFailure(hr, "Failed to copy language.");
  1261. } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, L"simple", -1)) {
  1262. _engine->SetVariableNumeric(L"SimpleInstall", 1);
  1263. }
  1264. } else if (_overridableVariables) {
  1265. int value;
  1266. const wchar_t* pwc = wcschr(argv[i], L'=');
  1267. if (pwc) {
  1268. hr = StrAllocString(&sczVariableName, argv[i], pwc - argv[i]);
  1269. BalExitOnFailure(hr, "Failed to copy variable name.");
  1270. hr = DictKeyExists(_overridableVariables, sczVariableName);
  1271. if (E_NOTFOUND == hr) {
  1272. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Ignoring attempt to set non-overridable variable: '%ls'.", sczVariableName);
  1273. hr = S_OK;
  1274. continue;
  1275. }
  1276. ExitOnFailure(hr, "Failed to check the dictionary of overridable variables.");
  1277. hr = StrAllocString(&sczVariableValue, ++pwc, 0);
  1278. BalExitOnFailure(hr, "Failed to copy variable value.");
  1279. if (::StrToIntEx(sczVariableValue, STIF_DEFAULT, &value)) {
  1280. hr = _engine->SetVariableNumeric(sczVariableName, value);
  1281. } else {
  1282. hr = _engine->SetVariableString(sczVariableName, sczVariableValue);
  1283. }
  1284. BalExitOnFailure(hr, "Failed to set variable.");
  1285. } else {
  1286. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Ignoring unknown argument: %ls", argv[i]);
  1287. }
  1288. }
  1289. }
  1290. }
  1291. LExit:
  1292. if (argv) {
  1293. ::LocalFree(argv);
  1294. }
  1295. ReleaseStr(sczVariableName);
  1296. ReleaseStr(sczVariableValue);
  1297. return hr;
  1298. }
  1299. HRESULT LoadLocalization(__in_z LPCWSTR wzModulePath, __in_z_opt LPCWSTR wzLanguage) {
  1300. HRESULT hr = S_OK;
  1301. LPWSTR sczLocPath = nullptr;
  1302. LPCWSTR wzLocFileName = L"Default.wxl";
  1303. hr = LocProbeForFile(wzModulePath, wzLocFileName, wzLanguage, &sczLocPath);
  1304. BalExitOnFailure2(hr, "Failed to probe for loc file: %ls in path: %ls", wzLocFileName, wzModulePath);
  1305. hr = LocLoadFromFile(sczLocPath, &_wixLoc);
  1306. BalExitOnFailure1(hr, "Failed to load loc file from path: %ls", sczLocPath);
  1307. if (WIX_LOCALIZATION_LANGUAGE_NOT_SET != _wixLoc->dwLangId) {
  1308. ::SetThreadLocale(_wixLoc->dwLangId);
  1309. }
  1310. hr = StrAllocString(&_confirmCloseMessage, L"#(loc.ConfirmCancelMessage)", 0);
  1311. ExitOnFailure(hr, "Failed to initialize confirm message loc identifier.");
  1312. hr = LocLocalizeString(_wixLoc, &_confirmCloseMessage);
  1313. BalExitOnFailure1(hr, "Failed to localize confirm close message: %ls", _confirmCloseMessage);
  1314. LExit:
  1315. ReleaseStr(sczLocPath);
  1316. return hr;
  1317. }
  1318. HRESULT LoadTheme(__in_z LPCWSTR wzModulePath, __in_z_opt LPCWSTR wzLanguage) {
  1319. HRESULT hr = S_OK;
  1320. LPWSTR sczThemePath = nullptr;
  1321. LPCWSTR wzThemeFileName = L"Default.thm";
  1322. LPWSTR sczCaption = nullptr;
  1323. hr = LocProbeForFile(wzModulePath, wzThemeFileName, wzLanguage, &sczThemePath);
  1324. BalExitOnFailure2(hr, "Failed to probe for theme file: %ls in path: %ls", wzThemeFileName, wzModulePath);
  1325. hr = ThemeLoadFromFile(sczThemePath, &_theme);
  1326. BalExitOnFailure1(hr, "Failed to load theme from path: %ls", sczThemePath);
  1327. hr = ThemeLocalize(_theme, _wixLoc);
  1328. BalExitOnFailure1(hr, "Failed to localize theme: %ls", sczThemePath);
  1329. // Update the caption if there are any formatted strings in it.
  1330. // If the wix developer is showing a hidden variable in the UI, then
  1331. // obviously they don't care about keeping it safe so don't go down the
  1332. // rabbit hole of making sure that this is securely freed.
  1333. hr = BalFormatString(_theme->sczCaption, &sczCaption);
  1334. if (SUCCEEDED(hr)) {
  1335. ThemeUpdateCaption(_theme, sczCaption);
  1336. }
  1337. LExit:
  1338. ReleaseStr(sczCaption);
  1339. ReleaseStr(sczThemePath);
  1340. return hr;
  1341. }
  1342. HRESULT ParseOverridableVariablesFromXml(__in IXMLDOMDocument* pixdManifest) {
  1343. HRESULT hr = S_OK;
  1344. IXMLDOMNode* pNode = nullptr;
  1345. IXMLDOMNodeList* pNodes = nullptr;
  1346. DWORD cNodes = 0;
  1347. LPWSTR scz = nullptr;
  1348. BOOL hidden = FALSE;
  1349. // get the list of variables users can override on the command line
  1350. hr = XmlSelectNodes(pixdManifest, L"/BootstrapperApplicationData/WixStdbaOverridableVariable", &pNodes);
  1351. if (S_FALSE == hr) {
  1352. ExitFunction1(hr = S_OK);
  1353. }
  1354. ExitOnFailure(hr, "Failed to select overridable variable nodes.");
  1355. hr = pNodes->get_length((long*)&cNodes);
  1356. ExitOnFailure(hr, "Failed to get overridable variable node count.");
  1357. if (cNodes) {
  1358. hr = DictCreateStringList(&_overridableVariables, 32, DICT_FLAG_NONE);
  1359. ExitOnFailure(hr, "Failed to create the string dictionary.");
  1360. for (DWORD i = 0; i < cNodes; ++i) {
  1361. hr = XmlNextElement(pNodes, &pNode, nullptr);
  1362. ExitOnFailure(hr, "Failed to get next node.");
  1363. // @Name
  1364. hr = XmlGetAttributeEx(pNode, L"Name", &scz);
  1365. ExitOnFailure(hr, "Failed to get @Name.");
  1366. hr = XmlGetYesNoAttribute(pNode, L"Hidden", &hidden);
  1367. if (!hidden) {
  1368. hr = DictAddKey(_overridableVariables, scz);
  1369. ExitOnFailure1(hr, "Failed to add \"%ls\" to the string dictionary.", scz);
  1370. }
  1371. // prepare next iteration
  1372. ReleaseNullObject(pNode);
  1373. }
  1374. }
  1375. LExit:
  1376. ReleaseObject(pNode);
  1377. ReleaseObject(pNodes);
  1378. ReleaseStr(scz);
  1379. return hr;
  1380. }
  1381. //
  1382. // Get the file version of the bootstrapper and record in bootstrapper log file
  1383. //
  1384. HRESULT GetBundleFileVersion() {
  1385. HRESULT hr = S_OK;
  1386. ULARGE_INTEGER uliVersion = { };
  1387. LPWSTR sczCurrentPath = nullptr;
  1388. hr = PathForCurrentProcess(&sczCurrentPath, nullptr);
  1389. BalExitOnFailure(hr, "Failed to get bundle path.");
  1390. hr = FileVersion(sczCurrentPath, &uliVersion.HighPart, &uliVersion.LowPart);
  1391. BalExitOnFailure(hr, "Failed to get bundle file version.");
  1392. hr = _engine->SetVariableVersion(PYBA_VARIABLE_BUNDLE_FILE_VERSION, uliVersion.QuadPart);
  1393. BalExitOnFailure(hr, "Failed to set WixBundleFileVersion variable.");
  1394. LExit:
  1395. ReleaseStr(sczCurrentPath);
  1396. return hr;
  1397. }
  1398. //
  1399. // CreateMainWindow - creates the main install window.
  1400. //
  1401. HRESULT CreateMainWindow() {
  1402. HRESULT hr = S_OK;
  1403. HICON hIcon = reinterpret_cast<HICON>(_theme->hIcon);
  1404. WNDCLASSW wc = { };
  1405. DWORD dwWindowStyle = 0;
  1406. int x = CW_USEDEFAULT;
  1407. int y = CW_USEDEFAULT;
  1408. POINT ptCursor = { };
  1409. HMONITOR hMonitor = nullptr;
  1410. MONITORINFO mi = { };
  1411. COLORREF fg, bg;
  1412. HBRUSH bgBrush;
  1413. // If the theme did not provide an icon, try using the icon from the bundle engine.
  1414. if (!hIcon) {
  1415. HMODULE hBootstrapperEngine = ::GetModuleHandleW(nullptr);
  1416. if (hBootstrapperEngine) {
  1417. hIcon = ::LoadIconW(hBootstrapperEngine, MAKEINTRESOURCEW(1));
  1418. }
  1419. }
  1420. fg = RGB(0, 0, 0);
  1421. bg = RGB(255, 255, 255);
  1422. bgBrush = (HBRUSH)(COLOR_WINDOW+1);
  1423. if (_theme->dwFontId < _theme->cFonts) {
  1424. THEME_FONT *font = &_theme->rgFonts[_theme->dwFontId];
  1425. fg = font->crForeground;
  1426. bg = font->crBackground;
  1427. bgBrush = font->hBackground;
  1428. RemapColor(&fg, &bg, &bgBrush);
  1429. }
  1430. // Register the window class and create the window.
  1431. wc.lpfnWndProc = PythonBootstrapperApplication::WndProc;
  1432. wc.hInstance = _hModule;
  1433. wc.hIcon = hIcon;
  1434. wc.hCursor = ::LoadCursorW(nullptr, (LPCWSTR)IDC_ARROW);
  1435. wc.hbrBackground = bgBrush;
  1436. wc.lpszMenuName = nullptr;
  1437. wc.lpszClassName = PYBA_WINDOW_CLASS;
  1438. if (!::RegisterClassW(&wc)) {
  1439. ExitWithLastError(hr, "Failed to register window.");
  1440. }
  1441. _registered = TRUE;
  1442. // Calculate the window style based on the theme style and command display value.
  1443. dwWindowStyle = _theme->dwStyle;
  1444. if (BOOTSTRAPPER_DISPLAY_NONE >= _command.display) {
  1445. dwWindowStyle &= ~WS_VISIBLE;
  1446. }
  1447. // Don't show the window if there is a splash screen (it will be made visible when the splash screen is hidden)
  1448. if (::IsWindow(_command.hwndSplashScreen)) {
  1449. dwWindowStyle &= ~WS_VISIBLE;
  1450. }
  1451. // Center the window on the monitor with the mouse.
  1452. if (::GetCursorPos(&ptCursor)) {
  1453. hMonitor = ::MonitorFromPoint(ptCursor, MONITOR_DEFAULTTONEAREST);
  1454. if (hMonitor) {
  1455. mi.cbSize = sizeof(mi);
  1456. if (::GetMonitorInfoW(hMonitor, &mi)) {
  1457. x = mi.rcWork.left + (mi.rcWork.right - mi.rcWork.left - _theme->nWidth) / 2;
  1458. y = mi.rcWork.top + (mi.rcWork.bottom - mi.rcWork.top - _theme->nHeight) / 2;
  1459. }
  1460. }
  1461. }
  1462. _hWnd = ::CreateWindowExW(
  1463. 0,
  1464. wc.lpszClassName,
  1465. _theme->sczCaption,
  1466. dwWindowStyle,
  1467. x,
  1468. y,
  1469. _theme->nWidth,
  1470. _theme->nHeight,
  1471. HWND_DESKTOP,
  1472. nullptr,
  1473. _hModule,
  1474. this
  1475. );
  1476. ExitOnNullWithLastError(_hWnd, hr, "Failed to create window.");
  1477. hr = S_OK;
  1478. LExit:
  1479. return hr;
  1480. }
  1481. //
  1482. // InitializeTaskbarButton - initializes taskbar button for progress.
  1483. //
  1484. void InitializeTaskbarButton() {
  1485. HRESULT hr = S_OK;
  1486. hr = ::CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_ALL, __uuidof(ITaskbarList3), reinterpret_cast<LPVOID*>(&_taskbarList));
  1487. if (REGDB_E_CLASSNOTREG == hr) {
  1488. // not supported before Windows 7
  1489. ExitFunction1(hr = S_OK);
  1490. }
  1491. BalExitOnFailure(hr, "Failed to create ITaskbarList3. Continuing.");
  1492. _taskbarButtonCreatedMessage = ::RegisterWindowMessageW(L"TaskbarButtonCreated");
  1493. BalExitOnNullWithLastError(_taskbarButtonCreatedMessage, hr, "Failed to get TaskbarButtonCreated message. Continuing.");
  1494. LExit:
  1495. return;
  1496. }
  1497. //
  1498. // DestroyMainWindow - clean up all the window registration.
  1499. //
  1500. void DestroyMainWindow() {
  1501. if (::IsWindow(_hWnd)) {
  1502. ::DestroyWindow(_hWnd);
  1503. _hWnd = nullptr;
  1504. _taskbarButtonOK = FALSE;
  1505. }
  1506. if (_registered) {
  1507. ::UnregisterClassW(PYBA_WINDOW_CLASS, _hModule);
  1508. _registered = FALSE;
  1509. }
  1510. }
  1511. //
  1512. // WndProc - standard windows message handler.
  1513. //
  1514. static LRESULT CALLBACK WndProc(
  1515. __in HWND hWnd,
  1516. __in UINT uMsg,
  1517. __in WPARAM wParam,
  1518. __in LPARAM lParam
  1519. ) {
  1520. #pragma warning(suppress:4312)
  1521. auto pBA = reinterpret_cast<PythonBootstrapperApplication*>(::GetWindowLongPtrW(hWnd, GWLP_USERDATA));
  1522. switch (uMsg) {
  1523. case WM_NCCREATE: {
  1524. LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam);
  1525. pBA = reinterpret_cast<PythonBootstrapperApplication*>(lpcs->lpCreateParams);
  1526. #pragma warning(suppress:4244)
  1527. ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pBA));
  1528. break;
  1529. }
  1530. case WM_NCDESTROY: {
  1531. LRESULT lres = ThemeDefWindowProc(pBA ? pBA->_theme : nullptr, hWnd, uMsg, wParam, lParam);
  1532. ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, 0);
  1533. return lres;
  1534. }
  1535. case WM_CREATE:
  1536. if (!pBA->OnCreate(hWnd)) {
  1537. return -1;
  1538. }
  1539. break;
  1540. case WM_QUERYENDSESSION:
  1541. return IDCANCEL != pBA->OnSystemShutdown(static_cast<DWORD>(lParam), IDCANCEL);
  1542. case WM_CLOSE:
  1543. // If the user chose not to close, do *not* let the default window proc handle the message.
  1544. if (!pBA->OnClose()) {
  1545. return 0;
  1546. }
  1547. break;
  1548. case WM_DESTROY:
  1549. ::PostQuitMessage(0);
  1550. break;
  1551. case WM_PAINT: __fallthrough;
  1552. case WM_ERASEBKGND:
  1553. if (pBA && pBA->_suppressPaint) {
  1554. return TRUE;
  1555. }
  1556. break;
  1557. case WM_PYBA_SHOW_HELP:
  1558. pBA->OnShowHelp();
  1559. return 0;
  1560. case WM_PYBA_DETECT_PACKAGES:
  1561. pBA->OnDetect();
  1562. return 0;
  1563. case WM_PYBA_PLAN_PACKAGES:
  1564. pBA->OnPlan(static_cast<BOOTSTRAPPER_ACTION>(lParam));
  1565. return 0;
  1566. case WM_PYBA_APPLY_PACKAGES:
  1567. pBA->OnApply();
  1568. return 0;
  1569. case WM_PYBA_CHANGE_STATE:
  1570. pBA->OnChangeState(static_cast<PYBA_STATE>(lParam));
  1571. return 0;
  1572. case WM_PYBA_SHOW_FAILURE:
  1573. pBA->OnShowFailure();
  1574. return 0;
  1575. case WM_COMMAND:
  1576. switch (LOWORD(wParam)) {
  1577. // Customize commands
  1578. // Success/failure commands
  1579. case ID_SUCCESS_RESTART_BUTTON: __fallthrough;
  1580. case ID_FAILURE_RESTART_BUTTON:
  1581. pBA->OnClickRestartButton();
  1582. return 0;
  1583. case IDCANCEL: __fallthrough;
  1584. case ID_INSTALL_CANCEL_BUTTON: __fallthrough;
  1585. case ID_CUSTOM1_CANCEL_BUTTON: __fallthrough;
  1586. case ID_CUSTOM2_CANCEL_BUTTON: __fallthrough;
  1587. case ID_MODIFY_CANCEL_BUTTON: __fallthrough;
  1588. case ID_PROGRESS_CANCEL_BUTTON: __fallthrough;
  1589. case ID_SUCCESS_CANCEL_BUTTON: __fallthrough;
  1590. case ID_FAILURE_CANCEL_BUTTON: __fallthrough;
  1591. case ID_CLOSE_BUTTON:
  1592. pBA->OnCommand(ID_CLOSE_BUTTON);
  1593. return 0;
  1594. default:
  1595. pBA->OnCommand((CONTROL_ID)LOWORD(wParam));
  1596. }
  1597. break;
  1598. case WM_NOTIFY:
  1599. if (lParam) {
  1600. LPNMHDR pnmhdr = reinterpret_cast<LPNMHDR>(lParam);
  1601. switch (pnmhdr->code) {
  1602. case NM_CLICK: __fallthrough;
  1603. case NM_RETURN:
  1604. switch (static_cast<DWORD>(pnmhdr->idFrom)) {
  1605. case ID_FAILURE_LOGFILE_LINK:
  1606. pBA->OnClickLogFileLink();
  1607. return 1;
  1608. }
  1609. }
  1610. }
  1611. break;
  1612. case WM_CTLCOLORSTATIC:
  1613. case WM_CTLCOLORBTN:
  1614. if (pBA) {
  1615. HBRUSH brush = nullptr;
  1616. if (pBA->SetControlColor((HWND)lParam, (HDC)wParam, &brush)) {
  1617. return (LRESULT)brush;
  1618. }
  1619. }
  1620. break;
  1621. }
  1622. if (pBA && pBA->_taskbarList && uMsg == pBA->_taskbarButtonCreatedMessage) {
  1623. pBA->_taskbarButtonOK = TRUE;
  1624. return 0;
  1625. }
  1626. return ThemeDefWindowProc(pBA ? pBA->_theme : nullptr, hWnd, uMsg, wParam, lParam);
  1627. }
  1628. //
  1629. // OnCreate - finishes loading the theme.
  1630. //
  1631. BOOL OnCreate(__in HWND hWnd) {
  1632. HRESULT hr = S_OK;
  1633. hr = ThemeLoadControls(_theme, hWnd, CONTROL_ID_NAMES, countof(CONTROL_ID_NAMES));
  1634. BalExitOnFailure(hr, "Failed to load theme controls.");
  1635. C_ASSERT(COUNT_PAGE == countof(PAGE_NAMES));
  1636. C_ASSERT(countof(_pageIds) == countof(PAGE_NAMES));
  1637. ThemeGetPageIds(_theme, PAGE_NAMES, _pageIds, countof(_pageIds));
  1638. // Initialize the text on all "application" (non-page) controls.
  1639. for (DWORD i = 0; i < _theme->cControls; ++i) {
  1640. THEME_CONTROL* pControl = _theme->rgControls + i;
  1641. LPWSTR text = nullptr;
  1642. if (!pControl->wPageId && pControl->sczText && *pControl->sczText) {
  1643. HRESULT hrFormat;
  1644. // If the wix developer is showing a hidden variable in the UI,
  1645. // then obviously they don't care about keeping it safe so don't
  1646. // go down the rabbit hole of making sure that this is securely
  1647. // freed.
  1648. hrFormat = BalFormatString(pControl->sczText, &text);
  1649. if (SUCCEEDED(hrFormat)) {
  1650. ThemeSetTextControl(_theme, pControl->wId, text);
  1651. ReleaseStr(text);
  1652. }
  1653. }
  1654. }
  1655. LExit:
  1656. return SUCCEEDED(hr);
  1657. }
  1658. void RemapColor(COLORREF *fg, COLORREF *bg, HBRUSH *bgBrush) {
  1659. if (*fg == RGB(0, 0, 0)) {
  1660. *fg = GetSysColor(COLOR_WINDOWTEXT);
  1661. } else if (*fg == RGB(128, 128, 128)) {
  1662. *fg = GetSysColor(COLOR_GRAYTEXT);
  1663. }
  1664. if (*bgBrush && *bg == RGB(255, 255, 255)) {
  1665. *bg = GetSysColor(COLOR_WINDOW);
  1666. *bgBrush = GetSysColorBrush(COLOR_WINDOW);
  1667. }
  1668. }
  1669. BOOL SetControlColor(HWND hWnd, HDC hDC, HBRUSH *brush) {
  1670. for (int i = 0; i < _theme->cControls; ++i) {
  1671. if (_theme->rgControls[i].hWnd != hWnd) {
  1672. continue;
  1673. }
  1674. DWORD fontId = _theme->rgControls[i].dwFontId;
  1675. if (fontId > _theme->cFonts) {
  1676. fontId = 0;
  1677. }
  1678. THEME_FONT *fnt = &_theme->rgFonts[fontId];
  1679. COLORREF fg = fnt->crForeground, bg = fnt->crBackground;
  1680. *brush = fnt->hBackground;
  1681. RemapColor(&fg, &bg, brush);
  1682. ::SetTextColor(hDC, fg);
  1683. ::SetBkColor(hDC, bg);
  1684. return TRUE;
  1685. }
  1686. return FALSE;
  1687. }
  1688. //
  1689. // OnShowFailure - display the failure page.
  1690. //
  1691. void OnShowFailure() {
  1692. SetState(PYBA_STATE_FAILED, S_OK);
  1693. // If the UI should be visible, display it now and hide the splash screen
  1694. if (BOOTSTRAPPER_DISPLAY_NONE < _command.display) {
  1695. ::ShowWindow(_theme->hwndParent, SW_SHOW);
  1696. }
  1697. _engine->CloseSplashScreen();
  1698. return;
  1699. }
  1700. //
  1701. // OnShowHelp - display the help page.
  1702. //
  1703. void OnShowHelp() {
  1704. SetState(PYBA_STATE_HELP, S_OK);
  1705. // If the UI should be visible, display it now and hide the splash screen
  1706. if (BOOTSTRAPPER_DISPLAY_NONE < _command.display) {
  1707. ::ShowWindow(_theme->hwndParent, SW_SHOW);
  1708. }
  1709. _engine->CloseSplashScreen();
  1710. return;
  1711. }
  1712. //
  1713. // OnDetect - start the processing of packages.
  1714. //
  1715. void OnDetect() {
  1716. HRESULT hr = S_OK;
  1717. if (_baFunction) {
  1718. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running detect BA function");
  1719. hr = _baFunction->OnDetect();
  1720. BalExitOnFailure(hr, "Failed calling detect BA function.");
  1721. }
  1722. SetState(PYBA_STATE_DETECTING, hr);
  1723. // If the UI should be visible, display it now and hide the splash screen
  1724. if (BOOTSTRAPPER_DISPLAY_NONE < _command.display) {
  1725. ::ShowWindow(_theme->hwndParent, SW_SHOW);
  1726. }
  1727. _engine->CloseSplashScreen();
  1728. // Tell the core we're ready for the packages to be processed now.
  1729. hr = _engine->Detect();
  1730. BalExitOnFailure(hr, "Failed to start detecting chain.");
  1731. LExit:
  1732. if (FAILED(hr)) {
  1733. SetState(PYBA_STATE_DETECTING, hr);
  1734. }
  1735. return;
  1736. }
  1737. HRESULT UpdateUIStrings(__in BOOTSTRAPPER_ACTION action) {
  1738. HRESULT hr = S_OK;
  1739. LPCWSTR likeInstalling = nullptr;
  1740. LPCWSTR likeInstallation = nullptr;
  1741. switch (action) {
  1742. case BOOTSTRAPPER_ACTION_INSTALL:
  1743. likeInstalling = L"Installing";
  1744. likeInstallation = L"Installation";
  1745. break;
  1746. case BOOTSTRAPPER_ACTION_MODIFY:
  1747. // For modify, we actually want to pass INSTALL
  1748. action = BOOTSTRAPPER_ACTION_INSTALL;
  1749. likeInstalling = L"Modifying";
  1750. likeInstallation = L"Modification";
  1751. break;
  1752. case BOOTSTRAPPER_ACTION_REPAIR:
  1753. likeInstalling = L"Repairing";
  1754. likeInstallation = L"Repair";
  1755. break;
  1756. case BOOTSTRAPPER_ACTION_UNINSTALL:
  1757. likeInstalling = L"Uninstalling";
  1758. likeInstallation = L"Uninstallation";
  1759. break;
  1760. }
  1761. if (likeInstalling) {
  1762. LPWSTR locName = nullptr;
  1763. LOC_STRING *locText = nullptr;
  1764. hr = StrAllocFormatted(&locName, L"#(loc.%ls)", likeInstalling);
  1765. if (SUCCEEDED(hr)) {
  1766. hr = LocGetString(_wixLoc, locName, &locText);
  1767. ReleaseStr(locName);
  1768. }
  1769. _engine->SetVariableString(
  1770. L"ActionLikeInstalling",
  1771. SUCCEEDED(hr) && locText ? locText->wzText : likeInstalling
  1772. );
  1773. }
  1774. if (likeInstallation) {
  1775. LPWSTR locName = nullptr;
  1776. LOC_STRING *locText = nullptr;
  1777. hr = StrAllocFormatted(&locName, L"#(loc.%ls)", likeInstallation);
  1778. if (SUCCEEDED(hr)) {
  1779. hr = LocGetString(_wixLoc, locName, &locText);
  1780. ReleaseStr(locName);
  1781. }
  1782. _engine->SetVariableString(
  1783. L"ActionLikeInstallation",
  1784. SUCCEEDED(hr) && locText ? locText->wzText : likeInstallation
  1785. );
  1786. }
  1787. return hr;
  1788. }
  1789. //
  1790. // OnPlan - plan the detected changes.
  1791. //
  1792. void OnPlan(__in BOOTSTRAPPER_ACTION action) {
  1793. HRESULT hr = S_OK;
  1794. _plannedAction = action;
  1795. hr = UpdateUIStrings(action);
  1796. BalExitOnFailure(hr, "Failed to update strings");
  1797. // If we are going to apply a downgrade, bail.
  1798. if (_downgradingOtherVersion && BOOTSTRAPPER_ACTION_UNINSTALL < action) {
  1799. if (_suppressDowngradeFailure) {
  1800. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "A newer version of this product is installed but downgrade failure has been suppressed; continuing...");
  1801. } else {
  1802. hr = HRESULT_FROM_WIN32(ERROR_PRODUCT_VERSION);
  1803. BalExitOnFailure(hr, "Cannot install a product when a newer version is installed.");
  1804. }
  1805. }
  1806. SetState(PYBA_STATE_PLANNING, hr);
  1807. if (_baFunction) {
  1808. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running plan BA function");
  1809. _baFunction->OnPlan();
  1810. }
  1811. hr = _engine->Plan(action);
  1812. BalExitOnFailure(hr, "Failed to start planning packages.");
  1813. LExit:
  1814. if (FAILED(hr)) {
  1815. SetState(PYBA_STATE_PLANNING, hr);
  1816. }
  1817. return;
  1818. }
  1819. //
  1820. // OnApply - apply the packages.
  1821. //
  1822. void OnApply() {
  1823. HRESULT hr = S_OK;
  1824. SetState(PYBA_STATE_APPLYING, hr);
  1825. SetProgressState(hr);
  1826. SetTaskbarButtonProgress(0);
  1827. hr = _engine->Apply(_hWnd);
  1828. BalExitOnFailure(hr, "Failed to start applying packages.");
  1829. ThemeControlEnable(_theme, ID_PROGRESS_CANCEL_BUTTON, TRUE); // ensure the cancel button is enabled before starting.
  1830. LExit:
  1831. if (FAILED(hr)) {
  1832. SetState(PYBA_STATE_APPLYING, hr);
  1833. }
  1834. return;
  1835. }
  1836. //
  1837. // OnChangeState - change state.
  1838. //
  1839. void OnChangeState(__in PYBA_STATE state) {
  1840. LPWSTR unformattedText = nullptr;
  1841. _state = state;
  1842. // If our install is at the end (success or failure) and we're not showing full UI
  1843. // then exit (prompt for restart if required).
  1844. if ((PYBA_STATE_APPLIED <= _state && BOOTSTRAPPER_DISPLAY_FULL > _command.display)) {
  1845. // If a restart was required but we were not automatically allowed to
  1846. // accept the reboot then do the prompt.
  1847. if (_restartRequired && !_allowRestart) {
  1848. StrAllocFromError(&unformattedText, HRESULT_FROM_WIN32(ERROR_SUCCESS_REBOOT_REQUIRED), nullptr);
  1849. _allowRestart = IDOK == ::MessageBoxW(
  1850. _hWnd,
  1851. unformattedText ? unformattedText : L"The requested operation is successful. Changes will not be effective until the system is rebooted.",
  1852. _theme->sczCaption,
  1853. MB_ICONEXCLAMATION | MB_OKCANCEL
  1854. );
  1855. }
  1856. // Quietly exit.
  1857. ::PostMessageW(_hWnd, WM_CLOSE, 0, 0);
  1858. } else { // try to change the pages.
  1859. DWORD newPageId = 0;
  1860. DeterminePageId(_state, &newPageId);
  1861. if (_visiblePageId != newPageId) {
  1862. ShowPage(newPageId);
  1863. }
  1864. }
  1865. ReleaseStr(unformattedText);
  1866. }
  1867. //
  1868. // Called before showing a page to handle all controls.
  1869. //
  1870. void ProcessPageControls(THEME_PAGE *pPage) {
  1871. if (!pPage) {
  1872. return;
  1873. }
  1874. for (DWORD i = 0; i < pPage->cControlIndices; ++i) {
  1875. THEME_CONTROL* pControl = _theme->rgControls + pPage->rgdwControlIndices[i];
  1876. BOOL enableControl = TRUE;
  1877. // If this is a named control, try to set its default state.
  1878. if (pControl->sczName && *pControl->sczName) {
  1879. // If this is a checkable control, try to set its default state
  1880. // to the state of a matching named Burn variable.
  1881. if (IsCheckable(pControl)) {
  1882. LONGLONG llValue = 0;
  1883. HRESULT hr = BalGetNumericVariable(pControl->sczName, &llValue);
  1884. // If the control value isn't set then disable it.
  1885. if (!SUCCEEDED(hr)) {
  1886. enableControl = FALSE;
  1887. } else {
  1888. ThemeSendControlMessage(
  1889. _theme,
  1890. pControl->wId,
  1891. BM_SETCHECK,
  1892. SUCCEEDED(hr) && llValue ? BST_CHECKED : BST_UNCHECKED,
  1893. 0
  1894. );
  1895. }
  1896. }
  1897. // Hide or disable controls based on the control name with 'State' appended
  1898. LPWSTR controlName = nullptr;
  1899. HRESULT hr = StrAllocFormatted(&controlName, L"%lsState", pControl->sczName);
  1900. if (SUCCEEDED(hr)) {
  1901. LPWSTR controlState = nullptr;
  1902. hr = BalGetStringVariable(controlName, &controlState);
  1903. if (SUCCEEDED(hr) && controlState && *controlState) {
  1904. if (controlState[0] == '[') {
  1905. LPWSTR formatted = nullptr;
  1906. if (SUCCEEDED(BalFormatString(controlState, &formatted))) {
  1907. StrFree(controlState);
  1908. controlState = formatted;
  1909. }
  1910. }
  1911. if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, controlState, -1, L"disable", -1)) {
  1912. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Disable control %ls", pControl->sczName);
  1913. enableControl = FALSE;
  1914. } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, controlState, -1, L"hide", -1)) {
  1915. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Hide control %ls", pControl->sczName);
  1916. // TODO: This doesn't work
  1917. ThemeShowControl(_theme, pControl->wId, SW_HIDE);
  1918. } else {
  1919. // An explicit state can override the lack of a
  1920. // backing variable.
  1921. enableControl = TRUE;
  1922. }
  1923. }
  1924. StrFree(controlState);
  1925. }
  1926. StrFree(controlName);
  1927. controlName = nullptr;
  1928. // If a command link has a note, then add it.
  1929. if ((pControl->dwStyle & BS_TYPEMASK) == BS_COMMANDLINK ||
  1930. (pControl->dwStyle & BS_TYPEMASK) == BS_DEFCOMMANDLINK) {
  1931. hr = StrAllocFormatted(&controlName, L"#(loc.%lsNote)", pControl->sczName);
  1932. if (SUCCEEDED(hr)) {
  1933. LOC_STRING *locText = nullptr;
  1934. hr = LocGetString(_wixLoc, controlName, &locText);
  1935. if (SUCCEEDED(hr) && locText && locText->wzText && locText->wzText[0]) {
  1936. LPWSTR text = nullptr;
  1937. hr = BalFormatString(locText->wzText, &text);
  1938. if (SUCCEEDED(hr) && text && text[0]) {
  1939. ThemeSendControlMessage(_theme, pControl->wId, BCM_SETNOTE, 0, (LPARAM)text);
  1940. ReleaseStr(text);
  1941. text = nullptr;
  1942. }
  1943. }
  1944. ReleaseStr(controlName);
  1945. controlName = nullptr;
  1946. }
  1947. hr = S_OK;
  1948. }
  1949. }
  1950. ThemeControlEnable(_theme, pControl->wId, enableControl);
  1951. // Format the text in each of the new page's controls
  1952. if (pControl->sczText && *pControl->sczText) {
  1953. // If the wix developer is showing a hidden variable
  1954. // in the UI, then obviously they don't care about
  1955. // keeping it safe so don't go down the rabbit hole
  1956. // of making sure that this is securely freed.
  1957. LPWSTR text = nullptr;
  1958. HRESULT hr = BalFormatString(pControl->sczText, &text);
  1959. if (SUCCEEDED(hr)) {
  1960. ThemeSetTextControl(_theme, pControl->wId, text);
  1961. }
  1962. }
  1963. }
  1964. }
  1965. //
  1966. // OnClose - called when the window is trying to be closed.
  1967. //
  1968. BOOL OnClose() {
  1969. BOOL close = FALSE;
  1970. // If we've already succeeded or failed or showing the help page, just close (prompts are annoying if the bootstrapper is done).
  1971. if (PYBA_STATE_APPLIED <= _state || PYBA_STATE_HELP == _state) {
  1972. close = TRUE;
  1973. } else {
  1974. // prompt the user or force the cancel if there is no UI.
  1975. close = PromptCancel(
  1976. _hWnd,
  1977. BOOTSTRAPPER_DISPLAY_FULL != _command.display,
  1978. _confirmCloseMessage ? _confirmCloseMessage : L"Are you sure you want to cancel?",
  1979. _theme->sczCaption
  1980. );
  1981. }
  1982. // If we're doing progress then we never close, we just cancel to let rollback occur.
  1983. if (PYBA_STATE_APPLYING <= _state && PYBA_STATE_APPLIED > _state) {
  1984. // If we canceled disable cancel button since clicking it again is silly.
  1985. if (close) {
  1986. ThemeControlEnable(_theme, ID_PROGRESS_CANCEL_BUTTON, FALSE);
  1987. }
  1988. close = FALSE;
  1989. }
  1990. return close;
  1991. }
  1992. //
  1993. // OnClickCloseButton - close the application.
  1994. //
  1995. void OnClickCloseButton() {
  1996. ::SendMessageW(_hWnd, WM_CLOSE, 0, 0);
  1997. }
  1998. //
  1999. // OnClickRestartButton - allows the restart and closes the app.
  2000. //
  2001. void OnClickRestartButton() {
  2002. AssertSz(_restartRequired, "Restart must be requested to be able to click on the restart button.");
  2003. _allowRestart = TRUE;
  2004. ::SendMessageW(_hWnd, WM_CLOSE, 0, 0);
  2005. return;
  2006. }
  2007. //
  2008. // OnClickLogFileLink - show the log file.
  2009. //
  2010. void OnClickLogFileLink() {
  2011. HRESULT hr = S_OK;
  2012. LPWSTR sczLogFile = nullptr;
  2013. hr = BalGetStringVariable(_bundle.sczLogVariable, &sczLogFile);
  2014. BalExitOnFailure1(hr, "Failed to get log file variable '%ls'.", _bundle.sczLogVariable);
  2015. hr = ShelExec(L"notepad.exe", sczLogFile, L"open", nullptr, SW_SHOWDEFAULT, _hWnd, nullptr);
  2016. BalExitOnFailure1(hr, "Failed to open log file target: %ls", sczLogFile);
  2017. LExit:
  2018. ReleaseStr(sczLogFile);
  2019. return;
  2020. }
  2021. //
  2022. // SetState
  2023. //
  2024. void SetState(__in PYBA_STATE state, __in HRESULT hrStatus) {
  2025. if (FAILED(hrStatus)) {
  2026. _hrFinal = hrStatus;
  2027. }
  2028. if (FAILED(_hrFinal)) {
  2029. state = PYBA_STATE_FAILED;
  2030. }
  2031. if (_state != state) {
  2032. ::PostMessageW(_hWnd, WM_PYBA_CHANGE_STATE, 0, state);
  2033. }
  2034. }
  2035. //
  2036. // GoToPage
  2037. //
  2038. void GoToPage(__in PAGE page) {
  2039. _installPage = page;
  2040. ::PostMessageW(_hWnd, WM_PYBA_CHANGE_STATE, 0, _state);
  2041. }
  2042. void DeterminePageId(__in PYBA_STATE state, __out DWORD* pdwPageId) {
  2043. LONGLONG simple;
  2044. if (BOOTSTRAPPER_DISPLAY_PASSIVE == _command.display) {
  2045. switch (state) {
  2046. case PYBA_STATE_INITIALIZED:
  2047. *pdwPageId = BOOTSTRAPPER_ACTION_HELP == _command.action
  2048. ? _pageIds[PAGE_HELP]
  2049. : _pageIds[PAGE_LOADING];
  2050. break;
  2051. case PYBA_STATE_HELP:
  2052. *pdwPageId = _pageIds[PAGE_HELP];
  2053. break;
  2054. case PYBA_STATE_DETECTING:
  2055. *pdwPageId = _pageIds[PAGE_LOADING]
  2056. ? _pageIds[PAGE_LOADING]
  2057. : _pageIds[PAGE_PROGRESS_PASSIVE]
  2058. ? _pageIds[PAGE_PROGRESS_PASSIVE]
  2059. : _pageIds[PAGE_PROGRESS];
  2060. break;
  2061. case PYBA_STATE_DETECTED: __fallthrough;
  2062. case PYBA_STATE_PLANNING: __fallthrough;
  2063. case PYBA_STATE_PLANNED: __fallthrough;
  2064. case PYBA_STATE_APPLYING: __fallthrough;
  2065. case PYBA_STATE_CACHING: __fallthrough;
  2066. case PYBA_STATE_CACHED: __fallthrough;
  2067. case PYBA_STATE_EXECUTING: __fallthrough;
  2068. case PYBA_STATE_EXECUTED:
  2069. *pdwPageId = _pageIds[PAGE_PROGRESS_PASSIVE]
  2070. ? _pageIds[PAGE_PROGRESS_PASSIVE]
  2071. : _pageIds[PAGE_PROGRESS];
  2072. break;
  2073. default:
  2074. *pdwPageId = 0;
  2075. break;
  2076. }
  2077. } else if (BOOTSTRAPPER_DISPLAY_FULL == _command.display) {
  2078. switch (state) {
  2079. case PYBA_STATE_INITIALIZING:
  2080. *pdwPageId = 0;
  2081. break;
  2082. case PYBA_STATE_INITIALIZED:
  2083. *pdwPageId = BOOTSTRAPPER_ACTION_HELP == _command.action
  2084. ? _pageIds[PAGE_HELP]
  2085. : _pageIds[PAGE_LOADING];
  2086. break;
  2087. case PYBA_STATE_HELP:
  2088. *pdwPageId = _pageIds[PAGE_HELP];
  2089. break;
  2090. case PYBA_STATE_DETECTING:
  2091. *pdwPageId = _pageIds[PAGE_LOADING];
  2092. break;
  2093. case PYBA_STATE_DETECTED:
  2094. if (_installPage == PAGE_LOADING) {
  2095. switch (_command.action) {
  2096. case BOOTSTRAPPER_ACTION_INSTALL:
  2097. if (_upgrading) {
  2098. _installPage = PAGE_UPGRADE;
  2099. } else if (SUCCEEDED(BalGetNumericVariable(L"SimpleInstall", &simple)) && simple) {
  2100. _installPage = PAGE_SIMPLE_INSTALL;
  2101. } else {
  2102. _installPage = PAGE_INSTALL;
  2103. }
  2104. break;
  2105. case BOOTSTRAPPER_ACTION_MODIFY: __fallthrough;
  2106. case BOOTSTRAPPER_ACTION_REPAIR: __fallthrough;
  2107. case BOOTSTRAPPER_ACTION_UNINSTALL:
  2108. _installPage = PAGE_MODIFY;
  2109. break;
  2110. }
  2111. }
  2112. *pdwPageId = _pageIds[_installPage];
  2113. break;
  2114. case PYBA_STATE_PLANNING: __fallthrough;
  2115. case PYBA_STATE_PLANNED: __fallthrough;
  2116. case PYBA_STATE_APPLYING: __fallthrough;
  2117. case PYBA_STATE_CACHING: __fallthrough;
  2118. case PYBA_STATE_CACHED: __fallthrough;
  2119. case PYBA_STATE_EXECUTING: __fallthrough;
  2120. case PYBA_STATE_EXECUTED:
  2121. *pdwPageId = _pageIds[PAGE_PROGRESS];
  2122. break;
  2123. case PYBA_STATE_APPLIED:
  2124. *pdwPageId = _pageIds[PAGE_SUCCESS];
  2125. break;
  2126. case PYBA_STATE_FAILED:
  2127. *pdwPageId = _pageIds[PAGE_FAILURE];
  2128. break;
  2129. }
  2130. }
  2131. }
  2132. BOOL WillElevate() {
  2133. static BAL_CONDITION WILL_ELEVATE_CONDITION = {
  2134. L"not WixBundleElevated and ("
  2135. /*Elevate when installing for all users*/
  2136. L"InstallAllUsers or "
  2137. /*Elevate when installing the launcher for all users and it was not detected*/
  2138. L"(Include_launcher and InstallLauncherAllUsers and not DetectedLauncher)"
  2139. L")",
  2140. L""
  2141. };
  2142. BOOL result;
  2143. return SUCCEEDED(BalConditionEvaluate(&WILL_ELEVATE_CONDITION, _engine, &result, nullptr)) && result;
  2144. }
  2145. BOOL IsCrtInstalled() {
  2146. if (_crtInstalledToken > 0) {
  2147. return TRUE;
  2148. } else if (_crtInstalledToken == 0) {
  2149. return FALSE;
  2150. }
  2151. // Check whether at least CRT v10.0.10137.0 is available.
  2152. // It should only be installed as a Windows Update package, which means
  2153. // we don't need to worry about 32-bit/64-bit.
  2154. LPCWSTR crtFile = L"ucrtbase.dll";
  2155. DWORD cbVer = GetFileVersionInfoSizeW(crtFile, nullptr);
  2156. if (!cbVer) {
  2157. _crtInstalledToken = 0;
  2158. return FALSE;
  2159. }
  2160. void *pData = malloc(cbVer);
  2161. if (!pData) {
  2162. _crtInstalledToken = 0;
  2163. return FALSE;
  2164. }
  2165. if (!GetFileVersionInfoW(crtFile, 0, cbVer, pData)) {
  2166. free(pData);
  2167. _crtInstalledToken = 0;
  2168. return FALSE;
  2169. }
  2170. VS_FIXEDFILEINFO *ffi;
  2171. UINT cb;
  2172. BOOL result = FALSE;
  2173. if (VerQueryValueW(pData, L"\\", (LPVOID*)&ffi, &cb) &&
  2174. ffi->dwFileVersionMS == 0x000A0000 && ffi->dwFileVersionLS >= 0x27990000) {
  2175. result = TRUE;
  2176. }
  2177. free(pData);
  2178. _crtInstalledToken = result ? 1 : 0;
  2179. return result;
  2180. }
  2181. BOOL QueryElevateForCrtInstall() {
  2182. // Called to prompt the user that even though they think they won't need
  2183. // to elevate, they actually will because of the CRT install.
  2184. if (IsCrtInstalled()) {
  2185. // CRT is already installed - no need to prompt
  2186. return TRUE;
  2187. }
  2188. LONGLONG elevated;
  2189. HRESULT hr = BalGetNumericVariable(L"WixBundleElevated", &elevated);
  2190. if (SUCCEEDED(hr) && elevated) {
  2191. // Already elevated - no need to prompt
  2192. return TRUE;
  2193. }
  2194. LOC_STRING *locStr;
  2195. hr = LocGetString(_wixLoc, L"#(loc.ElevateForCRTInstall)", &locStr);
  2196. if (FAILED(hr)) {
  2197. BalLogError(hr, "Failed to get ElevateForCRTInstall string");
  2198. return FALSE;
  2199. }
  2200. return ::MessageBoxW(_hWnd, locStr->wzText, _theme->sczCaption, MB_YESNO) != IDNO;
  2201. }
  2202. HRESULT EvaluateConditions() {
  2203. HRESULT hr = S_OK;
  2204. BOOL result = FALSE;
  2205. for (DWORD i = 0; i < _conditions.cConditions; ++i) {
  2206. BAL_CONDITION* pCondition = _conditions.rgConditions + i;
  2207. hr = BalConditionEvaluate(pCondition, _engine, &result, &_failedMessage);
  2208. BalExitOnFailure(hr, "Failed to evaluate condition.");
  2209. if (!result) {
  2210. // Hope they didn't have hidden variables in their message, because it's going in the log in plaintext.
  2211. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "%ls", _failedMessage);
  2212. hr = E_WIXSTDBA_CONDITION_FAILED;
  2213. // todo: remove in WiX v4, in case people are relying on v3.x logging behavior
  2214. BalExitOnFailure1(hr, "Bundle condition evaluated to false: %ls", pCondition->sczCondition);
  2215. }
  2216. }
  2217. ReleaseNullStrSecure(_failedMessage);
  2218. LExit:
  2219. return hr;
  2220. }
  2221. void SetTaskbarButtonProgress(__in DWORD dwOverallPercentage) {
  2222. HRESULT hr = S_OK;
  2223. if (_taskbarButtonOK) {
  2224. hr = _taskbarList->SetProgressValue(_hWnd, dwOverallPercentage, 100UL);
  2225. BalExitOnFailure1(hr, "Failed to set taskbar button progress to: %d%%.", dwOverallPercentage);
  2226. }
  2227. LExit:
  2228. return;
  2229. }
  2230. void SetTaskbarButtonState(__in TBPFLAG tbpFlags) {
  2231. HRESULT hr = S_OK;
  2232. if (_taskbarButtonOK) {
  2233. hr = _taskbarList->SetProgressState(_hWnd, tbpFlags);
  2234. BalExitOnFailure1(hr, "Failed to set taskbar button state.", tbpFlags);
  2235. }
  2236. LExit:
  2237. return;
  2238. }
  2239. void SetProgressState(__in HRESULT hrStatus) {
  2240. TBPFLAG flag = TBPF_NORMAL;
  2241. if (IsCanceled() || HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT) == hrStatus) {
  2242. flag = TBPF_PAUSED;
  2243. } else if (IsRollingBack() || FAILED(hrStatus)) {
  2244. flag = TBPF_ERROR;
  2245. }
  2246. SetTaskbarButtonState(flag);
  2247. }
  2248. HRESULT LoadBootstrapperBAFunctions() {
  2249. HRESULT hr = S_OK;
  2250. LPWSTR sczBafPath = nullptr;
  2251. hr = PathRelativeToModule(&sczBafPath, L"bafunctions.dll", _hModule);
  2252. BalExitOnFailure(hr, "Failed to get path to BA function DLL.");
  2253. #ifdef DEBUG
  2254. BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "PYBA: LoadBootstrapperBAFunctions() - BA function DLL %ls", sczBafPath);
  2255. #endif
  2256. _hBAFModule = ::LoadLibraryW(sczBafPath);
  2257. if (_hBAFModule) {
  2258. auto pfnBAFunctionCreate = reinterpret_cast<PFN_BOOTSTRAPPER_BA_FUNCTION_CREATE>(::GetProcAddress(_hBAFModule, "CreateBootstrapperBAFunction"));
  2259. BalExitOnNullWithLastError1(pfnBAFunctionCreate, hr, "Failed to get CreateBootstrapperBAFunction entry-point from: %ls", sczBafPath);
  2260. hr = pfnBAFunctionCreate(_engine, _hBAFModule, &_baFunction);
  2261. BalExitOnFailure(hr, "Failed to create BA function.");
  2262. }
  2263. #ifdef DEBUG
  2264. else {
  2265. BalLogError(HRESULT_FROM_WIN32(::GetLastError()), "PYBA: LoadBootstrapperBAFunctions() - Failed to load DLL %ls", sczBafPath);
  2266. }
  2267. #endif
  2268. LExit:
  2269. if (_hBAFModule && !_baFunction) {
  2270. ::FreeLibrary(_hBAFModule);
  2271. _hBAFModule = nullptr;
  2272. }
  2273. ReleaseStr(sczBafPath);
  2274. return hr;
  2275. }
  2276. BOOL IsCheckable(THEME_CONTROL* pControl) {
  2277. if (!pControl->sczName || !pControl->sczName[0]) {
  2278. return FALSE;
  2279. }
  2280. if (pControl->type == THEME_CONTROL_TYPE_CHECKBOX) {
  2281. return TRUE;
  2282. }
  2283. if (pControl->type == THEME_CONTROL_TYPE_BUTTON) {
  2284. if ((pControl->dwStyle & BS_TYPEMASK) == BS_AUTORADIOBUTTON) {
  2285. return TRUE;
  2286. }
  2287. }
  2288. return FALSE;
  2289. }
  2290. void SavePageSettings() {
  2291. DWORD pageId = 0;
  2292. THEME_PAGE* pPage = nullptr;
  2293. DeterminePageId(_state, &pageId);
  2294. pPage = ThemeGetPage(_theme, pageId);
  2295. if (!pPage) {
  2296. return;
  2297. }
  2298. for (DWORD i = 0; i < pPage->cControlIndices; ++i) {
  2299. // Loop through all the checkable controls and set a Burn variable
  2300. // with that name to true or false.
  2301. THEME_CONTROL* pControl = _theme->rgControls + pPage->rgdwControlIndices[i];
  2302. if (IsCheckable(pControl) && ThemeControlEnabled(_theme, pControl->wId)) {
  2303. BOOL checked = ThemeIsControlChecked(_theme, pControl->wId);
  2304. _engine->SetVariableNumeric(pControl->sczName, checked ? 1 : 0);
  2305. }
  2306. // Loop through all the editbox controls with names and set a
  2307. // Burn variable with that name to the contents.
  2308. if (THEME_CONTROL_TYPE_EDITBOX == pControl->type && pControl->sczName && *pControl->sczName) {
  2309. LPWSTR sczValue = nullptr;
  2310. ThemeGetTextControl(_theme, pControl->wId, &sczValue);
  2311. _engine->SetVariableString(pControl->sczName, sczValue);
  2312. }
  2313. }
  2314. }
  2315. static bool IsTargetPlatformx64(__in IBootstrapperEngine* pEngine) {
  2316. WCHAR platform[8];
  2317. DWORD platformLen = 8;
  2318. if (FAILED(pEngine->GetVariableString(L"TargetPlatform", platform, &platformLen))) {
  2319. return S_FALSE;
  2320. }
  2321. return ::CompareStringW(LOCALE_NEUTRAL, 0, platform, -1, L"x64", -1) == CSTR_EQUAL;
  2322. }
  2323. static HRESULT LoadOptionalFeatureStatesFromKey(
  2324. __in IBootstrapperEngine* pEngine,
  2325. __in HKEY hkHive,
  2326. __in LPCWSTR subkey
  2327. ) {
  2328. HKEY hKey;
  2329. LRESULT res;
  2330. if (IsTargetPlatformx64(pEngine)) {
  2331. res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
  2332. } else {
  2333. res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_32KEY, &hKey);
  2334. }
  2335. if (res == ERROR_FILE_NOT_FOUND) {
  2336. return S_FALSE;
  2337. }
  2338. if (res != ERROR_SUCCESS) {
  2339. return HRESULT_FROM_WIN32(res);
  2340. }
  2341. for (auto p = OPTIONAL_FEATURES; p->regName; ++p) {
  2342. res = RegQueryValueExW(hKey, p->regName, nullptr, nullptr, nullptr, nullptr);
  2343. if (res == ERROR_FILE_NOT_FOUND) {
  2344. pEngine->SetVariableNumeric(p->variableName, 0);
  2345. } else if (res == ERROR_SUCCESS) {
  2346. pEngine->SetVariableNumeric(p->variableName, 1);
  2347. } else {
  2348. RegCloseKey(hKey);
  2349. return HRESULT_FROM_WIN32(res);
  2350. }
  2351. }
  2352. RegCloseKey(hKey);
  2353. return S_OK;
  2354. }
  2355. static HRESULT LoadTargetDirFromKey(
  2356. __in IBootstrapperEngine* pEngine,
  2357. __in HKEY hkHive,
  2358. __in LPCWSTR subkey
  2359. ) {
  2360. HKEY hKey;
  2361. LRESULT res;
  2362. DWORD dataType;
  2363. BYTE buffer[1024];
  2364. DWORD bufferLen = sizeof(buffer);
  2365. if (IsTargetPlatformx64(pEngine)) {
  2366. res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
  2367. } else {
  2368. res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_32KEY, &hKey);
  2369. }
  2370. if (res == ERROR_FILE_NOT_FOUND) {
  2371. return S_FALSE;
  2372. }
  2373. if (res != ERROR_SUCCESS) {
  2374. return HRESULT_FROM_WIN32(res);
  2375. }
  2376. res = RegQueryValueExW(hKey, nullptr, nullptr, &dataType, buffer, &bufferLen);
  2377. if (res == ERROR_SUCCESS && dataType == REG_SZ && bufferLen < sizeof(buffer)) {
  2378. pEngine->SetVariableString(L"TargetDir", reinterpret_cast<wchar_t*>(buffer));
  2379. }
  2380. RegCloseKey(hKey);
  2381. return HRESULT_FROM_WIN32(res);
  2382. }
  2383. static HRESULT LoadAssociateFilesStateFromKey(
  2384. __in IBootstrapperEngine* pEngine,
  2385. __in HKEY hkHive
  2386. ) {
  2387. const LPCWSTR subkey = L"Software\\Python\\PyLauncher";
  2388. HKEY hKey;
  2389. LRESULT res;
  2390. HRESULT hr;
  2391. res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_32KEY, &hKey);
  2392. if (res == ERROR_FILE_NOT_FOUND) {
  2393. return S_FALSE;
  2394. }
  2395. if (res != ERROR_SUCCESS) {
  2396. return HRESULT_FROM_WIN32(res);
  2397. }
  2398. res = RegQueryValueExW(hKey, L"AssociateFiles", nullptr, nullptr, nullptr, nullptr);
  2399. if (res == ERROR_FILE_NOT_FOUND) {
  2400. hr = S_FALSE;
  2401. } else if (res == ERROR_SUCCESS) {
  2402. hr = S_OK;
  2403. } else {
  2404. hr = HRESULT_FROM_WIN32(res);
  2405. }
  2406. RegCloseKey(hKey);
  2407. return hr;
  2408. }
  2409. static void LoadOptionalFeatureStates(__in IBootstrapperEngine* pEngine) {
  2410. WCHAR subkeyFmt[256];
  2411. WCHAR subkey[256];
  2412. DWORD subkeyLen;
  2413. HRESULT hr;
  2414. HKEY hkHive;
  2415. // The launcher installation is separate from the Python install, so we
  2416. // check its state later. For now, assume we don't want the launcher or
  2417. // file associations, and if they have already been installed then
  2418. // loading the state will reactivate these settings.
  2419. pEngine->SetVariableNumeric(L"Include_launcher", 0);
  2420. pEngine->SetVariableNumeric(L"AssociateFiles", 0);
  2421. // Get the registry key from the bundle, to save having to duplicate it
  2422. // in multiple places.
  2423. subkeyLen = sizeof(subkeyFmt) / sizeof(subkeyFmt[0]);
  2424. hr = pEngine->GetVariableString(L"OptionalFeaturesRegistryKey", subkeyFmt, &subkeyLen);
  2425. BalExitOnFailure(hr, "Failed to locate registry key");
  2426. subkeyLen = sizeof(subkey) / sizeof(subkey[0]);
  2427. hr = pEngine->FormatString(subkeyFmt, subkey, &subkeyLen);
  2428. BalExitOnFailure1(hr, "Failed to format %ls", subkeyFmt);
  2429. // Check the current user's registry for existing features
  2430. hkHive = HKEY_CURRENT_USER;
  2431. hr = LoadOptionalFeatureStatesFromKey(pEngine, hkHive, subkey);
  2432. BalExitOnFailure1(hr, "Failed to read from HKCU\\%ls", subkey);
  2433. if (hr == S_FALSE) {
  2434. // Now check the local machine registry
  2435. hkHive = HKEY_LOCAL_MACHINE;
  2436. hr = LoadOptionalFeatureStatesFromKey(pEngine, hkHive, subkey);
  2437. BalExitOnFailure1(hr, "Failed to read from HKLM\\%ls", subkey);
  2438. if (hr == S_OK) {
  2439. // Found a system-wide install, so enable these settings.
  2440. pEngine->SetVariableNumeric(L"InstallAllUsers", 1);
  2441. pEngine->SetVariableNumeric(L"CompileAll", 1);
  2442. }
  2443. }
  2444. if (hr == S_OK) {
  2445. // Cannot change InstallAllUsersState when upgrading. While there's
  2446. // no good reason to not allow installing a per-user and an all-user
  2447. // version simultaneously, Burn can't handle the state management
  2448. // and will need to uninstall the old one.
  2449. pEngine->SetVariableString(L"InstallAllUsersState", L"disable");
  2450. // Get the previous install directory. This can be changed by the
  2451. // user.
  2452. subkeyLen = sizeof(subkeyFmt) / sizeof(subkeyFmt[0]);
  2453. hr = pEngine->GetVariableString(L"TargetDirRegistryKey", subkeyFmt, &subkeyLen);
  2454. BalExitOnFailure(hr, "Failed to locate registry key");
  2455. subkeyLen = sizeof(subkey) / sizeof(subkey[0]);
  2456. hr = pEngine->FormatString(subkeyFmt, subkey, &subkeyLen);
  2457. BalExitOnFailure1(hr, "Failed to format %ls", subkeyFmt);
  2458. LoadTargetDirFromKey(pEngine, hkHive, subkey);
  2459. }
  2460. LExit:
  2461. return;
  2462. }
  2463. HRESULT EnsureTargetDir() {
  2464. LONGLONG installAllUsers;
  2465. LPWSTR targetDir = nullptr, defaultDir = nullptr;
  2466. HRESULT hr = BalGetStringVariable(L"TargetDir", &targetDir);
  2467. if (FAILED(hr) || !targetDir || !targetDir[0]) {
  2468. ReleaseStr(targetDir);
  2469. targetDir = nullptr;
  2470. hr = BalGetNumericVariable(L"InstallAllUsers", &installAllUsers);
  2471. ExitOnFailure(hr, L"Failed to get install scope");
  2472. hr = BalGetStringVariable(
  2473. installAllUsers ? L"DefaultAllUsersTargetDir" : L"DefaultJustForMeTargetDir",
  2474. &defaultDir
  2475. );
  2476. BalExitOnFailure(hr, "Failed to get the default install directory");
  2477. if (!defaultDir || !defaultDir[0]) {
  2478. BalLogError(E_INVALIDARG, "Default install directory is blank");
  2479. }
  2480. hr = BalFormatString(defaultDir, &targetDir);
  2481. BalExitOnFailure1(hr, "Failed to format '%ls'", defaultDir);
  2482. hr = _engine->SetVariableString(L"TargetDir", targetDir);
  2483. BalExitOnFailure(hr, "Failed to set install target directory");
  2484. }
  2485. LExit:
  2486. ReleaseStr(defaultDir);
  2487. ReleaseStr(targetDir);
  2488. return hr;
  2489. }
  2490. void ValidateOperatingSystem() {
  2491. LOC_STRING *pLocString = nullptr;
  2492. if (IsWindows7SP1OrGreater()) {
  2493. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Target OS is Windows 7 SP1 or later");
  2494. return;
  2495. } else if (IsWindows7OrGreater()) {
  2496. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows 7 RTM");
  2497. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Service Pack 1 is required to continue installation");
  2498. LocGetString(_wixLoc, L"#(loc.FailureWin7MissingSP1)", &pLocString);
  2499. } else if (IsWindowsVistaSP2OrGreater()) {
  2500. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Target OS is Windows Vista SP2");
  2501. return;
  2502. } else if (IsWindowsVistaOrGreater()) {
  2503. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows Vista RTM or SP1");
  2504. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Service Pack 2 is required to continue installation");
  2505. LocGetString(_wixLoc, L"#(loc.FailureVistaMissingSP2)", &pLocString);
  2506. } else {
  2507. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows XP or earlier");
  2508. BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Windows Vista SP2 or later is required to continue installation");
  2509. LocGetString(_wixLoc, L"#(loc.FailureXPOrEarlier)", &pLocString);
  2510. }
  2511. if (pLocString && pLocString->wzText) {
  2512. BalFormatString(pLocString->wzText, &_failedMessage);
  2513. }
  2514. _hrFinal = E_WIXSTDBA_CONDITION_FAILED;
  2515. }
  2516. public:
  2517. //
  2518. // Constructor - initialize member variables.
  2519. //
  2520. PythonBootstrapperApplication(
  2521. __in HMODULE hModule,
  2522. __in BOOL fPrereq,
  2523. __in HRESULT hrHostInitialization,
  2524. __in IBootstrapperEngine* pEngine,
  2525. __in const BOOTSTRAPPER_COMMAND* pCommand
  2526. ) : CBalBaseBootstrapperApplication(pEngine, pCommand, 3, 3000) {
  2527. _hModule = hModule;
  2528. memcpy_s(&_command, sizeof(_command), pCommand, sizeof(BOOTSTRAPPER_COMMAND));
  2529. LONGLONG llInstalled = 0;
  2530. HRESULT hr = BalGetNumericVariable(L"WixBundleInstalled", &llInstalled);
  2531. if (SUCCEEDED(hr) && BOOTSTRAPPER_RESUME_TYPE_REBOOT != _command.resumeType && 0 < llInstalled && BOOTSTRAPPER_ACTION_INSTALL == _command.action) {
  2532. _command.action = BOOTSTRAPPER_ACTION_MODIFY;
  2533. } else if (0 == llInstalled && (BOOTSTRAPPER_ACTION_MODIFY == _command.action || BOOTSTRAPPER_ACTION_REPAIR == _command.action)) {
  2534. _command.action = BOOTSTRAPPER_ACTION_INSTALL;
  2535. }
  2536. _plannedAction = BOOTSTRAPPER_ACTION_UNKNOWN;
  2537. // When resuming from restart doing some install-like operation, try to find the package that forced the
  2538. // restart. We'll use this information during planning.
  2539. _nextPackageAfterRestart = nullptr;
  2540. if (BOOTSTRAPPER_RESUME_TYPE_REBOOT == _command.resumeType && BOOTSTRAPPER_ACTION_UNINSTALL < _command.action) {
  2541. // Ensure the forced restart package variable is null when it is an empty string.
  2542. HRESULT hr = BalGetStringVariable(L"WixBundleForcedRestartPackage", &_nextPackageAfterRestart);
  2543. if (FAILED(hr) || !_nextPackageAfterRestart || !*_nextPackageAfterRestart) {
  2544. ReleaseNullStr(_nextPackageAfterRestart);
  2545. }
  2546. }
  2547. _crtInstalledToken = -1;
  2548. pEngine->SetVariableNumeric(L"CRTInstalled", IsCrtInstalled() ? 1 : 0);
  2549. _wixLoc = nullptr;
  2550. memset(&_bundle, 0, sizeof(_bundle));
  2551. memset(&_conditions, 0, sizeof(_conditions));
  2552. _confirmCloseMessage = nullptr;
  2553. _failedMessage = nullptr;
  2554. _language = nullptr;
  2555. _theme = nullptr;
  2556. memset(_pageIds, 0, sizeof(_pageIds));
  2557. _hUiThread = nullptr;
  2558. _registered = FALSE;
  2559. _hWnd = nullptr;
  2560. _state = PYBA_STATE_INITIALIZING;
  2561. _visiblePageId = 0;
  2562. _installPage = PAGE_LOADING;
  2563. _hrFinal = hrHostInitialization;
  2564. _downgradingOtherVersion = FALSE;
  2565. _restartResult = BOOTSTRAPPER_APPLY_RESTART_NONE;
  2566. _restartRequired = FALSE;
  2567. _allowRestart = FALSE;
  2568. _suppressDowngradeFailure = FALSE;
  2569. _suppressRepair = FALSE;
  2570. _modifying = FALSE;
  2571. _upgrading = FALSE;
  2572. _overridableVariables = nullptr;
  2573. _taskbarList = nullptr;
  2574. _taskbarButtonCreatedMessage = UINT_MAX;
  2575. _taskbarButtonOK = FALSE;
  2576. _showingInternalUIThisPackage = FALSE;
  2577. _suppressPaint = FALSE;
  2578. pEngine->AddRef();
  2579. _engine = pEngine;
  2580. _hBAFModule = nullptr;
  2581. _baFunction = nullptr;
  2582. }
  2583. //
  2584. // Destructor - release member variables.
  2585. //
  2586. ~PythonBootstrapperApplication() {
  2587. AssertSz(!::IsWindow(_hWnd), "Window should have been destroyed before destructor.");
  2588. AssertSz(!_theme, "Theme should have been released before destructor.");
  2589. ReleaseObject(_taskbarList);
  2590. ReleaseDict(_overridableVariables);
  2591. ReleaseStr(_failedMessage);
  2592. ReleaseStr(_confirmCloseMessage);
  2593. BalConditionsUninitialize(&_conditions);
  2594. BalInfoUninitialize(&_bundle);
  2595. LocFree(_wixLoc);
  2596. ReleaseStr(_language);
  2597. ReleaseStr(_nextPackageAfterRestart);
  2598. ReleaseNullObject(_engine);
  2599. if (_hBAFModule) {
  2600. ::FreeLibrary(_hBAFModule);
  2601. _hBAFModule = nullptr;
  2602. }
  2603. }
  2604. private:
  2605. HMODULE _hModule;
  2606. BOOTSTRAPPER_COMMAND _command;
  2607. IBootstrapperEngine* _engine;
  2608. BOOTSTRAPPER_ACTION _plannedAction;
  2609. LPWSTR _nextPackageAfterRestart;
  2610. WIX_LOCALIZATION* _wixLoc;
  2611. BAL_INFO_BUNDLE _bundle;
  2612. BAL_CONDITIONS _conditions;
  2613. LPWSTR _failedMessage;
  2614. LPWSTR _confirmCloseMessage;
  2615. LPWSTR _language;
  2616. THEME* _theme;
  2617. DWORD _pageIds[countof(PAGE_NAMES)];
  2618. HANDLE _hUiThread;
  2619. BOOL _registered;
  2620. HWND _hWnd;
  2621. PYBA_STATE _state;
  2622. HRESULT _hrFinal;
  2623. DWORD _visiblePageId;
  2624. PAGE _installPage;
  2625. BOOL _startedExecution;
  2626. DWORD _calculatedCacheProgress;
  2627. DWORD _calculatedExecuteProgress;
  2628. BOOL _downgradingOtherVersion;
  2629. BOOTSTRAPPER_APPLY_RESTART _restartResult;
  2630. BOOL _restartRequired;
  2631. BOOL _allowRestart;
  2632. BOOL _suppressDowngradeFailure;
  2633. BOOL _suppressRepair;
  2634. BOOL _modifying;
  2635. BOOL _upgrading;
  2636. int _crtInstalledToken;
  2637. STRINGDICT_HANDLE _overridableVariables;
  2638. ITaskbarList3* _taskbarList;
  2639. UINT _taskbarButtonCreatedMessage;
  2640. BOOL _taskbarButtonOK;
  2641. BOOL _showingInternalUIThisPackage;
  2642. BOOL _suppressPaint;
  2643. HMODULE _hBAFModule;
  2644. IBootstrapperBAFunction* _baFunction;
  2645. };
  2646. //
  2647. // CreateBootstrapperApplication - creates a new IBootstrapperApplication object.
  2648. //
  2649. HRESULT CreateBootstrapperApplication(
  2650. __in HMODULE hModule,
  2651. __in BOOL fPrereq,
  2652. __in HRESULT hrHostInitialization,
  2653. __in IBootstrapperEngine* pEngine,
  2654. __in const BOOTSTRAPPER_COMMAND* pCommand,
  2655. __out IBootstrapperApplication** ppApplication
  2656. ) {
  2657. HRESULT hr = S_OK;
  2658. if (fPrereq) {
  2659. hr = E_INVALIDARG;
  2660. ExitWithLastError(hr, "Failed to create UI thread.");
  2661. }
  2662. PythonBootstrapperApplication* pApplication = nullptr;
  2663. pApplication = new PythonBootstrapperApplication(hModule, fPrereq, hrHostInitialization, pEngine, pCommand);
  2664. ExitOnNull(pApplication, hr, E_OUTOFMEMORY, "Failed to create new standard bootstrapper application object.");
  2665. *ppApplication = pApplication;
  2666. pApplication = nullptr;
  2667. LExit:
  2668. ReleaseObject(pApplication);
  2669. return hr;
  2670. }