| 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 |
| 4 | { |
| 5 | using System.Collections.Generic; |
| 6 | using System.Linq; |
| 7 | using WixToolset.Core.Link; |
| 8 | using WixToolset.Data; |
| 9 | using WixToolset.Data.Symbols; |
| 10 | |
| 11 | internal class AssignDefaultFeatureCommand |
| 12 | { |
| 13 | public AssignDefaultFeatureCommand(FindEntrySectionAndLoadSymbolsCommand find, List<IntermediateSection> sections) |
| 14 | { |
| 15 | this.Find = find; |
| 16 | this.Sections = sections; |
| 17 | } |
| 18 | |
| 19 | public IEnumerable<IntermediateSection> Sections { get; } |
| 20 | |
| 21 | public FindEntrySectionAndLoadSymbolsCommand Find { get; } |
| 22 | |
| 23 | public void Execute() |
| 24 | { |
| 25 | if (this.Find.EntrySection.Type == SectionType.Package |
| 26 | && !this.Sections.Where(s => s.Id != WixStandardLibraryIdentifiers.DefaultFeatureName) |
| 27 | .SelectMany(s => s.Symbols).OfType<FeatureSymbol>().Any()) |
| 28 | { |
| 29 | var addedToDefaultFeature = false; |
| 30 | |
| 31 | foreach (var section in this.Sections) |
| 32 | { |
| 33 | var components = section.Symbols.OfType<ComponentSymbol>().ToList(); |
| 34 | foreach (var component in components) |
| 35 | { |
| 36 | this.Find.EntrySection.AddSymbol(new WixComplexReferenceSymbol(component.SourceLineNumbers) |
| 37 | { |
| 38 | Parent = WixStandardLibraryIdentifiers.DefaultFeatureName, |
| 39 | ParentType = ComplexReferenceParentType.Feature, |
| 40 | ParentLanguage = null, |
| 41 | Child = component.Id.Id, |
| 42 | ChildType = ComplexReferenceChildType.Component, |
| 43 | IsPrimary = true, |
| 44 | }); |
| 45 | |
| 46 | this.Find.EntrySection.AddSymbol(new WixGroupSymbol(component.SourceLineNumbers) |
| 47 | { |
| 48 | ParentId = WixStandardLibraryIdentifiers.DefaultFeatureName, |
| 49 | ParentType = ComplexReferenceParentType.Feature, |
| 50 | ChildId = component.Id.Id, |
| 51 | ChildType = ComplexReferenceChildType.Component, |
| 52 | }); |
| 53 | |
| 54 | addedToDefaultFeature = true; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | if (addedToDefaultFeature) |
| 59 | { |
| 60 | this.Find.EntrySection.AddSymbol(new WixSimpleReferenceSymbol() |
| 61 | { |
| 62 | Table = "Feature", |
| 63 | PrimaryKeys = WixStandardLibraryIdentifiers.DefaultFeatureName, |
| 64 | }); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |