ZeroInstall.Publish.Capture.SnapshotDiff.CollectContextMenus C# (CSharp) Метод

CollectContextMenus() публичный Метод

Collects data about context menu entries.
There was an error accessing the registry. Read access to the registry was not permitted.
public CollectContextMenus ( [ commandMapper, [ capabilities ) : void
commandMapper [ Provides best-match command-line to mapping.
capabilities [ The capability list to add the collected data to.
Результат void
        public void CollectContextMenus([NotNull] CommandMapper commandMapper, [NotNull] CapabilityList capabilities)
        {
            #region Sanity checks
            if (capabilities == null) throw new ArgumentNullException(nameof(capabilities));
            if (commandMapper == null) throw new ArgumentNullException(nameof(commandMapper));
            #endregion

            using (var progIDKey = Registry.ClassesRoot.OpenSubKey(DesktopIntegration.Windows.ContextMenu.RegKeyClassesFiles))
            {
                if (progIDKey == null) throw new IOException("Registry key not found");
                foreach (string entry in ContextMenuFiles)
                {
                    capabilities.Entries.Add(new ContextMenu
                    {
                        ID = "files-" + entry,
                        Target = ContextMenuTarget.Files,
                        Verb = GetVerb(progIDKey, commandMapper, entry)
                    });
                }
            }

            using (var progIDKey = Registry.ClassesRoot.OpenSubKey(DesktopIntegration.Windows.ContextMenu.RegKeyClassesExecutableFiles[0]))
            {
                if (progIDKey == null) throw new IOException("Registry key not found");
                foreach (string entry in ContextMenuExecutableFiles)
                {
                    capabilities.Entries.Add(new ContextMenu
                    {
                        ID = "executable-files-" + entry,
                        Target = ContextMenuTarget.ExecutableFiles,
                        Verb = GetVerb(progIDKey, commandMapper, entry)
                    });
                }
            }

            using (var progIDKey = Registry.ClassesRoot.OpenSubKey(DesktopIntegration.Windows.ContextMenu.RegKeyClassesDirectories))
            {
                if (progIDKey == null) throw new IOException("Registry key not found");
                foreach (string entry in ContextMenuDirectories)
                {
                    capabilities.Entries.Add(new ContextMenu
                    {
                        ID = "directories-" + entry,
                        Target = ContextMenuTarget.Directories,
                        Verb = GetVerb(progIDKey, commandMapper, entry)
                    });
                }
            }

            using (var progIDKey = Registry.ClassesRoot.OpenSubKey(DesktopIntegration.Windows.ContextMenu.RegKeyClassesAll))
            {
                if (progIDKey == null) throw new IOException("Registry key not found");
                foreach (string entry in ContextMenuAll)
                {
                    capabilities.Entries.Add(new ContextMenu
                    {
                        ID = "all-" + entry,
                        Target = ContextMenuTarget.Directories,
                        Verb = GetVerb(progIDKey, commandMapper, entry)
                    });
                }
            }
        }
    }

Usage Example

Пример #1
0
        private static CapabilityList GetCapabilityList(CommandMapper commandMapper, SnapshotDiff diff)
        {
            var capabilities = new CapabilityList {
                OS = OS.Windows
            };
            string appName = null, appDescription = null;

            diff.CollectFileTypes(commandMapper, capabilities);
            diff.CollectContextMenus(commandMapper, capabilities);
            diff.CollectAutoPlays(commandMapper, capabilities);
            diff.CollectDefaultPrograms(commandMapper, capabilities, ref appName);

            var appRegistration = diff.GetAppRegistration(commandMapper, capabilities, ref appName, ref appDescription);

            if (appRegistration != null)
            {
                capabilities.Entries.Add(appRegistration);
            }
            else
            { // Only collect URL protocols if there wasn't already an application registration that covered them
                diff.CollectProtocolAssocs(commandMapper, capabilities);
            }

            return(capabilities);
        }
All Usage Examples Of ZeroInstall.Publish.Capture.SnapshotDiff::CollectContextMenus