| 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.Core.WindowsInstaller.Bind |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using System.Linq; |
| 8 | using WixToolset.Data; |
| 9 | using WixToolset.Data.Symbols; |
| 10 | |
| 11 | internal class CreateSpecialPropertiesCommand |
| 12 | { |
| 13 | public CreateSpecialPropertiesCommand(IntermediateSection section) |
| 14 | { |
| 15 | this.Section = section; |
| 16 | } |
| 17 | |
| 18 | private IntermediateSection Section { get; } |
| 19 | |
| 20 | public void Execute() |
| 21 | { |
| 22 | // Create lists of the properties that contribute to the special lists of properties. |
| 23 | var adminProperties = new SortedSet<string>(); |
| 24 | var secureProperties = new SortedSet<string>(); |
| 25 | var hiddenProperties = new SortedSet<string>(); |
| 26 | |
| 27 | foreach (var wixPropertyRow in this.Section.Symbols.OfType<WixPropertySymbol>()) |
| 28 | { |
| 29 | if (wixPropertyRow.Admin) |
| 30 | { |
| 31 | adminProperties.Add(wixPropertyRow.PropertyRef); |
| 32 | } |
| 33 | |
| 34 | if (wixPropertyRow.Hidden) |
| 35 | { |
| 36 | hiddenProperties.Add(wixPropertyRow.PropertyRef); |
| 37 | } |
| 38 | |
| 39 | if (wixPropertyRow.Secure) |
| 40 | { |
| 41 | secureProperties.Add(wixPropertyRow.PropertyRef); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // Hide properties for in-script custom actions that have HideTarget set. |
| 46 | var hideTargetCustomActions = this.Section.Symbols.OfType<CustomActionSymbol>().Where( |
| 47 | ca => ca.Hidden |
| 48 | && (ca.ExecutionType == CustomActionExecutionType.Deferred |
| 49 | || ca.ExecutionType == CustomActionExecutionType.Commit |
| 50 | || ca.ExecutionType == CustomActionExecutionType.Rollback)) |
| 51 | .Select(ca => ca.Id.Id); |
| 52 | hiddenProperties.UnionWith(hideTargetCustomActions); |
| 53 | |
| 54 | // Ensure upgrade action properties are secure. |
| 55 | var actionProperties = this.Section.Symbols.OfType<UpgradeSymbol>().Select(u => u.ActionProperty); |
| 56 | secureProperties.UnionWith(actionProperties); |
| 57 | |
| 58 | if (0 < adminProperties.Count) |
| 59 | { |
| 60 | this.Section.AddSymbol(new PropertySymbol(null, new Identifier(AccessModifier.Section, "AdminProperties")) |
| 61 | { |
| 62 | Value = String.Join(";", adminProperties), |
| 63 | }); |
| 64 | } |
| 65 | |
| 66 | if (0 < secureProperties.Count) |
| 67 | { |
| 68 | this.Section.AddSymbol(new PropertySymbol(null, new Identifier(AccessModifier.Section, "SecureCustomProperties")) |
| 69 | { |
| 70 | Value = String.Join(";", secureProperties), |
| 71 | }); |
| 72 | } |
| 73 | |
| 74 | if (0 < hiddenProperties.Count) |
| 75 | { |
| 76 | this.Section.AddSymbol(new PropertySymbol(null, new Identifier(AccessModifier.Section, "MsiHiddenProperties")) |
| 77 | { |
| 78 | Value = String.Join(";", hiddenProperties) |
| 79 | }); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |