예제 #1
0
        public static IGrepEngine GetReplaceEngine(string fileName, GrepEngineInitParams param, FileFilter filter)
        {
            Debug.Assert(param != null);
            Debug.Assert(filter != null);

            LoadPlugins();

            string fileExtension = Path.GetExtension(fileName).ToLower().TrimStart('.');

            if (fileTypeEngines.ContainsKey(fileExtension) && !fileTypeEngines[fileExtension].IsSearchOnly)
            {
                IGrepEngine engine = fileTypeEngines[fileExtension].CreateEngine();
                if (engine != null && engine.Initialize(param, filter))
                {
                    loadedEngines.Add(engine);
                    return(engine);
                }
                else
                {
                    failedEngines[engine.GetType().Name] = "Failed to initialize the plugin. See error log for details.";
                    return(GetPlainTextEngine(fileExtension, param, filter));
                }
            }
            else
            {
                return(GetPlainTextEngine(fileExtension, param, filter));
            }
        }
예제 #2
0
        private static IGrepEngine GetHexEngine(GrepEngineInitParams param, FileFilter filter)
        {
            IGrepEngine engine = new GrepEngineHex();

            loadedEngines.Add(engine);
            engine.Initialize(param, filter);
            return(engine);
        }
예제 #3
0
        public static IGrepEngine GetSearchEngine(string fileName, GrepEngineInitParams param, FileFilter filter)
        {
            Debug.Assert(param != null);
            Debug.Assert(filter != null);

            loadPlugins();

            string fileExtension = Path.GetExtension(fileName).ToLower();

            if (fileExtension.Length > 1)
            {
                fileExtension = fileExtension.Substring(1);
            }

            if (!fileTypeEngines.ContainsKey(fileExtension))
            {
                foreach (GrepPlugin plugin in plugings)
                {
                    if (plugin.Extensions.Contains(fileExtension))
                    {
                        fileTypeEngines[fileExtension] = plugin;
                    }
                }
            }
            GrepEnginePlainText plainTextEngine = new GrepEnginePlainText();

            plainTextEngine.Initialize(param, filter);

            if (fileTypeEngines.ContainsKey(fileExtension) && fileTypeEngines[fileExtension].Enabled)
            {
                if (FrameworkVersionsAreCompatible(fileTypeEngines[fileExtension].Engine.FrameworkVersion, plainTextEngine.FrameworkVersion))
                {
                    if (fileTypeEngines[fileExtension].Engine.Initialize(param, filter))
                    {
                        return(fileTypeEngines[fileExtension].Engine);
                    }
                    else
                    {
                        failedEngines[fileTypeEngines[fileExtension].Engine.GetType().Name] = "Failed to initialize the plugin. See error log for details.";
                        return(plainTextEngine);
                    }
                }
                else
                {
                    failedEngines[fileTypeEngines[fileExtension].Engine.GetType().Name] = "Plugin developed under outdated framework. Please update the plugin.";
                    return(plainTextEngine);
                }
            }
            else
            {
                return(plainTextEngine);
            }
        }
예제 #4
0
        public static IGrepEngine GetSearchEngine(string fileName, GrepEngineInitParams param, FileFilter filter, SearchType searchType)
        {
            Debug.Assert(param != null);
            Debug.Assert(filter != null);

            LoadPlugins();

            string fileExtension = Path.GetExtension(fileName).ToLower().TrimStart('.');

            lock (lockObj)
            {
                if (searchType == SearchType.Hex)
                {
                    return(GetHexEngine(param, filter));
                }

                IGrepEngine poolEngine = FetchFromPool(fileExtension);
                if (poolEngine != null)
                {
                    poolEngine.Initialize(param, filter);
                    return(poolEngine);
                }

                if (ArchiveDirectory.Extensions.Contains(fileExtension))
                {
                    return(GetArchiveEngine(fileExtension, param, filter));
                }

                if (fileTypeEngines.ContainsKey(fileExtension))
                {
                    IGrepEngine engine = fileTypeEngines[fileExtension].CreateEngine();
                    if (engine != null && engine.Initialize(param, filter))
                    {
                        loadedEngines.Add(engine);
                        logger.Debug(string.Format("Using plugin: {0} for extension {1}", engine.ToString(), fileExtension));
                        return(engine);
                    }
                    else
                    {
                        logger.Debug(string.Format("File type engines failed to initialize: {0}, using plainTextEngine", fileExtension));
                        failedEngines[engine.GetType().Name] = "Failed to initialize the plugin. See error log for details.";
                        return(GetPlainTextEngine(fileExtension, param, filter));
                    }
                }
                else
                {
                    logger.Debug(string.Format("File type engines has no key for: {0}, using plainTextEngine", fileExtension));
                    return(GetPlainTextEngine(fileExtension, param, filter));
                }
            }
        }
예제 #5
0
        public void SetSearchOptions(FileFilter filter, GrepEngineInitParams initParams)
        {
            precacheResults       = GrepSettings.Instance.Get <bool>(GrepSettings.Key.ExpandResults);
            fileFilter            = filter;
            searchParams          = initParams;
            includeSearchPatterns = new List <string>();
            bool hasSearchPattern = Utils.PrepareSearchPatterns(filter, includeSearchPatterns);

            includeRegexPatterns   = new List <Regex>();
            excludeRegexPatterns   = new List <Regex>();
            includeShebangPatterns = new List <Regex>();
            Utils.PrepareFilters(filter, includeRegexPatterns, excludeRegexPatterns, includeShebangPatterns, hasSearchPattern);

            hiddenDirectories.Clear();
        }
예제 #6
0
		public virtual bool Initialize(GrepEngineInitParams param)
		{
            this.showLinesInContext = param.ShowLinesInContext;
            if (this.showLinesInContext)
            {
                this.linesBefore = param.LinesBefore;
                this.linesAfter = param.LinesAfter;
            }
            else
            {
                this.linesBefore = 0;
                this.linesAfter = 0;
            }
			this.fuzzyMatchThreshold = param.FuzzyMatchThreshold;
			return true;
		}
예제 #7
0
 public virtual bool Initialize(GrepEngineInitParams param)
 {
     this.showLinesInContext = param.ShowLinesInContext;
     if (this.showLinesInContext)
     {
         this.linesBefore = param.LinesBefore;
         this.linesAfter  = param.LinesAfter;
     }
     else
     {
         this.linesBefore = 0;
         this.linesAfter  = 0;
     }
     this.fuzzyMatchThreshold = param.FuzzyMatchThreshold;
     return(true);
 }
예제 #8
0
		public override bool Initialize(GrepEngineInitParams param)
		{
            base.Initialize(param);
			try
			{
				// Make sure pdftotext.exe exists
				pathToPdfToText = Utils.GetCurrentPath(typeof(GrepEnginePdf)) + "\\pdftotext.exe";
				if (File.Exists(pathToPdfToText))
					return true;
				else
					return false;
			}
			catch (Exception ex)
			{
				logger.LogException(LogLevel.Error, "Failed to find pdftotext.exe.", ex);
				return false;
			}
		}
예제 #9
0
        public static IGrepEngine GetSearchEngine(string fileName, GrepEngineInitParams param)
        {
            loadPlugins();

            string fileExtension = Path.GetExtension(fileName).ToLower();
            if (fileExtension.Length > 1)
                fileExtension = fileExtension.Substring(1);

            if (!fileTypeEngines.ContainsKey(fileExtension)) 
            {
                foreach (GrepPlugin plugin in plugings)
                {
                    if (plugin.Extensions.Contains(fileExtension))
                    {
                        fileTypeEngines[fileExtension] = plugin;
                    }
                }
            }
            GrepEnginePlainText plainTextEngine = new GrepEnginePlainText();
            plainTextEngine.Initialize(param);

            if (fileTypeEngines.ContainsKey(fileExtension) && fileTypeEngines[fileExtension].Enabled)
            {
                if (FrameworkVersionsAreCompatible(fileTypeEngines[fileExtension].Engine.FrameworkVersion, plainTextEngine.FrameworkVersion))
                {
                    if (fileTypeEngines[fileExtension].Engine.Initialize(param))
                    {
                        return fileTypeEngines[fileExtension].Engine;
                    }
                    else
                    {
                        failedEngines[fileTypeEngines[fileExtension].Engine.GetType().Name] = "Failed to initialize the plugin. See error log for details.";
                        return plainTextEngine;
                    }
                }
                else
                {
                    failedEngines[fileTypeEngines[fileExtension].Engine.GetType().Name] = "Plugin developed under outdated framework. Please update the plugin.";
                    return plainTextEngine;
                }
            }
            else
                return plainTextEngine;
        }
예제 #10
0
        private static IGrepEngine GetPlainTextEngine(string fileExtension, GrepEngineInitParams param, FileFilter filter)
        {
            if (!poolKeys.ContainsKey(fileExtension))
            {
                poolKeys.Add(fileExtension, "GrepEnginePlainText");
            }

            IGrepEngine poolEngine = FetchFromPool(fileExtension);

            if (poolEngine != null)
            {
                poolEngine.Initialize(param, filter);
                return(poolEngine);
            }

            IGrepEngine engine = new GrepEnginePlainText();

            loadedEngines.Add(engine);
            engine.Initialize(param, filter);
            return(engine);
        }
예제 #11
0
		public GrepEngineBase(GrepEngineInitParams param)
		{
			Initialize(param);
		}
예제 #12
0
 public virtual bool Initialize(GrepEngineInitParams param, FileFilter filter)
 {
     initParams = param;
     FileFilter = filter;
     return(true);
 }
예제 #13
0
 public GrepEngineBase(GrepEngineInitParams param)
 {
     initParams = param;
 }
예제 #14
0
 public GrepEngineBase(GrepEngineInitParams param)
 {
     Initialize(param);
 }