Exemplo n.º 1
0
        /// <summary>
        /// Attempt to convert search options in registry to most recent style.
        /// </summary>
        /// <remarks>
        /// Removes any registry settings for search options if found and successfully converted.
        /// </remarks>
        /// <history>
        /// [Curtis_Beard]		10/10/2006	Created
        /// [Curtis_Beard]	   03/07/2012	ADD: 3131609, exclusions
        /// [Curtis_Beard]	   11/06/2014	CHG: convert exclusionitem to filteritem
        /// </history>
        public static void ConvertSearchSettings()
        {
            if (Registry.CheckStartupSetting("USE_REG_EXPRESSIONS"))
            {
                AstroGrep.Core.SearchSettings.UseRegularExpressions = Registry.GetStartupSetting("USE_REG_EXPRESSIONS", false);
                Registry.DeleteStartupSetting("USE_REG_EXPRESSIONS");
            }

            if (Registry.CheckStartupSetting("USE_CASE_SENSITIVE"))
            {
                AstroGrep.Core.SearchSettings.UseCaseSensitivity = Registry.GetStartupSetting("USE_CASE_SENSITIVE", false);
                Registry.DeleteStartupSetting("USE_CASE_SENSITIVE");
            }

            if (Registry.CheckStartupSetting("USE_WHOLE_WORD"))
            {
                AstroGrep.Core.SearchSettings.UseWholeWordMatching = Registry.GetStartupSetting("USE_WHOLE_WORD", false);
                Registry.DeleteStartupSetting("USE_WHOLE_WORD");
            }

            if (Registry.CheckStartupSetting("USE_LINE_NUMBERS"))
            {
                AstroGrep.Core.SearchSettings.IncludeLineNumbers = Registry.GetStartupSetting("USE_LINE_NUMBERS", true);
                Registry.DeleteStartupSetting("USE_LINE_NUMBERS");
            }

            if (Registry.CheckStartupSetting("USE_RECURSION"))
            {
                AstroGrep.Core.SearchSettings.UseRecursion = Registry.GetStartupSetting("USE_RECURSION", true);
                Registry.DeleteStartupSetting("USE_RECURSION");
            }

            if (Registry.CheckStartupSetting("SHOW_FILE_NAMES_ONLY"))
            {
                AstroGrep.Core.SearchSettings.ReturnOnlyFileNames = Registry.GetStartupSetting("SHOW_FILE_NAMES_ONLY", false);
                Registry.DeleteStartupSetting("SHOW_FILE_NAMES_ONLY");
            }

            if (Registry.CheckStartupSetting("USE_NEGATION"))
            {
                AstroGrep.Core.SearchSettings.UseNegation = Registry.GetStartupSetting("USE_NEGATION", false);
                Registry.DeleteStartupSetting("USE_NEGATION");
            }

            if (Registry.CheckStartupSetting("NUM_CONTEXT_LINES"))
            {
                int lines = Registry.GetStartupSetting("NUM_CONTEXT_LINES", 0);
                if (lines < 0 || lines > Constants.MAX_CONTEXT_LINES)
                {
                    lines = 0;
                }
                AstroGrep.Core.SearchSettings.ContextLines = lines;
                Registry.DeleteStartupSetting("NUM_CONTEXT_LINES");
            }

            var filterItems = new System.Collections.Generic.List <libAstroGrep.FilterItem>();

            // old list to new search option
            if (!string.IsNullOrEmpty(Core.GeneralSettings.ExtensionExcludeList))
            {
                var extensions = Core.GeneralSettings.ExtensionExcludeList.Split(';');

                foreach (var ext in extensions)
                {
                    libAstroGrep.FilterItem item = new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Extension), ext, libAstroGrep.FilterType.ValueOptions.None, false, true);
                    filterItems.Add(item);
                }

                // set extension exclude to list to empty
                Core.GeneralSettings.ExtensionExcludeList = string.Empty;
            }

            // ExclusionItems to FilterItems
            if (!string.IsNullOrEmpty(Core.SearchSettings.Exclusions))
            {
                var exclusionItems = libAstroGrep.ExclusionItem.ConvertStringToExclusions(Core.SearchSettings.Exclusions);
                foreach (var oldItem in exclusionItems)
                {
                    libAstroGrep.FilterItem item = new libAstroGrep.FilterItem();
                    item.Enabled         = oldItem.Enabled;
                    item.Value           = oldItem.Value;
                    item.ValueIgnoreCase = oldItem.IgnoreCase;
                    switch (oldItem.Option)
                    {
                    case libAstroGrep.ExclusionItem.OptionsTypes.Contains:
                        item.ValueOption = libAstroGrep.FilterType.ValueOptions.Contains;
                        break;

                    case libAstroGrep.ExclusionItem.OptionsTypes.EndsWith:
                        item.ValueOption = libAstroGrep.FilterType.ValueOptions.EndsWith;
                        break;

                    case libAstroGrep.ExclusionItem.OptionsTypes.Equals:
                        item.ValueOption = libAstroGrep.FilterType.ValueOptions.Equals;
                        break;

                    case libAstroGrep.ExclusionItem.OptionsTypes.None:
                        item.ValueOption = libAstroGrep.FilterType.ValueOptions.None;
                        break;

                    case libAstroGrep.ExclusionItem.OptionsTypes.StartsWith:
                        item.ValueOption = libAstroGrep.FilterType.ValueOptions.StartsWith;
                        break;
                    }
                    switch (oldItem.Type)
                    {
                    case libAstroGrep.ExclusionItem.ExclusionTypes.DirectoryName:
                        item.FilterType = new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.Directory, libAstroGrep.FilterType.SubCategories.Name);
                        break;

                    case libAstroGrep.ExclusionItem.ExclusionTypes.DirectoryPath:
                        item.FilterType = new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.Directory, libAstroGrep.FilterType.SubCategories.Path);
                        break;

                    case libAstroGrep.ExclusionItem.ExclusionTypes.FileExtension:
                        item.FilterType = new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Extension);
                        break;

                    case libAstroGrep.ExclusionItem.ExclusionTypes.FileName:
                        item.FilterType = new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Name);
                        break;

                    case libAstroGrep.ExclusionItem.ExclusionTypes.FilePath:
                        item.FilterType = new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Path);
                        break;
                    }
                    filterItems.Add(item);
                }

                // set exclusions list to empty
                Core.SearchSettings.Exclusions = string.Empty;
            }

            if (Core.SearchSettings.MinimumFileCount > 0)
            {
                filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.MinimumHitCount),
                                                            Core.SearchSettings.MinimumFileCount.ToString(), libAstroGrep.FilterType.ValueOptions.None, false, true));

                Core.SearchSettings.MinimumFileCount = 0;
            }

            if (Core.SearchSettings.SkipHidden)
            {
                filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Hidden),
                                                            string.Empty, libAstroGrep.FilterType.ValueOptions.None, false, true));

                filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.Directory, libAstroGrep.FilterType.SubCategories.Hidden),
                                                            string.Empty, libAstroGrep.FilterType.ValueOptions.None, false, true));

                Core.SearchSettings.SkipHidden = false;
            }

            if (Core.SearchSettings.SkipSystem)
            {
                filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.System),
                                                            string.Empty, libAstroGrep.FilterType.ValueOptions.None, false, true));

                filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.Directory, libAstroGrep.FilterType.SubCategories.System),
                                                            string.Empty, libAstroGrep.FilterType.ValueOptions.None, false, true));

                Core.SearchSettings.SkipSystem = false;
            }

            if (!string.IsNullOrEmpty(Core.SearchSettings.MinimumFileSize))
            {
                filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Size),
                                                            Core.SearchSettings.MinimumFileSize, libAstroGrep.FilterType.ValueOptions.LessThan, false, Core.SearchSettings.MinimumFileSizeType, true));

                Core.SearchSettings.MinimumFileSize     = string.Empty;
                Core.SearchSettings.MinimumFileSizeType = string.Empty;
            }

            if (!string.IsNullOrEmpty(Core.SearchSettings.MaximumFileSize))
            {
                filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Size),
                                                            Core.SearchSettings.MaximumFileSize, libAstroGrep.FilterType.ValueOptions.GreaterThan, false, Core.SearchSettings.MaximumFileSizeType, true));

                Core.SearchSettings.MaximumFileSize     = string.Empty;
                Core.SearchSettings.MaximumFileSizeType = string.Empty;
            }

            if (!string.IsNullOrEmpty(Core.SearchSettings.ModifiedDateStart))
            {
                filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.DateModified),
                                                            Core.SearchSettings.ModifiedDateStart, libAstroGrep.FilterType.ValueOptions.LessThan, false, true));

                Core.SearchSettings.ModifiedDateStart = string.Empty;
            }

            if (!string.IsNullOrEmpty(Core.SearchSettings.ModifiedDateEnd))
            {
                filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.DateModified),
                                                            Core.SearchSettings.ModifiedDateEnd, libAstroGrep.FilterType.ValueOptions.GreaterThan, false, true));

                Core.SearchSettings.ModifiedDateEnd = string.Empty;
            }

            // set filteritems list to new value
            if (filterItems.Count > 0)
            {
                Core.SearchSettings.FilterItems = libAstroGrep.FilterItem.ConvertFilterItemsToString(filterItems);
            }

            AstroGrep.Core.SearchSettings.Save();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempt to convert search options in registry to most recent style.
        /// </summary>
        /// <remarks>
        /// Removes any registry settings for search options if found and successfully converted.
        /// </remarks>
        /// <history>
        /// [Curtis_Beard]		10/10/2006	Created
        /// [Curtis_Beard]	   03/07/2012	ADD: 3131609, exclusions
        /// [Curtis_Beard]	   11/06/2014	CHG: convert exclusionitem to filteritem
        /// </history>
        public static void ConvertSearchSettings()
        {
            if (Registry.CheckStartupSetting("USE_REG_EXPRESSIONS"))
             {
            AstroGrep.Core.SearchSettings.UseRegularExpressions = Registry.GetStartupSetting("USE_REG_EXPRESSIONS", false);
            Registry.DeleteStartupSetting("USE_REG_EXPRESSIONS");
             }

             if (Registry.CheckStartupSetting("USE_CASE_SENSITIVE"))
             {
            AstroGrep.Core.SearchSettings.UseCaseSensitivity = Registry.GetStartupSetting("USE_CASE_SENSITIVE", false);
            Registry.DeleteStartupSetting("USE_CASE_SENSITIVE");
             }

             if (Registry.CheckStartupSetting("USE_WHOLE_WORD"))
             {
            AstroGrep.Core.SearchSettings.UseWholeWordMatching = Registry.GetStartupSetting("USE_WHOLE_WORD", false);
            Registry.DeleteStartupSetting("USE_WHOLE_WORD");
             }

             if (Registry.CheckStartupSetting("USE_LINE_NUMBERS"))
             {
            AstroGrep.Core.SearchSettings.IncludeLineNumbers = Registry.GetStartupSetting("USE_LINE_NUMBERS", true);
            Registry.DeleteStartupSetting("USE_LINE_NUMBERS");
             }

             if (Registry.CheckStartupSetting("USE_RECURSION"))
             {
            AstroGrep.Core.SearchSettings.UseRecursion = Registry.GetStartupSetting("USE_RECURSION", true);
            Registry.DeleteStartupSetting("USE_RECURSION");
             }

             if (Registry.CheckStartupSetting("SHOW_FILE_NAMES_ONLY"))
             {
            AstroGrep.Core.SearchSettings.ReturnOnlyFileNames = Registry.GetStartupSetting("SHOW_FILE_NAMES_ONLY", false);
            Registry.DeleteStartupSetting("SHOW_FILE_NAMES_ONLY");
             }

             if (Registry.CheckStartupSetting("USE_NEGATION"))
             {
            AstroGrep.Core.SearchSettings.UseNegation = Registry.GetStartupSetting("USE_NEGATION", false);
            Registry.DeleteStartupSetting("USE_NEGATION");
             }

             if (Registry.CheckStartupSetting("NUM_CONTEXT_LINES"))
             {
            int lines = Registry.GetStartupSetting("NUM_CONTEXT_LINES", 0);
            if (lines < 0 || lines > Constants.MAX_CONTEXT_LINES)
               lines = 0;
            AstroGrep.Core.SearchSettings.ContextLines = lines;
            Registry.DeleteStartupSetting("NUM_CONTEXT_LINES");
             }

             var filterItems = new System.Collections.Generic.List<libAstroGrep.FilterItem>();

             // old list to new search option
             if (!string.IsNullOrEmpty(Core.GeneralSettings.ExtensionExcludeList))
             {
            var extensions = Core.GeneralSettings.ExtensionExcludeList.Split(';');

            foreach (var ext in extensions)
            {
               libAstroGrep.FilterItem item = new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Extension), ext, libAstroGrep.FilterType.ValueOptions.None, false, true);
               filterItems.Add(item);
            }

            // set extension exclude to list to empty
            Core.GeneralSettings.ExtensionExcludeList = string.Empty;
             }

             // ExclusionItems to FilterItems
             if (!string.IsNullOrEmpty(Core.SearchSettings.Exclusions))
             {
            var exclusionItems = libAstroGrep.ExclusionItem.ConvertStringToExclusions(Core.SearchSettings.Exclusions);
            foreach (var oldItem in exclusionItems)
            {
               libAstroGrep.FilterItem item = new libAstroGrep.FilterItem();
               item.Enabled = oldItem.Enabled;
               item.Value = oldItem.Value;
               item.ValueIgnoreCase = oldItem.IgnoreCase;
               switch (oldItem.Option)
               {
                  case libAstroGrep.ExclusionItem.OptionsTypes.Contains:
                     item.ValueOption = libAstroGrep.FilterType.ValueOptions.Contains;
                     break;

                  case libAstroGrep.ExclusionItem.OptionsTypes.EndsWith:
                     item.ValueOption = libAstroGrep.FilterType.ValueOptions.EndsWith;
                     break;

                  case libAstroGrep.ExclusionItem.OptionsTypes.Equals:
                     item.ValueOption = libAstroGrep.FilterType.ValueOptions.Equals;
                     break;

                  case libAstroGrep.ExclusionItem.OptionsTypes.None:
                     item.ValueOption = libAstroGrep.FilterType.ValueOptions.None;
                     break;

                  case libAstroGrep.ExclusionItem.OptionsTypes.StartsWith:
                     item.ValueOption = libAstroGrep.FilterType.ValueOptions.StartsWith;
                     break;
               }
               switch (oldItem.Type)
               {
                  case libAstroGrep.ExclusionItem.ExclusionTypes.DirectoryName:
                     item.FilterType = new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.Directory, libAstroGrep.FilterType.SubCategories.Name);
                     break;

                  case libAstroGrep.ExclusionItem.ExclusionTypes.DirectoryPath:
                     item.FilterType = new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.Directory, libAstroGrep.FilterType.SubCategories.Path);
                     break;

                  case libAstroGrep.ExclusionItem.ExclusionTypes.FileExtension:
                     item.FilterType = new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Extension);
                     break;

                  case libAstroGrep.ExclusionItem.ExclusionTypes.FileName:
                     item.FilterType = new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Name);
                     break;

                  case libAstroGrep.ExclusionItem.ExclusionTypes.FilePath:
                     item.FilterType = new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Path);
                     break;
               }
               filterItems.Add(item);
            }

            // set exclusions list to empty
            Core.SearchSettings.Exclusions = string.Empty;
             }

             if (Core.SearchSettings.MinimumFileCount > 0)
             {
            filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.MinimumHitCount),
               Core.SearchSettings.MinimumFileCount.ToString(), libAstroGrep.FilterType.ValueOptions.None, false, true));

            Core.SearchSettings.MinimumFileCount = 0;
             }

             if (Core.SearchSettings.SkipHidden)
             {
            filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Hidden),
               string.Empty, libAstroGrep.FilterType.ValueOptions.None, false, true));

            filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.Directory, libAstroGrep.FilterType.SubCategories.Hidden),
               string.Empty, libAstroGrep.FilterType.ValueOptions.None, false, true));

            Core.SearchSettings.SkipHidden = false;
             }

             if (Core.SearchSettings.SkipSystem)
             {
            filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.System),
               string.Empty, libAstroGrep.FilterType.ValueOptions.None, false, true));

            filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.Directory, libAstroGrep.FilterType.SubCategories.System),
               string.Empty, libAstroGrep.FilterType.ValueOptions.None, false, true));

            Core.SearchSettings.SkipSystem = false;
             }

             if (!string.IsNullOrEmpty(Core.SearchSettings.MinimumFileSize))
             {
            filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Size),
               Core.SearchSettings.MinimumFileSize, libAstroGrep.FilterType.ValueOptions.LessThan, false, Core.SearchSettings.MinimumFileSizeType, true));

            Core.SearchSettings.MinimumFileSize = string.Empty;
            Core.SearchSettings.MinimumFileSizeType = string.Empty;
             }

             if (!string.IsNullOrEmpty(Core.SearchSettings.MaximumFileSize))
             {
            filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.Size),
               Core.SearchSettings.MaximumFileSize, libAstroGrep.FilterType.ValueOptions.GreaterThan, false, Core.SearchSettings.MaximumFileSizeType, true));

            Core.SearchSettings.MaximumFileSize = string.Empty;
            Core.SearchSettings.MaximumFileSizeType = string.Empty;
             }

             if (!string.IsNullOrEmpty(Core.SearchSettings.ModifiedDateStart))
             {
            filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.DateModified),
               Core.SearchSettings.ModifiedDateStart, libAstroGrep.FilterType.ValueOptions.LessThan, false, true));

            Core.SearchSettings.ModifiedDateStart = string.Empty;
             }

             if (!string.IsNullOrEmpty(Core.SearchSettings.ModifiedDateEnd))
             {
            filterItems.Add(new libAstroGrep.FilterItem(new libAstroGrep.FilterType(libAstroGrep.FilterType.Categories.File, libAstroGrep.FilterType.SubCategories.DateModified),
               Core.SearchSettings.ModifiedDateEnd, libAstroGrep.FilterType.ValueOptions.GreaterThan, false, true));

            Core.SearchSettings.ModifiedDateEnd = string.Empty;
             }

             // set filteritems list to new value
             if (filterItems.Count > 0)
             {
            Core.SearchSettings.FilterItems = libAstroGrep.FilterItem.ConvertFilterItemsToString(filterItems);
             }

             AstroGrep.Core.SearchSettings.Save();
        }