public void ScanAddinsFile(IProgressStatus monitor, string file, string domain, AddinScanResult scanResult) { XmlTextReader r = null; ArrayList directories = new ArrayList(); ArrayList directoriesWithSubdirs = new ArrayList(); string basePath = Path.GetDirectoryName(file); try { r = new XmlTextReader(new StreamReader(file)); r.MoveToContent(); if (r.IsEmptyElement) { return; } r.ReadStartElement(); r.MoveToContent(); while (r.NodeType != XmlNodeType.EndElement) { if (r.NodeType == XmlNodeType.Element && r.LocalName == "Directory") { string subs = r.GetAttribute("include-subdirs"); string sdom; string share = r.GetAttribute("shared"); if (share == "true") { sdom = AddinDatabase.GlobalDomain; } else if (share == "false") { sdom = null; } else { sdom = domain; // Inherit the domain } string path = r.ReadElementString().Trim(); if (path.Length > 0) { path = Util.NormalizePath(path); if (subs == "true") { directoriesWithSubdirs.Add(new string[] { path, sdom }); } else { directories.Add(new string[] { path, sdom }); } } } else if (r.NodeType == XmlNodeType.Element && r.LocalName == "GacAssembly") { string aname = r.ReadElementString().Trim(); if (aname.Length > 0) { aname = Util.NormalizePath(aname); aname = Util.GetGacPath(aname); if (aname != null) { // Gac assemblies always use the global domain directories.Add(new string[] { aname, AddinDatabase.GlobalDomain }); } } } else if (r.NodeType == XmlNodeType.Element && r.LocalName == "Exclude") { string path = r.ReadElementString().Trim(); if (path.Length > 0) { path = Util.NormalizePath(path); if (!Path.IsPathRooted(path)) { path = Path.Combine(basePath, path); } scanResult.AddPathToIgnore(Util.GetFullPath(path)); } } else { r.Skip(); } r.MoveToContent(); } } catch (Exception ex) { monitor.ReportError("Could not process addins file: " + file, ex); return; } finally { if (r != null) { r.Close(); } } foreach (string[] d in directories) { string dir = d[0]; if (!Path.IsPathRooted(dir)) { dir = Path.Combine(basePath, dir); } ScanFolder(monitor, dir, d[1], scanResult); } foreach (string[] d in directoriesWithSubdirs) { string dir = d[0]; if (!Path.IsPathRooted(dir)) { dir = Path.Combine(basePath, dir); } ScanFolderRec(monitor, dir, d[1], scanResult); } }
List <AddinsEntry> ParseAddinsFile(IProgressStatus monitor, string file, string domain) { List <AddinsEntry> entries = new List <AddinsEntry>(); XmlTextReader r = null; string basePath = Path.GetDirectoryName(file); try { r = new XmlTextReader(FileSystem.OpenTextFile(file)); r.MoveToContent(); if (r.IsEmptyElement) { return(entries); } r.ReadStartElement(); r.MoveToContent(); while (r.NodeType != XmlNodeType.EndElement) { if (r.NodeType == XmlNodeType.Element && r.LocalName == "Directory") { bool.TryParse(r.GetAttribute("include-subdirs"), out var subs); string sdom; string share = r.GetAttribute("shared"); if (share == "true") { sdom = AddinDatabase.GlobalDomain; } else if (share == "false") { sdom = null; } else { sdom = domain; // Inherit the domain } string path = r.ReadElementString().Trim(); if (path.Length > 0) { path = Util.NormalizePath(path); entries.Add(new AddinsEntry { Folder = path, Domain = sdom, Recursive = subs }); } } else if (r.NodeType == XmlNodeType.Element && r.LocalName == "GacAssembly") { string aname = r.ReadElementString().Trim(); if (aname.Length > 0) { aname = Util.NormalizePath(aname); aname = Util.GetGacPath(aname); if (aname != null) { // Gac assemblies always use the global domain entries.Add(new AddinsEntry { Folder = aname, Domain = AddinDatabase.GlobalDomain }); } } } else if (r.NodeType == XmlNodeType.Element && r.LocalName == "Exclude") { string path = r.ReadElementString().Trim(); if (path.Length > 0) { path = Util.NormalizePath(path); if (!Path.IsPathRooted(path)) { path = Path.Combine(basePath, path); } ScanContext.AddPathToIgnore(Path.GetFullPath(path)); } } else { r.Skip(); } r.MoveToContent(); } } catch (Exception ex) { if (monitor != null) { monitor.ReportError("Could not process addins file: " + file, ex); } } finally { if (r != null) { r.Close(); } } return(entries); }