public static AddinInfo ReadFromAddinFile(StreamReader r) { XmlDocument doc = new XmlDocument(); doc.Load(r); r.Close(); AddinInfo info = new AddinInfo(); info.id = doc.DocumentElement.GetAttribute("id"); info.namspace = doc.DocumentElement.GetAttribute("namespace"); info.name = doc.DocumentElement.GetAttribute("name"); if (info.id == "") { info.id = info.name; } info.version = doc.DocumentElement.GetAttribute("version"); info.author = doc.DocumentElement.GetAttribute("author"); info.copyright = doc.DocumentElement.GetAttribute("copyright"); info.url = doc.DocumentElement.GetAttribute("url"); info.description = doc.DocumentElement.GetAttribute("description"); info.category = doc.DocumentElement.GetAttribute("category"); info.baseVersion = doc.DocumentElement.GetAttribute("compatVersion"); AddinPropertyCollectionImpl props = new AddinPropertyCollectionImpl(); info.properties = props; ReadHeader(info, props, doc.DocumentElement); ReadDependencies(info.Dependencies, info.OptionalDependencies, doc.DocumentElement); return(info); }
void ExtractSupportFiles(string targetDir, string file, AddinInfo ainfo) { Random r = new Random(); ZipFile zfile = new ZipFile(file); foreach (var prop in ainfo.Properties) { ZipEntry ze = zfile.GetEntry(prop.Value); if (ze != null) { string fname; do { fname = Path.Combine(targetDir, r.Next().ToString("x") + Path.GetExtension(prop.Value)); } while (File.Exists(fname)); if (!Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } using (var f = File.OpenWrite(fname)) { using (Stream s = zfile.GetInputStream(ze)) { byte[] buffer = new byte [8092]; int nr = 0; while ((nr = s.Read(buffer, 0, buffer.Length)) > 0) { f.Write(buffer, 0, nr); } } } prop.Value = Path.Combine(addinFilesDir, Path.GetFileName(fname)); } } }
public static AddinPackage FromInstalledAddin(Addin sinfo) { AddinPackage pack = new AddinPackage(); pack.info = AddinInfo.ReadFromDescription(sinfo.Description); return(pack); }
internal static AddinInfo ReadFromDescription(AddinDescription description) { AddinInfo info = new AddinInfo(); info.id = description.LocalId; info.namspace = description.Namespace; info.name = description.Name; info.version = description.Version; info.author = description.Author; info.copyright = description.Copyright; info.url = description.Url; info.description = description.Description; info.category = description.Category; info.baseVersion = description.CompatVersion; info.properties = new AddinPropertyCollectionImpl(description.Properties); foreach (Dependency dep in description.MainModule.Dependencies) { info.Dependencies.Add(dep); } foreach (ModuleDescription mod in description.OptionalModules) { foreach (Dependency dep in mod.Dependencies) { info.OptionalDependencies.Add(dep); } } return(info); }
internal void RegisterAddin(IProgressMonitor monitor, AddinInfo info, string sourceDir) { monitor.Log.WriteLine("Installing " + info.Name + " v" + info.Version); string addinDir = GetAddinDirectory(info); if (!Directory.Exists(addinDir)) { Directory.CreateDirectory(addinDir); } CopyDirectory(sourceDir, addinDir); ResetCachedData(); }
static AddinInfo ReadAddinInfo(string file) { ZipFile zfile = new ZipFile(file); foreach (ZipEntry ze in zfile) { if (ze.Name == "addin.info") { using (Stream s = zfile.GetInputStream(ze)) { return(AddinInfo.ReadFromAddinFile(new StreamReader(s))); } } } throw new InstallException("Addin configuration file not found in package."); }
static void ReadHeader(AddinInfo info, AddinPropertyCollectionImpl properties, XmlElement elem) { elem = elem.SelectSingleNode("Header") as XmlElement; if (elem == null) { return; } foreach (XmlNode xprop in elem.ChildNodes) { XmlElement prop = xprop as XmlElement; if (prop != null) { switch (prop.LocalName) { case "Id": info.id = prop.InnerText; break; case "Namespace": info.namspace = prop.InnerText; break; case "Version": info.version = prop.InnerText; break; case "CompatVersion": info.baseVersion = prop.InnerText; break; default: { AddinProperty aprop = new AddinProperty(); aprop.Name = prop.LocalName; if (prop.HasAttribute("locale")) { aprop.Locale = prop.GetAttribute("locale"); } aprop.Value = prop.InnerText; properties.Add(aprop); break; } } } } }
void DeleteSupportFiles(string targetDir, AddinInfo ainfo) { foreach (var prop in ainfo.Properties) { if (prop.Value.StartsWith(addinFilesDir + Path.DirectorySeparatorChar)) { string file = Path.Combine(targetDir, Path.GetFileName(prop.Value)); if (File.Exists(file)) { File.Delete(file); } } } if (Directory.Exists(targetDir) && Directory.GetFileSystemEntries(targetDir).Length == 0) { Directory.Delete(targetDir, true); } }
internal string GetAddinDirectory(AddinInfo info) { return(Path.Combine(service.InstallDirectory, info.Id.Replace(',', '.'))); }
/// <summary> /// Gets information about an add-in /// </summary> /// <param name="addin"> /// The add-in /// </param> /// <returns> /// Add-in header data /// </returns> public static AddinHeader GetAddinHeader(Addin addin) { return(AddinInfo.ReadFromDescription(addin.Description)); }
void DeleteSupportFiles(string targetDir, AddinInfo ainfo) { foreach (var prop in ainfo.Properties) { if (prop.Value.StartsWith (addinFilesDir + Path.DirectorySeparatorChar)) { string file = Path.Combine (targetDir, Path.GetFileName (prop.Value)); if (File.Exists (file)) File.Delete (file); } } if (Directory.Exists (targetDir) && Directory.GetFileSystemEntries (targetDir).Length == 0) Directory.Delete (targetDir, true); }
public void Add(AddinInfo p) { List.Add(p); }
static void ReadHeader (AddinInfo info, AddinPropertyCollectionImpl properties, XmlElement elem) { elem = elem.SelectSingleNode ("Header") as XmlElement; if (elem == null) return; foreach (XmlNode xprop in elem.ChildNodes) { XmlElement prop = xprop as XmlElement; if (prop != null) { switch (prop.LocalName) { case "Id": info.id = prop.InnerText; break; case "Namespace": info.namspace = prop.InnerText; break; case "Version": info.version = prop.InnerText; break; case "CompatVersion": info.baseVersion = prop.InnerText; break; default: { AddinProperty aprop = new AddinProperty (); aprop.Name = prop.LocalName; if (prop.HasAttribute ("locale")) aprop.Locale = prop.GetAttribute ("locale"); aprop.Value = prop.InnerText; properties.Add (aprop); break; }} } } }
public void Add (AddinInfo p) { List.Add (p); }
public static AddinInfo ReadFromAddinFile(StreamReader r) { XmlDocument doc = new XmlDocument (); doc.Load (r); r.Close (); AddinInfo info = new AddinInfo (); info.id = doc.DocumentElement.GetAttribute ("id"); info.namspace = doc.DocumentElement.GetAttribute ("namespace"); info.name = doc.DocumentElement.GetAttribute ("name"); if (info.id == "") info.id = info.name; info.version = doc.DocumentElement.GetAttribute ("version"); info.author = doc.DocumentElement.GetAttribute ("author"); info.copyright = doc.DocumentElement.GetAttribute ("copyright"); info.url = doc.DocumentElement.GetAttribute ("url"); info.description = doc.DocumentElement.GetAttribute ("description"); info.category = doc.DocumentElement.GetAttribute ("category"); info.baseVersion = doc.DocumentElement.GetAttribute ("compatVersion"); ReadDependencies (info.Dependencies, info.OptionalDependencies, doc.DocumentElement); return info; }
internal static AddinInfo ReadFromDescription(AddinDescription description) { AddinInfo info = new AddinInfo (); info.id = description.LocalId; info.namspace = description.Namespace; info.name = description.Name; info.version = description.Version; info.author = description.Author; info.copyright = description.Copyright; info.url = description.Url; info.description = description.Description; info.category = description.Category; info.baseVersion = description.CompatVersion; foreach (Dependency dep in description.MainModule.Dependencies) info.Dependencies.Add (dep); foreach (ModuleDescription mod in description.OptionalModules) { foreach (Dependency dep in mod.Dependencies) info.OptionalDependencies.Add (dep); } return info; }
void ExtractSupportFiles(string targetDir, string file, AddinInfo ainfo) { Random r = new Random (); ZipFile zfile = new ZipFile (file); foreach (var prop in ainfo.Properties) { ZipEntry ze = zfile.GetEntry (prop.Value); if (ze != null) { string fname; do { fname = Path.Combine (targetDir, r.Next().ToString ("x") + Path.GetExtension (prop.Value)); } while (File.Exists (fname)); if (!Directory.Exists (targetDir)) Directory.CreateDirectory (targetDir); using (var f = File.OpenWrite (fname)) { using (Stream s = zfile.GetInputStream (ze)) { byte[] buffer = new byte [8092]; int nr = 0; while ((nr = s.Read (buffer, 0, buffer.Length)) > 0) f.Write (buffer, 0, nr); } } prop.Value = Path.Combine (addinFilesDir, Path.GetFileName (fname)); } } }