Ejemplo n.º 1
0
        private SearchDir IndexFiles(string parent, string strUncompiledFile = null)
        {
            //strDecompiledFile = if we are indexing a decompiled CHM or other file, in which case we index everything.
            //Index files and count all bytes.
            SearchDir newDir = new SearchDir(parent);

            try
            {
                string[] dirs = Directory.GetDirectories(parent);

                foreach (string filename in Directory.GetFiles(parent))
                {
                    string baseName = System.IO.Path.GetFileName(filename);
                    if ((strUncompiledFile != null) || MatchText(baseName, _lstFileNameSearchTokens, _cboFileName.Text, _chkFilenameRegex.Checked))
                    {
                        FileInfo fi = new FileInfo(filename);
                        newDir.Files.Add(new SearchFile(filename, fi.Length, fi.LastWriteTime, strUncompiledFile));
                        newDir.SearchSizeBytes += newDir.Files[newDir.Files.Count - 1].Length;
                    }
                }

                lock (_nFoundFiles_Lock)
                {
                    _nFoundFiles += newDir.Files.Count;
                    if (strUncompiledFile == null)
                    {
                        SetStatus("Found " + _nFoundFiles);
                    }
                }

                foreach (string dir in dirs)
                {
                    SearchDir t = IndexFiles(dir, strUncompiledFile);
                    newDir.SearchSizeBytes += t.SearchSizeBytes;
                    newDir.Dirs.Add(t);
                    newDir.TotalNumSubFiles += t.Files.Count + t.TotalNumSubFiles;
                }
            }
            catch (Exception ex)
            {
                Globals.LogWarn("Failed to index files in '" + parent + "': " + ex.ToString());
                //Dir may not be authorized.
            }


            return(newDir);
        }
Ejemplo n.º 2
0
        private void PerformSearch(SearchDir sd, bool regex, bool caseSensitive, bool wholefile)
        {
            bool bHasNotBeenSearched = false;

            lock (_searchedDirs)
            {
                if (_searchedDirs.Contains(sd.Name) == false)
                {
                    bHasNotBeenSearched = true;
                    _searchedDirs.Add(sd.Name);
                }
            }

            if (bHasNotBeenSearched)
            {
                //Note: The searchfiles here are already matched to the file filter. (not all files in dir)
                //List<string> toDecompile = new List<string>();
                foreach (SearchFile sf in sd.Files)
                {
                    //This is really a bottleneck
                    SetStatus(sf.Name);

                    string ext  = Path.GetExtension(sf.Name);
                    string extl = ext.ToLower();
                    if (extl == ".chm" && _chkSearchChm.Checked)
                    {
                        LookThroughCHM(sf, regex, caseSensitive, wholefile);
                    }
                    else if ((extl == ".doc" || extl == ".docx") && _chkSearchDoc.Checked)
                    {
                    }
                    else if (extl == ".pdf" && _chkSearchPdf.Checked)
                    {
                    }
                    else
                    {
                        LookThroughFile(sf, caseSensitive, regex, wholefile);
                    }
                }

                //Recursive
                foreach (SearchDir d in sd.Dirs)
                {
                    PerformSearch(d, regex, caseSensitive, wholefile);
                }
            }
        }
Ejemplo n.º 3
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());
            }
        }
Ejemplo n.º 4
0
        private void DistributeSearchToCore(SearchDir sd, int iProcessor)
        {
            //Toss the File search across virtual threads.
            DistributedThread t = new DistributedThread(() =>
            {
                PerformSearch(sd, _chkFileContentsRegex.Checked, _chkFileContentsCaseSensitive.Checked, _chkMatchWholeFile.Checked);

                SearchCoreComplete(iProcessor);
            });

            t.ProcessorAffinity = iProcessor;
            lock (_lstSearchThreads)
            {
                _lstSearchThreads.Add(t);
            }
            //thread.ManagedThread.Name = "ThreadOnCPU2";
            t.Start();
        }