/// <summary> /// Adds all default (e.g. builtin) plugins to the given list, /// in the default display order. /// </summary> /// <param name="plugins">List where to add plugins.</param> /// <param name="settings">Optional <see cref="UserSettings"/> /// used to fetch icon files if present.</param> private static void GetDefaultPlugins(List <Plugin> plugins, UserSettings settings) { Debug.Assert(plugins != null); Debug.Assert(settings != null); SeparatorPlugin separator = new SeparatorPlugin(); // This mimics the code in PathCopyCopyPluginsRegistry.cpp in the C++ project. plugins.Add(CreateDefaultPlugin(Resources.SHORT_NAME_PLUGIN_ID, Resources.SHORT_NAME_PLUGIN_DESCRIPTION, settings)); plugins.Add(CreateDefaultPlugin(Resources.LONG_NAME_PLUGIN_ID, Resources.LONG_NAME_PLUGIN_DESCRIPTION, settings)); plugins.Add(separator); plugins.Add(CreateDefaultPlugin(Resources.SHORT_PATH_PLUGIN_ID, Resources.SHORT_PATH_PLUGIN_DESCRIPTION, settings)); plugins.Add(CreateDefaultPlugin(Resources.LONG_PATH_PLUGIN_ID, Resources.LONG_PATH_PLUGIN_DESCRIPTION, settings)); plugins.Add(separator); plugins.Add(CreateDefaultPlugin(Resources.SHORT_FOLDER_PLUGIN_ID, Resources.SHORT_FOLDER_PLUGIN_DESCRIPTION, settings)); plugins.Add(CreateDefaultPlugin(Resources.LONG_FOLDER_PLUGIN_ID, Resources.LONG_FOLDER_PLUGIN_DESCRIPTION, settings)); plugins.Add(separator); plugins.Add(CreateDefaultPlugin(Resources.SHORT_UNC_PATH_PLUGIN_ID, Resources.SHORT_UNC_PATH_PLUGIN_DESCRIPTION, settings)); plugins.Add(CreateDefaultPlugin(Resources.LONG_UNC_PATH_PLUGIN_ID, Resources.LONG_UNC_PATH_PLUGIN_DESCRIPTION, settings)); plugins.Add(separator); plugins.Add(CreateDefaultPlugin(Resources.SHORT_UNC_FOLDER_PATH_PLUGIN_ID, Resources.SHORT_UNC_FOLDER_PATH_PLUGIN_DESCRIPTION, settings)); plugins.Add(CreateDefaultPlugin(Resources.LONG_UNC_FOLDER_PATH_PLUGIN_ID, Resources.LONG_UNC_FOLDER_PATH_PLUGIN_DESCRIPTION, settings)); plugins.Add(separator); plugins.Add(CreateDefaultPlugin(Resources.INTERNET_PATH_PLUGIN_ID, Resources.INTERNET_PATH_PLUGIN_DESCRIPTION, settings)); plugins.Add(separator); plugins.Add(CreateDefaultPlugin(Resources.UNIX_PATH_PLUGIN_ID, Resources.UNIX_PATH_PLUGIN_DESCRIPTION, settings)); plugins.Add(CreateDefaultPlugin(Resources.CYGWIN_PATH_PLUGIN_ID, Resources.CYGWIN_PATH_PLUGIN_DESCRIPTION, settings)); }
/// <summary> /// Adds all COM plugins to the given list in the proper display order. /// </summary> /// <param name="plugins">List where to add plugins.</param> private static void GetCOMPlugins(List <Plugin> plugins) { Debug.Assert(plugins != null); List <COMPluginInfo> comPluginInfos = new List <COMPluginInfo>(); SeparatorPlugin separator = new SeparatorPlugin(); // Get path to the registry keys that contain the COM plugins. // If we're called by a 32-bit extension running under WOW64 we'll need to adjust. List <COMPluginsRegKeyInfo> regKeyInfos = new List <COMPluginsRegKeyInfo>(); regKeyInfos.Add(new COMPluginsRegKeyInfo { Global = true, KeyPath = (!PCCEnvironment.Is64Bit && PCCEnvironment.IsWow64) ? PCC_COM_PLUGINS_KEY_WOW64 : PCC_COM_PLUGINS_KEY }); regKeyInfos.Add(new COMPluginsRegKeyInfo { Global = false, KeyPath = PCC_COM_PLUGINS_KEY }); // Create executor to be able to fetch info for COM plugins. COMPluginExecutor executor = new COMPluginExecutor(); // Scan each registry key in turn. foreach (COMPluginsRegKeyInfo regKeyInfo in regKeyInfos) { try { using (RegistryKey pluginsKey = regKeyInfo.Root.OpenSubKey(regKeyInfo.KeyPath)) { if (pluginsKey != null) { // Key exists and user has access, scan for plugins. // Get names of all values. Each name is a plugin ID except for the marker. string[] ids = pluginsKey.GetValueNames(); foreach (string id in ids) { // Try converting this ID to a Guid. Note that there are other values // in that key so if it fails, simply skip it. Guid?idAsGuid = null; try { if (id != LEGACY_COM_PLUGINS_LAST_UPDATE_VALUE_NAME) { idAsGuid = new Guid(id); } } catch (FormatException) { idAsGuid = null; } catch (OverflowException) { idAsGuid = null; } if (idAsGuid != null) { // Fetch plugin infos using executor. string description = null; int groupId = 0; int groupPosition = 0; string iconFile = null; try { description = executor.GetDescription(idAsGuid.Value); groupId = executor.GetGroupId(idAsGuid.Value); groupPosition = executor.GetGroupPosition(idAsGuid.Value); if (executor.GetUseDefaultIcon(idAsGuid.Value)) { iconFile = String.Empty; } else { iconFile = executor.GetIconFile(idAsGuid.Value); if (String.IsNullOrEmpty(iconFile)) { // No icon file specified, assume no icon. iconFile = null; } } } catch (COMPluginExecutorException) { // Failed to fetch information, skip this plugin. idAsGuid = null; } if (idAsGuid != null) { // Construct bean for this plugin and add it to the list. comPluginInfos.Add(new COMPluginInfo { Plugin = new COMPlugin(idAsGuid.Value, description, iconFile, regKeyInfo.Global), GroupId = groupId, GroupPosition = groupPosition, }); } } } } } } catch (SecurityException) { // User does not have access to that key, skip. } catch (ObjectDisposedException) { // There's something seriously wrong with the .NET framework, but hey. } } // Sort list of COM plugins by IDs and remove duplicates, since a plugin might be // registered both globally and for the current user. if (comPluginInfos.Count > 1) { comPluginInfos.Sort(delegate(COMPluginInfo info1, COMPluginInfo info2) { return(info1.Plugin.Id.CompareTo(info2.Plugin.Id)); }); for (int i = comPluginInfos.Count - 1; i > 0; --i) { if (comPluginInfos[i].Plugin.Id.Equals(comPluginInfos[i - 1].Plugin.Id)) { comPluginInfos.RemoveAt(i); } } } // Now sort list of COM plugins first by group ID then by group position. comPluginInfos.Sort(delegate(COMPluginInfo info1, COMPluginInfo info2) { int cmp = info1.GroupId - info2.GroupId; if (cmp == 0) { cmp = info1.GroupPosition - info2.GroupPosition; } return(cmp); }); // Copy all plugins to provided list. Insert a separator between groups. if (comPluginInfos.Count > 0) { int currentGroup = Int32.MaxValue; foreach (var info in comPluginInfos) { if (plugins.Count > 0 && currentGroup != info.GroupId) { plugins.Add(separator); } plugins.Add(info.Plugin); currentGroup = info.GroupId; } } }