string BuildPackageInternal(IProgressStatus monitor, string targetDirectory, string filePath) { AddinDescription conf = registry.GetAddinDescription(monitor, filePath); if (conf == null) { monitor.ReportError("Could not read add-in file: " + filePath, null); return(null); } string basePath = Path.GetDirectoryName(filePath); if (targetDirectory == null) { targetDirectory = basePath; } // Generate the file name string name; if (conf.LocalId.Length == 0) { name = Path.GetFileNameWithoutExtension(filePath); } else { name = conf.LocalId; } name = Addin.GetFullId(conf.Namespace, name, conf.Version); name = name.Replace(',', '_').Replace(".__", "."); string outFilePath = Path.Combine(targetDirectory, name) + ".mpack"; ZipOutputStream s = new ZipOutputStream(File.Create(outFilePath)); s.SetLevel(5); // Generate a stripped down description of the add-in in a file, since the complete // description may be declared as assembly attributes XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.LoadXml(conf.SaveToXml().OuterXml); CleanDescription(doc.DocumentElement); MemoryStream ms = new MemoryStream(); XmlTextWriter tw = new XmlTextWriter(ms, System.Text.Encoding.UTF8); tw.Formatting = Formatting.Indented; doc.WriteTo(tw); tw.Flush(); byte[] data = ms.ToArray(); ZipEntry infoEntry = new ZipEntry("addin.info"); s.PutNextEntry(infoEntry); s.Write(data, 0, data.Length); // Now add the add-in files ArrayList list = new ArrayList(); if (!conf.AllFiles.Contains(Path.GetFileName(filePath))) { list.Add(Path.GetFileName(filePath)); } foreach (string f in conf.AllFiles) { list.Add(f); } foreach (var prop in conf.Properties) { try { if (File.Exists(Path.Combine(basePath, prop.Value))) { list.Add(prop.Value); } } catch { // Ignore errors } } monitor.Log("Creating package " + Path.GetFileName(outFilePath)); foreach (string file in list) { string fp = Path.Combine(basePath, file); using (FileStream fs = File.OpenRead(fp)) { byte[] buffer = new byte [fs.Length]; fs.Read(buffer, 0, buffer.Length); ZipEntry entry = new ZipEntry(file); s.PutNextEntry(entry); s.Write(buffer, 0, buffer.Length); } } s.Finish(); s.Close(); return(outFilePath); }
void PrintAddinInfo(string[] args) { if (args.Length == 0) { throw new InstallException("A file name or add-in ID is required."); } AddinDescription desc = null; if (File.Exists(args[0])) { desc = registry.GetAddinDescription(new Mono.Addins.ConsoleProgressStatus(verbose), args[0]); } else { Addin addin = registry.GetAddin(args [0]); if (addin != null) { desc = addin.Description; } } if (desc == null) { throw new InstallException("Add-in not found."); } Console.WriteLine(); Console.WriteLine("Addin Header"); Console.WriteLine("------------"); Console.WriteLine(); Console.WriteLine("Name: " + desc.Name); Console.WriteLine("Id: " + desc.LocalId); if (desc.Namespace.Length > 0) { Console.WriteLine("Namespace: " + desc.Namespace); } Console.Write("Version: " + desc.Version); if (desc.CompatVersion.Length > 0) { Console.WriteLine(" (compatible with: " + desc.CompatVersion + ")"); } else { Console.WriteLine(); } if (desc.AddinFile.Length > 0) { Console.WriteLine("File: " + desc.AddinFile); } if (desc.Author.Length > 0) { Console.WriteLine("Author: " + desc.Author); } if (desc.Category.Length > 0) { Console.WriteLine("Category: " + desc.Category); } if (desc.Copyright.Length > 0) { Console.WriteLine("Copyright: " + desc.Copyright); } if (desc.Url.Length > 0) { Console.WriteLine("Url: " + desc.Url); } if (desc.Description.Length > 0) { Console.WriteLine(); Console.WriteLine("Description: \n" + desc.Description); } if (desc.ExtensionPoints.Count > 0) { Console.WriteLine(); Console.WriteLine("Extenstion Points"); Console.WriteLine("-----------------"); foreach (ExtensionPoint ep in desc.ExtensionPoints) { PrintExtensionPoint(desc, ep); } } }
string BuildPackageInternal(IProgressStatus monitor, bool debugSymbols, string targetDirectory, string filePath, PackageFormat format) { AddinDescription conf = registry.GetAddinDescription(monitor, filePath); if (conf == null) { monitor.ReportError("Could not read add-in file: " + filePath, null); return(null); } string basePath = Path.GetDirectoryName(Path.GetFullPath(filePath)); if (targetDirectory == null) { targetDirectory = basePath; } // Generate the file name string name; if (conf.LocalId.Length == 0) { name = Path.GetFileNameWithoutExtension(filePath); } else { name = conf.LocalId; } name = Addin.GetFullId(conf.Namespace, name, conf.Version); name = name.Replace(',', '_').Replace(".__", "."); string outFilePath = Path.Combine(targetDirectory, name); switch (format) { case PackageFormat.Mpack: outFilePath += ".mpack"; break; case PackageFormat.Vsix: outFilePath += ".vsix"; break; default: throw new NotSupportedException(format.ToString()); } ZipOutputStream s = new ZipOutputStream(File.Create(outFilePath)); s.SetLevel(5); if (format == PackageFormat.Vsix) { XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.LoadXml(conf.SaveToVsixXml().OuterXml); MemoryStream ms = new MemoryStream(); XmlTextWriter tw = new XmlTextWriter(ms, System.Text.Encoding.UTF8); tw.Formatting = Formatting.Indented; doc.WriteTo(tw); tw.Flush(); byte [] data = ms.ToArray(); var infoEntry = new ZipEntry("extension.vsixmanifest") { Size = data.Length }; s.PutNextEntry(infoEntry); s.Write(data, 0, data.Length); s.CloseEntry(); } // Generate a stripped down description of the add-in in a file, since the complete // description may be declared as assembly attributes if (format == PackageFormat.Mpack || format == PackageFormat.Vsix) { XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.LoadXml(conf.SaveToXml().OuterXml); CleanDescription(doc.DocumentElement); MemoryStream ms = new MemoryStream(); XmlTextWriter tw = new XmlTextWriter(ms, System.Text.Encoding.UTF8); tw.Formatting = Formatting.Indented; doc.WriteTo(tw); tw.Flush(); byte [] data = ms.ToArray(); var infoEntry = new ZipEntry("addin.info") { Size = data.Length }; s.PutNextEntry(infoEntry); s.Write(data, 0, data.Length); s.CloseEntry(); } // Now add the add-in files var files = new HashSet <string> (); files.Add(Path.GetFileName(Util.NormalizePath(filePath))); foreach (string f in conf.AllFiles) { var file = Util.NormalizePath(f); files.Add(file); if (debugSymbols) { if (File.Exists(Path.ChangeExtension(file, ".pdb"))) { files.Add(Path.ChangeExtension(file, ".pdb")); } else if (File.Exists(file + ".mdb")) { files.Add(file + ".mdb"); } } } foreach (var prop in conf.Properties) { try { var file = Util.NormalizePath(prop.Value); if (File.Exists(Path.Combine(basePath, file))) { files.Add(file); } } catch { // Ignore errors } } //add satellite assemblies for assemblies in the list var satelliteFinder = new SatelliteAssemblyFinder(); foreach (var f in files.ToList()) { foreach (var satellite in satelliteFinder.FindSatellites(Path.Combine(basePath, f))) { var relativeSatellite = satellite.Substring(basePath.Length + 1); files.Add(relativeSatellite); } } monitor.Log("Creating package " + Path.GetFileName(outFilePath)); foreach (string file in files) { string fp = Path.Combine(basePath, file); using (FileStream fs = File.OpenRead(fp)) { byte[] buffer = new byte [fs.Length]; fs.Read(buffer, 0, buffer.Length); var fileName = Path.DirectorySeparatorChar == '\\' ? file.Replace('\\', '/') : file; var entry = new ZipEntry(fileName) { Size = fs.Length }; s.PutNextEntry(entry); s.Write(buffer, 0, buffer.Length); s.CloseEntry(); } } if (format == PackageFormat.Vsix) { files.Add("addin.info"); files.Add("extension.vsixmanifest"); XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = doc.DocumentElement; doc.InsertBefore(xmlDeclaration, root); HashSet <string> alreadyAddedExtensions = new HashSet <string> (); var typesEl = doc.CreateElement("Types"); typesEl.SetAttribute("xmlns", "http://schemas.openxmlformats.org/package/2006/content-types"); foreach (var file in files) { var extension = Path.GetExtension(file); if (string.IsNullOrEmpty(extension)) { continue; } if (extension.StartsWith(".", StringComparison.Ordinal)) { extension = extension.Substring(1); } if (alreadyAddedExtensions.Contains(extension)) { continue; } alreadyAddedExtensions.Add(extension); var typeEl = doc.CreateElement("Default"); typeEl.SetAttribute("Extension", extension); typeEl.SetAttribute("ContentType", GetContentType(extension)); typesEl.AppendChild(typeEl); } doc.AppendChild(typesEl); MemoryStream ms = new MemoryStream(); XmlTextWriter tw = new XmlTextWriter(ms, System.Text.Encoding.UTF8); tw.Formatting = Formatting.Indented; doc.WriteTo(tw); tw.Flush(); byte [] data = ms.ToArray(); var infoEntry = new ZipEntry("[Content_Types].xml") { Size = data.Length }; s.PutNextEntry(infoEntry); s.Write(data, 0, data.Length); s.CloseEntry(); } s.Finish(); s.Close(); return(outFilePath); }
string BuildPackageInternal(IProgressStatus monitor, bool debugSymbols, string targetDirectory, string filePath) { AddinDescription conf = registry.GetAddinDescription(monitor, filePath); if (conf == null) { monitor.ReportError("Could not read add-in file: " + filePath, null); return(null); } string basePath = Path.GetDirectoryName(Path.GetFullPath(filePath)); if (targetDirectory == null) { targetDirectory = basePath; } // Generate the file name string name; if (conf.LocalId.Length == 0) { name = Path.GetFileNameWithoutExtension(filePath); } else { name = conf.LocalId; } name = Addin.GetFullId(conf.Namespace, name, conf.Version); name = name.Replace(',', '_').Replace(".__", "."); string outFilePath = Path.Combine(targetDirectory, name) + ".mpack"; ZipOutputStream s = new ZipOutputStream(File.Create(outFilePath)); s.SetLevel(5); // Generate a stripped down description of the add-in in a file, since the complete // description may be declared as assembly attributes XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.LoadXml(conf.SaveToXml().OuterXml); CleanDescription(doc.DocumentElement); MemoryStream ms = new MemoryStream(); XmlTextWriter tw = new XmlTextWriter(ms, System.Text.Encoding.UTF8); tw.Formatting = Formatting.Indented; doc.WriteTo(tw); tw.Flush(); byte[] data = ms.ToArray(); var infoEntry = new ZipEntry("addin.info") { Size = data.Length }; s.PutNextEntry(infoEntry); s.Write(data, 0, data.Length); s.CloseEntry(); // Now add the add-in files var files = new HashSet <string> (); files.Add(Path.GetFileName(Util.NormalizePath(filePath))); foreach (string f in conf.AllFiles) { var file = Util.NormalizePath(f); files.Add(file); if (debugSymbols) { if (File.Exists(Path.ChangeExtension(file, ".pdb"))) { files.Add(Path.ChangeExtension(file, ".pdb")); } else if (File.Exists(file + ".mdb")) { files.Add(file + ".mdb"); } } } foreach (var prop in conf.Properties) { try { var file = Util.NormalizePath(prop.Value); if (File.Exists(Path.Combine(basePath, file))) { files.Add(file); } } catch { // Ignore errors } } //add satellite assemblies for assemblies in the list var satelliteFinder = new SatelliteAssemblyFinder(); foreach (var f in files.ToList()) { foreach (var satellite in satelliteFinder.FindSatellites(Path.Combine(basePath, f))) { var relativeSatellite = satellite.Substring(basePath.Length + 1); files.Add(relativeSatellite); } } monitor.Log("Creating package " + Path.GetFileName(outFilePath)); foreach (string file in files) { string fp = Path.Combine(basePath, file); using (FileStream fs = File.OpenRead(fp)) { byte[] buffer = new byte [fs.Length]; fs.Read(buffer, 0, buffer.Length); var fileName = Path.PathSeparator == '\\' ? file.Replace('\\', '/') : file; var entry = new ZipEntry(fileName) { Size = fs.Length }; s.PutNextEntry(entry); s.Write(buffer, 0, buffer.Length); s.CloseEntry(); } } s.Finish(); s.Close(); return(outFilePath); }
void PrintAddinInfo(string[] args) { bool generateXml = false; bool generateAll = false; bool pickNamespace = false; bool extensionModel = true; ArrayList addins = new ArrayList(); ArrayList namespaces = new ArrayList(); foreach (string a in args) { if (pickNamespace) { namespaces.Add(a); pickNamespace = false; continue; } if (a == "--xml") { generateXml = true; continue; } if (a == "--namespace" || a == "-n") { pickNamespace = true; continue; } if (a == "--all") { generateAll = true; continue; } if (a == "--full") { extensionModel = false; continue; } AddinDescription desc = null; if (File.Exists(args[0])) { desc = registry.GetAddinDescription(new Mono.Addins.ConsoleProgressStatus(verbose), args[0]); } else { Addin addin = registry.GetAddin(args [0]); if (addin != null) { desc = addin.Description; } } if (desc == null) { throw new InstallException(string.Format("Add-in '{0}' not found.", a)); } if (desc != null) { addins.Add(desc); } } if (generateAll) { ArrayList list = new ArrayList(); list.AddRange(registry.GetAddinRoots()); list.AddRange(registry.GetAddins()); foreach (Addin addin in list) { if (namespaces.Count > 0) { foreach (string ns in namespaces) { if (addin.Id.StartsWith(ns + ".")) { addins.Add(addin.Description); break; } } } else { addins.Add(addin.Description); } } } if (addins.Count == 0) { throw new InstallException("A file name or add-in ID is required."); } if (generateXml) { XmlTextWriter tw = new XmlTextWriter(Console.Out); tw.Formatting = Formatting.Indented; tw.WriteStartElement("Addins"); foreach (AddinDescription desc in addins) { if (extensionModel && desc.ExtensionPoints.Count == 0) { continue; } PrintAddinXml(tw, desc); } tw.Close(); } else { foreach (AddinDescription des in addins) { PrintAddin(des); } } }