public static bool Validate(Filter[] filters, string value) { if (filters == null || filters.Length <= 0) return false; int includeCount = 0; int excludeCount = 0; int validIncludeCount = 0; foreach (Filter filter in filters) { if (filter.IncludeRegularExpression != null) { ++includeCount; if (filter.ValidateInclude(value)) ++validIncludeCount; } if (filter.ExcludeRegularExpression != null) { ++excludeCount; if (filter.ValidateExclude(value)) return false; } } return (includeCount <= 0 || validIncludeCount > 0); }
private void populateForDirectory(XmlNode componentGroupNode, XmlNode node, DirectoryInfo dir, Filter[] filters, bool includeHiddenDirectories, bool includeHiddenFiles, List<string> collectedFiles, List<string> collectedDirectories, ref int fileCount) { string dirID; XmlNode dirNode; XmlNode fileNode; XmlNode componentNode; string componentNodeID; foreach (FileInfo f in dir.GetFiles()) { if (!includeHiddenFiles && isHidden(f)) continue; if (!Filter.Validate(filters, f.FullName)) continue; //Disregard if we've already added this file if (collectedFiles.Contains(f.FullName)) continue; collectedFiles.Add(f.FullName); ++fileCount; componentNodeID = createValidID(f.FullName); appendDefaultWiXAttribute((componentNode = appendDefaultWiXNode(node, "Component")), "Id", componentNodeID); appendDefaultWiXAttribute(componentNode, "Guid", trimStringToGUID(f.FullName)); //<Component /> requires a reference to the directory in which it's in //appendDefaultWiXAttribute(componentNode, "Directory", findDefaultWiXAttributeValue(node, "Id")); appendDefaultWiXAttribute((fileNode = appendDefaultWiXNode(componentNode, "File")), "Name", f.Name); appendDefaultWiXAttribute(fileNode, "Id", componentNodeID); appendDefaultWiXAttribute(fileNode, "Source", f.FullName); appendDefaultWiXAttribute(fileNode, "DefaultLanguage", "0"); appendDefaultWiXAttribute(fileNode, "KeyPath", "yes"); //Add to component group if (componentGroupNode != null) appendDefaultWiXAttribute(appendDefaultWiXNode(componentGroupNode, "ComponentRef"), "Id", componentNodeID); } foreach (DirectoryInfo d in dir.GetDirectories()) { if (!includeHiddenDirectories && isHidden(d)) continue; collectedDirectories.Add(d.FullName); int localFileCount = 0; dirID = createValidID(d.FullName); appendDefaultWiXAttribute((dirNode = createDefaultWiXNode(node, "Directory")), "Id", dirID); appendDefaultWiXAttribute(dirNode, "Name", d.Name); populateForDirectory(componentGroupNode, dirNode, d, filters, includeHiddenDirectories, includeHiddenFiles, collectedFiles, collectedDirectories, ref localFileCount); fileCount += localFileCount; //Only add directories that contain something if (localFileCount > 0) node.AppendChild(dirNode); } }