-
-
Notifications
You must be signed in to change notification settings - Fork 584
Expand file tree
/
Copy pathregistration.cpp
More file actions
1803 lines (1461 loc) · 66.3 KB
/
Copy pathregistration.cpp
File metadata and controls
1803 lines (1461 loc) · 66.3 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"
// constants
const LPCWSTR REGISTRY_RUN_ONCE_KEY = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce";
const LPCWSTR REGISTRY_BUNDLE_DISPLAY_ICON = L"DisplayIcon";
const LPCWSTR REGISTRY_BUNDLE_DISPLAY_VERSION = L"DisplayVersion";
const LPCWSTR REGISTRY_BUNDLE_ESTIMATED_SIZE = L"EstimatedSize";
const LPCWSTR REGISTRY_BUNDLE_INSTALL_DATE = L"InstallDate";
const LPCWSTR REGISTRY_BUNDLE_PUBLISHER = L"Publisher";
const LPCWSTR REGISTRY_BUNDLE_HELP_LINK = L"HelpLink";
const LPCWSTR REGISTRY_BUNDLE_HELP_TELEPHONE = L"HelpTelephone";
const LPCWSTR REGISTRY_BUNDLE_URL_INFO_ABOUT = L"URLInfoAbout";
const LPCWSTR REGISTRY_BUNDLE_URL_UPDATE_INFO = L"URLUpdateInfo";
const LPCWSTR REGISTRY_BUNDLE_PARENT_DISPLAY_NAME = L"ParentDisplayName";
const LPCWSTR REGISTRY_BUNDLE_PARENT_KEY_NAME = L"ParentKeyName";
const LPCWSTR REGISTRY_BUNDLE_COMMENTS = L"Comments";
const LPCWSTR REGISTRY_BUNDLE_CONTACT = L"Contact";
const LPCWSTR REGISTRY_BUNDLE_NO_MODIFY = L"NoModify";
const LPCWSTR REGISTRY_BUNDLE_MODIFY_PATH = L"ModifyPath";
const LPCWSTR REGISTRY_BUNDLE_NO_ELEVATE_ON_MODIFY = L"NoElevateOnModify";
const LPCWSTR REGISTRY_BUNDLE_NO_REMOVE = L"NoRemove";
const LPCWSTR REGISTRY_BUNDLE_SYSTEM_COMPONENT = L"SystemComponent";
const LPCWSTR REGISTRY_BUNDLE_QUIET_UNINSTALL_STRING = L"QuietUninstallString";
const LPCWSTR REGISTRY_BUNDLE_UNINSTALL_STRING = L"UninstallString";
const LPCWSTR REGISTRY_BUNDLE_RESUME_COMMAND_LINE = L"BundleResumeCommandLine";
const LPCWSTR REGISTRY_BUNDLE_VERSION_MAJOR = L"VersionMajor";
const LPCWSTR REGISTRY_BUNDLE_VERSION_MINOR = L"VersionMinor";
const LPCWSTR SWIDTAG_FOLDER = L"swidtag";
const LPCWSTR REGISTRY_BUNDLE_VARIABLE_KEY = L"variables";
const LPCWSTR REGISTRY_BUNDLE_INSTALLED = L"Installed";
// internal function declarations
static HRESULT ParseSoftwareTagsFromXml(
__in IXMLDOMNode* pixnRegistrationNode,
__out BURN_SOFTWARE_TAG** prgSoftwareTags,
__out DWORD* pcSoftwareTags
);
static HRESULT GetBundleManufacturer(
__in BURN_REGISTRATION* pRegistration,
__in BURN_VARIABLES* pVariables,
__out_z LPWSTR* psczBundleManufacturer
);
static HRESULT GetBundleInProgressName(
__in BURN_REGISTRATION* pRegistration,
__in BURN_VARIABLES* pVariables,
__out_z LPWSTR* psczBundleName
);
static HRESULT GetBundleName(
__in BURN_REGISTRATION* pRegistration,
__in BURN_VARIABLES* pVariables,
__out_z LPWSTR* psczBundleName
);
static HRESULT EnsureRegistrationVariable(
__in BURN_VARIABLES* pVariables,
__in_z LPCWSTR wzVariable,
__in_z LPCWSTR wzDefaultValue,
__out_z LPWSTR* psczValue
);
static HRESULT UpdateResumeMode(
__in BURN_REGISTRATION* pRegistration,
__in HKEY hkRegistration,
__in BURN_RESUME_MODE resumeMode,
__in BOOTSTRAPPER_REGISTRATION_TYPE registrationType,
__in BOOL fRestartInitiated
);
static HRESULT FormatUpdateRegistrationKey(
__in BURN_REGISTRATION* pRegistration,
__out_z LPWSTR* psczKey
);
static HRESULT WriteSoftwareTags(
__in BURN_VARIABLES* pVariables,
__in BURN_SOFTWARE_TAGS* pSoftwareTags
);
static HRESULT RemoveSoftwareTags(
__in BURN_VARIABLES* pVariables,
__in BURN_SOFTWARE_TAGS* pSoftwareTags
);
static HRESULT WriteUpdateRegistration(
__in BURN_REGISTRATION* pRegistration,
__in BURN_VARIABLES* pVariables
);
static HRESULT RemoveUpdateRegistration(
__in BURN_REGISTRATION* pRegistration
);
static HRESULT RegWriteStringVariable(
__in HKEY hkKey,
__in BURN_VARIABLES* pVariables,
__in LPCWSTR wzVariable,
__in LPCWSTR wzName
);
static HRESULT UpdateBundleNameRegistration(
__in BURN_REGISTRATION* pRegistration,
__in BURN_VARIABLES* pVariables,
__in HKEY hkRegistration,
__in BOOL fInProgressRegistration
);
static HRESULT UpdateEstimatedSize(
__in HKEY hkRegistration,
__in DWORD64 qwEstimatedSize
);
static BOOL IsWuRebootPending();
static BOOL IsRegistryRebootPending();
static HRESULT RegistrationDetectResumeTypeByHive(
__in HKEY hkRegistrationRoot,
__in BURN_REGISTRATION* pRegistration,
__out BOOTSTRAPPER_RESUME_TYPE* pResumeType
);
static HRESULT DetectInstalled(
__in BURN_REGISTRATION* pRegistration,
__in HKEY hkRoot
);
// function definitions
/*******************************************************************
RegistrationParseFromXml - Parses registration information from manifest.
*******************************************************************/
extern "C" HRESULT RegistrationParseFromXml(
__in BURN_REGISTRATION* pRegistration,
__in BURN_CACHE* pCache,
__in IXMLDOMNode* pixnBundle
)
{
HRESULT hr = S_OK;
IXMLDOMNode* pixnRegistrationNode = NULL;
IXMLDOMNode* pixnArpNode = NULL;
IXMLDOMNode* pixnUpdateNode = NULL;
LPWSTR scz = NULL;
BOOL fFoundXml = FALSE;
// select registration node
hr = XmlSelectSingleNode(pixnBundle, L"Registration", &pixnRegistrationNode);
ExitOnRequiredXmlQueryFailure(hr, "Failed to select registration node.");
// @Code
hr = XmlGetAttributeEx(pixnRegistrationNode, L"Code", &pRegistration->sczCode);
ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Code.");
// @Tag
hr = XmlGetAttributeEx(pixnRegistrationNode, L"Tag", &pRegistration->sczTag);
ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Tag.");
// @PrimaryUpgradeCode
hr = XmlGetAttributeEx(pixnRegistrationNode, L"PrimaryUpgradeCode", &pRegistration->sczPrimaryUpgradeCode);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @PrimaryUpgradeCode.");
hr = BundlePackageEngineParseRelatedCodes(pixnBundle, &pRegistration->rgsczDetectCodes, &pRegistration->cDetectCodes, &pRegistration->rgsczUpgradeCodes, &pRegistration->cUpgradeCodes, &pRegistration->rgsczAddonCodes, &pRegistration->cAddonCodes, &pRegistration->rgsczPatchCodes, &pRegistration->cPatchCodes);
ExitOnFailure(hr, "Failed to parse related bundles");
// @Version
hr = XmlGetAttributeEx(pixnRegistrationNode, L"Version", &scz);
ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Version.");
hr = VerParseVersion(scz, 0, FALSE, &pRegistration->pVersion);
ExitOnFailure(hr, "Failed to parse @Version: %ls", scz);
if (pRegistration->pVersion->fInvalid)
{
LogId(REPORT_WARNING, MSG_MANIFEST_INVALID_VERSION, scz);
}
// @ProviderKey
hr = XmlGetAttributeEx(pixnRegistrationNode, L"ProviderKey", &pRegistration->sczProviderKey);
ExitOnRequiredXmlQueryFailure(hr, "Failed to get @ProviderKey.");
// @ExecutableName
hr = XmlGetAttributeEx(pixnRegistrationNode, L"ExecutableName", &pRegistration->sczExecutableName);
ExitOnRequiredXmlQueryFailure(hr, "Failed to get @ExecutableName.");
// @Scope
hr = PackageParseScopeFromXml(pixnRegistrationNode, &pRegistration->scope);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @Scope.");
// select ARP node
hr = XmlSelectSingleNode(pixnRegistrationNode, L"Arp", &pixnArpNode);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to select ARP node.");
if (fFoundXml)
{
// @DisplayName
hr = XmlGetAttributeEx(pixnArpNode, L"DisplayName", &pRegistration->sczDisplayName);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @DisplayName.");
// @InProgressDisplayName
hr = XmlGetAttributeEx(pixnArpNode, L"InProgressDisplayName", &pRegistration->sczInProgressDisplayName);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @InProgressDisplayName.");
// @DisplayVersion
hr = XmlGetAttributeEx(pixnArpNode, L"DisplayVersion", &pRegistration->sczDisplayVersion);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @DisplayVersion.");
// @Publisher
hr = XmlGetAttributeEx(pixnArpNode, L"Publisher", &pRegistration->sczPublisher);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @Publisher.");
// @HelpLink
hr = XmlGetAttributeEx(pixnArpNode, L"HelpLink", &pRegistration->sczHelpLink);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @HelpLink.");
// @HelpTelephone
hr = XmlGetAttributeEx(pixnArpNode, L"HelpTelephone", &pRegistration->sczHelpTelephone);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @HelpTelephone.");
// @AboutUrl
hr = XmlGetAttributeEx(pixnArpNode, L"AboutUrl", &pRegistration->sczAboutUrl);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @AboutUrl.");
// @UpdateUrl
hr = XmlGetAttributeEx(pixnArpNode, L"UpdateUrl", &pRegistration->sczUpdateUrl);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @UpdateUrl.");
// @ParentDisplayName
hr = XmlGetAttributeEx(pixnArpNode, L"ParentDisplayName", &pRegistration->sczParentDisplayName);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @ParentDisplayName.");
// @Comments
hr = XmlGetAttributeEx(pixnArpNode, L"Comments", &pRegistration->sczComments);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @Comments.");
// @Contact
hr = XmlGetAttributeEx(pixnArpNode, L"Contact", &pRegistration->sczContact);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @Contact.");
// @DisableModify
hr = XmlGetAttributeEx(pixnArpNode, L"DisableModify", &scz);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @DisableModify.");
if (fFoundXml)
{
if (CSTR_EQUAL == ::CompareStringOrdinal(scz, -1, L"button", -1, FALSE))
{
pRegistration->modify = BURN_REGISTRATION_MODIFY_DISABLE_BUTTON;
}
else if (CSTR_EQUAL == ::CompareStringOrdinal(scz, -1, L"yes", -1, FALSE))
{
pRegistration->modify = BURN_REGISTRATION_MODIFY_DISABLE;
}
else if (CSTR_EQUAL == ::CompareStringOrdinal(scz, -1, L"no", -1, FALSE))
{
pRegistration->modify = BURN_REGISTRATION_MODIFY_ENABLED;
}
else
{
ExitWithRootFailure(hr, E_UNEXPECTED, "Invalid modify disabled type: %ls", scz);
}
}
else
{
pRegistration->modify = BURN_REGISTRATION_MODIFY_ENABLED;
}
// @DisableRemove
hr = XmlGetYesNoAttribute(pixnArpNode, L"DisableRemove", &pRegistration->fNoRemove);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @DisableRemove.");
}
if (pRegistration->fNoRemove && BURN_REGISTRATION_MODIFY_ENABLED != pRegistration->modify)
{
pRegistration->fForceSystemComponent = TRUE;
}
hr = ParseSoftwareTagsFromXml(pixnRegistrationNode, &pRegistration->softwareTags.rgSoftwareTags, &pRegistration->softwareTags.cSoftwareTags);
ExitOnFailure(hr, "Failed to parse software tag.");
// select Update node
hr = XmlSelectSingleNode(pixnRegistrationNode, L"Update", &pixnUpdateNode);
ExitOnOptionalXmlQueryFailure(hr, pRegistration->update.fRegisterUpdate, "Failed to select Update node.");
if (pRegistration->update.fRegisterUpdate)
{
// @Manufacturer
hr = XmlGetAttributeEx(pixnUpdateNode, L"Manufacturer", &pRegistration->update.sczManufacturer);
ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Manufacturer.");
// @Department
hr = XmlGetAttributeEx(pixnUpdateNode, L"Department", &pRegistration->update.sczDepartment);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @Department.");
// @ProductFamily
hr = XmlGetAttributeEx(pixnUpdateNode, L"ProductFamily", &pRegistration->update.sczProductFamily);
ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @ProductFamily.");
// @Name
hr = XmlGetAttributeEx(pixnUpdateNode, L"Name", &pRegistration->update.sczName);
ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Name.");
// @Classification
hr = XmlGetAttributeEx(pixnUpdateNode, L"Classification", &pRegistration->update.sczClassification);
ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Classification.");
}
// Handle the easy case of build-time bundle scope early.
if (BOOTSTRAPPER_PACKAGE_SCOPE_PER_MACHINE == pRegistration->scope || BOOTSTRAPPER_PACKAGE_SCOPE_PER_USER == pRegistration->scope)
{
pRegistration->fPerMachine = BOOTSTRAPPER_PACKAGE_SCOPE_PER_MACHINE == pRegistration->scope;
hr = RegistrationSetPaths(pRegistration, pCache);
ExitOnFailure(hr, "Failed to set registration paths for fixed scope.");
}
else
{
pRegistration->hkRoot = reinterpret_cast<HKEY>(0ull);
}
// build uninstall registry key path
hr = StrAllocFormatted(&pRegistration->sczRegistrationKey, L"%ls\\%ls", BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY, pRegistration->sczCode);
ExitOnFailure(hr, "Failed to build uninstall registry key path.");
LExit:
ReleaseObject(pixnRegistrationNode);
ReleaseObject(pixnArpNode);
ReleaseObject(pixnUpdateNode);
ReleaseStr(scz);
return hr;
}
/*******************************************************************
RegistrationUninitialize -
*******************************************************************/
extern "C" void RegistrationUninitialize(
__in BURN_REGISTRATION* pRegistration
)
{
ReleaseStr(pRegistration->sczCode);
ReleaseStr(pRegistration->sczTag);
ReleaseStr(pRegistration->sczPrimaryUpgradeCode);
for (DWORD i = 0; i < pRegistration->cDetectCodes; ++i)
{
ReleaseStr(pRegistration->rgsczDetectCodes[i]);
}
ReleaseMem(pRegistration->rgsczDetectCodes);
for (DWORD i = 0; i < pRegistration->cUpgradeCodes; ++i)
{
ReleaseStr(pRegistration->rgsczUpgradeCodes[i]);
}
ReleaseMem(pRegistration->rgsczUpgradeCodes);
for (DWORD i = 0; i < pRegistration->cAddonCodes; ++i)
{
ReleaseStr(pRegistration->rgsczAddonCodes[i]);
}
ReleaseMem(pRegistration->rgsczAddonCodes);
for (DWORD i = 0; i < pRegistration->cPatchCodes; ++i)
{
ReleaseStr(pRegistration->rgsczPatchCodes[i]);
}
ReleaseMem(pRegistration->rgsczPatchCodes);
ReleaseStr(pRegistration->sczProviderKey);
ReleaseStr(pRegistration->sczExecutableName);
ReleaseStr(pRegistration->sczRegistrationKey);
ReleaseStr(pRegistration->sczCacheExecutablePath);
ReleaseStr(pRegistration->sczResumeCommandLine);
ReleaseStr(pRegistration->sczStateFile);
ReleaseStr(pRegistration->sczDisplayName);
ReleaseStr(pRegistration->sczInProgressDisplayName);
ReleaseStr(pRegistration->sczDisplayVersion);
ReleaseStr(pRegistration->sczPublisher);
ReleaseStr(pRegistration->sczHelpLink);
ReleaseStr(pRegistration->sczHelpTelephone);
ReleaseStr(pRegistration->sczAboutUrl);
ReleaseStr(pRegistration->sczUpdateUrl);
ReleaseStr(pRegistration->sczParentDisplayName);
ReleaseStr(pRegistration->sczComments);
ReleaseStr(pRegistration->sczContact);
ReleaseStr(pRegistration->update.sczManufacturer);
ReleaseStr(pRegistration->update.sczDepartment);
ReleaseStr(pRegistration->update.sczProductFamily);
ReleaseStr(pRegistration->update.sczName);
ReleaseStr(pRegistration->update.sczClassification);
if (pRegistration->softwareTags.rgSoftwareTags)
{
for (DWORD i = 0; i < pRegistration->softwareTags.cSoftwareTags; ++i)
{
ReleaseStr(pRegistration->softwareTags.rgSoftwareTags[i].sczFilename);
ReleaseStr(pRegistration->softwareTags.rgSoftwareTags[i].sczRegid);
ReleaseStr(pRegistration->softwareTags.rgSoftwareTags[i].sczPath);
ReleaseStr(pRegistration->softwareTags.rgSoftwareTags[i].sczTag);
}
MemFree(pRegistration->softwareTags.rgSoftwareTags);
}
ReleaseStr(pRegistration->sczDetectedProviderKeyBundleCode);
ReleaseStr(pRegistration->sczBundlePackageAncestors);
RelatedBundlesUninitialize(&pRegistration->relatedBundles);
if (pRegistration->rgDependents)
{
ReleaseDependencyArray(pRegistration->rgDependents, pRegistration->cDependents);
}
// clear struct
memset(pRegistration, 0, sizeof(BURN_REGISTRATION));
}
/*******************************************************************
RegistrationSetVariables - Initializes bundle variables that map to
registration entities.
*******************************************************************/
extern "C" HRESULT RegistrationSetVariables(
__in BURN_REGISTRATION* pRegistration,
__in BURN_VARIABLES* pVariables
)
{
HRESULT hr = S_OK;
LPWSTR scz = NULL;
// Ensure the registration bundle name is updated.
hr = GetBundleInProgressName(pRegistration, pVariables, &scz);
ExitOnFailure(hr, "Failed to initialize bundle name.");
hr = GetBundleName(pRegistration, pVariables, &scz);
ExitOnFailure(hr, "Failed to initialize bundle name.");
hr = GetBundleManufacturer(pRegistration, pVariables, &scz);
ExitOnFailure(hr, "Failed to initialize bundle manufacturer.");
hr = VariableSetString(pVariables, BURN_BUNDLE_PROVIDER_KEY, pRegistration->sczProviderKey, TRUE, FALSE);
ExitOnFailure(hr, "Failed to overwrite the bundle provider key built-in variable.");
hr = VariableSetString(pVariables, BURN_BUNDLE_TAG, pRegistration->sczTag, TRUE, FALSE);
ExitOnFailure(hr, "Failed to overwrite the bundle tag built-in variable.");
hr = VariableSetVersion(pVariables, BURN_BUNDLE_VERSION, pRegistration->pVersion, TRUE);
ExitOnFailure(hr, "Failed to overwrite the bundle version built-in variable.");
hr = VariableSetNumeric(pVariables, BURN_BUNDLE_AUTHORED_SCOPE, pRegistration->scope, TRUE);
ExitOnFailure(hr, "Failed to set the bundle authored scope built-in variable.");
LExit:
ReleaseStr(scz);
return hr;
}
/*******************************************************************
RegistrationSetDynamicVariables - Initializes bundle variables that
map to registration entities that can change during execution.
*******************************************************************/
extern "C" HRESULT RegistrationSetDynamicVariables(
__in BURN_REGISTRATION* pRegistration,
__in BURN_VARIABLES* pVariables
)
{
HRESULT hr = S_OK;
LONGLONG llInstalled = 0;
// Detect if bundle is already installed.
hr = RegistrationDetectInstalled(pRegistration);
ExitOnFailure(hr, "Failed to detect bundle install state.");
llInstalled = BOOTSTRAPPER_REGISTRATION_TYPE_FULL == pRegistration->detectedRegistrationType ? 1 : 0;
hr = VariableSetNumeric(pVariables, BURN_BUNDLE_INSTALLED, llInstalled, TRUE);
ExitOnFailure(hr, "Failed to set the bundle installed built-in variable.");
hr = VariableSetNumeric(pVariables, BURN_BUNDLE_DETECTED_SCOPE, pRegistration->detectedScope, TRUE);
ExitOnFailure(hr, "Failed to set the bundle detected scope built-in variable.");
hr = VariableSetNumeric(pVariables, VARIABLE_REBOOTPENDING, IsWuRebootPending() || IsRegistryRebootPending(), TRUE);
ExitOnFailure(hr, "Failed to overwrite the bundle reboot-pending built-in variable.");
LExit:
return hr;
}
extern "C" HRESULT RegistrationDetectInstalled(
__in BURN_REGISTRATION* pRegistration
)
{
HRESULT hr = S_OK;
if (pRegistration->hkRoot)
{
hr = DetectInstalled(pRegistration, pRegistration->hkRoot);
}
else
{
// For PUOM/PMOU bundles, check per-machine then fall back to per-user.
hr = DetectInstalled(pRegistration, HKEY_LOCAL_MACHINE);
if (FAILED(hr))
{
hr = DetectInstalled(pRegistration, HKEY_CURRENT_USER);
}
}
//LExit:
// Not finding the key or value is okay.
if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
{
hr = S_OK;
}
return hr;
}
/*******************************************************************
RegistrationDetectResumeMode - Detects registration information on the system
to determine if a resume is taking place.
*******************************************************************/
extern "C" HRESULT RegistrationDetectResumeType(
__in BURN_REGISTRATION* pRegistration,
__out BOOTSTRAPPER_RESUME_TYPE* pResumeType
)
{
HRESULT hr = S_OK;
if (pRegistration->hkRoot)
{
hr = RegistrationDetectResumeTypeByHive(pRegistration->hkRoot, pRegistration, pResumeType);
}
else
{
hr = RegistrationDetectResumeTypeByHive(HKEY_LOCAL_MACHINE, pRegistration, pResumeType);
if (BOOTSTRAPPER_RESUME_TYPE_NONE == *pResumeType)
{
hr = RegistrationDetectResumeTypeByHive(HKEY_CURRENT_USER, pRegistration, pResumeType);
}
}
ExitOnFailure(hr, "Failed to find bundle registration: %ls", pRegistration->sczRegistrationKey);
LExit:
return hr;
}
/*******************************************************************
RegistrationDetectRelatedBundles - finds the bundles with same
upgrade/detect/addon/patch codes.
*******************************************************************/
extern "C" HRESULT RegistrationDetectRelatedBundles(
__in BURN_REGISTRATION* pRegistration
)
{
HRESULT hr = S_OK;
hr = RelatedBundlesInitializeForScope(TRUE, pRegistration, &pRegistration->relatedBundles);
ExitOnFailure(hr, "Failed to initialize per-machine related bundles.");
hr = RelatedBundlesInitializeForScope(FALSE, pRegistration, &pRegistration->relatedBundles);
ExitOnFailure(hr, "Failed to initialize per-user related bundles.");
RelatedBundlesSortDetect(&pRegistration->relatedBundles);
LExit:
return hr;
}
extern "C" HRESULT RegistrationPlanInitialize(
__in BURN_REGISTRATION* pRegistration
)
{
HRESULT hr = S_OK;
if (pRegistration->relatedBundles.cRelatedBundles && !pRegistration->relatedBundles.rgpPlanSortedRelatedBundles)
{
hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pRegistration->relatedBundles.rgpPlanSortedRelatedBundles), pRegistration->relatedBundles.cRelatedBundles, sizeof(BURN_RELATED_BUNDLE*), 5);
ExitOnFailure(hr, "Failed to initialize plan related bundles array.");
for (DWORD i = 0; i < pRegistration->relatedBundles.cRelatedBundles; ++i)
{
pRegistration->relatedBundles.rgpPlanSortedRelatedBundles[i] = pRegistration->relatedBundles.rgRelatedBundles + i;
}
}
LExit:
return hr;
}
/*******************************************************************
RegistrationSessionBegin - Registers a run session on the system.
*******************************************************************/
extern "C" HRESULT RegistrationSessionBegin(
__in_z LPCWSTR wzEngineWorkingPath,
__in BURN_REGISTRATION* pRegistration,
__in BURN_CACHE* pCache,
__in BURN_VARIABLES* pVariables,
__in DWORD dwRegistrationOptions,
__in DWORD64 qwEstimatedSize,
__in BOOTSTRAPPER_REGISTRATION_TYPE registrationType
)
{
HRESULT hr = S_OK;
HKEY hkRegistration = NULL;
BOOL fCreated = FALSE;
LPWSTR sczPublisher = NULL;
SYSTEMTIME systime = { };
DWORD er = ERROR_SUCCESS;
AssertSz(BOOTSTRAPPER_REGISTRATION_TYPE_NONE != registrationType, "Registration type can't be NONE");
LogId(REPORT_VERBOSE, MSG_SESSION_BEGIN, pRegistration->sczRegistrationKey, LoggingInstallScopeToString(pRegistration->fPerMachine), dwRegistrationOptions, LoggingBoolToString(pRegistration->fDisableResume));
// Cache bundle executable.
if (dwRegistrationOptions & BURN_REGISTRATION_ACTION_OPERATIONS_CACHE_BUNDLE)
{
hr = CacheCompleteBundle(pCache, pRegistration->fPerMachine, pRegistration->sczExecutableName, pRegistration->sczCode, wzEngineWorkingPath
#ifdef DEBUG
, pRegistration->sczCacheExecutablePath
#endif
);
ExitOnFailure(hr, "Failed to cache bundle from path: %ls", wzEngineWorkingPath);
}
// create registration key
hr = RegCreateEx(pRegistration->hkRoot, pRegistration->sczRegistrationKey, KEY_WRITE, REG_KEY_DEFAULT, FALSE, NULL, &hkRegistration, &fCreated);
ExitOnFailure(hr, "Failed to create registration key.");
// Write any ARP values and software tags.
hr = RegWriteString(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH, pRegistration->sczCacheExecutablePath);
ExitOnFailure(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH);
hr = RegWriteStringArray(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, pRegistration->rgsczUpgradeCodes, pRegistration->cUpgradeCodes);
ExitOnFailure(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE);
hr = RegWriteStringArray(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_ADDON_CODE, pRegistration->rgsczAddonCodes, pRegistration->cAddonCodes);
ExitOnFailure(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_ADDON_CODE);
hr = RegWriteStringArray(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_DETECT_CODE, pRegistration->rgsczDetectCodes, pRegistration->cDetectCodes);
ExitOnFailure(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_DETECT_CODE);
hr = RegWriteStringArray(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_PATCH_CODE, pRegistration->rgsczPatchCodes, pRegistration->cPatchCodes);
ExitOnFailure(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_PATCH_CODE);
hr = RegWriteString(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION, pRegistration->pVersion->sczVersion);
ExitOnFailure(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION);
hr = RegWriteNumber(hkRegistration, REGISTRY_BUNDLE_VERSION_MAJOR, pRegistration->pVersion->dwMajor);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_VERSION_MAJOR);
hr = RegWriteNumber(hkRegistration, REGISTRY_BUNDLE_VERSION_MINOR, pRegistration->pVersion->dwMinor);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_VERSION_MINOR);
if (pRegistration->sczProviderKey)
{
hr = RegWriteString(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY, pRegistration->sczProviderKey);
ExitOnFailure(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY);
}
if (pRegistration->sczTag)
{
hr = RegWriteString(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_TAG, pRegistration->sczTag);
ExitOnFailure(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_TAG);
}
hr = RegWriteStringFormatted(hkRegistration, BURN_REGISTRATION_REGISTRY_ENGINE_VERSION, L"%hs", szVerMajorMinorBuild);
ExitOnFailure(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_ENGINE_VERSION);
hr = RegWriteNumber(hkRegistration, BURN_REGISTRATION_REGISTRY_ENGINE_PROTOCOL_VERSION, BURN_PROTOCOL_VERSION);
ExitOnFailure(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_ENGINE_PROTOCOL_VERSION);
// DisplayIcon: [path to exe] and ",0" to refer to the first icon in the executable.
hr = RegWriteStringFormatted(hkRegistration, REGISTRY_BUNDLE_DISPLAY_ICON, L"%s,0", pRegistration->sczCacheExecutablePath);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_DISPLAY_ICON);
hr = RegWriteNumber(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_SCOPE, pRegistration->fPerMachine ? BOOTSTRAPPER_SCOPE_PER_MACHINE : BOOTSTRAPPER_SCOPE_PER_USER);
ExitOnFailure(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_SCOPE);
// update display name
hr = UpdateBundleNameRegistration(pRegistration, pVariables, hkRegistration, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS == registrationType);
ExitOnFailure(hr, "Failed to update name and publisher.");
// DisplayVersion: provided by UI
if (pRegistration->sczDisplayVersion)
{
hr = RegWriteString(hkRegistration, REGISTRY_BUNDLE_DISPLAY_VERSION, pRegistration->sczDisplayVersion);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_DISPLAY_VERSION);
}
// Publisher: provided by UI
hr = GetBundleManufacturer(pRegistration, pVariables, &sczPublisher);
hr = RegWriteString(hkRegistration, REGISTRY_BUNDLE_PUBLISHER, SUCCEEDED(hr) ? sczPublisher : pRegistration->sczPublisher);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_PUBLISHER);
// HelpLink: provided by UI
if (pRegistration->sczHelpLink)
{
hr = RegWriteString(hkRegistration, REGISTRY_BUNDLE_HELP_LINK, pRegistration->sczHelpLink);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_HELP_LINK);
}
// HelpTelephone: provided by UI
if (pRegistration->sczHelpTelephone)
{
hr = RegWriteString(hkRegistration, REGISTRY_BUNDLE_HELP_TELEPHONE, pRegistration->sczHelpTelephone);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_HELP_TELEPHONE);
}
// URLInfoAbout, provided by UI
if (pRegistration->sczAboutUrl)
{
hr = RegWriteString(hkRegistration, REGISTRY_BUNDLE_URL_INFO_ABOUT, pRegistration->sczAboutUrl);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_URL_INFO_ABOUT);
}
// URLUpdateInfo, provided by UI
if (pRegistration->sczUpdateUrl)
{
hr = RegWriteString(hkRegistration, REGISTRY_BUNDLE_URL_UPDATE_INFO, pRegistration->sczUpdateUrl);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_URL_UPDATE_INFO);
}
// ParentDisplayName
if (pRegistration->sczParentDisplayName)
{
hr = RegWriteString(hkRegistration, REGISTRY_BUNDLE_PARENT_DISPLAY_NAME, pRegistration->sczParentDisplayName);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_PARENT_DISPLAY_NAME);
// Need to write the ParentKeyName but can be set to anything.
hr = RegWriteString(hkRegistration, REGISTRY_BUNDLE_PARENT_KEY_NAME, pRegistration->sczParentDisplayName);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_PARENT_KEY_NAME);
}
// Comments, provided by UI
if (pRegistration->sczComments)
{
hr = RegWriteString(hkRegistration, REGISTRY_BUNDLE_COMMENTS, pRegistration->sczComments);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_COMMENTS);
}
// Contact, provided by UI
if (pRegistration->sczContact)
{
hr = RegWriteString(hkRegistration, REGISTRY_BUNDLE_CONTACT, pRegistration->sczContact);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_CONTACT);
}
// InstallLocation: provided by UI
// TODO: need to figure out what "InstallLocation" means in a chainer. <smile/>
// NoModify
if (BURN_REGISTRATION_MODIFY_DISABLE == pRegistration->modify)
{
hr = RegWriteNumber(hkRegistration, REGISTRY_BUNDLE_NO_MODIFY, 1);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_NO_MODIFY);
}
else if (BURN_REGISTRATION_MODIFY_DISABLE_BUTTON != pRegistration->modify) // if support modify (aka: did not disable anything)
{
// ModifyPath: [path to exe] /modify
hr = RegWriteStringFormatted(hkRegistration, REGISTRY_BUNDLE_MODIFY_PATH, L"\"%ls\" /modify", pRegistration->sczCacheExecutablePath);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_MODIFY_PATH);
// NoElevateOnModify: 1
hr = RegWriteNumber(hkRegistration, REGISTRY_BUNDLE_NO_ELEVATE_ON_MODIFY, 1);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_NO_ELEVATE_ON_MODIFY);
}
// NoRemove: should this be allowed?
if (pRegistration->fNoRemove)
{
hr = RegWriteNumber(hkRegistration, REGISTRY_BUNDLE_NO_REMOVE, 1);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_NO_REMOVE);
}
// Conditionally hide the ARP entry.
if (pRegistration->fForceSystemComponent || (dwRegistrationOptions & BURN_REGISTRATION_ACTION_OPERATIONS_ARP_SYSTEM_COMPONENT))
{
hr = RegWriteNumber(hkRegistration, REGISTRY_BUNDLE_SYSTEM_COMPONENT, 1);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_SYSTEM_COMPONENT);
}
else
{
er = ::RegDeleteValueW(hkRegistration, REGISTRY_BUNDLE_SYSTEM_COMPONENT);
if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er)
{
er = ERROR_SUCCESS;
}
ExitOnWin32Error(er, hr, "Failed to delete %ls value.", REGISTRY_BUNDLE_SYSTEM_COMPONENT);
}
// QuietUninstallString: [path to exe] /uninstall /quiet
hr = RegWriteStringFormatted(hkRegistration, REGISTRY_BUNDLE_QUIET_UNINSTALL_STRING, L"\"%ls\" /uninstall /quiet", pRegistration->sczCacheExecutablePath);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_QUIET_UNINSTALL_STRING);
// UninstallString, [path to exe]
// If the modify button is to be disabled, we'll add "/modify" to the uninstall string because the button is "Uninstall/Change". Otherwise,
// it's just the "Uninstall" button so we add "/uninstall" to make the program just go away.
LPCWSTR wzUninstallParameters = (BURN_REGISTRATION_MODIFY_DISABLE_BUTTON == pRegistration->modify) ? L"/modify" : L" /uninstall";
hr = RegWriteStringFormatted(hkRegistration, REGISTRY_BUNDLE_UNINSTALL_STRING, L"\"%ls\" %ls", pRegistration->sczCacheExecutablePath, wzUninstallParameters);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_UNINSTALL_STRING);
if (pRegistration->softwareTags.cSoftwareTags)
{
hr = WriteSoftwareTags(pVariables, &pRegistration->softwareTags);
ExitOnFailure(hr, "Failed to write software tags.");
}
// Only set install date and initial estimated size here for the first time.
// Estimated size will always get updated at the end of the session.
if (fCreated)
{
// Write the install date.
::GetLocalTime(&systime);
hr = RegWriteStringFormatted(hkRegistration, REGISTRY_BUNDLE_INSTALL_DATE, L"%04u%02u%02u", systime.wYear, systime.wMonth, systime.wDay);
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_INSTALL_DATE);
// Write the initial estimated size.
hr = UpdateEstimatedSize(hkRegistration, qwEstimatedSize);
ExitOnFailure(hr, "Failed to update estimated size.");
}
// Register the bundle dependency key.
if (dwRegistrationOptions & BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_PROVIDER_KEY)
{
hr = DependencyRegisterBundle(pRegistration);
ExitOnFailure(hr, "Failed to register the bundle dependency key.");
}
// update resume mode
hr = UpdateResumeMode(pRegistration, hkRegistration, BURN_RESUME_MODE_ACTIVE, registrationType, FALSE);
ExitOnFailure(hr, "Failed to update resume mode.");
LExit:
ReleaseStr(sczPublisher);
ReleaseRegKey(hkRegistration);
return hr;
}
/*******************************************************************
RegistrationSessionEnd - Unregisters a run session from the system.
*******************************************************************/
extern "C" HRESULT RegistrationSessionEnd(
__in BURN_REGISTRATION* pRegistration,
__in BURN_CACHE* pCache,
__in BURN_VARIABLES* pVariables,
__in BURN_PACKAGES* pPackages,
__in BURN_RESUME_MODE resumeMode,
__in BOOTSTRAPPER_APPLY_RESTART restart,
__in DWORD64 qwEstimatedSize,
__in BOOTSTRAPPER_REGISTRATION_TYPE registrationType
)
{
HRESULT hr = S_OK;
HKEY hkRegistration = NULL;
BOOL fDeleted = FALSE;
// If no resume mode, then remove the bundle registration.
if (BURN_RESUME_MODE_NONE == resumeMode)
{
AssertSz(BOOTSTRAPPER_REGISTRATION_TYPE_NONE == registrationType, "Registration type must be NONE if resume mode is NONE");
// Remove the bundle dependencies.
DependencyUnregisterBundle(pRegistration, pPackages);
// Delete update registration key.
if (pRegistration->update.fRegisterUpdate)
{
RemoveUpdateRegistration(pRegistration);
}
RemoveSoftwareTags(pVariables, &pRegistration->softwareTags);
// Delete registration key.
hr = RegDelete(pRegistration->hkRoot, pRegistration->sczRegistrationKey, REG_KEY_DEFAULT, TRUE);
ExitOnPathFailure(hr, fDeleted, "Failed to delete registration key: %ls", pRegistration->sczRegistrationKey);
CacheRemoveBundle(pCache, pRegistration->fPerMachine, pRegistration->sczCode);
}
else // the mode needs to be updated so open the registration key.
{
AssertSz(BOOTSTRAPPER_REGISTRATION_TYPE_NONE != registrationType, "Registration type must not be NONE if resume mode is not NONE");
// Open registration key.
hr = RegOpen(pRegistration->hkRoot, pRegistration->sczRegistrationKey, KEY_WRITE, &hkRegistration);
ExitOnFailure(hr, "Failed to open registration key for ending session.");
// update display name
hr = UpdateBundleNameRegistration(pRegistration, pVariables, hkRegistration, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS == registrationType);
ExitOnFailure(hr, "Failed to update name and publisher.");
hr = UpdateEstimatedSize(hkRegistration, qwEstimatedSize);
ExitOnFailure(hr, "Failed to update estimated size.");
// Update registration.
if (pRegistration->update.fRegisterUpdate)
{
hr = WriteUpdateRegistration(pRegistration, pVariables);
ExitOnFailure(hr, "Failed to write update registration.");
}
}
// Update resume mode.
hr = UpdateResumeMode(pRegistration, hkRegistration, resumeMode, registrationType, BOOTSTRAPPER_APPLY_RESTART_INITIATED == restart);
ExitOnFailure(hr, "Failed to update resume mode.");
LExit:
ReleaseRegKey(hkRegistration);
return hr;
}
/*******************************************************************
RegistrationSaveState - Saves an engine state BLOB for retreval after a resume.
*******************************************************************/
extern "C" HRESULT RegistrationSaveState(
__in BURN_REGISTRATION* pRegistration,
__in_bcount(cbBuffer) BYTE* pbBuffer,
__in SIZE_T cbBuffer
)
{
HRESULT hr = S_OK;
BURN_VARIABLES variables = { };
SIZE_T iBuffer_Unused = 0;
HKEY hkRegistration = NULL;
LPWSTR sczVariableKey = NULL;
LPWSTR sczVariableValue = NULL;
LPWSTR sczValueName = NULL;
DWORD dwType = 0;
DWORD dwNumberOfExistingValues = 0;
DWORD er = ERROR_SUCCESS;
// write data to file
hr = FileWrite(pRegistration->sczStateFile, FILE_ATTRIBUTE_NORMAL, pbBuffer, cbBuffer, NULL);
if (E_PATHNOTFOUND == hr)
{
// TODO: should we log that the bundle's cache folder was not present so the state file wasn't created either?
hr = S_OK;
}
ExitOnFailure(hr, "Failed to write state to file: %ls", pRegistration->sczStateFile);
::InitializeCriticalSection(&variables.csAccess);
hr = VariableDeserialize(&variables, TRUE, pbBuffer, cbBuffer, &iBuffer_Unused);
ExitOnFailure(hr, "Failed to read variables.");
// build variable registry key path
hr = StrAllocFormatted(&sczVariableKey, L"%s\\%s", pRegistration->sczRegistrationKey, REGISTRY_BUNDLE_VARIABLE_KEY);
ExitOnFailure(hr, "Failed to build variable registry key path.");
// open registration variable key
hr = RegCreate(pRegistration->hkRoot, sczVariableKey, KEY_WRITE | KEY_QUERY_VALUE, &hkRegistration);
ExitOnFailure(hr, "Failed to create registration variable key.");
hr = RegQueryInfoKey(hkRegistration, 0, 0, 0, 0, 0, 0, &dwNumberOfExistingValues, 0, 0, 0, 0);
ExitOnFailure(hr, "Failed to query registration variable count.");
for (DWORD i = dwNumberOfExistingValues; i >= 0; --i)
{
hr = RegValueEnum(hkRegistration, i, &sczValueName, &dwType);
if (E_NOMOREITEMS == hr)
{
hr = S_OK;
break;
}
ExitOnFailure(hr, "Failed to enumerate value %u", i);
er = ::RegDeleteValueW(hkRegistration, sczValueName);
if (ERROR_FILE_NOT_FOUND != er)
{
ExitOnWin32Error(er, hr, "Failed to delete registration variable value.");
}
}
// Write variables.
for (DWORD i = 0; i < variables.cVariables; ++i)
{
BURN_VARIABLE* pVariable = &variables.rgVariables[i];
// Write variable value.
switch (pVariable->Value.Type)
{
case BURN_VARIANT_TYPE_NONE:
hr = RegWriteNone(hkRegistration, pVariable->sczName);
ExitOnFailure(hr, "Failed to set variable value.");
break;
case BURN_VARIANT_TYPE_NUMERIC: __fallthrough;
case BURN_VARIANT_TYPE_VERSION: __fallthrough;
case BURN_VARIANT_TYPE_FORMATTED: __fallthrough;
case BURN_VARIANT_TYPE_STRING:
hr = BVariantGetString(&pVariable->Value, &sczVariableValue);