diff options
Diffstat (limited to 'src/WixToolset.Core/Librarian.cs')
-rw-r--r-- | src/WixToolset.Core/Librarian.cs | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/src/WixToolset.Core/Librarian.cs b/src/WixToolset.Core/Librarian.cs index 092d81dc..50357d8a 100644 --- a/src/WixToolset.Core/Librarian.cs +++ b/src/WixToolset.Core/Librarian.cs | |||
@@ -6,40 +6,50 @@ namespace WixToolset.Core | |||
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
7 | using System.Linq; | 7 | using System.Linq; |
8 | using WixToolset.Core.Bind; | 8 | using WixToolset.Core.Bind; |
9 | using WixToolset.Core.Link; | ||
9 | using WixToolset.Data; | 10 | using WixToolset.Data; |
10 | using WixToolset.Link; | 11 | using WixToolset.Extensibility; |
11 | 12 | ||
12 | /// <summary> | 13 | /// <summary> |
13 | /// Core librarian tool. | 14 | /// Core librarian tool. |
14 | /// </summary> | 15 | /// </summary> |
15 | public sealed class Librarian | 16 | public sealed class Librarian |
16 | { | 17 | { |
17 | public Librarian(LibraryContext context) | 18 | private ILibraryContext Context { get; set; } |
18 | { | ||
19 | this.Context = context; | ||
20 | } | ||
21 | |||
22 | private LibraryContext Context { get; } | ||
23 | 19 | ||
24 | /// <summary> | 20 | /// <summary> |
25 | /// Create a library by combining several intermediates (objects). | 21 | /// Create a library by combining several intermediates (objects). |
26 | /// </summary> | 22 | /// </summary> |
27 | /// <param name="sections">The sections to combine into a library.</param> | 23 | /// <param name="sections">The sections to combine into a library.</param> |
28 | /// <returns>Returns the new library.</returns> | 24 | /// <returns>Returns the new library.</returns> |
29 | public Library Combine() | 25 | public Intermediate Combine(ILibraryContext context) |
30 | { | 26 | { |
27 | this.Context = context ?? throw new ArgumentNullException(nameof(context)); | ||
28 | |||
29 | if (String.IsNullOrEmpty(this.Context.LibraryId)) | ||
30 | { | ||
31 | this.Context.LibraryId = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace('+', '.').Replace('/', '_'); | ||
32 | } | ||
33 | |||
31 | foreach (var extension in this.Context.Extensions) | 34 | foreach (var extension in this.Context.Extensions) |
32 | { | 35 | { |
33 | extension.PreCombine(this.Context); | 36 | extension.PreCombine(this.Context); |
34 | } | 37 | } |
35 | 38 | ||
39 | var sections = this.Context.Intermediates.SelectMany(i => i.Sections).ToList(); | ||
40 | |||
36 | var fileResolver = new FileResolver(this.Context.BindPaths, this.Context.Extensions); | 41 | var fileResolver = new FileResolver(this.Context.BindPaths, this.Context.Extensions); |
37 | 42 | ||
43 | var embedFilePaths = ResolveFilePathsToEmbed(sections, fileResolver); | ||
44 | |||
38 | var localizationsByCulture = CollateLocalizations(this.Context.Localizations); | 45 | var localizationsByCulture = CollateLocalizations(this.Context.Localizations); |
39 | 46 | ||
40 | var embedFilePaths = ResolveFilePathsToEmbed(this.Context.Sections, fileResolver); | 47 | foreach (var section in sections) |
48 | { | ||
49 | section.LibraryId = this.Context.LibraryId; | ||
50 | } | ||
41 | 51 | ||
42 | var library = new Library(this.Context.Sections, localizationsByCulture, embedFilePaths); | 52 | var library = new Intermediate(this.Context.LibraryId, sections, localizationsByCulture, embedFilePaths); |
43 | 53 | ||
44 | this.Validate(library); | 54 | this.Validate(library); |
45 | 55 | ||
@@ -55,7 +65,7 @@ namespace WixToolset.Core | |||
55 | /// Validate that a library contains one entry section and no duplicate symbols. | 65 | /// Validate that a library contains one entry section and no duplicate symbols. |
56 | /// </summary> | 66 | /// </summary> |
57 | /// <param name="library">Library to validate.</param> | 67 | /// <param name="library">Library to validate.</param> |
58 | private Library Validate(Library library) | 68 | private Intermediate Validate(Intermediate library) |
59 | { | 69 | { |
60 | FindEntrySectionAndLoadSymbolsCommand find = new FindEntrySectionAndLoadSymbolsCommand(library.Sections); | 70 | FindEntrySectionAndLoadSymbolsCommand find = new FindEntrySectionAndLoadSymbolsCommand(library.Sections); |
61 | find.Execute(); | 71 | find.Execute(); |
@@ -92,39 +102,35 @@ namespace WixToolset.Core | |||
92 | return localizationsByCulture; | 102 | return localizationsByCulture; |
93 | } | 103 | } |
94 | 104 | ||
95 | private List<string> ResolveFilePathsToEmbed(IEnumerable<Section> sections, FileResolver fileResolver) | 105 | private List<string> ResolveFilePathsToEmbed(IEnumerable<IntermediateSection> sections, FileResolver fileResolver) |
96 | { | 106 | { |
97 | var embedFilePaths = new List<string>(); | 107 | var embedFilePaths = new List<string>(); |
98 | 108 | ||
99 | // Resolve paths to files that are to be embedded in the library. | 109 | // Resolve paths to files that are to be embedded in the library. |
100 | if (this.Context.BindFiles) | 110 | if (this.Context.BindFiles) |
101 | { | 111 | { |
102 | foreach (Table table in sections.SelectMany(s => s.Tables)) | 112 | foreach (var tuple in sections.SelectMany(s => s.Tuples)) |
103 | { | 113 | { |
104 | foreach (Row row in table.Rows) | 114 | foreach (var field in tuple.Fields.Where(f => f.Type == IntermediateFieldType.Path)) |
105 | { | 115 | { |
106 | foreach (ObjectField objectField in row.Fields.OfType<ObjectField>()) | 116 | var pathField = field.AsPath(); |
117 | |||
118 | if (pathField != null) | ||
107 | { | 119 | { |
108 | if (null != objectField.Data) | 120 | var resolvedPath = this.Context.WixVariableResolver.ResolveVariables(tuple.SourceLineNumbers, pathField.Path, false); |
121 | |||
122 | var file = fileResolver.Resolve(tuple.SourceLineNumbers, tuple.Definition.Name, resolvedPath); | ||
123 | |||
124 | if (!String.IsNullOrEmpty(file)) | ||
109 | { | 125 | { |
110 | string resolvedPath = this.Context.WixVariableResolver.ResolveVariables(row.SourceLineNumbers, (string)objectField.Data, false); | 126 | // File was successfully resolved so track the embedded index as the embedded file index. |
111 | 127 | field.Set(new IntermediateFieldPathValue { EmbeddedFileIndex = embedFilePaths.Count }); | |
112 | string file = fileResolver.Resolve(row.SourceLineNumbers, table.Name, resolvedPath); | 128 | |
113 | 129 | embedFilePaths.Add(file); | |
114 | if (!String.IsNullOrEmpty(file)) | ||
115 | { | ||
116 | // File was successfully resolved so track the embedded index as the embedded file index. | ||
117 | objectField.EmbeddedFileIndex = embedFilePaths.Count; | ||
118 | embedFilePaths.Add(file); | ||
119 | } | ||
120 | else | ||
121 | { | ||
122 | Messaging.Instance.OnMessage(WixDataErrors.FileNotFound(row.SourceLineNumbers, (string)objectField.Data, table.Name)); | ||
123 | } | ||
124 | } | 130 | } |
125 | else // clear out embedded file id in case there was one there before. | 131 | else |
126 | { | 132 | { |
127 | objectField.EmbeddedFileIndex = null; | 133 | this.Context.Messaging.OnMessage(WixDataErrors.FileNotFound(tuple.SourceLineNumbers, pathField.Path, tuple.Definition.Name)); |
128 | } | 134 | } |
129 | } | 135 | } |
130 | } | 136 | } |