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

GetAppRegistration() public method

Retrieves data about registered applications.
There was an error accessing the registry. Read access to the registry was not permitted.
public GetAppRegistration ( [ commandMapper, [ capabilities, string &appName, string &appDescription ) : AppRegistration
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.
appDescription string Is set to a user-friendly description of the application; unchanged if the name was not found.
return AppRegistration
        public AppRegistration GetAppRegistration([NotNull] CommandMapper commandMapper, [NotNull] CapabilityList capabilities, ref string appName, ref string appDescription)
        {
            #region Sanity checks
            if (capabilities == null) throw new ArgumentNullException(nameof(capabilities));
            if (commandMapper == null) throw new ArgumentNullException(nameof(commandMapper));
            #endregion

            // Ambiguity warnings
            if (RegisteredApplications.Length == 0)
                return null;
            if (RegisteredApplications.Length > 1)
                Log.Warn(Resources.MultipleRegisteredAppsDetected);

            // Get registry path pointer
            string appRegName = RegisteredApplications[0];
            var capabilitiesRegPath = RegistryUtils.GetString(@"HKEY_LOCAL_MACHINE\" + DesktopIntegration.Windows.AppRegistration.RegKeyMachineRegisteredApplications, appRegName);
            if (string.IsNullOrEmpty(capabilitiesRegPath))
                return null;

            bool x64;
            using (var capsKey = RegistryUtils.OpenHklmKey(capabilitiesRegPath, out x64))
            {
                if (string.IsNullOrEmpty(appName)) appName = capsKey.GetValue(DesktopIntegration.Windows.AppRegistration.RegValueAppName, "").ToString();
                if (string.IsNullOrEmpty(appDescription)) appDescription = capsKey.GetValue(DesktopIntegration.Windows.AppRegistration.RegValueAppDescription, "").ToString();

                CollectProtocolAssocsEx(capsKey, commandMapper, capabilities);
                CollectFileAssocsEx(capsKey, capabilities);
                // Note: Contenders for StartMenu entries are detected elsewhere

                return new AppRegistration
                {
                    ID = appRegName,
                    CapabilityRegPath = capabilitiesRegPath
                };
            }
        }

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