diff options
Diffstat (limited to 'src/WixToolset.Core/Librarian.cs')
-rw-r--r-- | src/WixToolset.Core/Librarian.cs | 117 |
1 files changed, 67 insertions, 50 deletions
diff --git a/src/WixToolset.Core/Librarian.cs b/src/WixToolset.Core/Librarian.cs index daf53478..66a8c32d 100644 --- a/src/WixToolset.Core/Librarian.cs +++ b/src/WixToolset.Core/Librarian.cs | |||
@@ -4,8 +4,8 @@ namespace WixToolset | |||
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
7 | using System.Linq; | ||
7 | using WixToolset.Data; | 8 | using WixToolset.Data; |
8 | using WixToolset.Extensibility; | ||
9 | using WixToolset.Link; | 9 | using WixToolset.Link; |
10 | 10 | ||
11 | /// <summary> | 11 | /// <summary> |
@@ -14,69 +14,26 @@ namespace WixToolset | |||
14 | public sealed class Librarian | 14 | public sealed class Librarian |
15 | { | 15 | { |
16 | /// <summary> | 16 | /// <summary> |
17 | /// Instantiate a new Librarian class. | ||
18 | /// </summary> | ||
19 | public Librarian() | ||
20 | { | ||
21 | this.TableDefinitions = new TableDefinitionCollection(WindowsInstallerStandard.GetTableDefinitions()); | ||
22 | } | ||
23 | |||
24 | /// <summary> | ||
25 | /// Gets table definitions used by this librarian. | ||
26 | /// </summary> | ||
27 | /// <value>Table definitions.</value> | ||
28 | public TableDefinitionCollection TableDefinitions { get; private set; } | ||
29 | |||
30 | /// <summary> | ||
31 | /// Adds an extension's data. | ||
32 | /// </summary> | ||
33 | /// <param name="extension">The extension data to add.</param> | ||
34 | public void AddExtensionData(IExtensionData extension) | ||
35 | { | ||
36 | if (null != extension.TableDefinitions) | ||
37 | { | ||
38 | foreach (TableDefinition tableDefinition in extension.TableDefinitions) | ||
39 | { | ||
40 | try | ||
41 | { | ||
42 | this.TableDefinitions.Add(tableDefinition); | ||
43 | } | ||
44 | catch (ArgumentException) | ||
45 | { | ||
46 | Messaging.Instance.OnMessage(WixErrors.DuplicateExtensionTable(extension.GetType().ToString(), tableDefinition.Name)); | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// Create a library by combining several intermediates (objects). | 17 | /// Create a library by combining several intermediates (objects). |
54 | /// </summary> | 18 | /// </summary> |
55 | /// <param name="sections">The sections to combine into a library.</param> | 19 | /// <param name="sections">The sections to combine into a library.</param> |
56 | /// <returns>Returns the new library.</returns> | 20 | /// <returns>Returns the new library.</returns> |
57 | public Library Combine(IEnumerable<Section> sections) | 21 | public Library Combine(IEnumerable<Section> sections, IEnumerable<Localization> localizations, ILibraryBinaryFileResolver resolver) |
58 | { | 22 | { |
59 | Library library = new Library(sections); | 23 | var localizationsByCulture = CollateLocalizations(localizations); |
60 | 24 | ||
61 | this.Validate(library); | 25 | var embedFilePaths = ResolveFilePathsToEmbed(sections, resolver); |
62 | 26 | ||
63 | return (Messaging.Instance.EncounteredError ? null : library); | 27 | var library = new Library(sections, localizationsByCulture, embedFilePaths); |
64 | } | ||
65 | 28 | ||
66 | /// <summary> | 29 | return this.Validate(library); |
67 | /// Sends a message to the message delegate if there is one. | ||
68 | /// </summary> | ||
69 | /// <param name="mea">Message event arguments.</param> | ||
70 | public void OnMessage(MessageEventArgs e) | ||
71 | { | ||
72 | Messaging.Instance.OnMessage(e); | ||
73 | } | 30 | } |
74 | 31 | ||
75 | /// <summary> | 32 | /// <summary> |
76 | /// Validate that a library contains one entry section and no duplicate symbols. | 33 | /// Validate that a library contains one entry section and no duplicate symbols. |
77 | /// </summary> | 34 | /// </summary> |
78 | /// <param name="library">Library to validate.</param> | 35 | /// <param name="library">Library to validate.</param> |
79 | private void Validate(Library library) | 36 | private Library Validate(Library library) |
80 | { | 37 | { |
81 | FindEntrySectionAndLoadSymbolsCommand find = new FindEntrySectionAndLoadSymbolsCommand(library.Sections); | 38 | FindEntrySectionAndLoadSymbolsCommand find = new FindEntrySectionAndLoadSymbolsCommand(library.Sections); |
82 | find.Execute(); | 39 | find.Execute(); |
@@ -90,6 +47,66 @@ namespace WixToolset | |||
90 | // ReportDuplicateResolvedSymbolErrorsCommand reportDupes = new ReportDuplicateResolvedSymbolErrorsCommand(find.SymbolsWithDuplicates, resolve.ResolvedSections); | 47 | // ReportDuplicateResolvedSymbolErrorsCommand reportDupes = new ReportDuplicateResolvedSymbolErrorsCommand(find.SymbolsWithDuplicates, resolve.ResolvedSections); |
91 | // reportDupes.Execute(); | 48 | // reportDupes.Execute(); |
92 | // } | 49 | // } |
50 | |||
51 | return (Messaging.Instance.EncounteredError ? null : library); | ||
52 | } | ||
53 | |||
54 | private static Dictionary<string, Localization> CollateLocalizations(IEnumerable<Localization> localizations) | ||
55 | { | ||
56 | var localizationsByCulture = new Dictionary<string, Localization>(StringComparer.OrdinalIgnoreCase); | ||
57 | |||
58 | foreach (var localization in localizations) | ||
59 | { | ||
60 | if (localizationsByCulture.TryGetValue(localization.Culture, out var existingCulture)) | ||
61 | { | ||
62 | existingCulture.Merge(localization); | ||
63 | } | ||
64 | else | ||
65 | { | ||
66 | localizationsByCulture.Add(localization.Culture, localization); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | return localizationsByCulture; | ||
71 | } | ||
72 | |||
73 | private static List<string> ResolveFilePathsToEmbed(IEnumerable<Section> sections, ILibraryBinaryFileResolver resolver) | ||
74 | { | ||
75 | var embedFilePaths = new List<string>(); | ||
76 | |||
77 | // Resolve paths to files that are to be embedded in the library. | ||
78 | if (null != resolver) | ||
79 | { | ||
80 | foreach (Table table in sections.SelectMany(s => s.Tables)) | ||
81 | { | ||
82 | foreach (Row row in table.Rows) | ||
83 | { | ||
84 | foreach (ObjectField objectField in row.Fields.OfType<ObjectField>()) | ||
85 | { | ||
86 | if (null != objectField.Data) | ||
87 | { | ||
88 | string file = resolver.Resolve(row.SourceLineNumbers, table.Name, (string)objectField.Data); | ||
89 | if (!String.IsNullOrEmpty(file)) | ||
90 | { | ||
91 | // File was successfully resolved so track the embedded index as the embedded file index. | ||
92 | objectField.EmbeddedFileIndex = embedFilePaths.Count; | ||
93 | embedFilePaths.Add(file); | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | Messaging.Instance.OnMessage(WixDataErrors.FileNotFound(row.SourceLineNumbers, (string)objectField.Data, table.Name)); | ||
98 | } | ||
99 | } | ||
100 | else // clear out embedded file id in case there was one there before. | ||
101 | { | ||
102 | objectField.EmbeddedFileIndex = null; | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | |||
109 | return embedFilePaths; | ||
93 | } | 110 | } |
94 | } | 111 | } |
95 | } | 112 | } |