Ejemplo n.º 1
0
        /// <summary>
        /// Create or overwrite a current file association for this FileAssociator's set extension.
        /// </summary>
        /// <param name="progID">The basic application name that uses this file extension.</param>
        /// <param name="description">The desription of this file extension and/or program that uses it.</param>
        /// <param name="defaultIcon">The icon to show on the program and it's files.</param>
        /// <param name="execApp">The application that will be run when the file extension is clicked.</param>
        /// <param name="openWith">The programs that appear in the OpenWith list.</param>
        /// <exception cref="Exception">Thrown when an error occurs that will prevent it from working correctly.</exception>
        public void Create(string progID, string description, ProgramIcon defaultIcon, ExecApplication execApp, OpenWithList openWith)
        {
            if (progID != null)
            {
                if (defaultIcon.IsValid && execApp.IsValid)
                {
                    Registry.ClassesRoot.CreateSubKey(Extension).SetValue("", progID);
                    RegistryKey key = Registry.ClassesRoot.CreateSubKey(progID,
                                                                        RegistryKeyPermissionCheck.ReadWriteSubTree);

                    if (description != null)
                    {
                        key.SetValue("", description, RegistryValueKind.String);
                    }

                    if (defaultIcon != null && defaultIcon.IsValid)
                    {
                        key.CreateSubKey("DefaultIcon").SetValue("", defaultIcon.IconPath, RegistryValueKind.String);
                    }
                    else
                    {
                        throw new Exception("The default icon you entered is either null or doesn't exist...");
                    }

                    if (execApp != null && execApp.IsValid)
                    {
                        key.CreateSubKey(@"Shell\Open\Command").SetValue("", execApp.Path + " %1", RegistryValueKind.String);
                    }
                    else
                    {
                        throw new Exception("The executable application you entered is either null or not an .exe format...");
                    }

                    if (openWith != null)
                    {
                        key = key.CreateSubKey("OpenWithList", RegistryKeyPermissionCheck.ReadWriteSubTree);
                        foreach (string file in openWith.List)
                        {
                            key.CreateSubKey(file);
                        }
                    }

                    key.Flush();
                    key.Close();
                }
                else
                {
                    throw new Exception("Either the icon or executable application object is invalid...");
                }
            }
            else
            {
                throw new Exception("The program ID you entered is null...");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="icon"></param>
        protected void SetDefaultIcon(ProgramIcon icon)
        {
            if (!this.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            if (icon != ProgramIcon.None)
            {
                registryWrapper.Write(this.progId, "DefaultIcon", icon.ToString());

                ShellNotification.NotifyOfChange();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        protected ProgramIcon GetDefaultIcon()
        {
            if (!this.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            object val = registryWrapper.Read(this.progId + "\\DefaultIcon", "");

            if (val == null)
            {
                return(ProgramIcon.None);
            }

            return(ProgramIcon.Parse(val.ToString()));
        }
        /// <summary>
        /// Create or overwrite a current file association for this FileAssociator's set extension.
        /// </summary>
        /// <param name="progID">The basic application name that uses this file extension.</param>
        /// <param name="description">The desription of this file extension and/or program that uses it.</param>
        /// <param name="defaultIcon">The icon to show on the program and it's files.</param>
        /// <param name="execApp">The application that will be run when the file extension is clicked.</param>
        /// <param name="openWith">The programs that appear in the OpenWith list.</param>
        /// <exception cref="Exception">Thrown when an error occurs that will prevent it from working correctly.</exception>
        public void Create(string progID, string description, ProgramIcon defaultIcon, ExecApplication execApp, OpenWithList openWith)
        {
            if (progID != null)
            {
                if (defaultIcon.IsValid && execApp.IsValid)
                {
                    Registry.ClassesRoot.CreateSubKey(Extension).SetValue("", progID);
                    RegistryKey key = Registry.ClassesRoot.CreateSubKey(progID,
                        RegistryKeyPermissionCheck.ReadWriteSubTree);

                    if (description != null)
                        key.SetValue("", description, RegistryValueKind.String);

                    if (defaultIcon != null && defaultIcon.IsValid)
                        key.CreateSubKey("DefaultIcon").SetValue("", defaultIcon.IconPath, RegistryValueKind.String);
                    else
                        throw new Exception("The default icon you entered is either null or doesn't exist...");

                    if (execApp != null && execApp.IsValid)
                        key.CreateSubKey(@"Shell\Open\Command").SetValue("", execApp.Path + " %1", RegistryValueKind.String);
                    else
                        throw new Exception("The executable application you entered is either null or not an .exe format...");

                    if (openWith != null)
                    {
                        key = key.CreateSubKey("OpenWithList", RegistryKeyPermissionCheck.ReadWriteSubTree);
                        foreach (string file in openWith.List)
                        {
                            key.CreateSubKey(file);
                        }
                    }

                    key.Flush();
                    key.Close();
                }
                else
                {
                    throw new Exception("Either the icon or executable application object is invalid...");
                }
            }
            else
            {
                throw new Exception("The program ID you entered is null...");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="icon"></param>
        protected void SetDefaultIcon(ProgramIcon icon)
        {
            if (!Exists)
                throw new Exception("Extension does not exist");

            if (icon != ProgramIcon.None)
            {
                registryWrapper.Write(progId, "DefaultIcon", icon.ToString());

                ShellNotification.NotifyOfChange();
            }
        }