forked from wixtoolset/wix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplan.cpp
More file actions
3143 lines (2642 loc) · 121 KB
/
plan.cpp
File metadata and controls
3143 lines (2642 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 (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
#include "precomp.h"
#define PlanDumpLevel REPORT_DEBUG
// internal struct definitions
// internal function definitions
static void PlannedExecutePackage(
__in BURN_PLAN* pPlan,
__in BURN_PACKAGE* pPackage
);
static void UninitializeRegistrationAction(
__in BURN_DEPENDENT_REGISTRATION_ACTION* pAction
);
static void UninitializeCacheAction(
__in BURN_CACHE_ACTION* pCacheAction
);
static void ResetPlannedContainerState(
__in BURN_CONTAINER* pContainer
);
static void ResetPlannedPayloadsState(
__in BURN_PAYLOADS* pPayloads
);
static void ResetPlannedPayloadGroupState(
__in BURN_PAYLOAD_GROUP* pPayloadGroup
);
static void ResetPlannedPackageState(
__in BURN_PACKAGE* pPackage
);
static void ResetPlannedRollbackBoundaryState(
__in BURN_ROLLBACK_BOUNDARY* pRollbackBoundary
);
static HRESULT PlanPackagesHelper(
__in BURN_PACKAGE* rgPackages,
__in DWORD cPackages,
__in BURN_USER_EXPERIENCE* pUX,
__in BURN_PLAN* pPlan,
__in BURN_LOGGING* pLog,
__in BURN_VARIABLES* pVariables
);
static HRESULT InitializePackage(
__in BURN_PLAN* pPlan,
__in BURN_USER_EXPERIENCE* pUX,
__in BURN_VARIABLES* pVariables,
__in BURN_PACKAGE* pPackage
);
static HRESULT ProcessPackage(
__in BOOL fBundlePerMachine,
__in BURN_USER_EXPERIENCE* pUX,
__in BURN_PLAN* pPlan,
__in BURN_PACKAGE* pPackage,
__in BURN_LOGGING* pLog,
__in BURN_VARIABLES* pVariables,
__inout BURN_ROLLBACK_BOUNDARY** ppRollbackBoundary
);
static HRESULT ProcessPackageRollbackBoundary(
__in BURN_PLAN* pPlan,
__in BURN_USER_EXPERIENCE* pUX,
__in BURN_LOGGING* pLog,
__in BURN_VARIABLES* pVariables,
__in_opt BURN_ROLLBACK_BOUNDARY* pEffectiveRollbackBoundary,
__inout BURN_ROLLBACK_BOUNDARY** ppRollbackBoundary
);
static HRESULT GetActionDefaultRequestState(
__in BOOTSTRAPPER_ACTION action,
__in BOOTSTRAPPER_PACKAGE_STATE currentState,
__out BOOTSTRAPPER_REQUEST_STATE* pRequestState
);
static HRESULT AddRegistrationAction(
__in BURN_PLAN* pPlan,
__in BURN_DEPENDENT_REGISTRATION_ACTION_TYPE type,
__in_z LPCWSTR wzDependentProviderKey,
__in_z LPCWSTR wzOwnerBundleCode
);
static HRESULT AddCachePackage(
__in BURN_PLAN* pPlan,
__in BURN_PACKAGE* pPackage,
__in BOOL fVital
);
static HRESULT AddCachePackageHelper(
__in BURN_PLAN* pPlan,
__in BURN_PACKAGE* pPackage,
__in BOOL fVital
);
static HRESULT AddCacheSlipstreamMsps(
__in BURN_PLAN* pPlan,
__in BURN_PACKAGE* pPackage
);
static DWORD GetNextCheckpointId(
__in BURN_PLAN* pPlan
);
static HRESULT AppendCacheAction(
__in BURN_PLAN* pPlan,
__out BURN_CACHE_ACTION** ppCacheAction
);
static HRESULT AppendRollbackCacheAction(
__in BURN_PLAN* pPlan,
__out BURN_CACHE_ACTION** ppCacheAction
);
static HRESULT AppendCleanAction(
__in BURN_PLAN* pPlan,
__out BURN_CLEAN_ACTION** ppCleanAction
);
static HRESULT AppendRestoreRelatedBundleAction(
__in BURN_PLAN* pPlan,
__out BURN_EXECUTE_ACTION** ppExecuteAction
);
static HRESULT ProcessPayloadGroup(
__in BURN_PLAN* pPlan,
__in BURN_PAYLOAD_GROUP* pPayloadGroup
);
static void RemoveUnnecessaryActions(
__in BOOL fExecute,
__in BURN_EXECUTE_ACTION* rgActions,
__in DWORD cActions
);
static void FinalizePatchActions(
__in BOOL fExecute,
__in BURN_EXECUTE_ACTION* rgActions,
__in DWORD cActions
);
static void CalculateExpectedRegistrationStates(
__in BURN_PACKAGE* rgPackages,
__in DWORD cPackages
);
static HRESULT PlanDependencyActions(
__in BOOL fBundlePerMachine,
__in BURN_PLAN* pPlan,
__in BURN_PACKAGE* pPackage
);
static HRESULT CalculateExecuteActions(
__in BURN_PACKAGE* pPackage,
__in_opt BURN_ROLLBACK_BOUNDARY* pActiveRollbackBoundary
);
static BURN_CACHE_PACKAGE_TYPE GetCachePackageType(
__in BURN_PACKAGE* pPackage,
__in BOOL fExecute
);
static BOOL ForceCache(
__in BURN_PLAN* pPlan,
__in BURN_PACKAGE* pPackage
);
// function definitions
extern "C" void PlanReset(
__in BURN_PLAN* pPlan,
__in BURN_VARIABLES* pVariables,
__in BURN_CONTAINERS* pContainers,
__in BURN_PACKAGES* pPackages,
__in BURN_PAYLOAD_GROUP* pLayoutPayloads
)
{
ReleaseNullStr(pPlan->sczLayoutDirectory);
PackageUninitialize(&pPlan->forwardCompatibleBundle);
if (pPlan->rgRegistrationActions)
{
for (DWORD i = 0; i < pPlan->cRegistrationActions; ++i)
{
UninitializeRegistrationAction(&pPlan->rgRegistrationActions[i]);
}
MemFree(pPlan->rgRegistrationActions);
}
if (pPlan->rgRollbackRegistrationActions)
{
for (DWORD i = 0; i < pPlan->cRollbackRegistrationActions; ++i)
{
UninitializeRegistrationAction(&pPlan->rgRollbackRegistrationActions[i]);
}
MemFree(pPlan->rgRollbackRegistrationActions);
}
if (pPlan->rgCacheActions)
{
for (DWORD i = 0; i < pPlan->cCacheActions; ++i)
{
UninitializeCacheAction(&pPlan->rgCacheActions[i]);
}
MemFree(pPlan->rgCacheActions);
}
if (pPlan->rgExecuteActions)
{
for (DWORD i = 0; i < pPlan->cExecuteActions; ++i)
{
PlanUninitializeExecuteAction(&pPlan->rgExecuteActions[i]);
}
MemFree(pPlan->rgExecuteActions);
}
if (pPlan->rgRollbackActions)
{
for (DWORD i = 0; i < pPlan->cRollbackActions; ++i)
{
PlanUninitializeExecuteAction(&pPlan->rgRollbackActions[i]);
}
MemFree(pPlan->rgRollbackActions);
}
if (pPlan->rgRestoreRelatedBundleActions)
{
for (DWORD i = 0; i < pPlan->cRestoreRelatedBundleActions; ++i)
{
PlanUninitializeExecuteAction(&pPlan->rgRestoreRelatedBundleActions[i]);
}
MemFree(pPlan->rgRestoreRelatedBundleActions);
}
if (pPlan->rgCleanActions)
{
// Nothing needs to be freed inside clean actions today.
MemFree(pPlan->rgCleanActions);
}
if (pPlan->rgPlannedProviders)
{
ReleaseDependencyArray(pPlan->rgPlannedProviders, pPlan->cPlannedProviders);
}
if (pPlan->rgContainerProgress)
{
MemFree(pPlan->rgContainerProgress);
}
if (pPlan->shContainerProgress)
{
ReleaseDict(pPlan->shContainerProgress);
}
if (pPlan->rgPayloadProgress)
{
MemFree(pPlan->rgPayloadProgress);
}
if (pPlan->shPayloadProgress)
{
ReleaseDict(pPlan->shPayloadProgress);
}
if (pPlan->pPayloads)
{
ResetPlannedPayloadsState(pPlan->pPayloads);
}
memset(pPlan, 0, sizeof(BURN_PLAN));
if (pContainers->rgContainers)
{
for (DWORD i = 0; i < pContainers->cContainers; ++i)
{
ResetPlannedContainerState(&pContainers->rgContainers[i]);
}
}
// Reset the planned actions for each package.
if (pPackages->rgPackages)
{
for (DWORD i = 0; i < pPackages->cPackages; ++i)
{
ResetPlannedPackageState(&pPackages->rgPackages[i]);
}
}
ResetPlannedPayloadGroupState(pLayoutPayloads);
// Reset the planned state for each rollback boundary.
if (pPackages->rgRollbackBoundaries)
{
for (DWORD i = 0; i < pPackages->cRollbackBoundaries; ++i)
{
ResetPlannedRollbackBoundaryState(&pPackages->rgRollbackBoundaries[i]);
}
}
PlanSetVariables(BOOTSTRAPPER_ACTION_UNKNOWN, pVariables);
}
extern "C" void PlanUninitializeExecuteAction(
__in BURN_EXECUTE_ACTION* pExecuteAction
)
{
switch (pExecuteAction->type)
{
case BURN_EXECUTE_ACTION_TYPE_RELATED_BUNDLE:
ReleaseStr(pExecuteAction->relatedBundle.sczIgnoreDependencies);
ReleaseStr(pExecuteAction->relatedBundle.sczAncestors);
ReleaseStr(pExecuteAction->relatedBundle.sczEngineWorkingDirectory);
break;
case BURN_EXECUTE_ACTION_TYPE_BUNDLE_PACKAGE:
ReleaseStr(pExecuteAction->bundlePackage.sczParent);
ReleaseStr(pExecuteAction->bundlePackage.sczIgnoreDependencies);
ReleaseStr(pExecuteAction->bundlePackage.sczAncestors);
ReleaseStr(pExecuteAction->bundlePackage.sczEngineWorkingDirectory);
break;
case BURN_EXECUTE_ACTION_TYPE_EXE_PACKAGE:
ReleaseStr(pExecuteAction->exePackage.sczAncestors);
ReleaseStr(pExecuteAction->exePackage.sczEngineWorkingDirectory);
break;
case BURN_EXECUTE_ACTION_TYPE_MSI_PACKAGE:
ReleaseStr(pExecuteAction->msiPackage.sczLogPath);
ReleaseMem(pExecuteAction->msiPackage.rgFeatures);
break;
case BURN_EXECUTE_ACTION_TYPE_MSP_TARGET:
ReleaseStr(pExecuteAction->mspTarget.sczTargetProductCode);
ReleaseStr(pExecuteAction->mspTarget.sczLogPath);
ReleaseMem(pExecuteAction->mspTarget.rgOrderedPatches);
break;
case BURN_EXECUTE_ACTION_TYPE_MSU_PACKAGE:
ReleaseStr(pExecuteAction->msuPackage.sczLogPath);
break;
case BURN_EXECUTE_ACTION_TYPE_PACKAGE_DEPENDENCY:
ReleaseStr(pExecuteAction->packageDependency.sczBundleProviderKey);
break;
case BURN_EXECUTE_ACTION_TYPE_UNINSTALL_MSI_COMPATIBLE_PACKAGE:
ReleaseStr(pExecuteAction->uninstallMsiCompatiblePackage.sczLogPath);
break;
}
}
extern "C" HRESULT PlanSetVariables(
__in BOOTSTRAPPER_ACTION action,
__in BURN_VARIABLES* pVariables
)
{
HRESULT hr = S_OK;
hr = VariableSetNumeric(pVariables, BURN_BUNDLE_ACTION, action, TRUE);
ExitOnFailure(hr, "Failed to set the bundle action built-in variable.");
LExit:
return hr;
}
extern "C" HRESULT PlanDefaultPackageRequestState(
__in BURN_PACKAGE_TYPE packageType,
__in BOOTSTRAPPER_PACKAGE_STATE currentState,
__in BOOTSTRAPPER_ACTION action,
__in BOOTSTRAPPER_PACKAGE_CONDITION_RESULT installCondition,
__in BOOTSTRAPPER_PACKAGE_CONDITION_RESULT repairCondition,
__in BOOTSTRAPPER_RELATION_TYPE relationType,
__out BOOTSTRAPPER_REQUEST_STATE* pRequestState
)
{
HRESULT hr = S_OK;
BOOTSTRAPPER_REQUEST_STATE defaultRequestState = BOOTSTRAPPER_REQUEST_STATE_NONE;
// If doing layout, then always default to requesting the package be cached.
if (BOOTSTRAPPER_ACTION_LAYOUT == action)
{
*pRequestState = BOOTSTRAPPER_REQUEST_STATE_CACHE;
}
else if (BOOTSTRAPPER_ACTION_CACHE == action)
{
switch (currentState)
{
case BOOTSTRAPPER_PACKAGE_STATE_PRESENT: __fallthrough;
case BOOTSTRAPPER_PACKAGE_STATE_SUPERSEDED:
*pRequestState = BOOTSTRAPPER_REQUEST_STATE_PRESENT;
break;
default:
*pRequestState = BOOTSTRAPPER_REQUEST_STATE_CACHE;
break;
}
}
else // pick the best option for the action state and install condition.
{
hr = GetActionDefaultRequestState(action, currentState, &defaultRequestState);
ExitOnFailure(hr, "Failed to get default request state for action.");
if (BOOTSTRAPPER_ACTION_UNINSTALL != action && BOOTSTRAPPER_ACTION_UNSAFE_UNINSTALL != action)
{
if (BOOTSTRAPPER_RELATION_PATCH == relationType && BURN_PACKAGE_TYPE_MSP == packageType)
{
// For patch related bundles, only install a patch if currently absent during install, modify, or repair.
if (BOOTSTRAPPER_PACKAGE_STATE_ABSENT != currentState)
{
defaultRequestState = BOOTSTRAPPER_REQUEST_STATE_NONE;
}
else if (BOOTSTRAPPER_ACTION_INSTALL == action ||
BOOTSTRAPPER_ACTION_MODIFY == action ||
BOOTSTRAPPER_ACTION_REPAIR == action)
{
defaultRequestState = BOOTSTRAPPER_REQUEST_STATE_PRESENT;
}
}
// If we're not doing an uninstall, use the install condition
// to determine whether to use the default request state or make the package absent.
else if (BOOTSTRAPPER_PACKAGE_CONDITION_FALSE == installCondition)
{
defaultRequestState = BOOTSTRAPPER_REQUEST_STATE_ABSENT;
}
// Obsolete means the package is not on the machine and should not be installed,
// *except* patches can be obsolete and present.
// Superseded means the package is on the machine but not active, so only uninstall operations are allowed.
// All other operations do nothing.
else if (BOOTSTRAPPER_PACKAGE_STATE_OBSOLETE == currentState || BOOTSTRAPPER_PACKAGE_STATE_SUPERSEDED == currentState)
{
defaultRequestState = BOOTSTRAPPER_REQUEST_STATE_PRESENT <= defaultRequestState ? BOOTSTRAPPER_REQUEST_STATE_NONE : defaultRequestState;
}
else if (BOOTSTRAPPER_ACTION_REPAIR == action && BOOTSTRAPPER_PACKAGE_CONDITION_FALSE == repairCondition)
{
defaultRequestState = BOOTSTRAPPER_REQUEST_STATE_PRESENT;
}
}
*pRequestState = defaultRequestState;
}
LExit:
return hr;
}
extern "C" HRESULT PlanLayoutBundle(
__in BURN_PLAN* pPlan,
__in_z LPCWSTR wzExecutableName,
__in DWORD64 qwBundleSize,
__in BURN_VARIABLES* pVariables,
__in BURN_PAYLOAD_GROUP* pLayoutPayloads
)
{
HRESULT hr = S_OK;
BURN_CACHE_ACTION* pCacheAction = NULL;
LPWSTR sczLayoutDirectory = NULL;
LPWSTR sczExecutablePath = NULL;
// Get the layout directory.
hr = VariableGetString(pVariables, BURN_BUNDLE_LAYOUT_DIRECTORY, &sczLayoutDirectory);
if (E_NOTFOUND == hr) // if not set, use the current directory as the layout directory.
{
hr = PathForCurrentProcess(&sczExecutablePath, NULL);
ExitOnFailure(hr, "Failed to get path for current executing process as layout directory.");
hr = PathGetDirectory(sczExecutablePath, &sczLayoutDirectory);
ExitOnFailure(hr, "Failed to get executing process as layout directory.");
}
ExitOnFailure(hr, "Failed to get bundle layout directory property.");
hr = PathGetFullPathName(sczLayoutDirectory, &pPlan->sczLayoutDirectory, NULL, NULL);
ExitOnFailure(hr, "Failed to ensure layout directory is fully qualified.");
hr = PathBackslashTerminate(&pPlan->sczLayoutDirectory);
ExitOnFailure(hr, "Failed to ensure layout directory is backslash terminated.");
hr = ProcessPayloadGroup(pPlan, pLayoutPayloads);
ExitOnFailure(hr, "Failed to process payload group for bundle.");
// Plan the layout of the bundle engine itself.
hr = AppendCacheAction(pPlan, &pCacheAction);
ExitOnFailure(hr, "Failed to append bundle start action.");
pCacheAction->type = BURN_CACHE_ACTION_TYPE_LAYOUT_BUNDLE;
hr = StrAllocString(&pCacheAction->bundleLayout.sczExecutableName, wzExecutableName, 0);
ExitOnFailure(hr, "Failed to to copy executable name for bundle.");
hr = CacheCalculateBundleLayoutWorkingPath(pPlan->pCache, pPlan->wzBundleCode, &pCacheAction->bundleLayout.sczUnverifiedPath);
ExitOnFailure(hr, "Failed to calculate bundle layout working path.");
pCacheAction->bundleLayout.qwBundleSize = qwBundleSize;
pCacheAction->bundleLayout.pPayloadGroup = pLayoutPayloads;
// Acquire + Verify + Finalize
pPlan->qwCacheSizeTotal += 3 * qwBundleSize;
++pPlan->cOverallProgressTicksTotal;
LExit:
ReleaseStr(sczExecutablePath);
ReleaseStr(sczLayoutDirectory);
return hr;
}
extern "C" HRESULT PlanForwardCompatibleBundles(
__in BURN_USER_EXPERIENCE* pUX,
__in BURN_PLAN* pPlan,
__in BURN_REGISTRATION* pRegistration
)
{
HRESULT hr = S_OK;
BOOL fRecommendIgnore = TRUE;
BOOL fIgnoreBundle = FALSE;
BOOTSTRAPPER_ACTION action = pPlan->action;
if (!pRegistration->fForwardCompatibleBundleExists)
{
ExitFunction();
}
// Only change the recommendation if an active parent was provided.
if (pPlan->pInternalCommand->sczActiveParent && *pPlan->pInternalCommand->sczActiveParent)
{
// On install, recommend running the forward compatible bundle because there is an active parent. This
// will essentially register the parent with the forward compatible bundle.
if (BOOTSTRAPPER_ACTION_INSTALL == action)
{
fRecommendIgnore = FALSE;
}
else if (BOOTSTRAPPER_ACTION_UNSAFE_UNINSTALL == action ||
BOOTSTRAPPER_ACTION_UNINSTALL == action ||
BOOTSTRAPPER_ACTION_MODIFY == action ||
BOOTSTRAPPER_ACTION_REPAIR == action)
{
// When modifying the bundle, only recommend running the forward compatible bundle if the parent
// is already registered as a dependent of the provider key.
if (pRegistration->fParentRegisteredAsDependent)
{
fRecommendIgnore = FALSE;
}
}
}
for (DWORD iRelatedBundle = 0; iRelatedBundle < pRegistration->relatedBundles.cRelatedBundles; ++iRelatedBundle)
{
BURN_RELATED_BUNDLE* pRelatedBundle = pRegistration->relatedBundles.rgRelatedBundles + iRelatedBundle;
if (!pRelatedBundle->fForwardCompatible)
{
continue;
}
fIgnoreBundle = fRecommendIgnore;
hr = BACallbackOnPlanForwardCompatibleBundle(pUX, pRelatedBundle->package.sczId, pRelatedBundle->detectRelationType, pRelatedBundle->sczTag, pRelatedBundle->package.fPerMachine, pRelatedBundle->pVersion, &fIgnoreBundle);
ExitOnRootFailure(hr, "BA aborted plan forward compatible bundle.");
if (!fIgnoreBundle)
{
hr = PseudoBundleInitializePassthrough(&pPlan->forwardCompatibleBundle, pPlan->pInternalCommand, pPlan->pCommand, &pRelatedBundle->package);
ExitOnFailure(hr, "Failed to initialize pass through bundle.");
pPlan->fEnabledForwardCompatibleBundle = TRUE;
break;
}
}
LExit:
return hr;
}
extern "C" HRESULT PlanPackages(
__in BURN_USER_EXPERIENCE* pUX,
__in BURN_PACKAGES* pPackages,
__in BURN_PLAN* pPlan,
__in BURN_LOGGING* pLog,
__in BURN_VARIABLES* pVariables
)
{
HRESULT hr = S_OK;
hr = PlanPackagesHelper(pPackages->rgPackages, pPackages->cPackages, pUX, pPlan, pLog, pVariables);
return hr;
}
extern "C" HRESULT PlanRegistration(
__in BURN_PLAN* pPlan,
__in BURN_REGISTRATION* pRegistration,
__in BURN_DEPENDENCIES* pDependencies,
__in BOOTSTRAPPER_RESUME_TYPE /*resumeType*/,
__in BOOTSTRAPPER_RELATION_TYPE relationType,
__inout BOOL* pfContinuePlanning
)
{
HRESULT hr = S_OK;
STRINGDICT_HANDLE sdBundleDependents = NULL;
STRINGDICT_HANDLE sdIgnoreDependents = NULL;
BOOL fDependentBlocksUninstall = FALSE;
pPlan->fCanAffectMachineState = TRUE; // register the bundle since we're modifying machine state.
pPlan->fDisallowRemoval = FALSE; // by default the bundle can be planned to be removed
// Ensure the bundle is cached if not running from the cache.
if (!CacheBundleRunningFromCache(pPlan->pCache))
{
pPlan->dwRegistrationOperations |= BURN_REGISTRATION_ACTION_OPERATIONS_CACHE_BUNDLE;
}
if (pPlan->pInternalCommand->fArpSystemComponent)
{
pPlan->dwRegistrationOperations |= BURN_REGISTRATION_ACTION_OPERATIONS_ARP_SYSTEM_COMPONENT;
}
if (BOOTSTRAPPER_ACTION_UNINSTALL == pPlan->action || BOOTSTRAPPER_ACTION_UNSAFE_UNINSTALL == pPlan->action)
{
// If our provider key was not owned by a different bundle,
// then plan to write our provider key registration to "fix it" if broken
// in case the bundle isn't successfully uninstalled.
if (!pRegistration->fDetectedForeignProviderKeyBundleCode)
{
pPlan->dwRegistrationOperations |= BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_PROVIDER_KEY;
}
// Create the dictionary of dependents that should be ignored.
hr = DictCreateStringList(&sdIgnoreDependents, 5, DICT_FLAG_CASEINSENSITIVE);
ExitOnFailure(hr, "Failed to create the string dictionary.");
// If the self-dependent dependent exists, plan its removal. If we did not do this, we
// would prevent self-removal.
if (pRegistration->fSelfRegisteredAsDependent)
{
hr = AddRegistrationAction(pPlan, BURN_DEPENDENT_REGISTRATION_ACTION_TYPE_UNREGISTER, pDependencies->wzSelfDependent, pRegistration->sczCode);
ExitOnFailure(hr, "Failed to allocate registration action.");
hr = DependencyAddIgnoreDependencies(sdIgnoreDependents, pDependencies->wzSelfDependent);
ExitOnFailure(hr, "Failed to add self-dependent to ignore dependents.");
}
if (!pDependencies->fIgnoreAllDependents)
{
// If we are not doing an upgrade, we check to see if there are still dependents on us and if so we skip planning.
// However, when being upgraded, we always execute our uninstall because a newer version of us is probably
// already on the machine and we need to clean up the stuff specific to this bundle.
if (BOOTSTRAPPER_RELATION_UPGRADE != relationType)
{
// If there were other dependencies to ignore, add them.
for (DWORD iDependency = 0; iDependency < pDependencies->cIgnoredDependencies; ++iDependency)
{
DEPENDENCY* pDependency = pDependencies->rgIgnoredDependencies + iDependency;
hr = DictKeyExists(sdIgnoreDependents, pDependency->sczKey);
if (E_NOTFOUND != hr)
{
ExitOnFailure(hr, "Failed to check the dictionary of ignored dependents.");
}
else
{
hr = DictAddKey(sdIgnoreDependents, pDependency->sczKey);
ExitOnFailure(hr, "Failed to add dependent key to ignored dependents.");
}
}
// For addon or patch bundles, dependent related bundles should be ignored. This allows
// that addon or patch to be removed even though bundles it targets still are registered.
for (DWORD i = 0; i < pRegistration->relatedBundles.cRelatedBundles; ++i)
{
const BURN_RELATED_BUNDLE* pRelatedBundle = pRegistration->relatedBundles.rgRelatedBundles + i;
if (BOOTSTRAPPER_RELATION_DEPENDENT_ADDON == pRelatedBundle->planRelationType ||
BOOTSTRAPPER_RELATION_DEPENDENT_PATCH == pRelatedBundle->planRelationType)
{
for (DWORD j = 0; j < pRelatedBundle->package.cDependencyProviders; ++j)
{
const BURN_DEPENDENCY_PROVIDER* pProvider = pRelatedBundle->package.rgDependencyProviders + j;
hr = DependencyAddIgnoreDependencies(sdIgnoreDependents, pProvider->sczKey);
ExitOnFailure(hr, "Failed to add dependent bundle provider key to ignore dependents.");
}
}
}
// If there are any (non-ignored and not-planned-to-be-removed) dependents left, skip planning.
for (DWORD iDependent = 0; iDependent < pRegistration->cDependents; ++iDependent)
{
DEPENDENCY* pDependent = pRegistration->rgDependents + iDependent;
hr = DictKeyExists(sdIgnoreDependents, pDependent->sczKey);
if (E_NOTFOUND == hr)
{
hr = S_OK;
// TODO: callback to the BA and let it have the option to ignore this dependent?
if (!fDependentBlocksUninstall)
{
fDependentBlocksUninstall = TRUE;
LogId(REPORT_STANDARD, MSG_PLAN_SKIPPED_DUE_TO_DEPENDENTS);
}
LogId(REPORT_VERBOSE, MSG_DEPENDENCY_BUNDLE_DEPENDENT, pDependent->sczKey, LoggingStringOrUnknownIfNull(pDependent->sczName));
}
ExitOnFailure(hr, "Failed to check for remaining dependents during planning.");
}
if (fDependentBlocksUninstall)
{
if (BOOTSTRAPPER_ACTION_UNSAFE_UNINSTALL == pPlan->action)
{
fDependentBlocksUninstall = FALSE;
LogId(REPORT_STANDARD, MSG_PLAN_NOT_SKIPPED_DUE_TO_DEPENDENTS);
}
else
{
pPlan->fDisallowRemoval = TRUE; // ensure the registration stays
*pfContinuePlanning = FALSE; // skip the rest of planning.
}
}
}
}
}
else
{
BOOL fAddonOrPatchBundle = (pRegistration->cAddonCodes || pRegistration->cPatchCodes);
// Always plan to write our provider key registration when installing/modify/repair to "fix it"
// if broken.
pPlan->dwRegistrationOperations |= BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_PROVIDER_KEY;
// Create the dictionary of bundle dependents.
hr = DictCreateStringList(&sdBundleDependents, 5, DICT_FLAG_CASEINSENSITIVE);
ExitOnFailure(hr, "Failed to create the string dictionary.");
for (DWORD iDependent = 0; iDependent < pRegistration->cDependents; ++iDependent)
{
DEPENDENCY* pDependent = pRegistration->rgDependents + iDependent;
hr = DictKeyExists(sdBundleDependents, pDependent->sczKey);
if (E_NOTFOUND == hr)
{
hr = DictAddKey(sdBundleDependents, pDependent->sczKey);
ExitOnFailure(hr, "Failed to add dependent key to bundle dependents.");
}
ExitOnFailure(hr, "Failed to check the dictionary of bundle dependents.");
}
// Register each dependent related bundle. The ensures that addons and patches are reference
// counted and stick around until the last targeted bundle is removed.
for (DWORD i = 0; i < pRegistration->relatedBundles.cRelatedBundles; ++i)
{
const BURN_RELATED_BUNDLE* pRelatedBundle = pRegistration->relatedBundles.rgRelatedBundles + i;
if (BOOTSTRAPPER_RELATION_DEPENDENT_ADDON == pRelatedBundle->planRelationType ||
BOOTSTRAPPER_RELATION_DEPENDENT_PATCH == pRelatedBundle->planRelationType)
{
for (DWORD j = 0; j < pRelatedBundle->package.cDependencyProviders; ++j)
{
const BURN_DEPENDENCY_PROVIDER* pProvider = pRelatedBundle->package.rgDependencyProviders + j;
hr = DictKeyExists(sdBundleDependents, pProvider->sczKey);
if (E_NOTFOUND == hr)
{
hr = DictAddKey(sdBundleDependents, pProvider->sczKey);
ExitOnFailure(hr, "Failed to add new dependent key to bundle dependents.");
hr = AddRegistrationAction(pPlan, BURN_DEPENDENT_REGISTRATION_ACTION_TYPE_REGISTER, pProvider->sczKey, pRelatedBundle->package.sczId);
ExitOnFailure(hr, "Failed to add registration action for dependent related bundle.");
}
ExitOnFailure(hr, "Failed to check the dictionary of bundle dependents.");
}
}
}
// Only do the following if we decided there was a dependent self to register. If so and and an explicit parent was
// provided, register dependent self. Otherwise, if this bundle is not an addon or patch bundle then self-regisiter
// as our own dependent.
if (pDependencies->wzSelfDependent && !pRegistration->fSelfRegisteredAsDependent && (pDependencies->wzActiveParent || !fAddonOrPatchBundle))
{
hr = AddRegistrationAction(pPlan, BURN_DEPENDENT_REGISTRATION_ACTION_TYPE_REGISTER, pDependencies->wzSelfDependent, pRegistration->sczCode);
ExitOnFailure(hr, "Failed to add registration action for self dependent.");
}
}
LExit:
ReleaseDict(sdBundleDependents);
ReleaseDict(sdIgnoreDependents);
return hr;
}
extern "C" HRESULT PlanPassThroughBundle(
__in BURN_USER_EXPERIENCE* pUX,
__in BURN_PACKAGE* pPackage,
__in BURN_PLAN* pPlan,
__in BURN_LOGGING* pLog,
__in BURN_VARIABLES* pVariables
)
{
HRESULT hr = S_OK;
// Plan passthrough package.
hr = PlanPackagesHelper(pPackage, 1, pUX, pPlan, pLog, pVariables);
ExitOnFailure(hr, "Failed to process passthrough package.");
LExit:
return hr;
}
extern "C" HRESULT PlanUpdateBundle(
__in BURN_USER_EXPERIENCE* pUX,
__in BURN_PACKAGE* pPackage,
__in BURN_PLAN* pPlan,
__in BURN_LOGGING* pLog,
__in BURN_VARIABLES* pVariables
)
{
HRESULT hr = S_OK;
Assert(!pPackage->fPerMachine);
Assert(BURN_PACKAGE_TYPE_EXE == pPackage->type);
pPackage->Exe.fFireAndForget = BOOTSTRAPPER_ACTION_UPDATE_REPLACE == pPlan->action;
// Plan update package.
hr = PlanPackagesHelper(pPackage, 1, pUX, pPlan, pLog, pVariables);
ExitOnFailure(hr, "Failed to process update package.");
LExit:
return hr;
}
static HRESULT PlanPackagesHelper(
__in BURN_PACKAGE* rgPackages,
__in DWORD cPackages,
__in BURN_USER_EXPERIENCE* pUX,
__in BURN_PLAN* pPlan,
__in BURN_LOGGING* pLog,
__in BURN_VARIABLES* pVariables
)
{
HRESULT hr = S_OK;
BOOL fBundlePerMachine = pPlan->fPerMachine; // bundle is per-machine if plan starts per-machine.
BURN_ROLLBACK_BOUNDARY* pRollbackBoundary = NULL;
BOOL fReverseOrder = BOOTSTRAPPER_ACTION_UNINSTALL == pPlan->action || BOOTSTRAPPER_ACTION_UNSAFE_UNINSTALL == pPlan->action;
// Initialize the packages.
for (DWORD i = 0; i < cPackages; ++i)
{
DWORD iPackage = fReverseOrder ? cPackages - 1 - i : i;
BURN_PACKAGE* pPackage = rgPackages + iPackage;
hr = InitializePackage(pPlan, pUX, pVariables, pPackage);
ExitOnFailure(hr, "Failed to initialize package.");
}
// Initialize the patch targets after all packages, since they could rely on the requested state of packages that are after the patch's package in the chain.
for (DWORD i = 0; i < cPackages; ++i)
{
DWORD iPackage = fReverseOrder ? cPackages - 1 - i : i;
BURN_PACKAGE* pPackage = rgPackages + iPackage;
if (BURN_PACKAGE_TYPE_MSP == pPackage->type)
{
hr = MspEnginePlanInitializePackage(pPackage, pUX);
ExitOnFailure(hr, "Failed to initialize plan package: %ls", pPackage->sczId);
}
}
// Plan the packages.
for (DWORD i = 0; i < cPackages; ++i)
{
DWORD iPackage = fReverseOrder ? cPackages - 1 - i : i;
BURN_PACKAGE* pPackage = rgPackages + iPackage;
hr = ProcessPackage(fBundlePerMachine, pUX, pPlan, pPackage, pLog, pVariables, &pRollbackBoundary);
ExitOnFailure(hr, "Failed to process package.");
}
// If we still have an open rollback boundary, complete it.
if (pRollbackBoundary)
{
hr = PlanRollbackBoundaryComplete(pPlan);
ExitOnFailure(hr, "Failed to plan final rollback boundary complete.");
pRollbackBoundary = NULL;
}
// Passthrough packages are never cleaned up by the calling bundle (they delete themselves when appropriate).
if (!pPlan->fEnabledForwardCompatibleBundle && BOOTSTRAPPER_ACTION_LAYOUT != pPlan->action)
{
// Plan clean up of packages.
for (DWORD i = 0; i < cPackages; ++i)
{
DWORD iPackage = fReverseOrder ? cPackages - 1 - i : i;
BURN_PACKAGE* pPackage = rgPackages + iPackage;
hr = PlanCleanPackage(pPlan, pPackage);
ExitOnFailure(hr, "Failed to plan clean package.");
}
}
// Remove unnecessary actions.
hr = PlanFinalizeActions(pPlan);
ExitOnFailure(hr, "Failed to remove unnecessary actions from plan.");
CalculateExpectedRegistrationStates(rgPackages, cPackages);
// Let the BA know the actions that were planned.
for (DWORD i = 0; i < cPackages; ++i)
{
DWORD iPackage = fReverseOrder ? cPackages - 1 - i : i;
BURN_PACKAGE* pPackage = rgPackages + iPackage;
BACallbackOnPlannedPackage(pUX, pPackage->sczId, pPackage->execute, pPackage->rollback, NULL != pPackage->hCacheEvent, pPackage->fPlannedUncache);
if (pPackage->compatiblePackage.fPlannable)
{
BACallbackOnPlannedCompatiblePackage(pUX, pPackage->sczId, pPackage->compatiblePackage.compatibleEntry.sczId, pPackage->compatiblePackage.fRemove);
}
}
LExit:
return hr;
}
static HRESULT InitializePackage(
__in BURN_PLAN* pPlan,
__in BURN_USER_EXPERIENCE* pUX,
__in BURN_VARIABLES* pVariables,
__in BURN_PACKAGE* pPackage
)
{
HRESULT hr = S_OK;
BOOTSTRAPPER_PACKAGE_CONDITION_RESULT installCondition = BOOTSTRAPPER_PACKAGE_CONDITION_DEFAULT;
BOOTSTRAPPER_PACKAGE_CONDITION_RESULT repairCondition = BOOTSTRAPPER_PACKAGE_CONDITION_DEFAULT;
BOOL fEvaluatedCondition = FALSE;
BOOL fBeginCalled = FALSE;
BOOTSTRAPPER_RELATION_TYPE relationType = pPlan->pCommand->relationType;
if (BURN_PACKAGE_TYPE_EXE == pPackage->type && pPackage->Exe.fPseudoPackage)
{
// Exe pseudo packages are not configurable.
// The BA already requested this package to be executed
// * by the overall plan action for UpdateReplace
// * by enabling the forward compatible bundle for Passthrough
pPackage->defaultRequested = pPackage->requested = BOOTSTRAPPER_REQUEST_STATE_FORCE_PRESENT;
ExitFunction();
}
if (pPackage->fCanAffectRegistration)
{
pPackage->expectedCacheRegistrationState = pPackage->cacheRegistrationState;
pPackage->expectedInstallRegistrationState = pPackage->installRegistrationState;
}
if (pPackage->sczInstallCondition && *pPackage->sczInstallCondition)
{
hr = ConditionEvaluate(pVariables, pPackage->sczInstallCondition, &fEvaluatedCondition);
ExitOnFailure(hr, "Failed to evaluate install condition.");
installCondition = fEvaluatedCondition ? BOOTSTRAPPER_PACKAGE_CONDITION_TRUE : BOOTSTRAPPER_PACKAGE_CONDITION_FALSE;
}
if (pPackage->sczRepairCondition && *pPackage->sczRepairCondition)
{
hr = ConditionEvaluate(pVariables, pPackage->sczRepairCondition, &fEvaluatedCondition);
ExitOnFailure(hr, "Failed to evaluate repair condition.");
repairCondition = fEvaluatedCondition ? BOOTSTRAPPER_PACKAGE_CONDITION_TRUE : BOOTSTRAPPER_PACKAGE_CONDITION_FALSE;
}
// Remember the default requested state so the engine doesn't get blamed for planning the wrong thing if the BA changes it.
hr = PlanDefaultPackageRequestState(pPackage->type, pPackage->currentState, pPlan->action, installCondition, repairCondition, relationType, &pPackage->defaultRequested);
ExitOnFailure(hr, "Failed to set default package state.");
pPackage->requested = pPackage->defaultRequested;
fBeginCalled = TRUE;
hr = BACallbackOnPlanPackageBegin(pUX, pPackage->sczId, pPackage->currentState, pPackage->fCached, installCondition, repairCondition, &pPackage->requested, &pPackage->cacheType);
ExitOnRootFailure(hr, "BA aborted plan package begin.");
if (BURN_PACKAGE_TYPE_MSI == pPackage->type)
{
hr = MsiEnginePlanInitializePackage(pPackage, pPlan->action, pVariables, pUX);
ExitOnFailure(hr, "Failed to initialize plan package: %ls", pPackage->sczId);
}
LExit:
if (fBeginCalled)
{
BACallbackOnPlanPackageComplete(pUX, pPackage->sczId, hr, pPackage->requested);
}
return hr;
}
static HRESULT ProcessPackage(
__in BOOL fBundlePerMachine,
__in BURN_USER_EXPERIENCE* pUX,
__in BURN_PLAN* pPlan,
__in BURN_PACKAGE* pPackage,
__in BURN_LOGGING* pLog,
__in BURN_VARIABLES* pVariables,
__inout BURN_ROLLBACK_BOUNDARY** ppRollbackBoundary
)
{
HRESULT hr = S_OK;
BURN_ROLLBACK_BOUNDARY* pEffectiveRollbackBoundary = NULL;
BOOL fBackward = BOOTSTRAPPER_ACTION_UNINSTALL == pPlan->action || BOOTSTRAPPER_ACTION_UNSAFE_UNINSTALL == pPlan->action;
pEffectiveRollbackBoundary = fBackward ? pPackage->pRollbackBoundaryBackward : pPackage->pRollbackBoundaryForward;
hr = ProcessPackageRollbackBoundary(pPlan, pUX, pLog, pVariables, pEffectiveRollbackBoundary, ppRollbackBoundary);
ExitOnFailure(hr, "Failed to process package rollback boundary.");
if (BOOTSTRAPPER_ACTION_LAYOUT == pPlan->action)
{
if (BOOTSTRAPPER_REQUEST_STATE_NONE != pPackage->requested)
{
hr = PlanLayoutPackage(pPlan, pPackage, TRUE);