main
cpp 196 lines 6.03 KB
Raw
1 // 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.
2
3 #include "precomp.h"
4
5
6 static HRESULT ParseFromXml(
7 __in IXMLDOMDocument* pixdDocument,
8 __in BURN_ENGINE_STATE* pEngineState
9 );
10 #if DEBUG
11 static void ValidateHarvestingAttributes(
12 __in IXMLDOMDocument* pixdDocument
13 );
14 #endif
15
16 // function definitions
17
18 extern "C" HRESULT ManifestLoadXmlFromFile(
19 __in LPCWSTR wzPath,
20 __in BURN_ENGINE_STATE* pEngineState
21 )
22 {
23 HRESULT hr = S_OK;
24 IXMLDOMDocument* pixdDocument = NULL;
25
26 // load xml document
27 hr = XmlLoadDocumentFromFile(wzPath, &pixdDocument);
28 ExitOnFailure(hr, "Failed to load manifest as XML document.");
29
30 hr = ParseFromXml(pixdDocument, pEngineState);
31
32 LExit:
33 ReleaseObject(pixdDocument);
34
35 return hr;
36 }
37
38 extern "C" HRESULT ManifestLoadXmlFromBuffer(
39 __in_bcount(cbBuffer) BYTE* pbBuffer,
40 __in SIZE_T cbBuffer,
41 __in BURN_ENGINE_STATE* pEngineState
42 )
43 {
44 HRESULT hr = S_OK;
45 IXMLDOMDocument* pixdDocument = NULL;
46
47 // load xml document
48 hr = XmlLoadDocumentFromBuffer(pbBuffer, cbBuffer, &pixdDocument);
49 ExitOnFailure(hr, "Failed to load manifest as XML document.");
50
51 #if DEBUG
52 ValidateHarvestingAttributes(pixdDocument);
53 #endif
54
55 hr = ParseFromXml(pixdDocument, pEngineState);
56
57 LExit:
58 ReleaseObject(pixdDocument);
59
60 return hr;
61 }
62
63 static HRESULT ParseFromXml(
64 __in IXMLDOMDocument* pixdDocument,
65 __in BURN_ENGINE_STATE* pEngineState
66 )
67 {
68 HRESULT hr = S_OK;
69 IXMLDOMElement* pixeBundle = NULL;
70 IXMLDOMNode* pixnChain = NULL;
71
72 // get bundle element
73 hr = pixdDocument->get_documentElement(&pixeBundle);
74 ExitOnFailure(hr, "Failed to get bundle element.");
75
76 hr = LoggingParseFromXml(&pEngineState->log, pixeBundle);
77 ExitOnFailure(hr, "Failed to parse logging.");
78
79 // get the chain element
80 hr = XmlSelectSingleNode(pixeBundle, L"Chain", &pixnChain);
81 ExitOnFailure(hr, "Failed to get chain element.");
82
83 if (S_OK == hr)
84 {
85 // parse disable rollback
86 hr = XmlGetYesNoAttribute(pixnChain, L"DisableRollback", &pEngineState->fDisableRollback);
87 if (E_NOTFOUND != hr)
88 {
89 ExitOnFailure(hr, "Failed to get Chain/@DisableRollback");
90 }
91
92 // parse disable system restore
93 hr = XmlGetYesNoAttribute(pixnChain, L"DisableSystemRestore", &pEngineState->internalCommand.fDisableSystemRestore);
94 if (E_NOTFOUND != hr)
95 {
96 ExitOnFailure(hr, "Failed to get Chain/@DisableSystemRestore");
97 }
98
99 // parse parallel cache
100 hr = XmlGetYesNoAttribute(pixnChain, L"ParallelCache", &pEngineState->fParallelCacheAndExecute);
101 if (E_NOTFOUND != hr)
102 {
103 ExitOnFailure(hr, "Failed to get Chain/@ParallelCache");
104 }
105 }
106
107 // parse built-in condition
108 hr = ConditionGlobalParseFromXml(&pEngineState->condition, pixeBundle);
109 ExitOnFailure(hr, "Failed to parse global condition.");
110
111 // parse variables
112 hr = VariablesParseFromXml(&pEngineState->variables, pixeBundle);
113 ExitOnFailure(hr, "Failed to parse variables.");
114
115 // parse user experience
116 hr = BootstrapperApplicationParseFromXml(&pEngineState->userExperience, pixeBundle);
117 ExitOnFailure(hr, "Failed to parse bootstrapper application.");
118
119 // parse extensions
120 hr = BurnExtensionParseFromXml(&pEngineState->extensions, &pEngineState->userExperience.payloads, pixeBundle);
121 ExitOnFailure(hr, "Failed to parse extensions.");
122
123 // parse searches
124 hr = SearchesParseFromXml(&pEngineState->searches, &pEngineState->extensions, pixeBundle);
125 ExitOnFailure(hr, "Failed to parse searches.");
126
127 // parse registration
128 hr = RegistrationParseFromXml(&pEngineState->registration, &pEngineState->cache, pixeBundle);
129 ExitOnFailure(hr, "Failed to parse registration.");
130
131 // parse update
132 hr = UpdateParseFromXml(&pEngineState->update, pixeBundle);
133 ExitOnFailure(hr, "Failed to parse update.");
134
135 // parse containers
136 hr = ContainersParseFromXml(&pEngineState->containers, pixeBundle);
137 ExitOnFailure(hr, "Failed to parse containers.");
138
139 // parse payloads
140 hr = PayloadsParseFromXml(&pEngineState->payloads, &pEngineState->containers, &pEngineState->layoutPayloads, pixeBundle);
141 ExitOnFailure(hr, "Failed to parse payloads.");
142
143 // parse packages
144 hr = PackagesParseFromXml(&pEngineState->packages, &pEngineState->payloads, pixeBundle);
145 ExitOnFailure(hr, "Failed to parse packages.");
146
147 // parse approved exes for elevation
148 hr = ApprovedExesParseFromXml(&pEngineState->approvedExes, pixeBundle);
149 ExitOnFailure(hr, "Failed to parse approved exes.");
150
151 LExit:
152 ReleaseObject(pixnChain);
153 ReleaseObject(pixeBundle);
154 return hr;
155 }
156
157 #if DEBUG
158 static void ValidateHarvestingAttributes(
159 __in IXMLDOMDocument* pixdDocument
160 )
161 {
162 HRESULT hr = S_OK;
163 IXMLDOMElement* pixeBundle = NULL;
164 LPWSTR sczEngineVersion = NULL;
165 DWORD dwProtocolVersion = 0;
166 BOOL fWin64 = FALSE;
167
168 hr = pixdDocument->get_documentElement(&pixeBundle);
169 ExitOnFailure(hr, "Failed to get document element.");
170
171 hr = XmlGetAttributeEx(pixeBundle, L"EngineVersion", &sczEngineVersion);
172 ExitOnRequiredXmlQueryFailure(hr, "Failed to get BurnManifest/@EngineVersion attribute.");
173
174 hr = XmlGetAttributeUInt32(pixeBundle, L"ProtocolVersion", &dwProtocolVersion);
175 ExitOnRequiredXmlQueryFailure(hr, "Failed to get BurnManifest/@ProtocolVersion attribute.");
176
177 hr = XmlGetYesNoAttribute(pixeBundle, L"Win64", &fWin64);
178 ExitOnRequiredXmlQueryFailure(hr, "Failed to get BurnManifest/@Win64 attribute.");
179
180 Assert(CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, sczEngineVersion, -1, wzVerMajorMinorBuild, -1));
181
182 Assert(BURN_PROTOCOL_VERSION == dwProtocolVersion);
183
184 #if !defined(_WIN64)
185 Assert(!fWin64);
186 #else
187 Assert(fWin64);
188 #endif
189
190 LExit:
191 AssertSz(SUCCEEDED(hr), "Failed to get harvesting attributes.");
192
193 ReleaseStr(sczEngineVersion);
194 ReleaseObject(pixeBundle);
195 }
196 #endif