aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-10-01 14:17:53 -0700
committerRob Mensching <rob@firegiant.com>2017-10-01 14:17:53 -0700
commitcc997ec641d4634d2f3c6086a481fc8295e34b46 (patch)
tree362794d8bf0d734d01e7a6365fb1681685ceb66c /src
parent251fd7106e3b06cf960d80c651a3a054ee952ddd (diff)
downloadwix-cc997ec641d4634d2f3c6086a481fc8295e34b46.tar.gz
wix-cc997ec641d4634d2f3c6086a481fc8295e34b46.tar.bz2
wix-cc997ec641d4634d2f3c6086a481fc8295e34b46.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/WixToolset.Data/Library.cs76
-rw-r--r--src/WixToolset.Data/OutputType.cs3
2 files changed, 13 insertions, 66 deletions
diff --git a/src/WixToolset.Data/Library.cs b/src/WixToolset.Data/Library.cs
index bb04d216..d82e64e0 100644
--- a/src/WixToolset.Data/Library.cs
+++ b/src/WixToolset.Data/Library.cs
@@ -5,7 +5,6 @@ namespace WixToolset.Data
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.IO; 7 using System.IO;
8 using System.Linq;
9 using System.Xml; 8 using System.Xml;
10 9
11 /// <summary> 10 /// <summary>
@@ -17,6 +16,7 @@ namespace WixToolset.Data
17 private static readonly Version CurrentVersion = new Version("4.0.0.0"); 16 private static readonly Version CurrentVersion = new Version("4.0.0.0");
18 17
19 private string id; 18 private string id;
19 private List<string> embedFilePaths;
20 private Dictionary<string, Localization> localizations; 20 private Dictionary<string, Localization> localizations;
21 private List<Section> sections; 21 private List<Section> sections;
22 22
@@ -25,6 +25,7 @@ namespace WixToolset.Data
25 /// </summary> 25 /// </summary>
26 private Library() 26 private Library()
27 { 27 {
28 this.embedFilePaths = new List<string>();
28 this.localizations = new Dictionary<string, Localization>(); 29 this.localizations = new Dictionary<string, Localization>();
29 this.sections = new List<Section>(); 30 this.sections = new List<Section>();
30 } 31 }
@@ -33,12 +34,14 @@ namespace WixToolset.Data
33 /// Instantiate a new library populated with sections. 34 /// Instantiate a new library populated with sections.
34 /// </summary> 35 /// </summary>
35 /// <param name="sections">Sections to add to the library.</param> 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)
37 { 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);
39 this.sections = new List<Section>(sections); 43 this.sections = new List<Section>(sections);
40 44
41 this.id = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace('+', '.').Replace('/', '_');
42 foreach (Section section in this.sections) 45 foreach (Section section in this.sections)
43 { 46 {
44 section.LibraryId = this.id; 47 section.LibraryId = this.id;
@@ -49,24 +52,7 @@ namespace WixToolset.Data
49 /// Get the sections contained in this library. 52 /// Get the sections contained in this library.
50 /// </summary> 53 /// </summary>
51 /// <value>Sections contained in this library.</value> 54 /// <value>Sections contained in this library.</value>
52 public IEnumerable<Section> Sections { get { return this.sections; } } 55 public IEnumerable<Section> Sections => 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 }
70 56
71 /// <summary> 57 /// <summary>
72 /// Gets localization files from this library that match the cultures passed in, in the order of the array of cultures. 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
77 { 63 {
78 foreach (string culture in cultures ?? new string[0]) 64 foreach (string culture in cultures ?? new string[0])
79 { 65 {
80 Localization localization; 66 if (this.localizations.TryGetValue(culture, out var localization))
81 if (this.localizations.TryGetValue(culture, out localization))
82 { 67 {
83 yield return localization; 68 yield return localization;
84 } 69 }
@@ -137,49 +122,8 @@ namespace WixToolset.Data
137 /// </summary> 122 /// </summary>
138 /// <param name="path">Path to save library file to on disk.</param> 123 /// <param name="path">Path to save library file to on disk.</param>
139 /// <param name="resolver">The WiX path resolver.</param> 124 /// <param name="resolver">The WiX path resolver.</param>
140 public void Save(string path, ILibraryBinaryFileResolver resolver) 125 public void Save(string path)
141 { 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.
183 Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))); 127 Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));
184 128
185 using (FileStream stream = File.Create(path)) 129 using (FileStream stream = File.Create(path))
diff --git a/src/WixToolset.Data/OutputType.cs b/src/WixToolset.Data/OutputType.cs
index 74381737..67c56520 100644
--- a/src/WixToolset.Data/OutputType.cs
+++ b/src/WixToolset.Data/OutputType.cs
@@ -13,6 +13,9 @@ namespace WixToolset.Data
13 /// <summary>Bundle output type.</summary> 13 /// <summary>Bundle output type.</summary>
14 Bundle, 14 Bundle,
15 15
16 /// <summary>Library output type.</summary>
17 Library,
18
16 /// <summary>Module output type.</summary> 19 /// <summary>Module output type.</summary>
17 Module, 20 Module,
18 21