diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-09-17 15:35:20 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-09-17 16:00:11 -0700 |
| commit | d3d3649a68cb1fa589fdd987a6690dbd5d671f0d (patch) | |
| tree | 44fe37ee352b7e3a355cc1e08b1d7d5988c14cc0 /src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs | |
| parent | a62610d23d6feb98be3b1e529a4e81b19d77d9d8 (diff) | |
| download | wix-d3d3649a68cb1fa589fdd987a6690dbd5d671f0d.tar.gz wix-d3d3649a68cb1fa589fdd987a6690dbd5d671f0d.tar.bz2 wix-d3d3649a68cb1fa589fdd987a6690dbd5d671f0d.zip | |
Initial code commit
Diffstat (limited to 'src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs')
| -rw-r--r-- | src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs b/src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs new file mode 100644 index 00000000..68bfd8d7 --- /dev/null +++ b/src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs | |||
| @@ -0,0 +1,53 @@ | |||
| 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.Bind | ||
| 4 | { | ||
| 5 | using System.IO; | ||
| 6 | using System.Reflection; | ||
| 7 | using WixToolset.Data; | ||
| 8 | |||
| 9 | internal class ExtractEmbeddedFilesCommand : ICommand | ||
| 10 | { | ||
| 11 | public ExtractEmbeddedFiles FilesWithEmbeddedFiles { private get; set; } | ||
| 12 | |||
| 13 | public void Execute() | ||
| 14 | { | ||
| 15 | foreach (var baseUri in this.FilesWithEmbeddedFiles.Uris) | ||
| 16 | { | ||
| 17 | Stream stream = null; | ||
| 18 | try | ||
| 19 | { | ||
| 20 | // If the embedded files are stored in an assembly resource stream (usually | ||
| 21 | // a .wixlib embedded in a WixExtension). | ||
| 22 | if ("embeddedresource" == baseUri.Scheme) | ||
| 23 | { | ||
| 24 | string assemblyPath = Path.GetFullPath(baseUri.LocalPath); | ||
| 25 | string resourceName = baseUri.Fragment.TrimStart('#'); | ||
| 26 | |||
| 27 | Assembly assembly = Assembly.LoadFile(assemblyPath); | ||
| 28 | stream = assembly.GetManifestResourceStream(resourceName); | ||
| 29 | } | ||
| 30 | else // normal file (usually a binary .wixlib on disk). | ||
| 31 | { | ||
| 32 | stream = File.OpenRead(baseUri.LocalPath); | ||
| 33 | } | ||
| 34 | |||
| 35 | using (FileStructure fs = FileStructure.Read(stream)) | ||
| 36 | { | ||
| 37 | foreach (var embeddedFile in this.FilesWithEmbeddedFiles.GetExtractFilesForUri(baseUri)) | ||
| 38 | { | ||
| 39 | fs.ExtractEmbeddedFile(embeddedFile.EmbeddedFileIndex, embeddedFile.OutputPath); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | finally | ||
| 44 | { | ||
| 45 | if (null != stream) | ||
| 46 | { | ||
| 47 | stream.Close(); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | } | ||
