public void Search(FindArgs args) { _searchText = args.SearchText; _searchRegex = args.SearchRegex; _method = args.Method; _matchCase = args.MatchCase; _matchWholeWord = args.MatchWholeWord; _probeFilesOnly = args.ProbeFilesOnly; _panel = args.Panel; _includeFilter = new FilePatternFilter(args.IncludeExtensions); _excludeFilter = new FilePatternFilter(args.ExcludeExtensions); _thread = new Thread(new ThreadStart(ThreadProc)); _thread.Name = "Find in Probe Files"; _thread.Start(); }
public void TestIgnoreFilter() { var files = new[] { @"c:\bla\", @"c:\bla\file1.json", @"c:\bla\file1.xml", @"c:\bla\bla2\file1.json", @"c:\bla\bla2\file2.xml", @"c:\bla\bla2\text1.txt", @"c:\bla\bla2\bla3\test2.jpg", @"c:\blie\bla.xml" }; var basef = @"c:\bla"; // Basic glob filter var fi = new FilePatternFilter("*.xml"); var r = fi.Filter(basef, files); Assert.AreEqual(2, r.Count()); Assert.IsTrue(r.All(f => f.EndsWith(".xml"))); Assert.IsTrue(r.All(f => f.StartsWith(basef))); // Absolute select 1 file fi = new FilePatternFilter("/file1.json"); r = fi.Filter(basef, files); Assert.AreEqual(@"c:\bla\file1.json", r.Single()); // Absolute select 1 file - no match fi = new FilePatternFilter("/file1.crap"); r = fi.Filter(basef, files); Assert.AreEqual(0, r.Count()); // Absolute select with glob fi = new FilePatternFilter("/*.json"); r = fi.Filter(basef, files); Assert.AreEqual(1, r.Count()); Assert.AreEqual(@"c:\bla\file1.json", r.Single()); // Relative select file fi = new FilePatternFilter("file1.json"); r = fi.Filter(basef, files); Assert.AreEqual(2, r.Count()); Assert.IsTrue(r.All(f => f.EndsWith("file1.json"))); // Relative select file fi = new FilePatternFilter("**/file1.json"); r = fi.Filter(basef, files); Assert.AreEqual(2, r.Count()); Assert.IsTrue(r.All(f => f.EndsWith("file1.json"))); // Relative select file with glob fi = new FilePatternFilter("**/file1.*"); r = fi.Filter(basef, files); Assert.AreEqual(3, r.Count()); Assert.IsTrue(r.All(f => f.Contains("\\file1."))); // Relative select file with glob fi = new FilePatternFilter("**/*.txt"); r = fi.Filter(basef, files); Assert.AreEqual(1, r.Count()); Assert.AreEqual(@"c:\bla\bla2\text1.txt", r.Single()); // Relative select file with glob fi = new FilePatternFilter("**/file*.xml"); r = fi.Filter(basef, files); Assert.AreEqual(2, r.Count()); Assert.IsTrue(r.All(f => f.Contains("\\file") && f.EndsWith(".xml"))); // Relative select file with glob fi = new FilePatternFilter("file1.*"); r = fi.Filter(basef, files); Assert.AreEqual(3, r.Count()); Assert.IsTrue(r.All(f => f.Contains("\\file1."))); // Select whole directory fi = new FilePatternFilter("bla2/"); r = fi.Filter(basef, files); Assert.AreEqual(4, r.Count()); Assert.IsTrue(r.All(f => f.Contains("\\bla2\\"))); // Select whole directory fi = new FilePatternFilter("bla2/**"); r = fi.Filter(basef, files); Assert.AreEqual(4, r.Count()); Assert.IsTrue(r.All(f => f.Contains("\\bla2\\"))); // Select whole directory fi = new FilePatternFilter("/bla3/"); r = fi.Filter(basef, files); Assert.AreEqual(0, r.Count()); // Internal glob dir fi = new FilePatternFilter("/bla2/*/*.jpg"); r = fi.Filter(basef, files); Assert.AreEqual(1, r.Count()); Assert.AreEqual(@"c:\bla\bla2\bla3\test2.jpg", r.Single()); // Case-insensitive fi = new FilePatternFilter("TEST2.jpg"); r = fi.Filter(basef, files); Assert.AreEqual(1, r.Count()); Assert.AreEqual(@"c:\bla\bla2\bla3\test2.jpg", r.Single()); }
public void TestIgnoreFilter() { var files = new[] { Path.Combine("c:", "bla"), Path.Combine("c:", "bla", "file1.json"), Path.Combine("c:", "bla", "file1.xml"), Path.Combine("c:", "bla", "bla2", "file1.json"), Path.Combine("c:", "bla", "bla2", "file2.xml"), Path.Combine("c:", "bla", "bla2", "text1.txt"), Path.Combine("c:", "bla", "bla2", "bla3", "test2.jpg"), Path.Combine("c:", "blie", "bla.xml") }; var basef = Path.Combine("c:", "bla"); // Basic glob filter var fi = new FilePatternFilter("*.xml"); var r = fi.Filter(basef, files); Assert.AreEqual(2, r.Count()); Assert.IsTrue(r.All(f => f.EndsWith(".xml"))); Assert.IsTrue(r.All(f => f.StartsWith(basef))); // Absolute select 1 file fi = new FilePatternFilter("/file1.json"); r = fi.Filter(basef, files); Assert.AreEqual(Path.Combine("c:", "bla", "file1.json"), r.Single()); // Absolute select 1 file - no match fi = new FilePatternFilter("/file1.crap"); r = fi.Filter(basef, files); Assert.AreEqual(0, r.Count()); // Absolute select with glob fi = new FilePatternFilter("/*.json"); r = fi.Filter(basef, files); Assert.AreEqual(1, r.Count()); Assert.AreEqual(Path.Combine("c:", "bla", "file1.json"), r.Single()); // Relative select file fi = new FilePatternFilter("file1.json"); r = fi.Filter(basef, files); Assert.AreEqual(2, r.Count()); Assert.IsTrue(r.All(f => f.EndsWith("file1.json"))); // Relative select file fi = new FilePatternFilter("**/file1.json"); r = fi.Filter(basef, files); Assert.AreEqual(2, r.Count()); Assert.IsTrue(r.All(f => f.EndsWith("file1.json"))); // Relative select file with glob fi = new FilePatternFilter("**/file1.*"); r = fi.Filter(basef, files); Assert.AreEqual(3, r.Count()); Assert.IsTrue(r.All(f => f.Contains($"{Path.DirectorySeparatorChar}file1."))); // Relative select file with glob fi = new FilePatternFilter("**/*.txt"); r = fi.Filter(basef, files); Assert.AreEqual(1, r.Count()); Assert.AreEqual(Path.Combine("c:", "bla", "bla2", "text1.txt"), r.Single()); // Relative select file with glob fi = new FilePatternFilter("**/file*.xml"); r = fi.Filter(basef, files); Assert.AreEqual(2, r.Count()); Assert.IsTrue(r.All(f => f.Contains($"{Path.DirectorySeparatorChar}file") && f.EndsWith(".xml"))); // Relative select file with glob fi = new FilePatternFilter("file1.*"); r = fi.Filter(basef, files); Assert.AreEqual(3, r.Count()); Assert.IsTrue(r.All(f => f.Contains($"{Path.DirectorySeparatorChar}file1."))); // Select whole directory fi = new FilePatternFilter("bla2/"); r = fi.Filter(basef, files); Assert.AreEqual(4, r.Count()); Assert.IsTrue(r.All(f => f.Contains($"{Path.DirectorySeparatorChar}bla2{Path.DirectorySeparatorChar}"))); // Select whole directory fi = new FilePatternFilter("bla2/**"); r = fi.Filter(basef, files); Assert.AreEqual(4, r.Count()); Assert.IsTrue(r.All(f => f.Contains($"{Path.DirectorySeparatorChar}bla2{Path.DirectorySeparatorChar}"))); // Select whole directory fi = new FilePatternFilter("/bla3/"); r = fi.Filter(basef, files); Assert.AreEqual(0, r.Count()); // Internal glob dir fi = new FilePatternFilter("/bla2/*/*.jpg"); r = fi.Filter(basef, files); Assert.AreEqual(1, r.Count()); Assert.AreEqual(Path.Combine("c:", "bla", "bla2", "bla3", "test2.jpg"), r.Single()); // Case-insensitive fi = new FilePatternFilter("TEST2.jpg"); r = fi.Filter(basef, files); Assert.AreEqual(1, r.Count()); Assert.AreEqual(Path.Combine("c:", "bla", "bla2", "bla3", "test2.jpg"), r.Single()); }