@joebigelow / wix-1 / commits / f866ab77

Change the DetectSHA2Support element to WindowsFeatureSearch. This will make it easier to add support for other Windows features in the future.

Sean Hall committed Jul 10, 2020 at 21:25 UTC f866ab77f8fd0790f4d6628f54dcdf0bd66fccb6
11 files changed +176 -92
src/be/detectsha2support.cpp
+4 -4
@@ -3,7 +3,7 @@
3 #include "precomp.h"
4
5 // https://gist.github.com/navossoc/7572c7d82243e9f818989e2765e7793a
6 -HRESULT DetectSHA2Support(
6 +HRESULT DetectSHA2CodeSigning(
7 __out BOOL* pfSupported
8 )
9 {
@@ -38,7 +38,7 @@ LExit:
38 return hr;
39 }
40
41 -HRESULT UtilPerformDetectSHA2Support(
41 +HRESULT UtilPerformDetectSHA2CodeSigning(
42 __in LPCWSTR wzVariable,
43 __in UTIL_SEARCH* /*pSearch*/,
44 __in IBundleExtensionEngine* pEngine
@@ -47,8 +47,8 @@ HRESULT UtilPerformDetectSHA2Support(
47 HRESULT hr = S_OK;
48 BOOL fSupported = FALSE;
49
50 - hr = DetectSHA2Support(&fSupported);
51 - ExitOnFailure(hr, "DetectSHA2Support failed.");
50 + hr = DetectSHA2CodeSigning(&fSupported);
51 + ExitOnFailure(hr, "DetectSHA2CodeSigning failed.");
52
53 hr = pEngine->SetVariableNumeric(wzVariable, fSupported ? 1 : 0);
54 ExitOnFailure(hr, "Failed to set variable '%ls'", wzVariable);
src/be/detectsha2support.h
+1 -1
@@ -1,7 +1,7 @@
1 #pragma once
2 // 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.
3
4 -HRESULT UtilPerformDetectSHA2Support(
4 +HRESULT UtilPerformDetectSHA2CodeSigning(
5 __in LPCWSTR wzVariable,
6 __in UTIL_SEARCH* pSearch,
7 __in IBundleExtensionEngine* pEngine
src/be/utilsearch.cpp
+28 -5
@@ -13,9 +13,10 @@ STDMETHODIMP UtilSearchParseFromXml(
13 IXMLDOMNode* pixnNode = NULL;
14 DWORD cNodes = 0;
15 BSTR bstrNodeName = NULL;
16 + LPWSTR scz = NULL;
17
18 // Select Util search nodes.
18 - hr = XmlSelectNodes(pixnBundleExtension, L"WixDetectSHA2Support", &pixnNodes);
19 + hr = XmlSelectNodes(pixnBundleExtension, L"WixWindowsFeatureSearch", &pixnNodes);
20 ExitOnFailure(hr, "Failed to select Util search nodes.");
21
22 // Get Util search node count.
@@ -46,9 +47,23 @@ STDMETHODIMP UtilSearchParseFromXml(
47 ExitOnFailure(hr, "Failed to get @Id.");
48
49 // Read type specific attributes.
49 - if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"WixDetectSHA2Support", -1))
50 + if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"WixWindowsFeatureSearch", -1))
51 {
51 - pSearch->Type = UTIL_SEARCH_TYPE_DETECT_SHA2_SUPPORT;
52 + pSearch->Type = UTIL_SEARCH_TYPE_WINDOWS_FEATURE_SEARCH;
53 +
54 + // @Type
55 + hr = XmlGetAttributeEx(pixnNode, L"Type", &scz);
56 + ExitOnFailure(hr, "Failed to get @Type.");
57 +
58 + if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"sha2CodeSigning", -1))
59 + {
60 + pSearch->WindowsFeatureSearch.type = UTIL_WINDOWS_FEATURE_SEARCH_TYPE_SHA2_CODE_SIGNING;
61 + }
62 + else
63 + {
64 + hr = E_INVALIDARG;
65 + ExitOnFailure(hr, "Invalid value for @Type: %ls", scz);
66 + }
67 }
68 else
69 {
@@ -62,6 +77,7 @@ STDMETHODIMP UtilSearchParseFromXml(
77 }
78
79 LExit:
80 + ReleaseStr(scz);
81 ReleaseBSTR(bstrNodeName);
82 ReleaseObject(pixnNode);
83 ReleaseObject(pixnNodes);
@@ -100,8 +116,15 @@ STDMETHODIMP UtilSearchExecute(
116
117 switch (pSearch->Type)
118 {
103 - case UTIL_SEARCH_TYPE_DETECT_SHA2_SUPPORT:
104 - hr = UtilPerformDetectSHA2Support(wzVariable, pSearch, pEngine);
119 + case UTIL_SEARCH_TYPE_WINDOWS_FEATURE_SEARCH:
120 + switch (pSearch->WindowsFeatureSearch.type)
121 + {
122 + case UTIL_WINDOWS_FEATURE_SEARCH_TYPE_SHA2_CODE_SIGNING:
123 + hr = UtilPerformDetectSHA2CodeSigning(wzVariable, pSearch, pEngine);
124 + break;
125 + default:
126 + hr = E_UNEXPECTED;
127 + }
128 break;
129 default:
130 hr = E_UNEXPECTED;
src/be/utilsearch.h
+14 -1
@@ -7,7 +7,13 @@
7 enum UTIL_SEARCH_TYPE
8 {
9 UTIL_SEARCH_TYPE_NONE,
10 - UTIL_SEARCH_TYPE_DETECT_SHA2_SUPPORT,
10 + UTIL_SEARCH_TYPE_WINDOWS_FEATURE_SEARCH,
11 +};
12 +
13 +enum UTIL_WINDOWS_FEATURE_SEARCH_TYPE
14 +{
15 + UTIL_WINDOWS_FEATURE_SEARCH_TYPE_NONE,
16 + UTIL_WINDOWS_FEATURE_SEARCH_TYPE_SHA2_CODE_SIGNING,
17 };
18
19
@@ -18,6 +24,13 @@ typedef struct _UTIL_SEARCH
24 LPWSTR sczId;
25
26 UTIL_SEARCH_TYPE Type;
27 + union
28 + {
29 + struct
30 + {
31 + UTIL_WINDOWS_FEATURE_SEARCH_TYPE type;
32 + } WindowsFeatureSearch;
33 + };
34 } UTIL_SEARCH;
35
36 typedef struct _UTIL_SEARCHES
src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.wxs
+3 -3
@@ -1,11 +1,11 @@
1 -<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
1 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
2 <Bundle Name="!(loc.BundleName)" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
3 <BootstrapperApplication SourceFile="fakeba.dll" />
4
5 <util:RegistrySearchRef Id="RegistrySearchId" />
6 <util:ProductSearchRef Id="ProductSearchId" />
7 <util:FileSearchRef Id="FileSearchId" />
8 - <util:DetectSHA2SupportRef Id="DetectSHA2SupportId" />
8 + <util:WindowsFeatureSearchRef Id="DetectSHA2SupportId" />
9
10 <Chain>
11 <MsiPackage SourceFile="test.msi">
@@ -33,6 +33,6 @@
33 </Fragment>
34
35 <Fragment>
36 - <util:DetectSHA2Support Id="DetectSHA2SupportId" Variable="IsSHA2Supported" />
36 + <util:WindowsFeatureSearch Id="DetectSHA2SupportId" Variable="IsSHA2Supported" Feature="sha2CodeSigning" />
37 </Fragment>
38 </Wix>
src/test/WixToolsetTest.Util/UtilExtensionFixture.cs
+1 -1
@@ -172,7 +172,7 @@ namespace WixToolsetTest.Util
172 var bundleExtensionDatas = extractResult.SelectBundleExtensionDataNodes("/be:BundleExtensionData/be:BundleExtension[@Id='Wix4UtilBundleExtension_X86']");
173 Assert.Equal(1, bundleExtensionDatas.Count);
174 Assert.Equal("<BundleExtension Id='Wix4UtilBundleExtension_X86'>" +
175 - "<WixDetectSHA2Support Id='DetectSHA2SupportId' />" +
175 + "<WixWindowsFeatureSearch Id='DetectSHA2SupportId' Type='sha2CodeSigning' />" +
176 "</BundleExtension>", bundleExtensionDatas[0].GetTestXml());
177
178 var utilSearches = extractResult.SelectManifestNodes("/burn:BurnManifest/*[self::burn:ExtensionSearch or self::burn:FileSearch or self::burn:MsiProductSearch or self::burn:RegistrySearch]");
src/wixext/Symbols/UtilSymbolDefinitions.cs
+5 -5
@@ -20,12 +20,12 @@ namespace WixToolset.Util
20 User,
21 UserGroup,
22 WixCloseApplication,
23 - WixDetectSHA2Support,
23 WixFormatFiles,
24 WixInternetShortcut,
25 WixRemoveFolderEx,
26 WixRestartResource,
27 WixTouchFile,
28 + WixWindowsFeatureSearch,
29 XmlConfig,
30 XmlFile,
31 }
@@ -84,9 +84,6 @@ namespace WixToolset.Util
84 case UtilSymbolDefinitionType.WixCloseApplication:
85 return UtilSymbolDefinitions.WixCloseApplication;
86
87 - case UtilSymbolDefinitionType.WixDetectSHA2Support:
88 - return UtilSymbolDefinitions.WixDetectSHA2Support;
89 -
87 case UtilSymbolDefinitionType.WixFormatFiles:
88 return UtilSymbolDefinitions.WixFormatFiles;
89
@@ -102,6 +99,9 @@ namespace WixToolset.Util
99 case UtilSymbolDefinitionType.WixTouchFile:
100 return UtilSymbolDefinitions.WixTouchFile;
101
102 + case UtilSymbolDefinitionType.WixWindowsFeatureSearch:
103 + return UtilSymbolDefinitions.WixWindowsFeatureSearch;
104 +
105 case UtilSymbolDefinitionType.XmlConfig:
106 return UtilSymbolDefinitions.XmlConfig;
107
@@ -115,7 +115,7 @@ namespace WixToolset.Util
115
116 static UtilSymbolDefinitions()
117 {
118 - WixDetectSHA2Support.AddTag(BurnConstants.BundleExtensionSearchSymbolDefinitionTag);
118 + WixWindowsFeatureSearch.AddTag(BurnConstants.BundleExtensionSearchSymbolDefinitionTag);
119 }
120 }
121 }
src/wixext/Symbols/WixDetectSHA2SupportSymbol.cs deleted
-33
@@ -1,33 +0,0 @@
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 -namespace WixToolset.Util
4 -{
5 - using WixToolset.Data;
6 - using WixToolset.Util.Symbols;
7 -
8 - public static partial class UtilSymbolDefinitions
9 - {
10 - public static readonly IntermediateSymbolDefinition WixDetectSHA2Support = new IntermediateSymbolDefinition(
11 - UtilSymbolDefinitionType.WixDetectSHA2Support.ToString(),
12 - new IntermediateFieldDefinition[0],
13 - typeof(WixDetectSHA2SupportSymbol));
14 - }
15 -}
16 -
17 -namespace WixToolset.Util.Symbols
18 -{
19 - using WixToolset.Data;
20 -
21 - public class WixDetectSHA2SupportSymbol : IntermediateSymbol
22 - {
23 - public WixDetectSHA2SupportSymbol() : base(UtilSymbolDefinitions.WixDetectSHA2Support, null, null)
24 - {
25 - }
26 -
27 - public WixDetectSHA2SupportSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(UtilSymbolDefinitions.WixDetectSHA2Support, sourceLineNumber, id)
28 - {
29 - }
30 -
31 - public IntermediateField this[GroupSymbolFields index] => this.Fields[(int)index];
32 - }
33 -}
src/wixext/Symbols/WixWindowsFeatureSearchSymbol.cs new
+47
@@ -0,0 +1,47 @@
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 +namespace WixToolset.Util
4 +{
5 + using WixToolset.Data;
6 + using WixToolset.Util.Symbols;
7 +
8 + public static partial class UtilSymbolDefinitions
9 + {
10 + public static readonly IntermediateSymbolDefinition WixWindowsFeatureSearch = new IntermediateSymbolDefinition(
11 + UtilSymbolDefinitionType.WixWindowsFeatureSearch.ToString(),
12 + new[]
13 + {
14 + new IntermediateFieldDefinition(nameof(WixWindowsFeatureSearchSymbolFields.Type), IntermediateFieldType.String),
15 + },
16 + typeof(WixWindowsFeatureSearchSymbol));
17 + }
18 +}
19 +
20 +namespace WixToolset.Util.Symbols
21 +{
22 + using WixToolset.Data;
23 +
24 + public enum WixWindowsFeatureSearchSymbolFields
25 + {
26 + Type,
27 + }
28 +
29 + public class WixWindowsFeatureSearchSymbol : IntermediateSymbol
30 + {
31 + public WixWindowsFeatureSearchSymbol() : base(UtilSymbolDefinitions.WixWindowsFeatureSearch, null, null)
32 + {
33 + }
34 +
35 + public WixWindowsFeatureSearchSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(UtilSymbolDefinitions.WixWindowsFeatureSearch, sourceLineNumber, id)
36 + {
37 + }
38 +
39 + public IntermediateField this[WixWindowsFeatureSearchSymbolFields index] => this.Fields[(int)index];
40 +
41 + public string Type
42 + {
43 + get => this.Fields[(int)WixWindowsFeatureSearchSymbolFields.Type].AsString();
44 + set => this.Set((int)WixWindowsFeatureSearchSymbolFields.Type, value);
45 + }
46 + }
47 +}
src/wixext/UtilCompiler.cs
+35 -15
@@ -235,8 +235,6 @@ namespace WixToolset.Util
235 break;
236 case "ComponentSearch":
237 case "ComponentSearchRef":
238 - case "DetectSHA2Support":
239 - case "DetectSHA2SupportRef":
238 case "DirectorySearch":
239 case "DirectorySearchRef":
240 case "FileSearch":
@@ -245,6 +243,8 @@ namespace WixToolset.Util
243 case "ProductSearchRef":
244 case "RegistrySearch":
245 case "RegistrySearchRef":
246 + case "WindowsFeatureSearch":
247 + case "WindowsFeatureSearchRef":
248 // These will eventually be supported under Module/Product, but are not yet.
249 if (parentElement.Name.LocalName == "Bundle" || parentElement.Name.LocalName == "Fragment")
250 {
@@ -258,12 +258,6 @@ namespace WixToolset.Util
258 case "ComponentSearchRef":
259 this.ParseComponentSearchRefElement(intermediate, section, element);
260 break;
261 - case "DetectSHA2Support":
262 - this.ParseDetectSHA2SupportElement(intermediate, section, element);
263 - break;
264 - case "DetectSHA2SupportRef":
265 - this.ParseDetectSHA2SupportRefElement(intermediate, section, element);
266 - break;
261 case "DirectorySearch":
262 this.ParseDirectorySearchElement(intermediate, section, element);
263 break;
@@ -288,6 +282,12 @@ namespace WixToolset.Util
282 case "RegistrySearchRef":
283 this.ParseWixSearchRefElement(intermediate, section, element);
284 break;
285 + case "WindowsFeatureSearch":
286 + this.ParseWindowsFeatureSearchElement(intermediate, section, element);
287 + break;
288 + case "WindowsFeatureSearchRef":
289 + this.ParseWindowsFeatureSearchRefElement(intermediate, section, element);
290 + break;
291 }
292 }
293 else
@@ -508,16 +508,17 @@ namespace WixToolset.Util
508 }
509
510 /// <summary>
511 - /// Parses a DetectSHA2Support element.
511 + /// Parses a WindowsFeatureSearch element.
512 /// </summary>
513 /// <param name="element">Element to parse.</param>
514 - private void ParseDetectSHA2SupportElement(Intermediate intermediate, IntermediateSection section, XElement element)
514 + private void ParseWindowsFeatureSearchElement(Intermediate intermediate, IntermediateSection section, XElement element)
515 {
516 var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
517 Identifier id = null;
518 string variable = null;
519 string condition = null;
520 string after = null;
521 + string feature = null;
522
523 foreach (var attrib in element.Attributes())
524 {
@@ -531,6 +532,17 @@ namespace WixToolset.Util
532 case "After":
533 this.ParseCommonSearchAttributes(sourceLineNumbers, attrib, ref id, ref variable, ref condition, ref after);
534 break;
535 + case "Feature":
536 + feature = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
537 + switch (feature)
538 + {
539 + case "sha2CodeSigning":
540 + break;
541 + default:
542 + this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, element.Name.LocalName, "Feature", feature, "sha2CodeSigning"));
543 + break;
544 + }
545 + break;
546 default:
547 this.ParseHelper.UnexpectedAttribute(element, attrib);
548 break;
@@ -544,7 +556,12 @@ namespace WixToolset.Util
556
557 if (id == null)
558 {
547 - id = this.ParseHelper.CreateIdentifier("wds2s", variable, condition, after);
559 + id = this.ParseHelper.CreateIdentifier("wwfs", variable, condition, after);
560 + }
561 +
562 + if (feature == null)
563 + {
564 + this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Feature"));
565 }
566
567 this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element);
@@ -559,15 +576,18 @@ namespace WixToolset.Util
576
577 if (!this.Messaging.EncounteredError)
578 {
562 - section.AddSymbol(new WixDetectSHA2SupportSymbol(sourceLineNumbers, id));
579 + section.AddSymbol(new WixWindowsFeatureSearchSymbol(sourceLineNumbers, id)
580 + {
581 + Type = feature,
582 + });
583 }
584 }
585
586 /// <summary>
567 - /// Parses a DetectSHA2SupportRef element
587 + /// Parses a WindowsFeatureSearchRef element
588 /// </summary>
589 /// <param name="element">Element to parse.</param>
570 - private void ParseDetectSHA2SupportRefElement(Intermediate intermediate, IntermediateSection section, XElement element)
590 + private void ParseWindowsFeatureSearchRefElement(Intermediate intermediate, IntermediateSection section, XElement element)
591 {
592 var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
593
@@ -579,7 +599,7 @@ namespace WixToolset.Util
599 {
600 case "Id":
601 var refId = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
582 - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, UtilSymbolDefinitions.WixDetectSHA2Support, refId);
602 + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, UtilSymbolDefinitions.WixWindowsFeatureSearch, refId);
603 break;
604 default:
605 this.ParseHelper.UnexpectedAttribute(element, attrib);
src/wixext/util.xsd
+38 -24
@@ -174,30 +174,6 @@
174 <xs:attribute name="Id" type="xs:string" use="required" />
175 </xs:complexType>
176 </xs:element>
177 - <xs:element name="DetectSHA2Support">
178 - <xs:annotation>
179 - <xs:documentation>Detects support for SHA2.</xs:documentation>
180 - <xs:appinfo>
181 - <xse:parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="Bundle" />
182 - <xse:parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="Fragment" />
183 - </xs:appinfo>
184 - </xs:annotation>
185 - <xs:complexType>
186 - <xs:attributeGroup ref="SearchCommonAttributes" />
187 - </xs:complexType>
188 - </xs:element>
189 - <xs:element name="DetectSHA2SupportRef">
190 - <xs:annotation>
191 - <xs:documentation>References a DetectSHA2Support.</xs:documentation>
192 - <xs:appinfo>
193 - <xse:parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="Bundle" />
194 - <xse:parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="Fragment" />
195 - </xs:appinfo>
196 - </xs:annotation>
197 - <xs:complexType>
198 - <xs:attribute name="Id" type="xs:string" use="required" />
199 - </xs:complexType>
200 - </xs:element>
177 <xs:element name="DirectorySearch">
178 <xs:annotation>
179 <xs:documentation>Describes a directory search.</xs:documentation>
@@ -1389,6 +1365,44 @@
1365 </xs:attribute>
1366 </xs:complexType>
1367 </xs:element>
1368 + <xs:element name="WindowsFeatureSearch">
1369 + <xs:annotation>
1370 + <xs:documentation>Detects the existence of a Windows feature.</xs:documentation>
1371 + <xs:appinfo>
1372 + <xse:parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="Bundle" />
1373 + <xse:parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="Fragment" />
1374 + </xs:appinfo>
1375 + </xs:annotation>
1376 + <xs:complexType>
1377 + <xs:attributeGroup ref="SearchCommonAttributes" />
1378 + <xs:attribute name="Feature" use="required">
1379 + <xs:annotation>
1380 + <xs:documentation>The feature to detect.</xs:documentation>
1381 + </xs:annotation>
1382 + <xs:simpleType>
1383 + <xs:restriction base="xs:NMTOKEN">
1384 + <xs:enumeration value="sha2CodeSigning">
1385 + <xs:annotation>
1386 + <xs:documentation>The oldest OS with this feature is Win7 SP1 with KB3033929.</xs:documentation>
1387 + </xs:annotation>
1388 + </xs:enumeration>
1389 + </xs:restriction>
1390 + </xs:simpleType>
1391 + </xs:attribute>
1392 + </xs:complexType>
1393 + </xs:element>
1394 + <xs:element name="WindowsFeatureSearchRef">
1395 + <xs:annotation>
1396 + <xs:documentation>References a WindowsFeatureSearch.</xs:documentation>
1397 + <xs:appinfo>
1398 + <xse:parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="Bundle" />
1399 + <xse:parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="Fragment" />
1400 + </xs:appinfo>
1401 + </xs:annotation>
1402 + <xs:complexType>
1403 + <xs:attribute name="Id" type="xs:string" use="required" />
1404 + </xs:complexType>
1405 + </xs:element>
1406 <xs:element name="XmlFile">
1407 <xs:annotation>
1408 <xs:documentation>