From dbde9e7104b907bbbaea17e21247d8cafc8b3a4c Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 14 Oct 2017 16:12:07 -0700 Subject: Massive refactoring to introduce the concept of IBackend --- .../Bind/ExtractEmbeddedFilesCommand.cs | 29 ++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs') diff --git a/src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs b/src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs index 68bfd8d7..7de40fb8 100644 --- a/src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs +++ b/src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs @@ -1,19 +1,26 @@ // 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. -namespace WixToolset.Bind +namespace WixToolset.Core.Bind { + using System.Collections.Generic; using System.IO; + using System.Linq; using System.Reflection; using WixToolset.Data; + using WixToolset.Extensibility; - internal class ExtractEmbeddedFilesCommand : ICommand + public class ExtractEmbeddedFilesCommand { - public ExtractEmbeddedFiles FilesWithEmbeddedFiles { private get; set; } + public IEnumerable FilesWithEmbeddedFiles { private get; set; } public void Execute() { - foreach (var baseUri in this.FilesWithEmbeddedFiles.Uris) + var group = this.FilesWithEmbeddedFiles.GroupBy(e => e.Uri); + + foreach (var expectedEmbeddedFileByUri in group) { + var baseUri = expectedEmbeddedFileByUri.Key; + Stream stream = null; try { @@ -34,18 +41,20 @@ namespace WixToolset.Bind using (FileStructure fs = FileStructure.Read(stream)) { - foreach (var embeddedFile in this.FilesWithEmbeddedFiles.GetExtractFilesForUri(baseUri)) + var uniqueIndicies = new SortedSet(); + + foreach (var embeddedFile in expectedEmbeddedFileByUri) { - fs.ExtractEmbeddedFile(embeddedFile.EmbeddedFileIndex, embeddedFile.OutputPath); + if (uniqueIndicies.Add(embeddedFile.EmbeddedFileIndex)) + { + fs.ExtractEmbeddedFile(embeddedFile.EmbeddedFileIndex, embeddedFile.OutputPath); + } } } } finally { - if (null != stream) - { - stream.Close(); - } + stream?.Close(); } } } -- cgit v1.2.3-55-g6feb