diff options
Diffstat (limited to 'src/WixToolset.Core/Librarian.cs')
-rw-r--r-- | src/WixToolset.Core/Librarian.cs | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Librarian.cs b/src/WixToolset.Core/Librarian.cs new file mode 100644 index 00000000..daf53478 --- /dev/null +++ b/src/WixToolset.Core/Librarian.cs | |||
@@ -0,0 +1,95 @@ | |||
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 | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using WixToolset.Data; | ||
8 | using WixToolset.Extensibility; | ||
9 | using WixToolset.Link; | ||
10 | |||
11 | /// <summary> | ||
12 | /// Core librarian tool. | ||
13 | /// </summary> | ||
14 | public sealed class Librarian | ||
15 | { | ||
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). | ||
54 | /// </summary> | ||
55 | /// <param name="sections">The sections to combine into a library.</param> | ||
56 | /// <returns>Returns the new library.</returns> | ||
57 | public Library Combine(IEnumerable<Section> sections) | ||
58 | { | ||
59 | Library library = new Library(sections); | ||
60 | |||
61 | this.Validate(library); | ||
62 | |||
63 | return (Messaging.Instance.EncounteredError ? null : library); | ||
64 | } | ||
65 | |||
66 | /// <summary> | ||
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 | } | ||
74 | |||
75 | /// <summary> | ||
76 | /// Validate that a library contains one entry section and no duplicate symbols. | ||
77 | /// </summary> | ||
78 | /// <param name="library">Library to validate.</param> | ||
79 | private void Validate(Library library) | ||
80 | { | ||
81 | FindEntrySectionAndLoadSymbolsCommand find = new FindEntrySectionAndLoadSymbolsCommand(library.Sections); | ||
82 | find.Execute(); | ||
83 | |||
84 | // TODO: Consider bringing this sort of verification back. | ||
85 | // foreach (Section section in library.Sections) | ||
86 | // { | ||
87 | // ResolveReferencesCommand resolve = new ResolveReferencesCommand(find.EntrySection, find.Symbols); | ||
88 | // resolve.Execute(); | ||
89 | // | ||
90 | // ReportDuplicateResolvedSymbolErrorsCommand reportDupes = new ReportDuplicateResolvedSymbolErrorsCommand(find.SymbolsWithDuplicates, resolve.ResolvedSections); | ||
91 | // reportDupes.Execute(); | ||
92 | // } | ||
93 | } | ||
94 | } | ||
95 | } | ||