From b648204bc753ef5098f50b6d7342d03d2fc6f3a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E7=82=B9lilac?= Date: Sat, 26 Dec 2020 12:36:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9D=80=E8=BD=AF=E4=BF=9D?= =?UTF-8?q?=E6=8A=A4=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BulePointLilac.Methods/RegistryEx.cs | 4 +- ContextMenuManager/Controls/ShellExItem.cs | 22 ++++++-- ContextMenuManager/Controls/ShellItem.cs | 51 ++++++++++++------- 3 files changed, 54 insertions(+), 23 deletions(-) diff --git a/ContextMenuManager/BulePointLilac.Methods/RegistryEx.cs b/ContextMenuManager/BulePointLilac.Methods/RegistryEx.cs index f21a737..782b07f 100644 --- a/ContextMenuManager/BulePointLilac.Methods/RegistryEx.cs +++ b/ContextMenuManager/BulePointLilac.Methods/RegistryEx.cs @@ -34,13 +34,13 @@ namespace BulePointLilac.Methods public static void MoveTo(this RegistryKey srcKey, RegistryKey dstKey) { CopyTo(srcKey, dstKey); - DeleteKeyTree(srcKey.Name); + DeleteKeyTree(srcKey.Name, true); } public static void MoveTo(string srcPath, string dstPath) { CopyTo(srcPath, dstPath); - DeleteKeyTree(srcPath); + DeleteKeyTree(srcPath, true); } public static RegistryKey CreateSubKey(this RegistryKey key, string subKeyName, bool writable) diff --git a/ContextMenuManager/Controls/ShellExItem.cs b/ContextMenuManager/Controls/ShellExItem.cs index 5dc3498..421fdba 100644 --- a/ContextMenuManager/Controls/ShellExItem.cs +++ b/ContextMenuManager/Controls/ShellExItem.cs @@ -77,7 +77,15 @@ namespace ContextMenuManager.Controls set { if(!value && TryProtectOpenItem) return; - RegistryEx.MoveTo(RegPath, BackupPath); + try + { + RegistryEx.MoveTo(RegPath, BackupPath); + } + catch + { + MessageBoxEx.Show(AppString.MessageBox.AuthorityProtection); + return; + } RegPath = BackupPath; } } @@ -234,8 +242,16 @@ namespace ContextMenuManager.Controls public void DeleteMe() { - RegistryEx.DeleteKeyTree(this.RegPath); - RegistryEx.DeleteKeyTree(this.BackupPath); + try + { + RegistryEx.DeleteKeyTree(this.RegPath, true); + RegistryEx.DeleteKeyTree(this.BackupPath, true); + } + catch + { + MessageBoxEx.Show(AppString.MessageBox.AuthorityProtection); + return; + } this.Dispose(); } } diff --git a/ContextMenuManager/Controls/ShellItem.cs b/ContextMenuManager/Controls/ShellItem.cs index cfb5101..925e8c2 100644 --- a/ContextMenuManager/Controls/ShellItem.cs +++ b/ContextMenuManager/Controls/ShellItem.cs @@ -222,30 +222,37 @@ namespace ContextMenuManager.Controls } set { - if(value) + try { - RegistryEx.DeleteValue(RegPath, "CommandFlags"); - RegistryEx.DeleteValue(RegPath, "HideBasedOnVelocityId"); - RegistryEx.DeleteValue(RegPath, "LegacyDisable"); - RegistryEx.DeleteValue(RegPath, "ProgrammaticAccessOnly"); - } - else - { - if(TryProtectOpenItem) return; - if(!IsSubItem) + if(value) { - Registry.SetValue(RegPath, "LegacyDisable", string.Empty); - Registry.SetValue(RegPath, "ProgrammaticAccessOnly", string.Empty); - } - else if(WindowsOsVersion.IsAfterOrEqualWin10_1703) - { - Registry.SetValue(RegPath, "HideBasedOnVelocityId", 0x639bc8); + RegistryEx.DeleteValue(RegPath, "CommandFlags"); + RegistryEx.DeleteValue(RegPath, "HideBasedOnVelocityId"); + RegistryEx.DeleteValue(RegPath, "LegacyDisable"); + RegistryEx.DeleteValue(RegPath, "ProgrammaticAccessOnly"); } else { - MessageBoxEx.Show(AppString.MessageBox.CannotHideSubItem); + if(TryProtectOpenItem) return; + if(!IsSubItem) + { + Registry.SetValue(RegPath, "LegacyDisable", string.Empty); + Registry.SetValue(RegPath, "ProgrammaticAccessOnly", string.Empty); + } + else if(WindowsOsVersion.IsAfterOrEqualWin10_1703) + { + Registry.SetValue(RegPath, "HideBasedOnVelocityId", 0x639bc8); + } + else + { + MessageBoxEx.Show(AppString.MessageBox.CannotHideSubItem); + } } } + catch + { + MessageBoxEx.Show(AppString.MessageBox.AuthorityProtection); + } } } @@ -505,7 +512,15 @@ namespace ContextMenuManager.Controls public virtual void DeleteMe() { - RegistryEx.DeleteKeyTree(this.RegPath); + try + { + RegistryEx.DeleteKeyTree(this.RegPath, true); + } + catch + { + MessageBoxEx.Show(AppString.MessageBox.AuthorityProtection); + return; + } this.Dispose(); } }