/// <summary> /// Saves a library to a path on disk. /// </summary> /// <param name="path">Path to save library file to on disk.</param> /// <param name="resolver">The WiX path resolver.</param> public void Save(string path, ILibraryBinaryFileResolver resolver) { List <string> embedFilePaths = new List <string>(); // Resolve paths to files that are to be embedded in the library. if (null != resolver) { foreach (Table table in this.sections.SelectMany(s => s.Tables)) { foreach (Row row in table.Rows) { foreach (ObjectField objectField in row.Fields.Where(f => f is ObjectField)) { if (null != objectField.Data) { string file = resolver.Resolve(row.SourceLineNumbers, table.Name, (string)objectField.Data); if (!String.IsNullOrEmpty(file)) { // File was successfully resolved so track the embedded index as the embedded file index. objectField.EmbeddedFileIndex = embedFilePaths.Count; embedFilePaths.Add(file); } else { Messaging.Instance.OnMessage(WixDataErrors.FileNotFound(row.SourceLineNumbers, (string)objectField.Data, table.Name)); } } else // clear out embedded file id in case there was one there before. { objectField.EmbeddedFileIndex = null; } } } } } // Do not save the library if errors were found while resolving object paths. if (Messaging.Instance.EncounteredError) { return; } // Ensure the location to output the library exists and write it out. Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))); using (FileStream stream = File.Create(path)) using (FileStructure fs = FileStructure.Create(stream, FileFormat.Wixlib, embedFilePaths)) using (XmlWriter writer = XmlWriter.Create(fs.GetDataStream())) { writer.WriteStartDocument(); this.Write(writer); writer.WriteEndDocument(); } }
private static List <string> ResolveFilePathsToEmbed(IEnumerable <Section> sections, ILibraryBinaryFileResolver resolver) { var embedFilePaths = new List <string>(); // Resolve paths to files that are to be embedded in the library. if (null != resolver) { foreach (Table table in sections.SelectMany(s => s.Tables)) { foreach (Row row in table.Rows) { foreach (ObjectField objectField in row.Fields.OfType <ObjectField>()) { if (null != objectField.Data) { string file = resolver.Resolve(row.SourceLineNumbers, table.Name, (string)objectField.Data); if (!String.IsNullOrEmpty(file)) { // File was successfully resolved so track the embedded index as the embedded file index. objectField.EmbeddedFileIndex = embedFilePaths.Count; embedFilePaths.Add(file); } else { Messaging.Instance.OnMessage(WixDataErrors.FileNotFound(row.SourceLineNumbers, (string)objectField.Data, table.Name)); } } else // clear out embedded file id in case there was one there before. { objectField.EmbeddedFileIndex = null; } } } } } return(embedFilePaths); }