Ejemplo n.º 1
0
        private void LoadSettings()
        {
            CheckIfAdmin();
            if (!IsAdministrator)
            {
                WindowsIntegrationTooltip  = "To set shell integration run dnGREP with elevated privileges.";
                StartupAccelerationTooltip = "To enable startup acceleration run dnGREP with elevated privileges.";
                PanelTooltip = "To change shell integration and startup acceleration options run dnGREP with elevated privileges.";
            }
            else
            {
                WindowsIntegrationTooltip  = "Shell integration enables running an application from shell context menu.";
                StartupAccelerationTooltip = "Startup acceleration loads application libraries on machine start to improve application startup time.";
                PanelTooltip = "Shell integration enables running an application from shell context menu.";
            }
            EnableWindowsIntegration         = IsShellRegistered("Directory");
            EnableStartupAcceleration        = IsStartupRegistered();
            EnableCheckForUpdates            = Settings.Get <bool>(GrepSettings.Key.EnableUpdateChecking);
            CheckForUpdatesInterval          = Settings.Get <int>(GrepSettings.Key.UpdateCheckInterval);
            CustomEditorPath                 = Settings.Get <string>(GrepSettings.Key.CustomEditor);
            CustomEditorArgs                 = Settings.Get <string>(GrepSettings.Key.CustomEditorArgs);
            CompareApplicationPath           = Settings.Get <string>(GrepSettings.Key.CompareApplication);
            CompareApplicationArgs           = Settings.Get <string>(GrepSettings.Key.CompareApplicationArgs);
            ShowFilePathInResults            = Settings.Get <bool>(GrepSettings.Key.ShowFilePathInResults);
            AllowSearchWithEmptyPattern      = Settings.Get <bool>(GrepSettings.Key.AllowSearchingForFileNamePattern);
            DetectEncodingForFileNamePattern = Settings.Get <bool>(GrepSettings.Key.DetectEncodingForFileNamePattern);
            AutoExpandSearchTree             = Settings.Get <bool>(GrepSettings.Key.ExpandResults);
            ShowVerboseMatchCount            = Settings.Get <bool>(GrepSettings.Key.ShowVerboseMatchCount);
            ShowFileInfoTooltips             = Settings.Get <bool>(GrepSettings.Key.ShowFileInfoTooltips);
            MatchTimeout          = Settings.Get <double>(GrepSettings.Key.MatchTimeout);
            MatchThreshold        = Settings.Get <double>(GrepSettings.Key.FuzzyMatchThreshold);
            ShowLinesInContext    = Settings.Get <bool>(GrepSettings.Key.ShowLinesInContext);
            ContextLinesBefore    = Settings.Get <int>(GrepSettings.Key.ContextLinesBefore);
            ContextLinesAfter     = Settings.Get <int>(GrepSettings.Key.ContextLinesAfter);
            MaxSearchBookmarks    = Settings.Get <int>(GrepSettings.Key.MaxSearchBookmarks);
            MaxPathBookmarks      = Settings.Get <int>(GrepSettings.Key.MaxPathBookmarks);
            MaxExtensionBookmarks = Settings.Get <int>(GrepSettings.Key.MaxExtensionBookmarks);
            OptionsLocation       = Settings.Get <bool>(GrepSettings.Key.OptionsOnMainPanel) ?
                                    PanelSelection.MainPanel : PanelSelection.OptionsExpander;

            UseDefaultFont        = Settings.Get <bool>(GrepSettings.Key.UseDefaultFont);
            ApplicationFontFamily = EditApplicationFontFamily =
                ValueOrDefault(GrepSettings.Key.ApplicationFontFamily, SystemFonts.MessageFontFamily.Source);
            MainFormFontSize = EditMainFormFontSize =
                ValueOrDefault(GrepSettings.Key.MainFormFontSize, SystemFonts.MessageFontSize);
            ReplaceFormFontSize = EditReplaceFormFontSize =
                ValueOrDefault(GrepSettings.Key.ReplaceFormFontSize, SystemFonts.MessageFontSize);
            DialogFontSize = EditDialogFontSize =
                ValueOrDefault(GrepSettings.Key.DialogFontSize, SystemFonts.MessageFontSize);

            // current values may not equal the saved settings value
            CurrentTheme       = AppTheme.Instance.CurrentThemeName;
            FollowWindowsTheme = AppTheme.Instance.FollowWindowsTheme;


            {
                string nameKey = "Archive";
                string addKey  = "Add" + nameKey + "Extensions";
                string remKey  = "Rem" + nameKey + "Extensions";

                string addCsv = string.Empty;
                if (GrepSettings.Instance.ContainsKey(addKey))
                {
                    addCsv = GrepSettings.Instance.Get <string>(addKey).Trim();
                }

                string remCsv = string.Empty;
                if (GrepSettings.Instance.ContainsKey(remKey))
                {
                    remCsv = GrepSettings.Instance.Get <string>(remKey).Trim();
                }

                ArchiveOptions = new PluginOptions("Archive", true,
                                                   string.Join(", ", ArchiveDirectory.DefaultExtensions), addCsv, remCsv);
            }

            Plugins.Clear();
            foreach (var plugin in GrepEngineFactory.AllPlugins.OrderBy(p => p.Name))
            {
                string nameKey    = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(plugin.Name);
                string enabledkey = nameKey + "Enabled";
                string addKey     = "Add" + nameKey + "Extensions";
                string remKey     = "Rem" + nameKey + "Extensions";

                bool isEnabled = true;
                if (GrepSettings.Instance.ContainsKey(enabledkey))
                {
                    isEnabled = GrepSettings.Instance.Get <bool>(enabledkey);
                }

                string addCsv = string.Empty;
                if (GrepSettings.Instance.ContainsKey(addKey))
                {
                    addCsv = GrepSettings.Instance.Get <string>(addKey).Trim();
                }

                string remCsv = string.Empty;
                if (GrepSettings.Instance.ContainsKey(remKey))
                {
                    remCsv = GrepSettings.Instance.Get <string>(remKey).Trim();
                }

                var pluginOptions = new PluginOptions(
                    plugin.Name, isEnabled, string.Join(", ", plugin.DefaultExtensions), addCsv, remCsv);
                Plugins.Add(pluginOptions);
            }
        }
Ejemplo n.º 2
0
 public void UnloadAllPlugins()
 {
     DeactivateAllPlugins();
     Plugins.Clear();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes this instance and all the plugins.
        /// </summary>
        internal static void Initialize()
        {
            Main.Log.AppendLine("Loading plugins.");

            string pluginPath = "";

            {
                var v = Main.Config.GetValue(Main._Config_Plugin_Path);
                if (v != null)
                {
                    pluginPath = v.ToString();
                }
            }

            Main.Log.AppendLine("Path to plugins: \"" + pluginPath + "\".");

            DirectoryInfo dir = new DirectoryInfo(pluginPath);

            if (!dir.Exists)
            {
                Main.Log.AppendLine("Directory \"" + pluginPath + "\" does not exist.");
            }
            else
            {
                Dictionary <string, Plugin> plugins = new Dictionary <string, Plugin>(StringComparer.OrdinalIgnoreCase);
                FileInfo[] files = dir.GetFiles("*.dll", SearchOption.TopDirectoryOnly);
                foreach (var f in files)
                {
                    // Process all files.
                    try
                    {
                        ProcessFile(f, plugins);
                    }
                    catch (Exception e)
                    {
                        Main.Log.Append(e);
                    }
                }

                List <KeyValuePair <string, Plugin> > loadedOrder = new List <KeyValuePair <string, Plugin> >();
                var processing = plugins.ToList();
                foreach (var x in plugins)
                {
                    Plugins.Add(x);
                }

                Main._is_initializing_plugin++;

                bool lastLoaded = true;
                while (processing.Count != 0)
                {
                    bool nowLoaded = false;
                    for (int i = 0; i < processing.Count;)
                    {
                        var p = processing[i];
                        int r;
                        Main._is_initializing_plugin++;
                        try
                        {
                            r = p.Value._initialize(lastLoaded) ? 1 : 0;
                        }
                        catch (FileNotFoundException ex)
                        {
                            r = -1;
                            Main.Log.AppendLine("Exception occurred while trying to initialize plugin " + p.Value.GetInternalString() + ":");
                            Main.Log.Append(ex);
                            if (ex.Message != null && ex.Message.Contains("'NetScriptFramework.Skyrim,"))
                            {
                                //Main.Log.AppendLine("This exception appears to be due to plugin " + p.Value.GetInternalString() + " using old format of the framework! This plugin must be updated before it can be used.");
                                throw new ArgumentException("Plugin " + p.Value.GetInternalString() + " is using old format of framework and must be updated!");
                            }
                            throw;
                        }
                        catch (Exception ex)
                        {
                            r = -1;
                            Main.Log.AppendLine("Exception occurred while trying to initialize plugin " + p.Value.GetInternalString() + ":");
                            Main.Log.Append(ex);
                            throw;
                        }
                        Main._is_initializing_plugin--;
                        if (r > 0)
                        {
                            processing.RemoveAt(i);
                            nowLoaded = true;
                            loadedOrder.Add(p);
                        }
                        else if (r < 0)
                        {
                            processing.RemoveAt(i);
                            nowLoaded = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if (!nowLoaded && !lastLoaded)
                    {
                        StringBuilder str = new StringBuilder();
                        for (int i = 0; i < processing.Count; i++)
                        {
                            if (i > 0)
                            {
                                str.Append(", ");
                            }
                            str.Append(processing[i].Value.GetInternalString());
                        }

                        if (processing.Count == 1)
                        {
                            throw new InvalidOperationException("The following plugin refused to initialize: " + str.ToString());
                        }
                        throw new InvalidOperationException("All the following plugins refused to initialize: " + str.ToString());
                    }

                    lastLoaded = nowLoaded;
                }

                Main._is_initializing_plugin--;

                Plugins.Clear();
                Plugins.AddRange(loadedOrder);
            }

            Main.Log.AppendLine("Finished loading " + Plugins.Count + " plugin" + (Plugins.Count == 1 ? "" : "s") + ".");
        }