private int SearchFile(SearchFileResult result)
        {
            var text = File.ReadAllText(result.Filename);

            int matches = 0;
            int i       = 0;

            while (true)
            {
                var pos = text.IndexOfNth(SearchPhrase, i + 1, StringComparison.InvariantCultureIgnoreCase);
                i++;
                if (pos == -1)
                {
                    break;
                }

                if (NoMatchDetails)
                {
                    return(1);
                }

                matches++;

                var match = new SearchTextMatch();
                match.StartPos = pos;
                match.EndPos   = match.StartPos + SearchPhrase.Length;

                result.Matches.Add(match);
            }

            return(matches);
        }
        private void SearchFolder(List <SearchFileResult> list, string folder)
        {
            var filters = SearchFilePattern.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var filter in filters)
            {
                string[] files;
                try
                {
                    files = Directory.GetFiles(folder, filter, SearchOption.TopDirectoryOnly);
                }
                catch
                {
                    continue;
                }

                foreach (var file in files)
                {
                    var result = new SearchFileResult {
                        Filename = file
                    };
                    if (SearchFile(result) > 0 ||
                        System.IO.Path.GetFileName(file)
                        .Contains(SearchPhrase, StringComparison.InvariantCultureIgnoreCase))
                    {
                        list.Add(result);
                    }
                }
            }

            if (!SearchSubFolders)
            {
                return;
            }

            try
            {
                var folders = Directory.GetDirectories(folder, "*.*");
                foreach (var childFolder in folders)
                {
                    SearchFolder(list, childFolder);
                }
            }
            catch { }
        }