ZeroInstall.Publish.Capture.SnapshotDiff.CollectDefaultPrograms C# (CSharp) Method

CollectDefaultPrograms() public method

Collects data about default programs.
There was an error accessing the registry. Read access to the registry was not permitted.
public CollectDefaultPrograms ( [ commandMapper, [ capabilities, string &appName ) : void
commandMapper [ Provides best-match command-line to mapping.
capabilities [ The capability list to add the collected data to.
appName string Is set to the name of the application as displayed to the user; unchanged if the name was not found.
return void
        public void CollectDefaultPrograms([NotNull] CommandMapper commandMapper, [NotNull] CapabilityList capabilities, ref string appName)
        {
            #region Sanity checks
            if (capabilities == null) throw new ArgumentNullException(nameof(capabilities));
            if (commandMapper == null) throw new ArgumentNullException(nameof(commandMapper));
            #endregion

            // Ambiguity warnings
            if (ServiceAssocs.Length > 1)
                Log.Warn(Resources.MultipleDefaultProgramsDetected);

            foreach (var serviceAssoc in ServiceAssocs)
            {
                string service = serviceAssoc.Key;
                string client = serviceAssoc.Value;

                using (var clientKey = Registry.LocalMachine.OpenSubKey(DesktopIntegration.Windows.DefaultProgram.RegKeyMachineClients + @"\" + service + @"\" + client))
                {
                    if (clientKey == null) continue;

                    if (string.IsNullOrEmpty(appName)) appName = clientKey.GetValue("", "").ToString();
                    if (string.IsNullOrEmpty(appName)) appName = clientKey.GetValue(DesktopIntegration.Windows.DefaultProgram.RegValueLocalizedName, "").ToString();

                    var defaultProgram = new DefaultProgram
                    {
                        ID = client,
                        Service = service
                    };
                    defaultProgram.Verbs.AddRange(GetVerbs(clientKey, commandMapper));
                    defaultProgram.InstallCommands = GetInstallCommands(clientKey, commandMapper.InstallationDir);
                    capabilities.Entries.Add(defaultProgram);
                }
            }
        }

Usage Example

        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::CollectDefaultPrograms