/// <summary> /// Loads an intermediate from a path on disk. /// </summary> /// <param name="path">Path to intermediate file saved on disk.</param> /// <param name="creator">ISymbolDefinitionCreator to use when reconstituting the intermediate.</param> /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> /// <returns>Returns the loaded intermediate.</returns> public static Intermediate Load(string path, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false) { using (var wixout = WixOutput.Read(path)) { return(Intermediate.LoadIntermediate(wixout, creator, suppressVersionCheck)); } }
/// <summary> /// Loads several intermediates from paths on disk using the same definitions. /// </summary> /// <param name="intermediateFiles">Paths to intermediate files saved on disk.</param> /// <param name="creator">ISymbolDefinitionCreator to use when reconstituting the intermediates.</param> /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> /// <returns>Returns the loaded intermediates</returns> public static IEnumerable <Intermediate> Load(IEnumerable <string> intermediateFiles, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false) { var jsons = new Queue <JsonWithPath>(); var intermediates = new List <Intermediate>(); foreach (var path in intermediateFiles) { using (var wixout = WixOutput.Read(path)) { var data = wixout.GetData(WixOutputStreamName); var json = Intermediate.LoadJson(data, wixout.Uri, suppressVersionCheck); Intermediate.LoadDefinitions(json, creator); jsons.Enqueue(new JsonWithPath { Json = json, Path = wixout.Uri }); } } while (jsons.Count > 0) { var jsonWithPath = jsons.Dequeue(); var intermediate = Intermediate.FinalizeLoad(jsonWithPath.Json, jsonWithPath.Path, creator); intermediates.Add(intermediate); } return(intermediates); }
/// <summary> /// Loads an intermediate from a stream. /// </summary> /// <param name="assembly">Assembly with intermediate embedded in resource stream.</param> /// <param name="resourceName">Name of resource stream.</param> /// <param name="creator">ISymbolDefinitionCreator to use when reconstituting the intermediate.</param> /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> /// <returns>Returns the loaded intermediate.</returns> public static Intermediate Load(Assembly assembly, string resourceName, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false) { using (var wixout = WixOutput.Read(assembly, resourceName)) { return(Intermediate.LoadIntermediate(wixout, creator, suppressVersionCheck)); } }
/// <summary> /// Creates a new file structure in memory. /// </summary> /// <returns>Newly created <c>WixOutput</c>.</returns> public static WixOutput Create() { var uri = new Uri("memorystream:"); var stream = new MemoryStream(); return(WixOutput.Create(uri, stream)); }
/// <summary> /// Loads an intermediate from a WixOutput. /// </summary> /// <param name="wixout">Source to load from.</param> /// <param name="creator">ISymbolDefinitionCreator to use when reconstituting the intermediate.</param> /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> /// <returns>Returns the loaded intermediate.</returns> private static Intermediate LoadIntermediate(WixOutput wixout, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false) { var data = wixout.GetData(WixOutputStreamName); var json = Intermediate.LoadJson(data, wixout.Uri, suppressVersionCheck); Intermediate.LoadDefinitions(json, creator); return(Intermediate.FinalizeLoad(json, wixout.Uri, creator)); }
/// <summary> /// Saves an intermediate to a path on disk. /// </summary> /// <param name="path">Path to save intermediate file to disk.</param> public void Save(string path) { Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))); using (var wixout = WixOutput.Create(path)) { this.Save(wixout); } }
/// <summary> /// Creates a new file structure on disk. /// </summary> /// <param name="path">Path to write file structure to.</param> /// <returns>Newly created <c>WixOutput</c>.</returns> public static WixOutput Create(string path) { var fullPath = Path.GetFullPath(path); Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); var uri = new Uri(fullPath); var stream = File.Create(path); return(WixOutput.Create(uri, stream)); }
private void SaveIR(WixOutput wixout) { using (var writer = new StreamWriter(wixout.CreateDataStream(WixOutputStreamName))) { var jsonObject = new JsonObject { { "id", this.Id }, { "level", this.Level }, { "version", Intermediate.CurrentVersion.ToString() } }; var sectionsJson = new JsonArray(this.Sections.Count); foreach (var section in this.Sections) { var sectionJson = section.Serialize(); sectionsJson.Add(sectionJson); } jsonObject.Add("sections", sectionsJson); var customDefinitions = this.GetCustomDefinitionsInSections(); if (customDefinitions.Count > 0) { var customDefinitionsJson = new JsonArray(customDefinitions.Count); foreach (var kvp in customDefinitions.OrderBy(d => d.Key)) { var customDefinitionJson = kvp.Value.Serialize(); customDefinitionsJson.Add(customDefinitionJson); } jsonObject.Add("definitions", customDefinitionsJson); } if (this.Localizations.Any()) { var localizationsJson = new JsonArray(); foreach (var localization in this.Localizations) { var localizationJson = localization.Serialize(); localizationsJson.Add(localizationJson); } jsonObject.Add("localizations", localizationsJson); } var json = SimpleJson.SerializeObject(jsonObject); writer.Write(json); } }
/// <summary> /// Loads a wixout from a path on disk or embedded resource in assembly. /// </summary> /// <param name="baseUri">Uri with local path to wixout file saved on disk or embedded resource in assembly.</param> /// <returns>Loaded created <c>WixOutput</c>.</returns> public static WixOutput Read(Uri baseUri) { // If the embedded files are stored in an assembly resource stream (usually // a .wixlib embedded in a WixExtension). if ("embeddedresource" == baseUri.Scheme) { var assemblyPath = Path.GetFullPath(baseUri.LocalPath); var resourceName = baseUri.Fragment.TrimStart('#'); var assembly = Assembly.LoadFile(assemblyPath); return(WixOutput.Read(assembly, resourceName)); } else // normal file (usually a binary .wixlib on disk). { var stream = File.OpenRead(baseUri.LocalPath); return(WixOutput.Read(baseUri, stream)); } }
private void SaveEmbedFiles(WixOutput wixout) { var embeddedFields = this.Sections.SelectMany(s => s.Symbols) .SelectMany(t => t.Fields) .Where(f => f?.Type == IntermediateFieldType.Path) .Select(f => f.AsPath()) .Where(f => f.Embed) .ToList(); var savedEmbedFields = new Dictionary <string, IntermediateFieldPathValue>(StringComparer.OrdinalIgnoreCase); var uniqueEntryNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var embeddedField in embeddedFields) { var key = String.Concat(embeddedField.BaseUri?.AbsoluteUri, "?", embeddedField.Path); if (savedEmbedFields.TryGetValue(key, out var existing)) { embeddedField.Path = existing.Path; } else { var entryName = CalculateUniqueEntryName(uniqueEntryNames, embeddedField.Path); if (embeddedField.BaseUri == null) { wixout.ImportDataStream(entryName, embeddedField.Path); } else // open the container specified in baseUri and copy the correct stream out of it. { using (var otherWixout = WixOutput.Read(embeddedField.BaseUri)) using (var stream = otherWixout.GetDataStream(embeddedField.Path)) using (var target = wixout.CreateDataStream(entryName)) { stream.CopyTo(target); } } embeddedField.Path = entryName; savedEmbedFields.Add(key, embeddedField); } } }
/// <summary> /// Saves an intermediate to a WixOutput. /// </summary> /// <param name="wixout">Destination to save.</param> public void Save(WixOutput wixout) { this.SaveEmbedFiles(wixout); this.SaveIR(wixout); }
/// <summary> /// Loads an intermediate from a WixOutput object. /// </summary> /// <param name="wixOutput">WixOutput object.</param> /// <param name="creator">ISymbolDefinitionCreator to use when reconstituting the intermediate.</param> /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> /// <returns>Returns the loaded intermediate.</returns> public static Intermediate Load(WixOutput wixOutput, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false) { return(Intermediate.LoadIntermediate(wixOutput, creator, suppressVersionCheck)); }