Pārlūkot izejas kodu

优化部分代码

蓝点lilac 4 gadi atpakaļ
vecāks
revīzija
9a754148f3

+ 1 - 2
ContextMenuManager/BluePointLilac.Controls/MyStatusBar.cs

@@ -1,5 +1,4 @@
 using BluePointLilac.Methods;
-using System;
 using System.Drawing;
 using System.Windows.Forms;
 
@@ -7,7 +6,7 @@ namespace BluePointLilac.Controls
 {
     public sealed class MyStatusBar : Panel
     {
-        public static readonly string DefaultText = $"Ver: {new Version(Application.ProductVersion).ToString(2)}    {Application.CompanyName}";
+        public static readonly string DefaultText = $"Ver: {Application.ProductVersion}    {Application.CompanyName}";
 
         public MyStatusBar()
         {

+ 23 - 0
ContextMenuManager/BluePointLilac.Controls/ReadOnlyRichTextBox.cs → ContextMenuManager/BluePointLilac.Controls/ReadOnlyTextBox.cs

@@ -4,6 +4,29 @@ using System.Windows.Forms;
 
 namespace BluePointLilac.Controls
 {
+    public sealed class ReadOnlyTextBox : TextBox
+    {
+        public ReadOnlyTextBox()
+        {
+            this.ReadOnly = true;
+            this.BackColor = Color.White;
+            this.ForeColor = Color.FromArgb(80, 80, 80);
+            this.Font = new Font(SystemFonts.MenuFont.FontFamily, 10F);
+        }
+
+        const int WM_SETFOCUS = 0x0007;
+        const int WM_KILLFOCUS = 0x0008;
+        protected override void WndProc(ref Message m)
+        {
+            switch(m.Msg)
+            {
+                case WM_SETFOCUS:
+                    m.Msg = WM_KILLFOCUS; break;
+            }
+            base.WndProc(ref m);
+        }
+    }
+
     public sealed class ReadOnlyRichTextBox : RichTextBox
     {
         public ReadOnlyRichTextBox()

+ 10 - 3
ContextMenuManager/BluePointLilac.Methods/RegTrustedInstaller.cs

@@ -225,11 +225,18 @@ namespace BluePointLilac.Methods
         {
             if(regPath.IsNullOrWhiteSpace()) return;
             TakeRegKeyOwnerShip(regPath);
-            using(RegistryKey key = RegistryEx.GetRegistryKey(regPath))
-                if(key != null)
+            try
+            {
+                using(RegistryKey key = RegistryEx.GetRegistryKey(regPath))
+                {
+                    if(key == null) return;
                     foreach(string subKeyName in key.GetSubKeyNames())
+                    {
                         TakeRegTreeOwnerShip($@"{key.Name}\{subKeyName}");
-
+                    }
+                }
+            }
+            catch { }
         }
     }
 }

+ 7 - 3
ContextMenuManager/BluePointLilac.Methods/RegistryEx.cs

@@ -45,8 +45,8 @@ namespace BluePointLilac.Methods
 
         public static RegistryKey CreateSubKey(this RegistryKey key, string subKeyName, bool writable)
         {
-            key.CreateSubKey(subKeyName).Close();
-            return key.OpenSubKey(subKeyName, writable);
+            using(key.CreateSubKey(subKeyName))
+                return key.OpenSubKey(subKeyName, writable);
         }
 
         /// <summary>获取指定路径注册表项的上一级路径</summary>
@@ -128,7 +128,11 @@ namespace BluePointLilac.Methods
             using(root)
             {
                 if(create) return root.CreateSubKey(keyPath, writable);
-                else return root.OpenSubKey(keyPath, writable);
+                else
+                {
+                    RegTrustedInstaller.TakeRegTreeOwnerShip(keyPath);
+                    return root.OpenSubKey(keyPath, writable);
+                }
             }
         }
 

+ 1 - 1
ContextMenuManager/ContextMenuManager.csproj

@@ -112,7 +112,7 @@
     <Compile Include="AppConfig.cs" />
     <Compile Include="AppDic.cs" />
     <Compile Include="BluePointLilac.Controls\MyToolTip.cs" />
-    <Compile Include="BluePointLilac.Controls\ReadOnlyRichTextBox.cs">
+    <Compile Include="BluePointLilac.Controls\ReadOnlyTextBox.cs">
       <SubType>Component</SubType>
     </Compile>
     <Compile Include="BluePointLilac.Controls\ResizbleForm.cs">

+ 2 - 4
ContextMenuManager/Controls/AboutApp.cs

@@ -184,12 +184,10 @@ namespace ContextMenuManager.Controls
             AutoSize = true
         };
 
-        readonly TextBox txtTranslators = new TextBox
+        readonly ReadOnlyTextBox txtTranslators = new ReadOnlyTextBox
         {
-            ReadOnly = true,
             Multiline = true,
-            ScrollBars = ScrollBars.Vertical,
-            ForeColor = Color.FromArgb(80, 80, 80)
+            ScrollBars = ScrollBars.Vertical
         };
 
         readonly PictureButton btnOpenDir = new PictureButton(AppImage.Open);

+ 9 - 6
ContextMenuManager/Controls/ShellExItem.cs

@@ -22,13 +22,17 @@ namespace ContextMenuManager.Controls
                     if(cmKey == null) continue;
                     foreach(string keyName in cmKey.GetSubKeyNames())
                     {
-                        using(RegistryKey key = cmKey.OpenSubKey(keyName))
+                        try
                         {
-                            if(!GuidEx.TryParse(key.GetValue("")?.ToString(), out Guid guid))
-                                GuidEx.TryParse(keyName, out guid);
-                            if(!guid.Equals(Guid.Empty))
-                                dic.Add(key.Name, guid);
+                            using(RegistryKey key = cmKey.OpenSubKey(keyName))
+                            {
+                                if(!GuidEx.TryParse(key.GetValue("")?.ToString(), out Guid guid))
+                                    GuidEx.TryParse(keyName, out guid);
+                                if(!guid.Equals(Guid.Empty))
+                                    dic.Add(key.Name, guid);
+                            }
                         }
+                        catch { continue; }
                     }
                 }
             }
@@ -69,7 +73,6 @@ namespace ContextMenuManager.Controls
         private string ParentKeyName => RegistryEx.GetKeyName(ParentPath);
         private string DefaultValue => Registry.GetValue(RegPath, "", null)?.ToString();
         public string ItemText => GuidInfo.GetText(Guid) ?? (KeyName.Equals(Guid.ToString("B"), StringComparison.OrdinalIgnoreCase) ? DefaultValue : KeyName);
-        private GuidInfo.IconLocation IconLocation => GuidInfo.GetIconLocation(Guid);
         private bool IsOpenLnkItem => Guid.ToString() == LnkOpenGuid;
         public bool IsDragDropItem => ParentKeyName.EndsWith(DdhParts[0], StringComparison.OrdinalIgnoreCase);
 

+ 2 - 2
ContextMenuManager/Properties/AssemblyInfo.cs

@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyCulture("")]
 [assembly: ComVisible(false)]
 [assembly: Guid("35190ec1-2515-488d-a2e9-825d6ff67aa2")]
-[assembly: AssemblyVersion("3.1.0.0")]
-[assembly: AssemblyFileVersion("3.1.0.0")]
+[assembly: AssemblyVersion("3.1.2.0")]
+[assembly: AssemblyFileVersion("3.1.2.0")]

+ 3 - 2
ContextMenuManager/Properties/Resources.Designer.cs

@@ -393,7 +393,7 @@ namespace ContextMenuManager.Properties {
         ///但是可通过GUID锁定屏蔽来禁用右键菜单项目,
         ///GUID查找位置:HKEY_CLASSES_ROOT\PackagedCom\Package\[包名]\Class\[GUID],
         ///Scene的各子节点为菜单项目出现位置, Item必须有Guid属性,
-        ///UwpName、Text、Icon、Tip等属性写在GuidInfosDic.ini里面,这里就可省略不写--&gt;
+        ///UwpName、Text、Icon、Tip等属性写在GuidInfosDic.ini里面--&gt;
         ///
         ///&lt;Scene&gt;
         ///	&lt;File&gt;
@@ -403,7 +403,8 @@ namespace ContextMenuManager.Properties {
         ///		&lt;Item Guid=&apos;9f156763-7844-4dc4-b2b1-901f640f5155&apos;/&gt;
         ///	&lt;/Directory&gt;
         ///	&lt;Background&gt;
-        ///		&lt;Item Guid=&apos;9f156763-7844-4dc4-b2b1-901f640f5155&apos;/ [字符串的其余部分被截断]&quot;; 的本地化字符串。
+        ///		&lt;Item Guid=&apos;9f156763-7844-4dc4-b2b1-901f640f5155&apos;/&gt;
+        ///	&lt;/Back [字符串的其余部分被截断]&quot;; 的本地化字符串。
         /// </summary>
         internal static string UwpModeItemsDic {
             get {

+ 9 - 0
ContextMenuManager/Properties/Resources/Texts/EnhanceMenusDic.xml

@@ -278,6 +278,15 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
           <Command Default='osk.exe'/>
         </SubKey>
       </Item>
+      <Item KeyName='OpenEdge'>
+        <OSVersion Compare=">=">10.0</OSVersion>
+        <Value>
+          <REG_SZ MUIVerb='打开Edge' Icon='%SystemRoot%\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe'/>
+        </Value>
+        <SubKey>
+          <Command Default='explorer.exe shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge'/>
+        </SubKey>
+      </Item>
       <Item KeyName='ShutDownMenu'>
         <Value>
           <REG_SZ MUIVerb='关机选项' Icon='shell32.dll,-28' SubCommands='' Position='bottom'/>

+ 1 - 1
ContextMenuManager/Properties/Resources/Texts/UwpModeItemsDic.xml

@@ -3,7 +3,7 @@
 但是可通过GUID锁定屏蔽来禁用右键菜单项目,
 GUID查找位置:HKEY_CLASSES_ROOT\PackagedCom\Package\[包名]\Class\[GUID],
 Scene的各子节点为菜单项目出现位置, Item必须有Guid属性,
-UwpName、Text、Icon、Tip等属性写在GuidInfosDic.ini里面,这里就可省略不写-->
+UwpName、Text、Icon、Tip等属性写在GuidInfosDic.ini里面-->
 
 <Scene>
 	<File>