GetLaunchCommandLine() 정적인 개인적인 메소드

Generates a command-line string for launching a Store.Model.Capabilities.Verb.
A problem occurs while writing to the filesystem. A problem occured while downloading additional data (such as icons). Write access to the filesystem is not permitted.
static private GetLaunchCommandLine ( FeedTarget target, Store verb, bool machineWide, ITaskHandler handler ) : string
target ZeroInstall.Store.FeedTarget The application being integrated.
verb Store The verb to get to launch command for.
machineWide bool Store the stub in a machine-wide directory instead of just for the current user.
handler ITaskHandler A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.
리턴 string
예제 #1
0
        /// <summary>
        /// Adds a context menu entry to the current system.
        /// </summary>
        /// <param name="target">The application being integrated.</param>
        /// <param name="contextMenu">The context menu entry to add.</param>
        /// <param name="machineWide">Add the context menu entry 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="contextMenu"/> is invalid.</exception>
        public static void Apply(FeedTarget target, Store.Model.Capabilities.ContextMenu contextMenu, bool machineWide, ITaskHandler handler)
        {
            #region Sanity checks
            if (contextMenu == null)
            {
                throw new ArgumentNullException(nameof(contextMenu));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            #endregion

            if (contextMenu.Verb == null)
            {
                throw new InvalidDataException("Missing verb");
            }
            if (string.IsNullOrEmpty(contextMenu.Verb.Name))
            {
                throw new InvalidDataException("Missing verb name");
            }

            var hive = machineWide ? Registry.LocalMachine : Registry.CurrentUser;
            foreach (string keyName in GetKeyName(contextMenu.Target))
            {
                using (var verbKey = hive.CreateSubKeyChecked(FileType.RegKeyClasses + @"\" + keyName + @"\shell\" + RegKeyPrefix + contextMenu.Verb.Name))
                {
                    string description = contextMenu.Verb.Descriptions.GetBestLanguage(CultureInfo.CurrentUICulture);
                    if (description != null)
                    {
                        verbKey.SetValue("", description);
                    }
                    if (contextMenu.Verb.Extended)
                    {
                        verbKey.SetValue(FileType.RegValueExtended, "");
                    }

                    using (var commandKey = verbKey.CreateSubKeyChecked("command"))
                        commandKey.SetValue("", FileType.GetLaunchCommandLine(target, contextMenu.Verb, machineWide, handler));
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Adds an AutoPlay handler registration to the current system.
        /// </summary>
        /// <param name="target">The application being integrated.</param>
        /// <param name="autoPlay">The AutoPlay handler information to be applied.</param>
        /// <param name="machineWide">Register the handler 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>
        /// <param name="accessPoint">Indicates that the handler should become the default handler for all <see cref="Store.Model.Capabilities.AutoPlay.Events"/>.</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="autoPlay"/> is invalid.</exception>
        public static void Register(FeedTarget target, [NotNull] Store.Model.Capabilities.AutoPlay autoPlay, bool machineWide, [NotNull] ITaskHandler handler, bool accessPoint = false)
        {
            #region Sanity checks
            if (autoPlay == null)
            {
                throw new ArgumentNullException(nameof(autoPlay));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            #endregion

            if (string.IsNullOrEmpty(autoPlay.ID))
            {
                throw new InvalidDataException("Missing ID");
            }
            if (autoPlay.Verb == null)
            {
                throw new InvalidDataException("Missing verb");
            }
            if (string.IsNullOrEmpty(autoPlay.Verb.Name))
            {
                throw new InvalidDataException("Missing verb name");
            }
            if (string.IsNullOrEmpty(autoPlay.Provider))
            {
                throw new InvalidDataException("Missing provider");
            }

            var hive = machineWide ? Registry.LocalMachine : Registry.CurrentUser;

            using (var commandKey = hive.CreateSubKeyChecked(FileType.RegKeyClasses + @"\" + FileType.RegKeyPrefix + ".AutoPlay" + autoPlay.ID + @"\shell\" + autoPlay.Verb.Name + @"\command"))
                commandKey.SetValue("", FileType.GetLaunchCommandLine(target, autoPlay.Verb, machineWide, handler));

            using (var handlerKey = hive.CreateSubKeyChecked(RegKeyHandlers + @"\" + FileType.RegKeyPrefix + autoPlay.ID))
            {
                // Add flag to remember whether created for capability or access point
                handlerKey.SetValue(accessPoint ? FileType.PurposeFlagAccessPoint : FileType.PurposeFlagCapability, "");

                handlerKey.SetValue(RegValueProgID, FileType.RegKeyPrefix + ".AutoPlay" + autoPlay.ID);
                handlerKey.SetValue(RegValueVerb, autoPlay.Verb.Name);
                handlerKey.SetValue(RegValueProvider, autoPlay.Provider);
                handlerKey.SetValue(RegValueDescription, autoPlay.Descriptions.GetBestLanguage(CultureInfo.CurrentUICulture) ?? autoPlay.Verb.Name);

                var icon = autoPlay.GetIcon(Icon.MimeTypeIco) ?? target.Feed.GetIcon(Icon.MimeTypeIco, autoPlay.Verb.Command);
                if (icon != null)
                {
                    handlerKey.SetValue(RegValueIcon, IconProvider.GetIconPath(icon, handler, machineWide) + ",0");
                }
            }

            foreach (var autoPlayEvent in autoPlay.Events.Except(x => string.IsNullOrEmpty(x.Name)))
            {
                using (var eventKey = hive.CreateSubKeyChecked(RegKeyAssocs + @"\" + autoPlayEvent.Name))
                    eventKey.SetValue(FileType.RegKeyPrefix + autoPlay.ID, "");

                if (accessPoint)
                {
                    using (var chosenEventKey = hive.CreateSubKeyChecked(RegKeyChosenAssocs + @"\" + autoPlayEvent.Name))
                        chosenEventKey.SetValue("", FileType.RegKeyPrefix + autoPlay.ID);
                }
            }
        }