| 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.Bind |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using System.Linq; |
| 8 | using WixToolset.Data; |
| 9 | using WixToolset.Extensibility.Data; |
| 10 | using WixToolset.Extensibility.Services; |
| 11 | |
| 12 | internal class ExtractEmbeddedFilesCommand |
| 13 | { |
| 14 | public ExtractEmbeddedFilesCommand(IBackendHelper backendHelper, IEnumerable<IExpectedExtractFile> embeddedFiles) |
| 15 | { |
| 16 | this.BackendHelper = backendHelper; |
| 17 | this.FilesWithEmbeddedFiles = embeddedFiles; |
| 18 | } |
| 19 | |
| 20 | public IReadOnlyList<ITrackedFile> TrackedFiles { get; private set; } |
| 21 | |
| 22 | private IBackendHelper BackendHelper { get; } |
| 23 | |
| 24 | private IEnumerable<IExpectedExtractFile> FilesWithEmbeddedFiles { get; } |
| 25 | |
| 26 | public void Execute() |
| 27 | { |
| 28 | var trackedFiles = new List<ITrackedFile>(); |
| 29 | var group = this.FilesWithEmbeddedFiles.GroupBy(e => e.Uri); |
| 30 | |
| 31 | foreach (var expectedEmbeddedFileByUri in group) |
| 32 | { |
| 33 | var baseUri = expectedEmbeddedFileByUri.Key; |
| 34 | trackedFiles.Add(this.BackendHelper.TrackFile(baseUri.LocalPath, TrackedFileType.Input)); |
| 35 | |
| 36 | using (var wixout = WixOutput.Read(baseUri)) |
| 37 | { |
| 38 | var uniqueIds = new SortedSet<string>(StringComparer.OrdinalIgnoreCase); |
| 39 | |
| 40 | foreach (var embeddedFile in expectedEmbeddedFileByUri) |
| 41 | { |
| 42 | if (uniqueIds.Add(embeddedFile.EmbeddedFileId)) |
| 43 | { |
| 44 | wixout.ExtractEmbeddedFile(embeddedFile.EmbeddedFileId, embeddedFile.OutputPath); |
| 45 | trackedFiles.Add(this.BackendHelper.TrackFile(embeddedFile.OutputPath, TrackedFileType.Intermediate)); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | this.TrackedFiles = trackedFiles; |
| 52 | } |
| 53 | } |
| 54 | } |