Exemplo n.º 1
0
        public void BuildIndex()
        {
            DirInfo       info        = SettingsManager.Instance.GetDirectories();
            List <string> directories = info.Directories;
            Dictionary <string, List <string> > extensions          = info.Extensions;
            Dictionary <string, bool>           includeDirectories  = info.IncludeDirectories;
            Dictionary <string, bool>           indexSubdirectories = info.IndexSubdirectories;

            _index.StartBuilding();
            for (int i = 0; i < directories.Count; i++)
            {
                string               directory = directories[i];
                List <string>        ext       = new List <string>(extensions[directory]);
                List <string>        fullpathes;
                List <IndexerPlugin> assistingPlugins = new List <IndexerPlugin>();

                foreach (IndexerPlugin plugin in _plugins)
                {
                    if (SettingsManager.Instance.GetDirectories().Plugins[directory].Contains(plugin.Name))
                    {
                        assistingPlugins.Add(plugin);
                        ext.AddRange(plugin.Extensions);
                    }
                }

                try
                {
                    fullpathes = new List <string>(FileSearcher.SearchFullNames(Environment.ExpandEnvironmentVariables(directory), ext, indexSubdirectories[directory], includeDirectories[directory], (CommonInfo.IsPortable ? true : false)));
                }
                catch (Exception)
                {
                    fullpathes = new List <string>();
                }

                for (int j = 0; j < fullpathes.Count; j++)
                {
                    string path = fullpathes[j];
                    string name = FileNameManipulator.GetFileName(Directory.Exists(path)
                                       ? Path.GetDirectoryName(path)
                                       : path);
                    Bitmap icon = null;
                    try
                    {
                        icon = IconManager.RetrieveIcon(path).ToBitmap();
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                    if (icon == null)
                    {
                        continue;
                    }

                    List <string> list_keywords = new List <string>(StringUtility.GenerateKeywords(name, true, true));
                    foreach (string key in list_keywords)
                    {
                        _index.AddEntry(key, name, list_keywords.Count, path, icon, false);
                    }
                    list_keywords.Clear();
                    foreach (IndexerPlugin plugin in assistingPlugins)
                    {
                        string[] tmp_keywords = plugin.GetFileKeywords(path);
                        foreach (string key in tmp_keywords)
                        {
                            list_keywords.AddRange(StringUtility.GenerateKeywords(key, true, true));
                        }
                    }
                    foreach (string key in list_keywords)
                    {
                        _index.AddEntry(key, name, list_keywords.Count, path, icon, false);
                    }
                }
            }

            _index.FinishBuilding();

            // clean up
            directories         = null;
            extensions          = null;
            indexSubdirectories = null;
            GC.Collect();
        }