Simplify Library to only be a data container and add as output type
The actual of the creation functionality for Libraries will move to the Librarian.
Rob Mensching committed
Oct 1, 2017 at 14:17 UTC
cc997ec641d4634d2f3c6086a481fc8295e34b46
2 files changed
+13
-66
src/WixToolset.Data/Library.cs
+10
-66
@@ -5,7 +5,6 @@ namespace WixToolset.Data
5
using System;
6
using System.Collections.Generic;
7
using System.IO;
8
- using System.Linq;
8
using System.Xml;
9
10
/// <summary>
@@ -17,6 +16,7 @@ namespace WixToolset.Data
16
private static readonly Version CurrentVersion = new Version("4.0.0.0");
17
18
private string id;
19
+ private List<string> embedFilePaths;
20
private Dictionary<string, Localization> localizations;
21
private List<Section> sections;
22
@@ -25,6 +25,7 @@ namespace WixToolset.Data
25
/// </summary>
26
private Library()
27
{
28
+ this.embedFilePaths = new List<string>();
29
this.localizations = new Dictionary<string, Localization>();
30
this.sections = new List<Section>();
31
}
@@ -33,12 +34,14 @@ namespace WixToolset.Data
34
/// Instantiate a new library populated with sections.
35
/// </summary>
36
/// <param name="sections">Sections to add to the library.</param>
36
- public Library(IEnumerable<Section> sections)
37
+ /// <param name="localizationsByCulture"></param>
38
+ public Library(IEnumerable<Section> sections, IDictionary<string, Localization> localizationsByCulture, IEnumerable<string> embedFilePaths)
39
{
38
- this.localizations = new Dictionary<string, Localization>();
40
+ this.id = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace('+', '.').Replace('/', '_');
41
+ this.embedFilePaths = new List<string>(embedFilePaths);
42
+ this.localizations = new Dictionary<string, Localization>(localizationsByCulture);
43
this.sections = new List<Section>(sections);
44
41
- this.id = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace('+', '.').Replace('/', '_');
45
foreach (Section section in this.sections)
46
{
47
section.LibraryId = this.id;
@@ -49,24 +52,7 @@ namespace WixToolset.Data
52
/// Get the sections contained in this library.
53
/// </summary>
54
/// <value>Sections contained in this library.</value>
52
- public IEnumerable<Section> Sections { get { return this.sections; } }
53
-
54
- /// <summary>
55
- /// Add a localization file to this library.
56
- /// </summary>
57
- /// <param name="localization">The localization file to add.</param>
58
- public void AddLocalization(Localization localization)
59
- {
60
- Localization existingCulture;
61
- if (this.localizations.TryGetValue(localization.Culture, out existingCulture))
62
- {
63
- existingCulture.Merge(localization);
64
- }
65
- else
66
- {
67
- this.localizations.Add(localization.Culture, localization);
68
- }
69
- }
55
+ public IEnumerable<Section> Sections => this.sections;
56
57
/// <summary>
58
/// Gets localization files from this library that match the cultures passed in, in the order of the array of cultures.
@@ -77,8 +63,7 @@ namespace WixToolset.Data
63
{
64
foreach (string culture in cultures ?? new string[0])
65
{
80
- Localization localization;
81
- if (this.localizations.TryGetValue(culture, out localization))
66
+ if (this.localizations.TryGetValue(culture, out var localization))
67
{
68
yield return localization;
69
}
@@ -137,49 +122,8 @@ namespace WixToolset.Data
122
/// </summary>
123
/// <param name="path">Path to save library file to on disk.</param>
124
/// <param name="resolver">The WiX path resolver.</param>
140
- public void Save(string path, ILibraryBinaryFileResolver resolver)
125
+ public void Save(string path)
126
{
142
- List<string> embedFilePaths = new List<string>();
143
-
144
- // Resolve paths to files that are to be embedded in the library.
145
- if (null != resolver)
146
- {
147
- foreach (Table table in this.sections.SelectMany(s => s.Tables))
148
- {
149
- foreach (Row row in table.Rows)
150
- {
151
- foreach (ObjectField objectField in row.Fields.Where(f => f is ObjectField))
152
- {
153
- if (null != objectField.Data)
154
- {
155
- string file = resolver.Resolve(row.SourceLineNumbers, table.Name, (string)objectField.Data);
156
- if (!String.IsNullOrEmpty(file))
157
- {
158
- // File was successfully resolved so track the embedded index as the embedded file index.
159
- objectField.EmbeddedFileIndex = embedFilePaths.Count;
160
- embedFilePaths.Add(file);
161
- }
162
- else
163
- {
164
- Messaging.Instance.OnMessage(WixDataErrors.FileNotFound(row.SourceLineNumbers, (string)objectField.Data, table.Name));
165
- }
166
- }
167
- else // clear out embedded file id in case there was one there before.
168
- {
169
- objectField.EmbeddedFileIndex = null;
170
- }
171
- }
172
- }
173
- }
174
- }
175
-
176
- // Do not save the library if errors were found while resolving object paths.
177
- if (Messaging.Instance.EncounteredError)
178
- {
179
- return;
180
- }
181
-
182
- // Ensure the location to output the library exists and write it out.
127
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));
128
129
using (FileStream stream = File.Create(path))
src/WixToolset.Data/OutputType.cs
+3
@@ -13,6 +13,9 @@ namespace WixToolset.Data
13
/// <summary>Bundle output type.</summary>
14
Bundle,
15
16
+ /// <summary>Library output type.</summary>
17
+ Library,
18
+
19
/// <summary>Module output type.</summary>
20
Module,
21