コード例 #1
0
        /// <summary>
        ///     Sets a value that indicates the filter component that is used to search for text within documents of this type.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo" /> that provides specifics of the extension to be changed.</param>
        /// <param name="persistentHandler">Guid of filter component.</param>
        protected void SetPersistentHandler(FileAssociationInfo file, Guid persistentHandler)
        {
            if (!file.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            if (persistentHandler == Guid.Empty)
            {
                return;
            }

            _registryWrapper.Write(file.Extension + "\\" + PersistentHandler, string.Empty, persistentHandler);

            ShellNotification.NotifyOfChange();
        }
コード例 #2
0
        /// <summary>
        ///     Sets a value that determines if the file's extension will always be shown.
        /// </summary>
        /// <param name="value">Value that specifies if the file's extension should be always displayed.</param>
        protected void SetAlwaysShowExt(bool value)
        {
            if (!Exists)
            {
                throw new Exception("Extension does not exist");
            }

            if (value)
            {
                _registryWrapper.Write(ProgId, "AlwaysShowExt", string.Empty);
            }
            else
            {
                _registryWrapper.Delete(ProgId, "AlwaysShowExt");
            }

            ShellNotification.NotifyOfChange();
        }
コード例 #3
0
        /// <summary>
        ///     Sets an array of <see cref="ProgramVerb" /> that define the verbs supported by this ProgID
        /// </summary>
        /// <param name="verbs">Array of <see cref="ProgramVerb" /> that contains verbs to be set.</param>
        protected void SetVerbs(ProgramVerb[] verbs)
        {
            if (!Exists)
            {
                throw new Exception("Extension does not exist");
            }

            var root = Registry.ClassesRoot;
            var key  = root.OpenSubKey(ProgId, true);

            if (key != null)
            {
                var tmpKey = key.OpenSubKey("shell", true);

                if (tmpKey != null)
                {
                    key.DeleteSubKeyTree("shell");
                }

                tmpKey = key.CreateSubKey("shell");
                foreach (var verb in verbs)
                {
                    if (tmpKey != null)
                    {
                        var newVerb = tmpKey.CreateSubKey(verb.Name.ToLower());
                        if (newVerb != null)
                        {
                            var command = newVerb.CreateSubKey("command");
                            if (command != null)
                            {
                                command.SetValue(string.Empty, verb.Command, RegistryValueKind.ExpandString);
                                command.Close();
                            }
                        }
                        if (newVerb != null)
                        {
                            newVerb.Close();
                        }
                    }
                }
            }

            ShellNotification.NotifyOfChange();
        }
コード例 #4
0
        /// <summary>
        ///     Adds single <see cref="ProgramVerb" /> that define the verb supported by this ProgID.
        /// </summary>
        /// <param name="verb">Single <see cref="ProgramVerb" /> that contains supported verb.</param>
        protected void AddVerbpublic(ProgramVerb verb)
        {
            var root       = Registry.ClassesRoot;
            var openSubKey = root.OpenSubKey(ProgId);

            if (openSubKey != null)
            {
                var key = openSubKey.OpenSubKey("shell", true);
                if (key == null)
                {
                    var registryKey = root.OpenSubKey(ProgId, true);
                    if (registryKey != null)
                    {
                        key = registryKey.CreateSubKey("shell");
                    }
                }

                if (key != null)
                {
                    var tmpkey = key.OpenSubKey(verb.Name, true) ?? key.CreateSubKey(verb.Name);
                    key = tmpkey;

                    if (key != null)
                    {
                        tmpkey = key.OpenSubKey("command", true) ?? key.CreateSubKey("command");
                        if (tmpkey != null)
                        {
                            tmpkey.Close();
                        }
                        key.Close();
                    }
                }
            }
            root.Close();

            ShellNotification.NotifyOfChange();
        }