Update registration code with more concise Exit* macros.
Sean Hall committed
Apr 4, 2022 at 14:14 UTC
5ac804d68360fc8a2f66ec020e1fe2536792f179
1 file changed
+42
-91
src/burn/engine/registration.cpp
+42
-91
@@ -122,29 +122,26 @@ extern "C" HRESULT RegistrationParseFromXml(
122
IXMLDOMNode* pixnArpNode = NULL;
123
IXMLDOMNode* pixnUpdateNode = NULL;
124
LPWSTR scz = NULL;
125
+ BOOL fFoundXml = FALSE;
126
127
// select registration node
128
hr = XmlSelectSingleNode(pixnBundle, L"Registration", &pixnRegistrationNode);
128
- if (S_FALSE == hr)
129
- {
130
- hr = E_NOTFOUND;
131
- }
132
- ExitOnFailure(hr, "Failed to select registration node.");
129
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to select registration node.");
130
131
// @Id
132
hr = XmlGetAttributeEx(pixnRegistrationNode, L"Id", &pRegistration->sczId);
136
- ExitOnFailure(hr, "Failed to get @Id.");
133
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Id.");
134
135
// @Tag
136
hr = XmlGetAttributeEx(pixnRegistrationNode, L"Tag", &pRegistration->sczTag);
140
- ExitOnFailure(hr, "Failed to get @Tag.");
137
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Tag.");
138
139
hr = BundlePackageEngineParseRelatedCodes(pixnBundle, &pRegistration->rgsczDetectCodes, &pRegistration->cDetectCodes, &pRegistration->rgsczUpgradeCodes, &pRegistration->cUpgradeCodes, &pRegistration->rgsczAddonCodes, &pRegistration->cAddonCodes, &pRegistration->rgsczPatchCodes, &pRegistration->cPatchCodes);
140
ExitOnFailure(hr, "Failed to parse related bundles");
141
142
// @Version
143
hr = XmlGetAttributeEx(pixnRegistrationNode, L"Version", &scz);
147
- ExitOnFailure(hr, "Failed to get @Version.");
144
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Version.");
145
146
hr = VerParseVersion(scz, 0, FALSE, &pRegistration->pVersion);
147
ExitOnFailure(hr, "Failed to parse @Version: %ls", scz);
@@ -156,106 +153,75 @@ extern "C" HRESULT RegistrationParseFromXml(
153
154
// @ProviderKey
155
hr = XmlGetAttributeEx(pixnRegistrationNode, L"ProviderKey", &pRegistration->sczProviderKey);
159
- ExitOnFailure(hr, "Failed to get @ProviderKey.");
156
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @ProviderKey.");
157
158
// @ExecutableName
159
hr = XmlGetAttributeEx(pixnRegistrationNode, L"ExecutableName", &pRegistration->sczExecutableName);
163
- ExitOnFailure(hr, "Failed to get @ExecutableName.");
160
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @ExecutableName.");
161
162
// @PerMachine
163
hr = XmlGetYesNoAttribute(pixnRegistrationNode, L"PerMachine", &pRegistration->fPerMachine);
167
- ExitOnFailure(hr, "Failed to get @PerMachine.");
164
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @PerMachine.");
165
166
// select ARP node
167
hr = XmlSelectSingleNode(pixnRegistrationNode, L"Arp", &pixnArpNode);
171
- if (S_FALSE != hr)
172
- {
173
- ExitOnFailure(hr, "Failed to select ARP node.");
168
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to select ARP node.");
169
170
+ if (fFoundXml)
171
+ {
172
// @Register
173
hr = XmlGetYesNoAttribute(pixnArpNode, L"Register", &pRegistration->fRegisterArp);
177
- ExitOnFailure(hr, "Failed to get @Register.");
174
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Register.");
175
176
// @DisplayName
177
hr = XmlGetAttributeEx(pixnArpNode, L"DisplayName", &pRegistration->sczDisplayName);
181
- if (E_NOTFOUND != hr)
182
- {
183
- ExitOnFailure(hr, "Failed to get @DisplayName.");
184
- }
178
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @DisplayName.");
179
180
// @InProgressDisplayName
181
hr = XmlGetAttributeEx(pixnArpNode, L"InProgressDisplayName", &pRegistration->sczInProgressDisplayName);
188
- if (E_NOTFOUND != hr)
189
- {
190
- ExitOnFailure(hr, "Failed to get @InProgressDisplayName.");
191
- }
182
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @InProgressDisplayName.");
183
184
// @DisplayVersion
185
hr = XmlGetAttributeEx(pixnArpNode, L"DisplayVersion", &pRegistration->sczDisplayVersion);
195
- if (E_NOTFOUND != hr)
196
- {
197
- ExitOnFailure(hr, "Failed to get @DisplayVersion.");
198
- }
186
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @DisplayVersion.");
187
188
// @Publisher
189
hr = XmlGetAttributeEx(pixnArpNode, L"Publisher", &pRegistration->sczPublisher);
202
- if (E_NOTFOUND != hr)
203
- {
204
- ExitOnFailure(hr, "Failed to get @Publisher.");
205
- }
190
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @Publisher.");
191
192
// @HelpLink
193
hr = XmlGetAttributeEx(pixnArpNode, L"HelpLink", &pRegistration->sczHelpLink);
209
- if (E_NOTFOUND != hr)
210
- {
211
- ExitOnFailure(hr, "Failed to get @HelpLink.");
212
- }
194
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @HelpLink.");
195
196
// @HelpTelephone
197
hr = XmlGetAttributeEx(pixnArpNode, L"HelpTelephone", &pRegistration->sczHelpTelephone);
216
- if (E_NOTFOUND != hr)
217
- {
218
- ExitOnFailure(hr, "Failed to get @HelpTelephone.");
219
- }
198
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @HelpTelephone.");
199
200
// @AboutUrl
201
hr = XmlGetAttributeEx(pixnArpNode, L"AboutUrl", &pRegistration->sczAboutUrl);
223
- if (E_NOTFOUND != hr)
224
- {
225
- ExitOnFailure(hr, "Failed to get @AboutUrl.");
226
- }
202
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @AboutUrl.");
203
204
// @UpdateUrl
205
hr = XmlGetAttributeEx(pixnArpNode, L"UpdateUrl", &pRegistration->sczUpdateUrl);
230
- if (E_NOTFOUND != hr)
231
- {
232
- ExitOnFailure(hr, "Failed to get @UpdateUrl.");
233
- }
206
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @UpdateUrl.");
207
208
// @ParentDisplayName
209
hr = XmlGetAttributeEx(pixnArpNode, L"ParentDisplayName", &pRegistration->sczParentDisplayName);
237
- if (E_NOTFOUND != hr)
238
- {
239
- ExitOnFailure(hr, "Failed to get @ParentDisplayName.");
240
- }
210
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @ParentDisplayName.");
211
212
// @Comments
213
hr = XmlGetAttributeEx(pixnArpNode, L"Comments", &pRegistration->sczComments);
244
- if (E_NOTFOUND != hr)
245
- {
246
- ExitOnFailure(hr, "Failed to get @Comments.");
247
- }
214
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @Comments.");
215
216
// @Contact
217
hr = XmlGetAttributeEx(pixnArpNode, L"Contact", &pRegistration->sczContact);
251
- if (E_NOTFOUND != hr)
252
- {
253
- ExitOnFailure(hr, "Failed to get @Contact.");
254
- }
218
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @Contact.");
219
220
// @DisableModify
221
hr = XmlGetAttributeEx(pixnArpNode, L"DisableModify", &scz);
258
- if (SUCCEEDED(hr))
222
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @DisableModify.");
223
+
224
+ if (fFoundXml)
225
{
226
if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"button", -1))
227
{
@@ -271,24 +237,17 @@ extern "C" HRESULT RegistrationParseFromXml(
237
}
238
else
239
{
274
- hr = E_UNEXPECTED;
275
- ExitOnRootFailure(hr, "Invalid modify disabled type: %ls", scz);
240
+ ExitWithRootFailure(hr, E_UNEXPECTED, "Invalid modify disabled type: %ls", scz);
241
}
242
}
278
- else if (E_NOTFOUND == hr)
243
+ else
244
{
245
pRegistration->modify = BURN_REGISTRATION_MODIFY_ENABLED;
281
- hr = S_OK;
246
}
283
- ExitOnFailure(hr, "Failed to get @DisableModify.");
247
248
// @DisableRemove
249
hr = XmlGetYesNoAttribute(pixnArpNode, L"DisableRemove", &pRegistration->fNoRemove);
287
- if (E_NOTFOUND != hr)
288
- {
289
- ExitOnFailure(hr, "Failed to get @DisableRemove.");
290
- pRegistration->fNoRemoveDefined = TRUE;
291
- }
250
+ ExitOnOptionalXmlQueryFailure(hr, pRegistration->fNoRemoveDefined, "Failed to get @DisableRemove.");
251
}
252
253
hr = ParseSoftwareTagsFromXml(pixnRegistrationNode, &pRegistration->softwareTags.rgSoftwareTags, &pRegistration->softwareTags.cSoftwareTags);
@@ -296,37 +255,29 @@ extern "C" HRESULT RegistrationParseFromXml(
255
256
// select Update node
257
hr = XmlSelectSingleNode(pixnRegistrationNode, L"Update", &pixnUpdateNode);
299
- if (S_FALSE != hr)
300
- {
301
- ExitOnFailure(hr, "Failed to select Update node.");
302
-
303
- pRegistration->update.fRegisterUpdate = TRUE;
258
+ ExitOnOptionalXmlQueryFailure(hr, pRegistration->update.fRegisterUpdate, "Failed to select Update node.");
259
260
+ if (pRegistration->update.fRegisterUpdate)
261
+ {
262
// @Manufacturer
263
hr = XmlGetAttributeEx(pixnUpdateNode, L"Manufacturer", &pRegistration->update.sczManufacturer);
307
- ExitOnFailure(hr, "Failed to get @Manufacturer.");
264
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Manufacturer.");
265
266
// @Department
267
hr = XmlGetAttributeEx(pixnUpdateNode, L"Department", &pRegistration->update.sczDepartment);
311
- if (E_NOTFOUND != hr)
312
- {
313
- ExitOnFailure(hr, "Failed to get @Department.");
314
- }
268
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @Department.");
269
270
// @ProductFamily
271
hr = XmlGetAttributeEx(pixnUpdateNode, L"ProductFamily", &pRegistration->update.sczProductFamily);
318
- if (E_NOTFOUND != hr)
319
- {
320
- ExitOnFailure(hr, "Failed to get @ProductFamily.");
321
- }
272
+ ExitOnOptionalXmlQueryFailure(hr, fFoundXml, "Failed to get @ProductFamily.");
273
274
// @Name
275
hr = XmlGetAttributeEx(pixnUpdateNode, L"Name", &pRegistration->update.sczName);
325
- ExitOnFailure(hr, "Failed to get @Name.");
276
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Name.");
277
278
// @Classification
279
hr = XmlGetAttributeEx(pixnUpdateNode, L"Classification", &pRegistration->update.sczClassification);
329
- ExitOnFailure(hr, "Failed to get @Classification.");
280
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Classification.");
281
}
282
283
hr = SetPaths(pRegistration, pCache);
@@ -1164,19 +1115,19 @@ static HRESULT ParseSoftwareTagsFromXml(
1115
BURN_SOFTWARE_TAG* pSoftwareTag = &pSoftwareTags[i];
1116
1117
hr = XmlNextElement(pixnNodes, &pixnNode, NULL);
1167
- ExitOnFailure(hr, "Failed to get next node.");
1118
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get next node.");
1119
1120
hr = XmlGetAttributeEx(pixnNode, L"Filename", &pSoftwareTag->sczFilename);
1170
- ExitOnFailure(hr, "Failed to get @Filename.");
1121
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Filename.");
1122
1123
hr = XmlGetAttributeEx(pixnNode, L"Regid", &pSoftwareTag->sczRegid);
1173
- ExitOnFailure(hr, "Failed to get @Regid.");
1124
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Regid.");
1125
1126
hr = XmlGetAttributeEx(pixnNode, L"Path", &pSoftwareTag->sczPath);
1176
- ExitOnFailure(hr, "Failed to get @Path.");
1127
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Path.");
1128
1129
hr = XmlGetText(pixnNode, &bstrTagXml);
1179
- ExitOnFailure(hr, "Failed to get SoftwareTag text.");
1130
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get SoftwareTag text.");
1131
1132
hr = StrAnsiAllocString(&pSoftwareTag->sczTag, bstrTagXml, 0, CP_UTF8);
1133
ExitOnFailure(hr, "Failed to convert SoftwareTag text to UTF-8");