aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Data/Intermediate.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Data/Intermediate.cs')
-rw-r--r--src/WixToolset.Data/Intermediate.cs49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/WixToolset.Data/Intermediate.cs b/src/WixToolset.Data/Intermediate.cs
index 4d4e17cc..81a97151 100644
--- a/src/WixToolset.Data/Intermediate.cs
+++ b/src/WixToolset.Data/Intermediate.cs
@@ -4,8 +4,9 @@ namespace WixToolset.Data
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.Linq;
8 using System.IO; 7 using System.IO;
8 using System.Linq;
9 using System.Reflection;
9 using SimpleJson; 10 using SimpleJson;
10 11
11 /// <summary> 12 /// <summary>
@@ -99,48 +100,60 @@ namespace WixToolset.Data
99 { 100 {
100 using (var stream = File.OpenRead(path)) 101 using (var stream = File.OpenRead(path))
101 { 102 {
103 var uri = new Uri(Path.GetFullPath(path));
102 var creator = new SimpleTupleDefinitionCreator(); 104 var creator = new SimpleTupleDefinitionCreator();
103 return Intermediate.Load(stream, path, creator, suppressVersionCheck); 105 return Intermediate.Load(stream, uri, creator, suppressVersionCheck);
104 } 106 }
105 } 107 }
106 108
107 /// <summary> 109 /// <summary>
108 /// Loads an intermediate from a stream. 110 /// Loads an intermediate from a stream.
109 /// </summary> 111 /// </summary>
110 /// <param name="stream">Stream to intermediate file.</param> 112 /// <param name="assembly">Assembly with intermediate embedded in resource stream.</param>
113 /// <param name="resourceName">Name of resource stream.</param>
111 /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> 114 /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param>
112 /// <returns>Returns the loaded intermediate.</returns> 115 /// <returns>Returns the loaded intermediate.</returns>
113 public static Intermediate Load(Stream stream, bool suppressVersionCheck = false) 116 public static Intermediate Load(Assembly assembly, string resourceName, bool suppressVersionCheck = false)
114 { 117 {
115 var creator = new SimpleTupleDefinitionCreator(); 118 var creator = new SimpleTupleDefinitionCreator();
116 return Intermediate.Load(stream, creator, suppressVersionCheck); 119 return Intermediate.Load(assembly, resourceName, creator, suppressVersionCheck);
117 } 120 }
118 121
119 /// <summary> 122 /// <summary>
120 /// Loads an intermediate from a path on disk. 123 /// Loads an intermediate from a stream.
121 /// </summary> 124 /// </summary>
122 /// <param name="path">Path to intermediate file saved on disk.</param> 125 /// <param name="assembly">Assembly with intermediate embedded in resource stream.</param>
126 /// <param name="resourceName">Name of resource stream.</param>
123 /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediate.</param> 127 /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediate.</param>
124 /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> 128 /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param>
125 /// <returns>Returns the loaded intermediate.</returns> 129 /// <returns>Returns the loaded intermediate.</returns>
126 public static Intermediate Load(string path, ITupleDefinitionCreator creator, bool suppressVersionCheck = false) 130 public static Intermediate Load(Assembly assembly, string resourceName, ITupleDefinitionCreator creator, bool suppressVersionCheck = false)
127 { 131 {
128 using (var stream = File.OpenRead(path)) 132 using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName))
129 { 133 {
130 return Intermediate.Load(stream, path, creator, suppressVersionCheck); 134 var uriBuilder = new UriBuilder(assembly.CodeBase);
135 uriBuilder.Scheme = "embeddedresource";
136 uriBuilder.Fragment = resourceName;
137
138 return Intermediate.Load(resourceStream, uriBuilder.Uri, creator, suppressVersionCheck);
131 } 139 }
132 } 140 }
133 141
134 /// <summary> 142 /// <summary>
135 /// Loads an intermediate from a path on disk. 143 /// Loads an intermediate from a path on disk.
136 /// </summary> 144 /// </summary>
137 /// <param name="stream">Stream to intermediate file.</param> 145 /// <param name="path">Path to intermediate file saved on disk.</param>
138 /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediate.</param> 146 /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediate.</param>
139 /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> 147 /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param>
140 /// <returns>Returns the loaded intermediate.</returns> 148 /// <returns>Returns the loaded intermediate.</returns>
141 public static Intermediate Load(Stream stream, ITupleDefinitionCreator creator, bool suppressVersionCheck = false) 149 public static Intermediate Load(string path, ITupleDefinitionCreator creator, bool suppressVersionCheck = false)
142 { 150 {
143 return Load(stream, "<unknown>", creator, suppressVersionCheck); 151 using (var stream = File.OpenRead(path))
152 {
153 var uri = new Uri(Path.GetFullPath(path));
154
155 return Intermediate.Load(stream, uri, creator, suppressVersionCheck);
156 }
144 } 157 }
145 158
146 /// <summary> 159 /// <summary>
@@ -206,11 +219,11 @@ namespace WixToolset.Data
206 /// Loads an intermediate from a path on disk. 219 /// Loads an intermediate from a path on disk.
207 /// </summary> 220 /// </summary>
208 /// <param name="stream">Stream to intermediate file.</param> 221 /// <param name="stream">Stream to intermediate file.</param>
209 /// <param name="path">Path name of intermediate file.</param> 222 /// <param name="baseUri">Path name of intermediate file.</param>
210 /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediate.</param> 223 /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediate.</param>
211 /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> 224 /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param>
212 /// <returns>Returns the loaded intermediate.</returns> 225 /// <returns>Returns the loaded intermediate.</returns>
213 internal static Intermediate Load(Stream stream, string path, ITupleDefinitionCreator creator, bool suppressVersionCheck = false) 226 internal static Intermediate Load(Stream stream, Uri baseUri, ITupleDefinitionCreator creator, bool suppressVersionCheck = false)
214 { 227 {
215 JsonObject jsonObject; 228 JsonObject jsonObject;
216 229
@@ -218,7 +231,7 @@ namespace WixToolset.Data
218 { 231 {
219 if (FileFormat.WixIR != fs.FileFormat) 232 if (FileFormat.WixIR != fs.FileFormat)
220 { 233 {
221 throw new WixUnexpectedFileFormatException(path, FileFormat.WixIR, fs.FileFormat); 234 throw new WixUnexpectedFileFormatException(baseUri.LocalPath, FileFormat.WixIR, fs.FileFormat);
222 } 235 }
223 236
224 var json = fs.GetData(); 237 var json = fs.GetData();
@@ -231,7 +244,7 @@ namespace WixToolset.Data
231 244
232 if (!Version.TryParse(versionJson, out var version) || !Intermediate.CurrentVersion.Equals(version)) 245 if (!Version.TryParse(versionJson, out var version) || !Intermediate.CurrentVersion.Equals(version))
233 { 246 {
234 throw new WixException(WixDataErrors.VersionMismatch(SourceLineNumber.CreateFromUri(path), "intermediate", versionJson, Intermediate.CurrentVersion.ToString())); 247 throw new WixException(WixDataErrors.VersionMismatch(SourceLineNumber.CreateFromUri(baseUri.AbsoluteUri), "intermediate", versionJson, Intermediate.CurrentVersion.ToString()));
235 } 248 }
236 } 249 }
237 250
@@ -253,7 +266,7 @@ namespace WixToolset.Data
253 var sectionsJson = jsonObject.GetValueOrDefault<JsonArray>("sections"); 266 var sectionsJson = jsonObject.GetValueOrDefault<JsonArray>("sections");
254 foreach (JsonObject sectionJson in sectionsJson) 267 foreach (JsonObject sectionJson in sectionsJson)
255 { 268 {
256 var section = IntermediateSection.Deserialize(creator, sectionJson); 269 var section = IntermediateSection.Deserialize(creator, baseUri, sectionJson);
257 sections.Add(section); 270 sections.Add(section);
258 } 271 }
259 272