-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Expand file tree
/
Copy pathPythonBootstrapperApplication.cpp
More file actions
3323 lines (2748 loc) · 121 KB
/
PythonBootstrapperApplication.cpp
File metadata and controls
3323 lines (2748 loc) · 121 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-------------------------------------------------------------------------------------------------
// <copyright file="WixStandardBootstrapperApplication.cpp" company="Outercurve Foundation">
// Copyright (c) 2004, Outercurve Foundation.
// This software is released under Microsoft Reciprocal License (MS-RL).
// The license and further copyright text can be found in the file
// LICENSE.TXT at the root directory of the distribution.
// </copyright>
//-------------------------------------------------------------------------------------------------
#include "pch.h"
static const LPCWSTR PYBA_WINDOW_CLASS = L"PythonBA";
static const DWORD PYBA_ACQUIRE_PERCENTAGE = 30;
static const LPCWSTR PYBA_VARIABLE_BUNDLE_FILE_VERSION = L"WixBundleFileVersion";
enum PYBA_STATE {
PYBA_STATE_INITIALIZING,
PYBA_STATE_INITIALIZED,
PYBA_STATE_HELP,
PYBA_STATE_DETECTING,
PYBA_STATE_DETECTED,
PYBA_STATE_PLANNING,
PYBA_STATE_PLANNED,
PYBA_STATE_APPLYING,
PYBA_STATE_CACHING,
PYBA_STATE_CACHED,
PYBA_STATE_EXECUTING,
PYBA_STATE_EXECUTED,
PYBA_STATE_APPLIED,
PYBA_STATE_FAILED,
};
static const int WM_PYBA_SHOW_HELP = WM_APP + 100;
static const int WM_PYBA_DETECT_PACKAGES = WM_APP + 101;
static const int WM_PYBA_PLAN_PACKAGES = WM_APP + 102;
static const int WM_PYBA_APPLY_PACKAGES = WM_APP + 103;
static const int WM_PYBA_CHANGE_STATE = WM_APP + 104;
static const int WM_PYBA_SHOW_FAILURE = WM_APP + 105;
// This enum must be kept in the same order as the PAGE_NAMES array.
enum PAGE {
PAGE_LOADING,
PAGE_HELP,
PAGE_INSTALL,
PAGE_UPGRADE,
PAGE_SIMPLE_INSTALL,
PAGE_CUSTOM1,
PAGE_CUSTOM2,
PAGE_MODIFY,
PAGE_PROGRESS,
PAGE_PROGRESS_PASSIVE,
PAGE_SUCCESS,
PAGE_FAILURE,
COUNT_PAGE,
};
// This array must be kept in the same order as the PAGE enum.
static LPCWSTR PAGE_NAMES[] = {
L"Loading",
L"Help",
L"Install",
L"Upgrade",
L"SimpleInstall",
L"Custom1",
L"Custom2",
L"Modify",
L"Progress",
L"ProgressPassive",
L"Success",
L"Failure",
};
enum CONTROL_ID {
// Non-paged controls
ID_CLOSE_BUTTON = THEME_FIRST_ASSIGN_CONTROL_ID,
ID_MINIMIZE_BUTTON,
// Welcome page
ID_INSTALL_BUTTON,
ID_INSTALL_CUSTOM_BUTTON,
ID_INSTALL_SIMPLE_BUTTON,
ID_INSTALL_UPGRADE_BUTTON,
ID_INSTALL_UPGRADE_CUSTOM_BUTTON,
ID_INSTALL_CANCEL_BUTTON,
ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX,
// Customize Page
ID_TARGETDIR_EDITBOX,
ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX,
ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX,
ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX,
ID_CUSTOM_INCLUDE_LAUNCHER_HELP_LABEL,
ID_CUSTOM_COMPILE_ALL_CHECKBOX,
ID_CUSTOM_BROWSE_BUTTON,
ID_CUSTOM_BROWSE_BUTTON_LABEL,
ID_CUSTOM_INSTALL_BUTTON,
ID_CUSTOM_NEXT_BUTTON,
ID_CUSTOM1_BACK_BUTTON,
ID_CUSTOM2_BACK_BUTTON,
ID_CUSTOM1_CANCEL_BUTTON,
ID_CUSTOM2_CANCEL_BUTTON,
// Modify page
ID_MODIFY_BUTTON,
ID_REPAIR_BUTTON,
ID_UNINSTALL_BUTTON,
ID_MODIFY_CANCEL_BUTTON,
// Progress page
ID_CACHE_PROGRESS_PACKAGE_TEXT,
ID_CACHE_PROGRESS_BAR,
ID_CACHE_PROGRESS_TEXT,
ID_EXECUTE_PROGRESS_PACKAGE_TEXT,
ID_EXECUTE_PROGRESS_BAR,
ID_EXECUTE_PROGRESS_TEXT,
ID_EXECUTE_PROGRESS_ACTIONDATA_TEXT,
ID_OVERALL_PROGRESS_PACKAGE_TEXT,
ID_OVERALL_PROGRESS_BAR,
ID_OVERALL_CALCULATED_PROGRESS_BAR,
ID_OVERALL_PROGRESS_TEXT,
ID_PROGRESS_CANCEL_BUTTON,
// Success page
ID_SUCCESS_TEXT,
ID_SUCCESS_RESTART_TEXT,
ID_SUCCESS_RESTART_BUTTON,
ID_SUCCESS_CANCEL_BUTTON,
ID_SUCCESS_MAX_PATH_BUTTON,
// Failure page
ID_FAILURE_LOGFILE_LINK,
ID_FAILURE_MESSAGE_TEXT,
ID_FAILURE_RESTART_TEXT,
ID_FAILURE_RESTART_BUTTON,
ID_FAILURE_CANCEL_BUTTON
};
static THEME_ASSIGN_CONTROL_ID CONTROL_ID_NAMES[] = {
{ ID_CLOSE_BUTTON, L"CloseButton" },
{ ID_MINIMIZE_BUTTON, L"MinimizeButton" },
{ ID_INSTALL_BUTTON, L"InstallButton" },
{ ID_INSTALL_CUSTOM_BUTTON, L"InstallCustomButton" },
{ ID_INSTALL_SIMPLE_BUTTON, L"InstallSimpleButton" },
{ ID_INSTALL_UPGRADE_BUTTON, L"InstallUpgradeButton" },
{ ID_INSTALL_UPGRADE_CUSTOM_BUTTON, L"InstallUpgradeCustomButton" },
{ ID_INSTALL_CANCEL_BUTTON, L"InstallCancelButton" },
{ ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, L"InstallLauncherAllUsers" },
{ ID_TARGETDIR_EDITBOX, L"TargetDir" },
{ ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, L"AssociateFiles" },
{ ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX, L"InstallAllUsers" },
{ ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, L"CustomInstallLauncherAllUsers" },
{ ID_CUSTOM_INCLUDE_LAUNCHER_HELP_LABEL, L"Include_launcherHelp" },
{ ID_CUSTOM_COMPILE_ALL_CHECKBOX, L"CompileAll" },
{ ID_CUSTOM_BROWSE_BUTTON, L"CustomBrowseButton" },
{ ID_CUSTOM_BROWSE_BUTTON_LABEL, L"CustomBrowseButtonLabel" },
{ ID_CUSTOM_INSTALL_BUTTON, L"CustomInstallButton" },
{ ID_CUSTOM_NEXT_BUTTON, L"CustomNextButton" },
{ ID_CUSTOM1_BACK_BUTTON, L"Custom1BackButton" },
{ ID_CUSTOM2_BACK_BUTTON, L"Custom2BackButton" },
{ ID_CUSTOM1_CANCEL_BUTTON, L"Custom1CancelButton" },
{ ID_CUSTOM2_CANCEL_BUTTON, L"Custom2CancelButton" },
{ ID_MODIFY_BUTTON, L"ModifyButton" },
{ ID_REPAIR_BUTTON, L"RepairButton" },
{ ID_UNINSTALL_BUTTON, L"UninstallButton" },
{ ID_MODIFY_CANCEL_BUTTON, L"ModifyCancelButton" },
{ ID_CACHE_PROGRESS_PACKAGE_TEXT, L"CacheProgressPackageText" },
{ ID_CACHE_PROGRESS_BAR, L"CacheProgressbar" },
{ ID_CACHE_PROGRESS_TEXT, L"CacheProgressText" },
{ ID_EXECUTE_PROGRESS_PACKAGE_TEXT, L"ExecuteProgressPackageText" },
{ ID_EXECUTE_PROGRESS_BAR, L"ExecuteProgressbar" },
{ ID_EXECUTE_PROGRESS_TEXT, L"ExecuteProgressText" },
{ ID_EXECUTE_PROGRESS_ACTIONDATA_TEXT, L"ExecuteProgressActionDataText" },
{ ID_OVERALL_PROGRESS_PACKAGE_TEXT, L"OverallProgressPackageText" },
{ ID_OVERALL_PROGRESS_BAR, L"OverallProgressbar" },
{ ID_OVERALL_CALCULATED_PROGRESS_BAR, L"OverallCalculatedProgressbar" },
{ ID_OVERALL_PROGRESS_TEXT, L"OverallProgressText" },
{ ID_PROGRESS_CANCEL_BUTTON, L"ProgressCancelButton" },
{ ID_SUCCESS_TEXT, L"SuccessText" },
{ ID_SUCCESS_RESTART_TEXT, L"SuccessRestartText" },
{ ID_SUCCESS_RESTART_BUTTON, L"SuccessRestartButton" },
{ ID_SUCCESS_CANCEL_BUTTON, L"SuccessCancelButton" },
{ ID_SUCCESS_MAX_PATH_BUTTON, L"SuccessMaxPathButton" },
{ ID_FAILURE_LOGFILE_LINK, L"FailureLogFileLink" },
{ ID_FAILURE_MESSAGE_TEXT, L"FailureMessageText" },
{ ID_FAILURE_RESTART_TEXT, L"FailureRestartText" },
{ ID_FAILURE_RESTART_BUTTON, L"FailureRestartButton" },
{ ID_FAILURE_CANCEL_BUTTON, L"FailureCancelButton" },
};
static struct { LPCWSTR regName; LPCWSTR variableName; } OPTIONAL_FEATURES[] = {
{ L"core_d", L"Include_debug" },
{ L"core_pdb", L"Include_symbols" },
{ L"dev", L"Include_dev" },
{ L"doc", L"Include_doc" },
{ L"exe", L"Include_exe" },
{ L"lib", L"Include_lib" },
{ L"path", L"PrependPath" },
{ L"appendpath", L"AppendPath" },
{ L"pip", L"Include_pip" },
{ L"tcltk", L"Include_tcltk" },
{ L"test", L"Include_test" },
{ L"tools", L"Include_tools" },
{ L"Shortcuts", L"Shortcuts" },
// Include_launcher and AssociateFiles are handled separately and so do
// not need to be included in this list.
{ L"freethreaded", L"Include_freethreaded" },
{ nullptr, nullptr }
};
class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
void ShowPage(DWORD newPageId) {
// Process each control for special handling in the new page.
ProcessPageControls(ThemeGetPage(_theme, newPageId));
// Enable disable controls per-page.
if (_pageIds[PAGE_INSTALL] == newPageId ||
_pageIds[PAGE_SIMPLE_INSTALL] == newPageId ||
_pageIds[PAGE_UPGRADE] == newPageId) {
InstallPage_Show();
} else if (_pageIds[PAGE_CUSTOM1] == newPageId) {
Custom1Page_Show();
} else if (_pageIds[PAGE_CUSTOM2] == newPageId) {
Custom2Page_Show();
} else if (_pageIds[PAGE_MODIFY] == newPageId) {
ModifyPage_Show();
} else if (_pageIds[PAGE_SUCCESS] == newPageId) {
SuccessPage_Show();
} else if (_pageIds[PAGE_FAILURE] == newPageId) {
FailurePage_Show();
}
// Prevent repainting while switching page to avoid ugly flickering
_suppressPaint = TRUE;
ThemeShowPage(_theme, newPageId, SW_SHOW);
ThemeShowPage(_theme, _visiblePageId, SW_HIDE);
_suppressPaint = FALSE;
InvalidateRect(_theme->hwndParent, nullptr, TRUE);
_visiblePageId = newPageId;
// On the install page set the focus to the install button or
// the next enabled control if install is disabled
if (_pageIds[PAGE_INSTALL] == newPageId) {
ThemeSetFocus(_theme, ID_INSTALL_BUTTON);
} else if (_pageIds[PAGE_SIMPLE_INSTALL] == newPageId) {
ThemeSetFocus(_theme, ID_INSTALL_SIMPLE_BUTTON);
}
}
//
// Handles control clicks
//
void OnCommand(CONTROL_ID id) {
LPWSTR defaultDir = nullptr;
LPWSTR targetDir = nullptr;
LONGLONG elevated, crtInstalled, installAllUsers;
BOOL checked, launcherChecked;
WCHAR wzPath[MAX_PATH] = { };
BROWSEINFOW browseInfo = { };
PIDLIST_ABSOLUTE pidl = nullptr;
DWORD pageId;
HRESULT hr = S_OK;
switch(id) {
case ID_CLOSE_BUTTON:
OnClickCloseButton();
break;
// Install commands
case ID_INSTALL_SIMPLE_BUTTON: __fallthrough;
case ID_INSTALL_UPGRADE_BUTTON: __fallthrough;
case ID_INSTALL_BUTTON:
SavePageSettings();
hr = BalGetNumericVariable(L"InstallAllUsers", &installAllUsers);
ExitOnFailure(hr, L"Failed to get install scope");
hr = _engine->SetVariableNumeric(L"CompileAll", installAllUsers);
ExitOnFailure(hr, L"Failed to update CompileAll");
hr = EnsureTargetDir();
ExitOnFailure(hr, L"Failed to set TargetDir");
OnPlan(BOOTSTRAPPER_ACTION_INSTALL);
break;
case ID_CUSTOM1_BACK_BUTTON:
SavePageSettings();
if (_modifying) {
GoToPage(PAGE_MODIFY);
} else if (_upgrading) {
GoToPage(PAGE_UPGRADE);
} else {
GoToPage(PAGE_INSTALL);
}
break;
case ID_INSTALL_CUSTOM_BUTTON: __fallthrough;
case ID_INSTALL_UPGRADE_CUSTOM_BUTTON: __fallthrough;
case ID_CUSTOM2_BACK_BUTTON:
SavePageSettings();
GoToPage(PAGE_CUSTOM1);
break;
case ID_CUSTOM_NEXT_BUTTON:
SavePageSettings();
GoToPage(PAGE_CUSTOM2);
break;
case ID_CUSTOM_INSTALL_BUTTON:
SavePageSettings();
hr = EnsureTargetDir();
ExitOnFailure(hr, L"Failed to set TargetDir");
hr = BalGetStringVariable(L"TargetDir", &targetDir);
if (SUCCEEDED(hr)) {
// TODO: Check whether directory exists and contains another installation
ReleaseStr(targetDir);
}
OnPlan(_command.action);
break;
case ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX:
checked = ThemeIsControlChecked(_theme, ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX);
_engine->SetVariableNumeric(L"InstallLauncherAllUsers", checked);
ThemeControlElevates(_theme, ID_INSTALL_BUTTON, WillElevate());
break;
case ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX:
checked = ThemeIsControlChecked(_theme, ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX);
_engine->SetVariableNumeric(L"InstallLauncherAllUsers", checked);
ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, WillElevate());
break;
case ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX:
checked = ThemeIsControlChecked(_theme, ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX);
_engine->SetVariableNumeric(L"InstallAllUsers", checked);
ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, WillElevate());
ThemeControlEnable(_theme, ID_CUSTOM_BROWSE_BUTTON_LABEL, !checked);
if (checked) {
_engine->SetVariableNumeric(L"CompileAll", 1);
ThemeSendControlMessage(_theme, ID_CUSTOM_COMPILE_ALL_CHECKBOX, BM_SETCHECK, BST_CHECKED, 0);
}
ThemeGetTextControl(_theme, ID_TARGETDIR_EDITBOX, &targetDir);
if (targetDir) {
// Check the current value against the default to see
// if we should switch it automatically.
hr = BalGetStringVariable(
checked ? L"DefaultJustForMeTargetDir" : L"DefaultAllUsersTargetDir",
&defaultDir
);
if (SUCCEEDED(hr) && defaultDir) {
LPWSTR formatted = nullptr;
if (defaultDir[0] && SUCCEEDED(BalFormatString(defaultDir, &formatted))) {
if (wcscmp(formatted, targetDir) == 0) {
ReleaseStr(defaultDir);
defaultDir = nullptr;
ReleaseStr(formatted);
formatted = nullptr;
hr = BalGetStringVariable(
checked ? L"DefaultAllUsersTargetDir" : L"DefaultJustForMeTargetDir",
&defaultDir
);
if (SUCCEEDED(hr) && defaultDir && defaultDir[0] && SUCCEEDED(BalFormatString(defaultDir, &formatted))) {
ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, formatted);
ReleaseStr(formatted);
}
} else {
ReleaseStr(formatted);
}
}
ReleaseStr(defaultDir);
}
}
break;
case ID_CUSTOM_BROWSE_BUTTON:
browseInfo.hwndOwner = _hWnd;
browseInfo.pszDisplayName = wzPath;
browseInfo.lpszTitle = _theme->sczCaption;
browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI;
pidl = ::SHBrowseForFolderW(&browseInfo);
if (pidl && ::SHGetPathFromIDListW(pidl, wzPath)) {
ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, wzPath);
}
if (pidl) {
::CoTaskMemFree(pidl);
}
break;
// Modify commands
case ID_MODIFY_BUTTON:
// Some variables cannot be modified
_engine->SetVariableString(L"InstallAllUsersState", L"disable");
_engine->SetVariableString(L"InstallLauncherAllUsersState", L"disable");
_engine->SetVariableString(L"TargetDirState", L"disable");
_engine->SetVariableString(L"CustomBrowseButtonState", L"disable");
_modifying = TRUE;
GoToPage(PAGE_CUSTOM1);
break;
case ID_REPAIR_BUTTON:
OnPlan(BOOTSTRAPPER_ACTION_REPAIR);
break;
case ID_UNINSTALL_BUTTON:
OnPlan(BOOTSTRAPPER_ACTION_UNINSTALL);
break;
case ID_SUCCESS_MAX_PATH_BUTTON:
EnableMaxPathSupport();
ThemeControlEnable(_theme, ID_SUCCESS_MAX_PATH_BUTTON, FALSE);
break;
}
LExit:
return;
}
void InstallPage_Show() {
// Ensure the All Users install button has a UAC shield
BOOL elevated = WillElevate();
ThemeControlElevates(_theme, ID_INSTALL_BUTTON, elevated);
ThemeControlElevates(_theme, ID_INSTALL_SIMPLE_BUTTON, elevated);
ThemeControlElevates(_theme, ID_INSTALL_UPGRADE_BUTTON, elevated);
LONGLONG blockedLauncher;
if (SUCCEEDED(BalGetNumericVariable(L"BlockedLauncher", &blockedLauncher)) && blockedLauncher) {
LOC_STRING *pLocString = nullptr;
if (SUCCEEDED(LocGetString(_wixLoc, L"#(loc.ShortInstallLauncherBlockedLabel)", &pLocString)) && pLocString) {
ThemeSetTextControl(_theme, ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, pLocString->wzText);
}
}
}
void Custom1Page_Show() {
LONGLONG installLauncherAllUsers;
if (FAILED(BalGetNumericVariable(L"InstallLauncherAllUsers", &installLauncherAllUsers))) {
installLauncherAllUsers = 0;
}
ThemeSendControlMessage(_theme, ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, BM_SETCHECK,
installLauncherAllUsers ? BST_CHECKED : BST_UNCHECKED, 0);
LOC_STRING *pLocString = nullptr;
LPCWSTR locKey = L"#(loc.Include_launcherHelp)";
LONGLONG blockedLauncher;
if (SUCCEEDED(BalGetNumericVariable(L"BlockedLauncher", &blockedLauncher)) && blockedLauncher) {
locKey = L"#(loc.Include_launcherRemove)";
} else if (SUCCEEDED(BalGetNumericVariable(L"DetectedOldLauncher", &blockedLauncher)) && blockedLauncher) {
locKey = L"#(loc.Include_launcherUpgrade)";
}
if (SUCCEEDED(LocGetString(_wixLoc, locKey, &pLocString)) && pLocString) {
ThemeSetTextControl(_theme, ID_CUSTOM_INCLUDE_LAUNCHER_HELP_LABEL, pLocString->wzText);
}
}
void Custom2Page_Show() {
HRESULT hr;
LONGLONG installAll, includeLauncher;
if (FAILED(BalGetNumericVariable(L"InstallAllUsers", &installAll))) {
installAll = 0;
}
if (WillElevate()) {
ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, TRUE);
ThemeShowControl(_theme, ID_CUSTOM_BROWSE_BUTTON_LABEL, SW_HIDE);
} else {
ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, FALSE);
ThemeShowControl(_theme, ID_CUSTOM_BROWSE_BUTTON_LABEL, SW_SHOW);
}
if (SUCCEEDED(BalGetNumericVariable(L"Include_launcher", &includeLauncher)) && includeLauncher) {
ThemeControlEnable(_theme, ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, TRUE);
} else {
ThemeSendControlMessage(_theme, ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, BM_SETCHECK, BST_UNCHECKED, 0);
ThemeControlEnable(_theme, ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, FALSE);
}
LPWSTR targetDir = nullptr;
hr = BalGetStringVariable(L"TargetDir", &targetDir);
if (SUCCEEDED(hr) && targetDir && targetDir[0]) {
ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, targetDir);
StrFree(targetDir);
} else if (SUCCEEDED(hr)) {
StrFree(targetDir);
targetDir = nullptr;
LPWSTR defaultTargetDir = nullptr;
hr = BalGetStringVariable(L"DefaultCustomTargetDir", &defaultTargetDir);
if (SUCCEEDED(hr) && defaultTargetDir && !defaultTargetDir[0]) {
StrFree(defaultTargetDir);
defaultTargetDir = nullptr;
hr = BalGetStringVariable(
installAll ? L"DefaultAllUsersTargetDir" : L"DefaultJustForMeTargetDir",
&defaultTargetDir
);
}
if (SUCCEEDED(hr) && defaultTargetDir) {
if (defaultTargetDir[0] && SUCCEEDED(BalFormatString(defaultTargetDir, &targetDir))) {
ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, targetDir);
StrFree(targetDir);
}
StrFree(defaultTargetDir);
}
}
}
void ModifyPage_Show() {
ThemeControlEnable(_theme, ID_REPAIR_BUTTON, !_suppressRepair);
}
void SuccessPage_Show() {
// on the "Success" page, check if the restart button should be enabled.
BOOL showRestartButton = FALSE;
LOC_STRING *successText = nullptr;
HRESULT hr = S_OK;
if (_restartRequired) {
if (BOOTSTRAPPER_RESTART_PROMPT == _command.restart) {
showRestartButton = TRUE;
}
}
switch (_plannedAction) {
case BOOTSTRAPPER_ACTION_INSTALL:
hr = LocGetString(_wixLoc, L"#(loc.SuccessInstallMessage)", &successText);
break;
case BOOTSTRAPPER_ACTION_MODIFY:
hr = LocGetString(_wixLoc, L"#(loc.SuccessModifyMessage)", &successText);
break;
case BOOTSTRAPPER_ACTION_REPAIR:
hr = LocGetString(_wixLoc, L"#(loc.SuccessRepairMessage)", &successText);
break;
case BOOTSTRAPPER_ACTION_UNINSTALL:
hr = LocGetString(_wixLoc, L"#(loc.SuccessRemoveMessage)", &successText);
break;
}
if (successText) {
LPWSTR formattedString = nullptr;
BalFormatString(successText->wzText, &formattedString);
if (formattedString) {
ThemeSetTextControl(_theme, ID_SUCCESS_TEXT, formattedString);
StrFree(formattedString);
}
}
ThemeControlEnable(_theme, ID_SUCCESS_RESTART_TEXT, showRestartButton);
ThemeControlEnable(_theme, ID_SUCCESS_RESTART_BUTTON, showRestartButton);
if (_command.action != BOOTSTRAPPER_ACTION_INSTALL ||
!IsWindowsVersionOrGreater(10, 0, 0)) {
ThemeControlEnable(_theme, ID_SUCCESS_MAX_PATH_BUTTON, FALSE);
} else {
DWORD dataType = 0, buffer = 0, bufferLen = sizeof(buffer);
HKEY hKey;
LRESULT res = RegOpenKeyExW(
HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\Control\\FileSystem",
0,
KEY_READ,
&hKey
);
if (res == ERROR_SUCCESS) {
res = RegQueryValueExW(hKey, L"LongPathsEnabled", nullptr, &dataType,
(LPBYTE)&buffer, &bufferLen);
RegCloseKey(hKey);
}
else {
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Failed to open SYSTEM\\CurrentControlSet\\Control\\FileSystem: error code %d", res);
}
if (res == ERROR_SUCCESS && dataType == REG_DWORD && buffer == 0) {
ThemeControlElevates(_theme, ID_SUCCESS_MAX_PATH_BUTTON, TRUE);
}
else {
if (res == ERROR_SUCCESS)
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Failed to read LongPathsEnabled value: error code %d", res);
else
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Hiding MAX_PATH button because it is already enabled");
ThemeControlEnable(_theme, ID_SUCCESS_MAX_PATH_BUTTON, FALSE);
}
}
}
void FailurePage_Show() {
// on the "Failure" page, show error message and check if the restart button should be enabled.
// if there is a log file variable then we'll assume the log file exists.
BOOL showLogLink = (_bundle.sczLogVariable && *_bundle.sczLogVariable);
BOOL showErrorMessage = FALSE;
BOOL showRestartButton = FALSE;
if (FAILED(_hrFinal)) {
LPWSTR unformattedText = nullptr;
LPWSTR text = nullptr;
// If we know the failure message, use that.
if (_failedMessage && *_failedMessage) {
StrAllocString(&unformattedText, _failedMessage, 0);
} else {
// try to get the error message from the error code.
StrAllocFromError(&unformattedText, _hrFinal, nullptr);
if (!unformattedText || !*unformattedText) {
StrAllocFromError(&unformattedText, E_FAIL, nullptr);
}
}
if (E_WIXSTDBA_CONDITION_FAILED == _hrFinal) {
if (unformattedText) {
StrAllocString(&text, unformattedText, 0);
}
} else {
StrAllocFormatted(&text, L"0x%08x - %ls", _hrFinal, unformattedText);
}
if (text) {
ThemeSetTextControl(_theme, ID_FAILURE_MESSAGE_TEXT, text);
showErrorMessage = TRUE;
}
ReleaseStr(text);
ReleaseStr(unformattedText);
}
if (_restartRequired && BOOTSTRAPPER_RESTART_PROMPT == _command.restart) {
showRestartButton = TRUE;
}
ThemeControlEnable(_theme, ID_FAILURE_LOGFILE_LINK, showLogLink);
ThemeControlEnable(_theme, ID_FAILURE_MESSAGE_TEXT, showErrorMessage);
ThemeControlEnable(_theme, ID_FAILURE_RESTART_TEXT, showRestartButton);
ThemeControlEnable(_theme, ID_FAILURE_RESTART_BUTTON, showRestartButton);
}
static void EnableMaxPathSupport() {
LPWSTR targetDir = nullptr, defaultDir = nullptr;
HRESULT hr = BalGetStringVariable(L"TargetDir", &targetDir);
if (FAILED(hr) || !targetDir || !targetDir[0]) {
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to get TargetDir");
return;
}
LPWSTR pythonw = nullptr;
StrAllocFormatted(&pythonw, L"%ls\\pythonw.exe", targetDir);
if (!pythonw || !pythonw[0]) {
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to construct pythonw.exe path");
return;
}
LPCWSTR arguments = L"-c \"import winreg; "
"winreg.SetValueEx("
"winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, "
"r'SYSTEM\\CurrentControlSet\\Control\\FileSystem'), "
"'LongPathsEnabled', "
"None, "
"winreg.REG_DWORD, "
"1"
")\"";
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Executing %ls %ls", pythonw, arguments);
HINSTANCE res = ShellExecuteW(0, L"runas", pythonw, arguments, NULL, SW_HIDE);
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "return code 0x%08x", res);
}
public: // IBootstrapperApplication
virtual STDMETHODIMP OnStartup() {
HRESULT hr = S_OK;
DWORD dwUIThreadId = 0;
// create UI thread
_hUiThread = ::CreateThread(nullptr, 0, UiThreadProc, this, 0, &dwUIThreadId);
if (!_hUiThread) {
ExitWithLastError(hr, "Failed to create UI thread.");
}
LExit:
return hr;
}
virtual STDMETHODIMP_(int) OnShutdown() {
int nResult = IDNOACTION;
// wait for UI thread to terminate
if (_hUiThread) {
::WaitForSingleObject(_hUiThread, INFINITE);
ReleaseHandle(_hUiThread);
}
// If a restart was required.
if (_restartRequired && _allowRestart) {
nResult = IDRESTART;
}
return nResult;
}
virtual STDMETHODIMP_(int) OnDetectRelatedMsiPackage(
__in_z LPCWSTR wzPackageId,
__in_z LPCWSTR /*wzProductCode*/,
__in BOOL fPerMachine,
__in DWORD64 /*dw64Version*/,
__in BOOTSTRAPPER_RELATED_OPERATION operation
) {
// Only check launcher_AllUsers because we'll find the same packages
// twice if we check launcher_JustForMe as well.
if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, L"launcher_AllUsers", -1)) {
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Detected existing launcher install");
LONGLONG blockedLauncher, detectedLauncher;
if (FAILED(BalGetNumericVariable(L"BlockedLauncher", &blockedLauncher))) {
blockedLauncher = 0;
}
// Get the prior DetectedLauncher value so we can see if we've
// detected more than one, and then update the stored variable
// (we use the original value later on via the local).
if (FAILED(BalGetNumericVariable(L"DetectedLauncher", &detectedLauncher))) {
detectedLauncher = 0;
}
if (!detectedLauncher) {
_engine->SetVariableNumeric(L"DetectedLauncher", 1);
}
if (blockedLauncher) {
// Nothing else to do, we're already blocking
}
else if (BOOTSTRAPPER_RELATED_OPERATION_DOWNGRADE == operation) {
// Found a higher version, so we can't install ours.
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Higher version launcher has been detected.");
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Launcher will not be installed");
_engine->SetVariableNumeric(L"BlockedLauncher", 1);
}
else if (detectedLauncher) {
if (!blockedLauncher) {
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Multiple launcher installs have been detected.");
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "No launcher will be installed or upgraded until one has been removed.");
_engine->SetVariableNumeric(L"BlockedLauncher", 1);
}
}
else if (BOOTSTRAPPER_RELATED_OPERATION_MAJOR_UPGRADE == operation) {
// Found an older version, so let's run the equivalent as an upgrade
// This overrides "unknown" all users options, but will leave alone
// any that have already been set/detected.
// User can deselect the option to include the launcher, but cannot
// change it from the current per user/machine setting.
LONGLONG includeLauncher, includeLauncherAllUsers;
if (FAILED(BalGetNumericVariable(L"Include_launcher", &includeLauncher))) {
includeLauncher = -1;
}
if (FAILED(BalGetNumericVariable(L"InstallLauncherAllUsers", &includeLauncherAllUsers))) {
includeLauncherAllUsers = -1;
}
if (includeLauncher < 0) {
_engine->SetVariableNumeric(L"Include_launcher", 1);
}
if (includeLauncherAllUsers < 0) {
_engine->SetVariableNumeric(L"InstallLauncherAllUsers", fPerMachine ? 1 : 0);
} else if (includeLauncherAllUsers != fPerMachine ? 1 : 0) {
// Requested AllUsers option is inconsistent, so block
_engine->SetVariableNumeric(L"BlockedLauncher", 1);
}
_engine->SetVariableNumeric(L"DetectedOldLauncher", 1);
}
}
return CheckCanceled() ? IDCANCEL : IDNOACTION;
}
virtual STDMETHODIMP_(int) OnDetectRelatedBundle(
__in LPCWSTR wzBundleId,
__in BOOTSTRAPPER_RELATION_TYPE relationType,
__in LPCWSTR /*wzBundleTag*/,
__in BOOL fPerMachine,
__in DWORD64 /*dw64Version*/,
__in BOOTSTRAPPER_RELATED_OPERATION operation
) {
BalInfoAddRelatedBundleAsPackage(&_bundle.packages, wzBundleId, relationType, fPerMachine);
// Remember when our bundle would cause a downgrade.
if (BOOTSTRAPPER_RELATED_OPERATION_DOWNGRADE == operation) {
_downgradingOtherVersion = TRUE;
} else if (BOOTSTRAPPER_RELATED_OPERATION_MAJOR_UPGRADE == operation) {
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Detected previous version - planning upgrade");
_upgrading = TRUE;
LoadOptionalFeatureStates(_engine);
} else if (BOOTSTRAPPER_RELATED_OPERATION_NONE == operation) {
if (_command.action == BOOTSTRAPPER_ACTION_INSTALL) {
LOC_STRING *pLocString = nullptr;
if (SUCCEEDED(LocGetString(_wixLoc, L"#(loc.FailureExistingInstall)", &pLocString)) && pLocString) {
BalFormatString(pLocString->wzText, &_failedMessage);
} else {
BalFormatString(L"Cannot install [WixBundleName] because it is already installed.", &_failedMessage);
}
BalLog(
BOOTSTRAPPER_LOG_LEVEL_ERROR,
"Related bundle %ls is preventing install",
wzBundleId
);
SetState(PYBA_STATE_FAILED, E_WIXSTDBA_CONDITION_FAILED);
}
}
return CheckCanceled() ? IDCANCEL : IDOK;
}
virtual STDMETHODIMP_(void) OnDetectPackageComplete(
__in LPCWSTR wzPackageId,
__in HRESULT hrStatus,
__in BOOTSTRAPPER_PACKAGE_STATE state
) { }
virtual STDMETHODIMP_(void) OnDetectComplete(__in HRESULT hrStatus) {
if (SUCCEEDED(hrStatus) && _baFunction) {
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running detect complete BA function");
_baFunction->OnDetectComplete();
}
if (SUCCEEDED(hrStatus)) {
// Update launcher install states
// If we didn't detect any existing installs, Include_launcher and
// InstallLauncherAllUsers will both be -1, so we will set to their
// defaults and leave the options enabled.
// Otherwise, if we detected an existing install, we disable the
// options so they remain fixed.
// The code in OnDetectRelatedMsiPackage is responsible for figuring
// out whether existing installs are compatible with the settings in
// place during detection.
LONGLONG blockedLauncher;
if (SUCCEEDED(BalGetNumericVariable(L"BlockedLauncher", &blockedLauncher))
&& blockedLauncher) {
_engine->SetVariableNumeric(L"Include_launcher", 0);
_engine->SetVariableNumeric(L"InstallLauncherAllUsers", 0);
_engine->SetVariableString(L"InstallLauncherAllUsersState", L"disable");
_engine->SetVariableString(L"Include_launcherState", L"disable");
}
else {
LONGLONG includeLauncher, includeLauncherAllUsers, associateFiles;
if (FAILED(BalGetNumericVariable(L"Include_launcher", &includeLauncher))) {
includeLauncher = -1;
}
if (FAILED(BalGetNumericVariable(L"InstallLauncherAllUsers", &includeLauncherAllUsers))) {
includeLauncherAllUsers = -1;
}
if (FAILED(BalGetNumericVariable(L"AssociateFiles", &associateFiles))) {
associateFiles = -1;
}
if (includeLauncherAllUsers < 0) {
includeLauncherAllUsers = 0;
_engine->SetVariableNumeric(L"InstallLauncherAllUsers", includeLauncherAllUsers);
}
if (includeLauncher < 0) {
if (BOOTSTRAPPER_ACTION_LAYOUT == _command.action ||
(BOOTSTRAPPER_ACTION_INSTALL == _command.action && !_upgrading)) {
// When installing/downloading, we include the launcher
// (though downloads should ignore this setting anyway)
_engine->SetVariableNumeric(L"Include_launcher", 1);
} else {
// Any other action, we should have detected an existing
// install (e.g. on remove/modify), so if we didn't, we
// assume it's not selected.
_engine->SetVariableNumeric(L"Include_launcher", 0);
_engine->SetVariableNumeric(L"AssociateFiles", 0);
}
}
if (associateFiles < 0) {
auto hr = LoadAssociateFilesStateFromKey(
_engine,
includeLauncherAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER
);
if (FAILED(hr)) {
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to load AssociateFiles state: error code 0x%08X", hr);
} else if (hr == S_OK) {
associateFiles = 1;
}
_engine->SetVariableNumeric(L"AssociateFiles", associateFiles);
}
}
}
if (SUCCEEDED(hrStatus)) {
hrStatus = EvaluateConditions();
}
if (SUCCEEDED(hrStatus)) {
// Ensure the default path has been set
hrStatus = EnsureTargetDir();
}
SetState(PYBA_STATE_DETECTED, hrStatus);
// If we're not interacting with the user or we're doing a layout or we're just after a force restart
// then automatically start planning.
if (BOOTSTRAPPER_DISPLAY_FULL > _command.display ||
BOOTSTRAPPER_ACTION_LAYOUT == _command.action ||
BOOTSTRAPPER_ACTION_UNINSTALL == _command.action ||
BOOTSTRAPPER_RESUME_TYPE_REBOOT == _command.resumeType) {
if (SUCCEEDED(hrStatus)) {
::PostMessageW(_hWnd, WM_PYBA_PLAN_PACKAGES, 0, _command.action);
}
}
}
virtual STDMETHODIMP_(int) OnPlanRelatedBundle(
__in_z LPCWSTR /*wzBundleId*/,
__inout_z BOOTSTRAPPER_REQUEST_STATE* pRequestedState
) {
return CheckCanceled() ? IDCANCEL : IDOK;
}
virtual STDMETHODIMP_(int) OnPlanPackageBegin(
__in_z LPCWSTR wzPackageId,
__inout BOOTSTRAPPER_REQUEST_STATE *pRequestState
) {
HRESULT hr = S_OK;
BAL_INFO_PACKAGE* pPackage = nullptr;
if (_nextPackageAfterRestart) {
// After restart we need to finish the dependency registration for our package so allow the package
// to go present.
if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, _nextPackageAfterRestart, -1)) {
// Do not allow a repair because that could put us in a perpetual restart loop.
if (BOOTSTRAPPER_REQUEST_STATE_REPAIR == *pRequestState) {
*pRequestState = BOOTSTRAPPER_REQUEST_STATE_PRESENT;
}
ReleaseNullStr(_nextPackageAfterRestart); // no more skipping now.
} else {
// not the matching package, so skip it.
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Skipping package: %ls, after restart because it was applied before the restart.", wzPackageId);
*pRequestState = BOOTSTRAPPER_REQUEST_STATE_NONE;
}
} else if ((_plannedAction == BOOTSTRAPPER_ACTION_INSTALL || _plannedAction == BOOTSTRAPPER_ACTION_MODIFY) &&
SUCCEEDED(BalInfoFindPackageById(&_bundle.packages, wzPackageId, &pPackage))) {
BOOL f = FALSE;
if (SUCCEEDED(_engine->EvaluateCondition(pPackage->sczInstallCondition, &f)) && f) {
*pRequestState = BOOTSTRAPPER_REQUEST_STATE_PRESENT;
}
}
return CheckCanceled() ? IDCANCEL : IDOK;
}
virtual STDMETHODIMP_(int) OnPlanMsiFeature(
__in_z LPCWSTR wzPackageId,
__in_z LPCWSTR wzFeatureId,
__inout BOOTSTRAPPER_FEATURE_STATE* pRequestedState
) {
LONGLONG install;
if (wcscmp(wzFeatureId, L"AssociateFiles") == 0 || wcscmp(wzFeatureId, L"Shortcuts") == 0) {
if (SUCCEEDED(_engine->GetVariableNumeric(wzFeatureId, &install)) && install) {
*pRequestedState = BOOTSTRAPPER_FEATURE_STATE_LOCAL;
} else {
*pRequestedState = BOOTSTRAPPER_FEATURE_STATE_ABSENT;
}
} else {
*pRequestedState = BOOTSTRAPPER_FEATURE_STATE_LOCAL;
}
return CheckCanceled() ? IDCANCEL : IDNOACTION;
}
virtual STDMETHODIMP_(void) OnPlanComplete(__in HRESULT hrStatus) {
if (SUCCEEDED(hrStatus) && _baFunction) {
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running plan complete BA function");