コード例 #1
0
ファイル: FileType.cs プロジェクト: modulexcite/0install-win
        /// <summary>
        /// Registers a <see cref="Store.Model.Capabilities.VerbCapability"/> in a registry key.
        /// </summary>
        /// <param name="registryKey">The registry key to write the new data to.</param>
        /// <param name="target">The application being integrated.</param>
        /// <param name="capability">The capability to register.</param>
        /// <param name="machineWide">Assume <paramref name="registryKey"/> is effective machine-wide instead of just for the current user.</param>
        /// <param name="handler">A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.</param>
        /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
        /// <exception cref="IOException">A problem occurs while writing to the filesystem or registry.</exception>
        /// <exception cref="WebException">A problem occured while downloading additional data (such as icons).</exception>
        /// <exception cref="UnauthorizedAccessException">Write access to the filesystem or registry is not permitted.</exception>
        /// <exception cref="InvalidDataException">The data in <paramref name="capability"/> is invalid.</exception>
        internal static void RegisterVerbCapability(RegistryKey registryKey, FeedTarget target, Store.Model.Capabilities.VerbCapability capability, bool machineWide, ITaskHandler handler)
        {
            #region Sanity checks
            if (capability == null) throw new ArgumentNullException("capability");
            if (handler == null) throw new ArgumentNullException("handler");
            #endregion

            if (capability is Store.Model.Capabilities.UrlProtocol) registryKey.SetValue(UrlProtocol.ProtocolIndicator, "");

            string description = capability.Descriptions.GetBestLanguage(CultureInfo.CurrentUICulture);
            if (description != null) registryKey.SetValue("", description);

            // Write verb command information
            using (var shellKey = registryKey.CreateSubKeyChecked("shell"))
            {
                foreach (var verb in capability.Verbs)
                {
                    using (var verbKey = shellKey.CreateSubKeyChecked(verb.Name))
                    {
                        string verbDescription = verb.Descriptions.GetBestLanguage(CultureInfo.CurrentUICulture);
                        if (verbDescription != null) verbKey.SetValue("", verbDescription);
                        if (verb.Extended) verbKey.SetValue(RegValueExtended, "");

                        using (var commandKey = verbKey.CreateSubKeyChecked("command"))
                            commandKey.SetValue("", GetLaunchCommandLine(target, verb, machineWide, handler));

                        // Prevent conflicts with existing entries
                        shellKey.DeleteSubKey("ddeexec", throwOnMissingSubKey: false);
                    }
                }
            }

            // Set specific icon if available, fall back to referencing the icon embedded in the stub EXE
            var icon = capability.GetIcon(Icon.MimeTypeIco) ?? target.Feed.GetIcon(Icon.MimeTypeIco);
            if (icon != null)
            {
                using (var iconKey = registryKey.CreateSubKeyChecked(RegSubKeyIcon))
                    iconKey.SetValue("", IconProvider.GetIconPath(icon, handler, machineWide) + ",0");
            }
        }