예제 #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
        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));
                }
            }
        }
예제 #3
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);
        }