aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2019-10-25 00:48:35 -0700
committerRob Mensching <rob@firegiant.com>2019-10-25 00:53:29 -0700
commit9c714a8f1baa6e0130e5cd00cbdca649cebaf6a5 (patch)
treeebf26d0e37244f3014e0c4924a29af7f7e56e2f2 /src/WixToolset.Core
parent87580cbe111a8df836231a0192dee674cf482f08 (diff)
downloadwix-9c714a8f1baa6e0130e5cd00cbdca649cebaf6a5.tar.gz
wix-9c714a8f1baa6e0130e5cd00cbdca649cebaf6a5.tar.bz2
wix-9c714a8f1baa6e0130e5cd00cbdca649cebaf6a5.zip
Update to WixOutput file structure to fix embedded file handling
Diffstat (limited to 'src/WixToolset.Core')
-rw-r--r--src/WixToolset.Core/Bind/ExpectedExtractFile.cs4
-rw-r--r--src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs38
-rw-r--r--src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs36
-rw-r--r--src/WixToolset.Core/Bind/ResolveFieldsCommand.cs4
-rw-r--r--src/WixToolset.Core/CommandLine/BuildCommand.cs38
-rw-r--r--src/WixToolset.Core/Librarian.cs14
-rw-r--r--src/WixToolset.Core/Linker.cs2
7 files changed, 60 insertions, 76 deletions
diff --git a/src/WixToolset.Core/Bind/ExpectedExtractFile.cs b/src/WixToolset.Core/Bind/ExpectedExtractFile.cs
index afad12fc..b27cdfee 100644
--- a/src/WixToolset.Core/Bind/ExpectedExtractFile.cs
+++ b/src/WixToolset.Core/Bind/ExpectedExtractFile.cs
@@ -1,4 +1,4 @@
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. 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 2
3namespace WixToolset.Core.Bind 3namespace WixToolset.Core.Bind
4{ 4{
@@ -9,7 +9,7 @@ namespace WixToolset.Core.Bind
9 { 9 {
10 public Uri Uri { get; set; } 10 public Uri Uri { get; set; }
11 11
12 public int EmbeddedFileIndex { get; set; } 12 public string EmbeddedFileId { get; set; }
13 13
14 public string OutputPath { get; set; } 14 public string OutputPath { get; set; }
15 } 15 }
diff --git a/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs b/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs
index 644e5c63..35c8a2f0 100644
--- a/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs
+++ b/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs
@@ -15,7 +15,7 @@ namespace WixToolset.Core.Bind
15 /// </summary> 15 /// </summary>
16 internal class ExtractEmbeddedFiles 16 internal class ExtractEmbeddedFiles
17 { 17 {
18 private Dictionary<Uri, SortedList<int, string>> filesWithEmbeddedFiles = new Dictionary<Uri, SortedList<int, string>>(); 18 private readonly Dictionary<Uri, SortedList<string, string>> filesWithEmbeddedFiles = new Dictionary<Uri, SortedList<string, string>>();
19 19
20 public IEnumerable<Uri> Uris => this.filesWithEmbeddedFiles.Keys; 20 public IEnumerable<Uri> Uris => this.filesWithEmbeddedFiles.Keys;
21 21
@@ -23,28 +23,28 @@ namespace WixToolset.Core.Bind
23 /// Adds an embedded file index to track and returns the path where the embedded file will be extracted. Duplicates will return the same extract path. 23 /// Adds an embedded file index to track and returns the path where the embedded file will be extracted. Duplicates will return the same extract path.
24 /// </summary> 24 /// </summary>
25 /// <param name="uri">Uri to file containing the embedded files.</param> 25 /// <param name="uri">Uri to file containing the embedded files.</param>
26 /// <param name="embeddedFileIndex">Index of the embedded file to extract.</param> 26 /// <param name="embeddedFileId">Id of the embedded file to extract.</param>
27 /// <param name="tempPath">Path where temporary files should be placed.</param> 27 /// <param name="extractFolder">Folder where extracted files should be placed.</param>
28 /// <returns>The extract path for the embedded file.</returns> 28 /// <returns>The extract path for the embedded file.</returns>
29 public string AddEmbeddedFileIndex(Uri uri, int embeddedFileIndex, string tempPath) 29 public string AddEmbeddedFileToExtract(Uri uri, string embeddedFileId, string extractFolder)
30 { 30 {
31 // If the uri to the file that contains the embedded file does not already have embedded files 31 // If the uri to the file that contains the embedded file does not already have embedded files
32 // being extracted, create the dictionary to track that. 32 // being extracted, create the dictionary to track that.
33 if (!this.filesWithEmbeddedFiles.TryGetValue(uri, out var extracts)) 33 if (!this.filesWithEmbeddedFiles.TryGetValue(uri, out var extracts))
34 { 34 {
35 extracts = new SortedList<int, string>(); 35 extracts = new SortedList<string, string>(StringComparer.OrdinalIgnoreCase);
36 this.filesWithEmbeddedFiles.Add(uri, extracts); 36 this.filesWithEmbeddedFiles.Add(uri, extracts);
37 } 37 }
38 38
39 // If the embedded file is not already tracked in the dictionary of extracts, add it. 39 // If the embedded file is not already tracked in the dictionary of extracts, add it.
40 if (!extracts.TryGetValue(embeddedFileIndex, out var extractPath)) 40 if (!extracts.TryGetValue(embeddedFileId, out var extractPath))
41 { 41 {
42 string localFileNameWithoutExtension = Path.GetFileNameWithoutExtension(uri.LocalPath); 42 var localFileNameWithoutExtension = Path.GetFileNameWithoutExtension(uri.LocalPath);
43 string unique = this.HashUri(uri.AbsoluteUri); 43 var unique = this.HashUri(uri.AbsoluteUri);
44 string extractedName = String.Format(CultureInfo.InvariantCulture, @"{0}_{1}\{2}", localFileNameWithoutExtension, unique, embeddedFileIndex); 44 var extractedName = String.Format(CultureInfo.InvariantCulture, @"{0}_{1}\{2}", localFileNameWithoutExtension, unique, embeddedFileId);
45 45
46 extractPath = Path.Combine(tempPath, extractedName); 46 extractPath = Path.GetFullPath(Path.Combine(extractFolder, extractedName));
47 extracts.Add(embeddedFileIndex, extractPath); 47 extracts.Add(embeddedFileId, extractPath);
48 } 48 }
49 49
50 return extractPath; 50 return extractPath;
@@ -52,35 +52,39 @@ namespace WixToolset.Core.Bind
52 52
53 public IEnumerable<ExpectedExtractFile> GetExpectedEmbeddedFiles() 53 public IEnumerable<ExpectedExtractFile> GetExpectedEmbeddedFiles()
54 { 54 {
55 var files = new List<ExpectedExtractFile>();
56
55 foreach (var uriWithExtracts in this.filesWithEmbeddedFiles) 57 foreach (var uriWithExtracts in this.filesWithEmbeddedFiles)
56 { 58 {
57 foreach (var extracts in uriWithExtracts.Value) 59 foreach (var extracts in uriWithExtracts.Value)
58 { 60 {
59 yield return new ExpectedExtractFile 61 files.Add(new ExpectedExtractFile
60 { 62 {
61 Uri = uriWithExtracts.Key, 63 Uri = uriWithExtracts.Key,
62 EmbeddedFileIndex = extracts.Key, 64 EmbeddedFileId = extracts.Key,
63 OutputPath = extracts.Value, 65 OutputPath = extracts.Value,
64 }; 66 });
65 } 67 }
66 } 68 }
69
70 return files;
67 } 71 }
68 72
69 public IEnumerable<ExpectedExtractFile> GetExtractFilesForUri(Uri uri) 73 public IEnumerable<ExpectedExtractFile> GetExtractFilesForUri(Uri uri)
70 { 74 {
71 if (!this.filesWithEmbeddedFiles.TryGetValue(uri, out var extracts)) 75 if (!this.filesWithEmbeddedFiles.TryGetValue(uri, out var extracts))
72 { 76 {
73 extracts = new SortedList<int, string>(); 77 extracts = new SortedList<string, string>(StringComparer.OrdinalIgnoreCase);
74 } 78 }
75 79
76 return extracts.Select(e => new ExpectedExtractFile() { Uri = uri, EmbeddedFileIndex = e.Key, OutputPath = e.Value }); 80 return extracts.Select(e => new ExpectedExtractFile { Uri = uri, EmbeddedFileId = e.Key, OutputPath = e.Value });
77 } 81 }
78 82
79 private string HashUri(string uri) 83 private string HashUri(string uri)
80 { 84 {
81 using (SHA1 sha1 = new SHA1CryptoServiceProvider()) 85 using (SHA1 sha1 = new SHA1CryptoServiceProvider())
82 { 86 {
83 byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(uri)); 87 var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(uri));
84 return Convert.ToBase64String(hash).TrimEnd('=').Replace('+', '-').Replace('/', '_'); 88 return Convert.ToBase64String(hash).TrimEnd('=').Replace('+', '-').Replace('/', '_');
85 } 89 }
86 } 90 }
diff --git a/src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs b/src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs
index d82609db..683c3c50 100644
--- a/src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs
+++ b/src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs
@@ -2,10 +2,9 @@
2 2
3namespace WixToolset.Core.Bind 3namespace WixToolset.Core.Bind
4{ 4{
5 using System;
5 using System.Collections.Generic; 6 using System.Collections.Generic;
6 using System.IO;
7 using System.Linq; 7 using System.Linq;
8 using System.Reflection;
9 using WixToolset.Data; 8 using WixToolset.Data;
10 using WixToolset.Extensibility.Data; 9 using WixToolset.Extensibility.Data;
11 10
@@ -26,41 +25,18 @@ namespace WixToolset.Core.Bind
26 { 25 {
27 var baseUri = expectedEmbeddedFileByUri.Key; 26 var baseUri = expectedEmbeddedFileByUri.Key;
28 27
29 Stream stream = null; 28 using (var wixout = WixOutput.Read(baseUri))
30 try
31 { 29 {
32 // If the embedded files are stored in an assembly resource stream (usually 30 var uniqueIds = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
33 // a .wixlib embedded in a WixExtension).
34 if ("embeddedresource" == baseUri.Scheme)
35 {
36 var assemblyPath = Path.GetFullPath(baseUri.LocalPath);
37 var resourceName = baseUri.Fragment.TrimStart('#');
38
39 var assembly = Assembly.LoadFile(assemblyPath);
40 stream = assembly.GetManifestResourceStream(resourceName);
41 }
42 else // normal file (usually a binary .wixlib on disk).
43 {
44 stream = File.OpenRead(baseUri.LocalPath);
45 }
46 31
47 using (var fs = FileStructure.Read(stream)) 32 foreach (var embeddedFile in expectedEmbeddedFileByUri)
48 { 33 {
49 var uniqueIndicies = new SortedSet<int>(); 34 if (uniqueIds.Add(embeddedFile.EmbeddedFileId))
50
51 foreach (var embeddedFile in expectedEmbeddedFileByUri)
52 { 35 {
53 if (uniqueIndicies.Add(embeddedFile.EmbeddedFileIndex)) 36 wixout.ExtractEmbeddedFile(embeddedFile.EmbeddedFileId, embeddedFile.OutputPath);
54 {
55 fs.ExtractEmbeddedFile(embeddedFile.EmbeddedFileIndex, embeddedFile.OutputPath);
56 }
57 } 37 }
58 } 38 }
59 } 39 }
60 finally
61 {
62 stream?.Close();
63 }
64 } 40 }
65 } 41 }
66 } 42 }
diff --git a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
index 2c213402..19a26915 100644
--- a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
+++ b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
@@ -98,9 +98,9 @@ namespace WixToolset.Core.Bind
98#endif 98#endif
99 99
100 // File is embedded and path to it was not modified above. 100 // File is embedded and path to it was not modified above.
101 if (objectField.EmbeddedFileIndex.HasValue && isDefault) 101 if (isDefault && objectField.Embed)
102 { 102 {
103 var extractPath = this.FilesWithEmbeddedFiles.AddEmbeddedFileIndex(objectField.BaseUri, objectField.EmbeddedFileIndex.Value, this.IntermediateFolder); 103 var extractPath = this.FilesWithEmbeddedFiles.AddEmbeddedFileToExtract(objectField.BaseUri, objectField.Path, this.IntermediateFolder);
104 104
105 // Set the path to the embedded file once where it will be extracted. 105 // Set the path to the embedded file once where it will be extracted.
106 field.Set(extractPath); 106 field.Set(extractPath);
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs
index 972258fe..5ee60984 100644
--- a/src/WixToolset.Core/CommandLine/BuildCommand.cs
+++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs
@@ -100,29 +100,38 @@ namespace WixToolset.Core.CommandLine
100 100
101 if (this.OutputType == OutputType.Library) 101 if (this.OutputType == OutputType.Library)
102 { 102 {
103 var wixlib = this.LibraryPhase(wixobjs, wxls, this.commandLine.BindFiles, this.commandLine.BindPaths); 103 using (new IntermediateFieldContext("wix.lib"))
104
105 if (!this.Messaging.EncounteredError)
106 { 104 {
107 wixlib.Save(this.commandLine.OutputFile); 105 var wixlib = this.LibraryPhase(wixobjs, wxls, this.commandLine.BindFiles, this.commandLine.BindPaths);
106
107 if (!this.Messaging.EncounteredError)
108 {
109 wixlib.Save(this.commandLine.OutputFile);
110 }
108 } 111 }
109 } 112 }
110 else 113 else
111 { 114 {
112 if (wixipl == null) 115 using (new IntermediateFieldContext("wix.link"))
113 {
114 wixipl = this.LinkPhase(wixobjs, this.commandLine.LibraryFilePaths, creator);
115 }
116
117 if (!this.Messaging.EncounteredError)
118 { 116 {
119 if (this.OutputType == OutputType.IntermediatePostLink) 117 if (wixipl == null)
120 { 118 {
121 wixipl.Save(this.commandLine.OutputFile); 119 wixipl = this.LinkPhase(wixobjs, this.commandLine.LibraryFilePaths, creator);
122 } 120 }
123 else 121
122 if (!this.Messaging.EncounteredError)
124 { 123 {
125 this.BindPhase(wixipl, wxls, filterCultures, this.commandLine.CabCachePath, this.commandLine.BindPaths, this.commandLine.BurnStubPath); 124 if (this.OutputType == OutputType.IntermediatePostLink)
125 {
126 wixipl.Save(this.commandLine.OutputFile);
127 }
128 else
129 {
130 using (new IntermediateFieldContext("wix.bind"))
131 {
132 this.BindPhase(wixipl, wxls, filterCultures, this.commandLine.CabCachePath, this.commandLine.BindPaths, this.commandLine.BurnStubPath);
133 }
134 }
126 } 135 }
127 } 136 }
128 } 137 }
@@ -469,6 +478,7 @@ namespace WixToolset.Core.CommandLine
469 break; 478 break;
470 } 479 }
471 480
481 case "bf":
472 case "bindfiles": 482 case "bindfiles":
473 this.BindFiles = true; 483 this.BindFiles = true;
474 return true; 484 return true;
diff --git a/src/WixToolset.Core/Librarian.cs b/src/WixToolset.Core/Librarian.cs
index 3c1810ac..5c0fb302 100644
--- a/src/WixToolset.Core/Librarian.cs
+++ b/src/WixToolset.Core/Librarian.cs
@@ -56,14 +56,14 @@ namespace WixToolset.Core
56 return null; 56 return null;
57 } 57 }
58 58
59 var embedFilePaths = this.ResolveFilePathsToEmbed(context, sections); 59 this.ResolveFilePathsToEmbed(context, sections);
60 60
61 foreach (var section in sections) 61 foreach (var section in sections)
62 { 62 {
63 section.LibraryId = context.LibraryId; 63 section.LibraryId = context.LibraryId;
64 } 64 }
65 65
66 library = new Intermediate(context.LibraryId, sections, localizationsByCulture, embedFilePaths); 66 library = new Intermediate(context.LibraryId, sections, localizationsByCulture);
67 67
68 this.Validate(library); 68 this.Validate(library);
69 } 69 }
@@ -78,10 +78,8 @@ namespace WixToolset.Core
78 return this.Messaging.EncounteredError ? null : library; 78 return this.Messaging.EncounteredError ? null : library;
79 } 79 }
80 80
81 private List<string> ResolveFilePathsToEmbed(ILibraryContext context, IEnumerable<IntermediateSection> sections) 81 private void ResolveFilePathsToEmbed(ILibraryContext context, IEnumerable<IntermediateSection> sections)
82 { 82 {
83 var embedFilePaths = new List<string>();
84
85 // Resolve paths to files that are to be embedded in the library. 83 // Resolve paths to files that are to be embedded in the library.
86 if (context.BindFiles) 84 if (context.BindFiles)
87 { 85 {
@@ -104,9 +102,7 @@ namespace WixToolset.Core
104 if (!String.IsNullOrEmpty(file)) 102 if (!String.IsNullOrEmpty(file))
105 { 103 {
106 // File was successfully resolved so track the embedded index as the embedded file index. 104 // File was successfully resolved so track the embedded index as the embedded file index.
107 field.Set(new IntermediateFieldPathValue { EmbeddedFileIndex = embedFilePaths.Count }); 105 field.Set(new IntermediateFieldPathValue { Embed = true, Path = file });
108
109 embedFilePaths.Add(file);
110 } 106 }
111 else 107 else
112 { 108 {
@@ -116,8 +112,6 @@ namespace WixToolset.Core
116 } 112 }
117 } 113 }
118 } 114 }
119
120 return embedFilePaths;
121 } 115 }
122 116
123 private void Validate(Intermediate library) 117 private void Validate(Intermediate library)
diff --git a/src/WixToolset.Core/Linker.cs b/src/WixToolset.Core/Linker.cs
index 81696840..6ef252b7 100644
--- a/src/WixToolset.Core/Linker.cs
+++ b/src/WixToolset.Core/Linker.cs
@@ -564,7 +564,7 @@ namespace WixToolset.Core
564 var collate = new CollateLocalizationsCommand(this.Messaging, localizations); 564 var collate = new CollateLocalizationsCommand(this.Messaging, localizations);
565 var localizationsByCulture = collate.Execute(); 565 var localizationsByCulture = collate.Execute();
566 566
567 intermediate = new Intermediate(resolvedSection.Id, new[] { resolvedSection }, localizationsByCulture, null); 567 intermediate = new Intermediate(resolvedSection.Id, new[] { resolvedSection }, localizationsByCulture);
568 568
569#if MOVE_TO_BACKEND 569#if MOVE_TO_BACKEND
570 this.CheckOutputConsistency(output); 570 this.CheckOutputConsistency(output);