diff options
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 | } | ||