Ejemplo n.º 1
0
        // Wipe the entries we use from the registry for the given extension
        // Do not use this for real extensions, it is intended only for cleaning up test extensions
        public static void Wipe(string ext)
        {
            if (Registry.ClassesRoot.GetSubKeyNames().Contains(ext))
            {
                Registry.ClassesRoot.DeleteSubKeyTree(ext);
            }

            using (RegistryKey assoc = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\SystemFileAssociations", true))
            {
                if (assoc.GetSubKeyNames().Contains(ext))
                {
                    assoc.DeleteSubKeyTree(ext);
                }
            }

            using (RegistryKey handlers = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\PropertySystem\PropertyHandlers", true))
            {
                if (handlers.GetSubKeyNames().Contains(ext))
                {
                    handlers.DeleteSubKeyTree(ext);
                }
            }

#if x64
            using (RegistryKey handlers = RegistryExtensions.OpenBaseKey(RegistryHive.LocalMachine, RegistryExtensions.RegistryHiveType.X86, true).
                                          OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\PropertySystem\PropertyHandlers", true))

            {
                if (handlers.GetSubKeyNames().Contains(ext))
                {
                    handlers.DeleteSubKeyTree(ext);
                }
            }
#endif
        }
Ejemplo n.º 2
0
        // Populate the state by reading the registry for the given extension
        public void Read(string ext)
        {
            using (RegistryKey target = GetHKCRProfileKey(ext))
            {
                if (target != null)
                {
                    ClsidFullDetails       = target.GetValue(Const.FullDetailsValueName) as string;
                    ClsidPreviewDetails    = target.GetValue(Const.PreviewDetailsValueName) as string;
                    ClsidInfoTip           = target.GetValue(Const.InfoTipValueName) as string;
                    ClsidOldFullDetails    = target.GetValue(Const.OldFullDetailsValueName) as string;
                    ClsidOldPreviewDetails = target.GetValue(Const.OldPreviewDetailsValueName) as string;
                    ClsidOldInfoTip        = target.GetValue(Const.OldInfoTipValueName) as string;
                    ClsidCustomProfile     = target.GetValue(Const.FileMetaCustomProfileValueName) as string;

                    using (RegistryKey keyHandler = target.OpenSubKey(Const.ContextMenuHandlersKeyName, false))
                    {
                        if (keyHandler != null)
                        {
                            ClsidContextMenuHandler = keyHandler.GetValue(null) as string;
                        }
                    }
                }
            }
            using (RegistryKey target = GetSystemFileAssociationsProfileKey(ext))
            {
                if (target != null)
                {
                    SystemFullDetails       = target.GetValue(Const.FullDetailsValueName) as string;
                    SystemPreviewDetails    = target.GetValue(Const.PreviewDetailsValueName) as string;
                    SystemInfoTip           = target.GetValue(Const.InfoTipValueName) as string;
                    SystemOldFullDetails    = target.GetValue(Const.OldFullDetailsValueName) as string;
                    SystemOldPreviewDetails = target.GetValue(Const.OldPreviewDetailsValueName) as string;
                    SystemOldInfoTip        = target.GetValue(Const.OldInfoTipValueName) as string;
                    SystemCustomProfile     = target.GetValue(Const.FileMetaCustomProfileValueName) as string;

                    using (RegistryKey keyHandler = target.OpenSubKey(Const.ContextMenuHandlersKeyName, false))
                    {
                        if (keyHandler != null)
                        {
                            SystemContextMenuHandler = keyHandler.GetValue(null) as string;
                        }
                    }
                }
            }
            using (RegistryKey handlers = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\PropertySystem\PropertyHandlers", false))
            {
                using (RegistryKey handler = handlers.OpenSubKey(ext, false))
                {
                    if (handler != null)
                    {
                        PropertyHandler        = handler.GetValue(null) as string;
                        ChainedPropertyHandler = handler.GetValue(Const.ChainedValueName) as string;
                    }
                }
            }
#if x64
            using (RegistryKey handlers = RegistryExtensions.OpenBaseKey(RegistryHive.LocalMachine, RegistryExtensions.RegistryHiveType.X86).
                                          OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\PropertySystem\PropertyHandlers", false))
            {
                using (RegistryKey handler = handlers.OpenSubKey(ext, false))
                {
                    if (handler != null)
                    {
                        PropertyHandler32        = handler.GetValue(null) as string;
                        ChainedPropertyHandler32 = handler.GetValue(Const.ChainedValueName) as string;
                    }
                }
            }
#endif
        }
Ejemplo n.º 3
0
        // Zap our state into the registry for the given extension
        // Do not use this for real extensions, it is intended only for setting up test extensions
        public void Zap(string ext)
        {
            using (RegistryKey target = GetHKCRProfileKey(ext, true))
            {
                SetOrDeleteValue(target, Const.FullDetailsValueName, ClsidFullDetails);
                SetOrDeleteValue(target, Const.PreviewDetailsValueName, ClsidPreviewDetails);
                SetOrDeleteValue(target, Const.InfoTipValueName, ClsidInfoTip);
                SetOrDeleteValue(target, Const.OldFullDetailsValueName, ClsidOldFullDetails);
                SetOrDeleteValue(target, Const.OldPreviewDetailsValueName, ClsidOldPreviewDetails);
                SetOrDeleteValue(target, Const.OldInfoTipValueName, ClsidOldInfoTip);
                SetOrDeleteValue(target, Const.FileMetaCustomProfileValueName, ClsidCustomProfile);

                if (ClsidContextMenuHandler != null)
                {
                    using (RegistryKey keyHandler = target.CreateSubKey(Const.ContextMenuHandlersKeyName))
                    {
                        keyHandler.SetValue(null, ClsidContextMenuHandler);
                    }
                }
                else
                {
                    target.DeleteSubKey(Const.ContextMenuHandlersKeyName, false);
                }
            }

            using (RegistryKey target = GetSystemFileAssociationsProfileKey(ext, true))
            {
                SetOrDeleteValue(target, Const.FullDetailsValueName, SystemFullDetails);
                SetOrDeleteValue(target, Const.PreviewDetailsValueName, SystemPreviewDetails);
                SetOrDeleteValue(target, Const.InfoTipValueName, SystemInfoTip);
                SetOrDeleteValue(target, Const.OldFullDetailsValueName, SystemOldFullDetails);
                SetOrDeleteValue(target, Const.OldPreviewDetailsValueName, SystemOldPreviewDetails);
                SetOrDeleteValue(target, Const.OldInfoTipValueName, SystemOldInfoTip);
                SetOrDeleteValue(target, Const.FileMetaCustomProfileValueName, SystemCustomProfile);

                if (SystemContextMenuHandler != null)
                {
                    using (RegistryKey keyHandler = target.CreateSubKey(Const.ContextMenuHandlersKeyName))
                    {
                        keyHandler.SetValue(null, SystemContextMenuHandler);
                    }
                }
                else
                {
                    target.DeleteSubKey(Const.ContextMenuHandlersKeyName, false);
                }
            }

            using (RegistryKey handlers = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\PropertySystem\PropertyHandlers", true))
            {
                if (PropertyHandler != null || ChainedPropertyHandler != null)
                {
                    using (RegistryKey handler = handlers.CreateSubKey(ext))
                    {
                        SetOrDeleteValue(handler, null, PropertyHandler);
                        SetOrDeleteValue(handler, Const.ChainedValueName, ChainedPropertyHandler);
                    }
                }
                else
                {
                    handlers.DeleteSubKey(ext, false);
                }
            }
#if x64
            using (RegistryKey handlers = RegistryExtensions.OpenBaseKey(RegistryHive.LocalMachine, RegistryExtensions.RegistryHiveType.X86, true).
                                          OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\PropertySystem\PropertyHandlers", true))
            {
                if (PropertyHandler32 != null || ChainedPropertyHandler32 != null)
                {
                    using (RegistryKey handler = handlers.CreateSubKey(ext))
                    {
                        SetOrDeleteValue(handler, null, PropertyHandler32);
                        SetOrDeleteValue(handler, Const.ChainedValueName, ChainedPropertyHandler32);
                    }
                }
                else
                {
                    handlers.DeleteSubKey(ext, false);
                }
            }
#endif
        }