| 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.Collections.Generic; |
| 6 | using System.Linq; |
| 7 | using WixToolset.Data; |
| 8 | using WixToolset.Data.Symbols; |
| 9 | |
| 10 | /// <summary> |
| 11 | /// Add CreateFolder symbols, if not already present, for null-keypath components. |
| 12 | /// </summary> |
| 13 | internal class AddCreateFoldersCommand |
| 14 | { |
| 15 | internal AddCreateFoldersCommand(IntermediateSection section) |
| 16 | { |
| 17 | this.Section = section; |
| 18 | } |
| 19 | |
| 20 | private IntermediateSection Section { get; } |
| 21 | |
| 22 | public void Execute() |
| 23 | { |
| 24 | var createFolderSymbolsByComponentRef = new HashSet<string>(this.Section.Symbols.OfType<CreateFolderSymbol>().Select(t => t.ComponentRef)); |
| 25 | foreach (var componentSymbol in this.Section.Symbols.OfType<ComponentSymbol>().Where(t => t.KeyPathType == ComponentKeyPathType.Directory).ToList()) |
| 26 | { |
| 27 | if (!createFolderSymbolsByComponentRef.Contains(componentSymbol.Id.Id)) |
| 28 | { |
| 29 | this.Section.AddSymbol(new CreateFolderSymbol(componentSymbol.SourceLineNumbers) |
| 30 | { |
| 31 | DirectoryRef = componentSymbol.DirectoryRef, |
| 32 | ComponentRef = componentSymbol.Id.Id, |
| 33 | }); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | } |