Ejemplo n.º 1
0
    /// <summary>
    /// Registers a <see cref="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="iconStore">Stores icon files downloaded from the web as local files.</param>
    /// <param name="machineWide">Assume <paramref name="registryKey"/> is effective machine-wide instead of just for the current user.</param>
    /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
    /// <exception cref="IOException">A problem occurred while writing to the filesystem or registry.</exception>
    /// <exception cref="WebException">A problem occurred while downloading additional data (such as icons).</exception>
    /// <exception cref="UnauthorizedAccessException">Write access to the filesystem or registry is not permitted.</exception>
    public static void Register(RegistryKey registryKey, FeedTarget target, VerbCapability capability, IIconStore iconStore, bool machineWide)
    {
        #region Sanity checks
        if (capability == null)
        {
            throw new ArgumentNullException(nameof(capability));
        }
        if (iconStore == null)
        {
            throw new ArgumentNullException(nameof(iconStore));
        }
        #endregion

        if ((capability.GetIcon(Icon.MimeTypeIco) ?? target.Feed.Icons.GetIcon(Icon.MimeTypeIco)) is {} icon)
        {
            using var iconKey = registryKey.CreateSubKeyChecked("DefaultIcon");
            iconKey.SetValue("", iconStore.GetFresh(icon) + ",0");
        }

        foreach (var verb in capability.Verbs)
        {
            using var verbKey = registryKey.CreateSubKeyChecked($@"shell\{verb.Name}");
            Register(verbKey, target, verb, iconStore, machineWide);
        }

        // Prevent conflicts with existing entries
        registryKey.DeleteSubKeyTree(@"shell\ddeexec", throwOnMissingSubKey: false);
    }
Ejemplo n.º 2
0
        /// <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(nameof(capability));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(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");
            }
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Registers a <see cref="Verb"/> in a registry key.
    /// </summary>
    /// <param name="verbKey">The registry key to write the new data to.</param>
    /// <param name="target">The application being integrated.</param>
    /// <param name="verb">The verb to register.</param>
    /// <param name="iconStore">Stores icon files downloaded from the web as local files.</param>
    /// <param name="machineWide">Assume <paramref name="verbKey"/> is effective machine-wide instead of just for the current user.</param>
    /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
    /// <exception cref="IOException">A problem occurred while writing to the filesystem or registry.</exception>
    /// <exception cref="WebException">A problem occurred while downloading additional data (such as icons).</exception>
    /// <exception cref="UnauthorizedAccessException">Write access to the filesystem or registry is not permitted.</exception>
    public static void Register(RegistryKey verbKey, FeedTarget target, Verb verb, IIconStore iconStore, bool machineWide)
    {
        string?description = verb.Descriptions.GetBestLanguage(CultureInfo.CurrentUICulture);

        verbKey.SetOrDelete("", description);
        verbKey.SetOrDelete("MUIVerb", description);

        verbKey.SetOrDelete("MultiSelectModel", verb.SingleElementOnly ? "Single" : null);

        if (verb.Extended)
        {
            verbKey.SetValue("Extended", "");
        }
        else
        {
            verbKey.DeleteValue("Extended", throwOnMissingValue: false);
        }

        var icon = target.Feed.GetBestIcon(Icon.MimeTypeIco, verb.Command)
                   ?? target.Feed.Icons.GetIcon(Icon.MimeTypeIco);

        verbKey.SetOrDelete("Icon", icon?.To(iconStore.GetFresh));

        using var commandKey = verbKey.CreateSubKeyChecked("command");
        commandKey.SetValue("", GetLaunchCommandLine(target, verb, iconStore, machineWide));
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Registers a <see cref="Verb"/> in a registry key.
        /// </summary>
        /// <param name="verbKey">The registry key to write the new data to.</param>
        /// <param name="target">The application being integrated.</param>
        /// <param name="verb">The verb to register.</param>
        /// <param name="iconStore">Stores icon files downloaded from the web as local files.</param>
        /// <param name="machineWide">Assume <paramref name="verbKey"/> is effective machine-wide instead of just for the current user.</param>
        /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
        /// <exception cref="IOException">A problem occurred while writing to the filesystem or registry.</exception>
        /// <exception cref="WebException">A problem occurred 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="verb"/> is invalid.</exception>
        public static void Register(RegistryKey verbKey, FeedTarget target, Verb verb, IIconStore iconStore, bool machineWide)
        {
            string?description = verb.Descriptions.GetBestLanguage(CultureInfo.CurrentUICulture);

            if (!string.IsNullOrEmpty(description))
            {
                verbKey.SetValue("", description);
                verbKey.SetValue("MUIVerb", description);
            }

            if (verb.Extended)
            {
                verbKey.SetValue("Extended", "");
            }

            var icon = target.Feed.GetIcon(Icon.MimeTypeIco, verb.Command);

            if (icon != null)
            {
                verbKey.SetValue("Icon", iconStore.GetPath(icon));
            }

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