/// <summary> /// Apply filters to filter list of files that will be checked for authenticode signed /// </summary> /// <param name="dirToProbeForFiles"></param> /// <returns></returns> private string[] ApplyFileFilter(string dirToProbeForFiles) { string[] filteredFiles = null; IEnumerable <string> startupCollection = new string[] { "" }; IEnumerable <string> files = startupCollection.Except <string>(new string[] { "" }); //we do this to construct an empty IEnumerable (TODO: is there a better way) if (string.IsNullOrEmpty(FileFilterPattern)) { files = Directory.EnumerateFiles(dirToProbeForFiles, "*", SearchOption.AllDirectories); } else { string[] listOfFilters = FileFilterPattern.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string filter in listOfFilters) { files = files.Concat <string>(Directory.EnumerateFiles(dirToProbeForFiles, filter, SearchOption.AllDirectories)); } } if (files.Any <string>() || files != null) { filteredFiles = files.ToArray <string>(); } return(filteredFiles); }
public void FilespecStarpObj_Include_DoesNotMatch(string path) { var f = new FileFilterPattern(true, "*.obj", FilesystemMatchType.FilesOnly); Assert.False(f.MatchesPath(path)); bool?r = f.IncludesPath(path); Assert.False(r.HasValue); Assert.IsNull(r); }
public void FilespecWildcard_Exclude_Matches(string path) { var f = new FileFilterPattern(false, "*", FilesystemMatchType.FilesOnly); Assert.True(f.MatchesPath(path)); bool?r = f.IncludesPath(path); Assert.True(r.HasValue); Assert.IsNotNull(r); Assert.False(r.Value); }
public void FilespecApBCStar_DoesNotMatch(string path) { var f = new FileFilterPattern(false, "A.BC*", FilesystemMatchType.FilesOnly); Assert.False(f.MatchesPath(path)); bool? r1 = f.IncludesPath(path); Assert.False(r1.HasValue); Assert.IsNull(r1); bool? r2 = f.ExcludesPath(path); Assert.False(r2.HasValue); Assert.IsNull(r2); }
public void FilespecABCQpXYZ_DoesMatch(string path) { var f = new FileFilterPattern(true, "ABC?.XYZ", FilesystemMatchType.FilesOnly); Assert.True(f.MatchesPath(path)); bool? r1 = f.IncludesPath(path); Assert.True(r1.HasValue); Assert.IsNotNull(r1); Assert.IsTrue(r1.Value); bool? r2 = f.ExcludesPath(path); Assert.True(r2.HasValue); Assert.IsNotNull(r2); Assert.IsFalse(r2.Value); }
public void FilespecApBCStar_DoesNotMatch(string path) { var f = new FileFilterPattern(false, "A.BC*", FilesystemMatchType.FilesOnly); Assert.False(f.MatchesPath(path)); bool?r1 = f.IncludesPath(path); Assert.False(r1.HasValue); Assert.IsNull(r1); bool?r2 = f.ExcludesPath(path); Assert.False(r2.HasValue); Assert.IsNull(r2); }
public void FilespecABCQpXYZ_DoesMatch(string path) { var f = new FileFilterPattern(true, "ABC?.XYZ", FilesystemMatchType.FilesOnly); Assert.True(f.MatchesPath(path)); bool?r1 = f.IncludesPath(path); Assert.True(r1.HasValue); Assert.IsNotNull(r1); Assert.IsTrue(r1.Value); bool?r2 = f.ExcludesPath(path); Assert.True(r2.HasValue); Assert.IsNotNull(r2); Assert.IsFalse(r2.Value); }
public void FilespecStarpObj_Include_DoesNotMatch(string path) { var f = new FileFilterPattern(true, "*.obj", FilesystemMatchType.FilesOnly); Assert.False(f.MatchesPath(path)); bool? r = f.IncludesPath(path); Assert.False(r.HasValue); Assert.IsNull(r); }
public void FilespecWildcard_Include_Matches(string path) { var f = new FileFilterPattern(true, "*", FilesystemMatchType.FilesOnly); Assert.True(f.MatchesPath(path)); bool? r = f.IncludesPath(path); Assert.True(r.HasValue); Assert.IsNotNull(r); Assert.True(r.Value); }