Exemple #1
0
        private void LookThroughCHM(SearchFile sf, bool regex, bool cs, bool wholefile)
        {
            try
            {
                string outDir = DecompileCHM(sf.Name);

                SearchDir sd = IndexFiles(outDir, sf.Name);
                PerformSearch(sd, regex, cs, wholefile);

                //Delete decompiled CHM so we don't eat up disk space.
                Directory.Delete(outDir, true);
            }
            catch (Exception ex)
            {
                Globals.LogError(ex.ToString());
            }
        }
Exemple #2
0
        private void _dgvFileSearchResults_SelectionChanged_1(object sender, EventArgs e)
        {
            if (_dgvFileSearchResults.SelectedRows.Count == 1)
            {
                DataGridViewRow r = _dgvFileSearchResults.SelectedRows[0];

                string     st = "";
                SearchFile sf = r.Tag as SearchFile;
                if (sf.MatchedLines != null)
                {
                    foreach (SearchLine sl in sf.MatchedLines)
                    {
                        st += sl.LineNumber + ": " + sl.Text + "\r\n";
                    }
                }
                _txtSearchResultsDetails.Text = st;
            }
        }
Exemple #3
0
        private void RegexSearch(SearchFile sf, string line, int iLine, bool caseSensitive)
        {
            bool matched = false;

            if (sf.MatchedLines == null)
            {
                sf.MatchedLines = new List <SearchLine>();
            }
            if (Regex.Match(line, _strFileContentsSearch, caseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase).Success)
            {
                sf.MatchedLines.Add(new SearchLine(iLine, line));
                matched = true;
            }
            if (matched)
            {
                AddMatch(sf);
            }
        }
Exemple #4
0
        private void LookThroughFile(SearchFile sf, bool caseSensitive, bool regex, bool wholefile)
        {
            if (String.IsNullOrEmpty(_strFileContentsSearch))
            {
                //No contents, user just wants to locate files.  Easy out.
                AddMatch(sf);
            }
            else
            {
                using (StreamReader sr = File.OpenText(sf.Name))
                {
                    string s = sr.ReadToEnd();

                    //If we are not matching the whole file then split the file up by \n newlines.
                    string[] lines = null;
                    if (wholefile == true)
                    {
                        lines = new string[1] {
                            s
                        };
                    }
                    else
                    {
                        lines = s.Split('\n');
                    }

                    int iLine = 1;
                    foreach (string line in lines)
                    {
                        if (regex)
                        {
                            RegexSearch(sf, line, iLine, caseSensitive);
                        }
                        else
                        {
                            NonRegexSearch(sf, line, iLine, caseSensitive);
                        }
                        iLine++;
                    }

                    sr.Close();
                }
            }
        }
Exemple #5
0
        private void AddMatch(SearchFile sf)
        {
            BeginInvoke((Action)(() =>
            {
                string file_name = sf.UncompiledFile == null ? sf.Name : sf.UncompiledFile;

                MatchedFiles.Add(sf);
                FileInfo fi = new FileInfo(file_name);
                string filetype = NativeMethods.GetShellFileType(file_name);
                string moddat = sf.LastModified.ToString("yyyy-mm-dd hh:mm:ss.fff");
                DataGridViewRow r = new DataGridViewRow();
                r.Tag = sf;
                r.CreateCells(_dgvFileSearchResults, new object[] {
                    file_name,
                    moddat,
                    filetype,
                    string.Format("{0:0.00}", (float)sf.Length / 1024.0f)
                });
                _dgvFileSearchResults.Rows.Add(r);
            }));
        }
Exemple #6
0
        private void NonRegexSearch(SearchFile sf, string line, int iLine, bool caseSensitive)
        {
            //Find.
            bool bFound = false;

            lock (MatchedFiles_Lock)
            {
                IEnumerable <string> ret = _objFileContentsSearchTrie.Find(caseSensitive ? line : line.ToLower());
                if (ret.Any())
                {
                    if (sf.MatchedLines == null)
                    {
                        sf.MatchedLines = new List <SearchLine>();
                    }
                    sf.MatchedLines.Add(new SearchLine(iLine, line));
                    bFound = true;
                }
            }
            if (bFound)
            {
                AddMatch(sf);
            }
        }