/// <summary> /// Main method to use the form. Will show the form as a modal dialog, /// allowing the user to edit the given pipeline plugin. When the user /// is done, the method will return the new <see cref="PipelinePluginInfo"/> /// if the user accepted the changes. /// </summary> /// <param name="owner">Owner of this dialog. Can be <c>null</c>.</param> /// <param name="oldInfo">Info about a pipeline plugin. If set, we'll /// populate the form with the plugin's values to allow the user to /// edit the plugin.</param> /// <param name="switchToExpert">Upon exit, will indicate whether user /// chose to switch to Expert Mode.</param> /// <returns>Info about the new plugin that user edited. Will be /// <c>null</c> if user cancels editing.</returns> public PipelinePluginInfo EditPlugin(IWin32Window owner, PipelinePluginInfo oldInfo, out bool switchToExpert) { // Save old info so that the OnLoad event handler can use it. oldPluginInfo = oldInfo; // If a plugin info was specified, decode its pipeline immediately. // We want pipeline exceptions to propagate out *before* we show the form. if (oldPluginInfo != null) { oldPipeline = PipelineDecoder.DecodePipeline(oldPluginInfo.EncodedElements); } // Save plugin ID, or generate a new one if this is a new plugin. if (oldPluginInfo != null) { pluginId = oldPluginInfo.Id; } else { pluginId = Guid.NewGuid(); } // Show the form and check result. DialogResult dialogRes = ShowDialog(owner); // If user saved, return the new info. Debug.Assert(dialogRes == DialogResult.Cancel || newPluginInfo != null); switchToExpert = dialogRes == DialogResult.Retry; return(dialogRes != DialogResult.Cancel ? newPluginInfo : null); }
/// <summary> /// Loads the list of pipeline plugins stored in the given registry key. /// Does not check the display order. /// </summary> /// <param name="regKey">Registry key from which to load plugins.</param> /// <param name="pipelinePlugins">Where to store the pipeline plugins /// loaded.</param> /// <param name="isGlobal">Whether this is the global key we're parsing.</param> private void LoadPipelinePluginsFromKey(RegistryKey regKey, List <PipelinePluginInfo> pipelinePlugins, bool isGlobal) { Debug.Assert(regKey != null); Debug.Assert(pipelinePlugins != null); // Plugins are stored as subkeys of the registry key. string[] pluginKeyNames = regKey.GetSubKeyNames(); foreach (string idAsString in pluginKeyNames) { // Convert this ID to a guid and make sure it works. try { Guid id = new Guid(idAsString); // Open the subkey and read values for the description, // encoded elements, icon file and required version. string description, encodedElements, iconFile, minVersionAsString; using (RegistryKey subKey = regKey.OpenSubKey(idAsString, false)) { description = (string)subKey.GetValue(PIPELINE_PLUGIN_DESCRIPTION_VALUE_NAME); iconFile = (string)subKey.GetValue(PIPELINE_PLUGIN_ICON_VALUE_NAME); minVersionAsString = (string)subKey.GetValue(PIPELINE_PLUGIN_REQUIRED_VERSION_VALUE_NAME); encodedElements = (string)subKey.GetValue(null); } // If we don't have min version in the registry, try to compute it now. Version minVersion; if (minVersionAsString != null) { minVersion = new Version(minVersionAsString); } else { try { Pipeline pipeline = PipelineDecoder.DecodePipeline(encodedElements); minVersion = pipeline.RequiredVersion; } catch (InvalidPipelineException) { // The encoded elements for this pipeline plugin is either invalid // or from a more recent version which we don't know of for some reason. // We can't do much, we'll have to pass null to the constructor below. minVersion = null; } } // If we made it here we have the plugin info, add it to the list. pipelinePlugins.Add(new PipelinePluginInfo(id, description, encodedElements, iconFile, isGlobal, minVersion)); } catch (FormatException) { } catch (OverflowException) { } } }
/// <summary> /// Private constructor called via <see cref="EditPlugin"/>. /// </summary> /// <param name="owner">Owner to use for new forms. Can be <c>null</c>.</param> /// <param name="oldInfo">Info about pipeline plugin to edit. If <c>null</c>, /// a new pipeline plugin will be edited.</param> private PipelinePluginEditor(IWin32Window owner, PipelinePluginInfo oldInfo) { // Save owner for any form we create. this.owner = owner; // Save old plugin info if we have one. pluginInfo = oldInfo; // If a plugin info was specified, decode its pipeline immediately. // We want pipeline exceptions to propagate out *before* we show a form. if (pluginInfo != null) { pipeline = PipelineDecoder.DecodePipeline(pluginInfo.EncodedElements); } }
/// <summary> /// Main method to use the form. Will show the form as a modal dialog, /// allowing the user to edit the given pipeline plugin. When the user /// is done, the method will return the new <see cref="PipelinePluginInfo"/> /// if the user accepted the changes. /// </summary> /// <param name="owner">Owner of this dialog. Can be <c>null</c>.</param> /// <param name="settings">Object to access user settings. If <c>null</c>, /// a new <see cref="UserSettings"/> object will be created.</param> /// <param name="oldInfo">Info about a pipeline plugin. If set, we'll /// populate the form with the plugin's values to allow the user to /// edit the plugin.</param> /// <returns>Info about the new plugin that user edited. Will be /// <c>null</c> if user cancels editing.</returns> public PipelinePluginInfo EditPlugin(IWin32Window owner, UserSettings settings, PipelinePluginInfo oldInfo) { // Save settings object or create one if we didn't get one. this.settings = settings ?? new UserSettings(); // Save old info so that the OnLoad event handler can use it. pluginInfo = oldInfo; // If a plugin info was specified, decode its pipeline immediately. // We want pipeline exceptions to propagate out *before* we show the form. if (pluginInfo != null) { pipeline = PipelineDecoder.DecodePipeline(pluginInfo.EncodedElements); } // Show the form and check result. DialogResult dialogRes = ShowDialog(owner); // If user saved, return the new info. Debug.Assert(dialogRes != DialogResult.OK || pluginInfo != null); return(dialogRes == DialogResult.OK ? pluginInfo : null); }