From 9fde37f2cca4c234b414dc30bb43ddcecea8e83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E7=82=B9lilac?= Date: Wed, 24 Feb 2021 11:30:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B03.1=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ContextMenuManager/AppConfig.cs | 27 +++++++++++++---- .../BluePointLilac.Methods/ExternalProgram.cs | 30 +++++++++++-------- .../BluePointLilac.Methods/GuidEx.cs | 7 +++-- .../BluePointLilac.Methods/IniWriter.cs | 5 ++++ ContextMenuManager/Controls/AboutApp.cs | 2 +- ContextMenuManager/Controls/RuleItem.cs | 2 +- ContextMenuManager/Controls/ShellExItem.cs | 2 +- .../Controls/ShellExecuteDialog.cs | 2 +- ContextMenuManager/Properties/AssemblyInfo.cs | 4 +-- .../Resources/Texts/GuidInfosDic.ini | 3 ++ ContextMenuManager/Updater.cs | 17 +++++++++-- Update.ini | 6 ++-- 12 files changed, 76 insertions(+), 31 deletions(-) diff --git a/ContextMenuManager/AppConfig.cs b/ContextMenuManager/AppConfig.cs index 92b9348..5f455fb 100644 --- a/ContextMenuManager/AppConfig.cs +++ b/ContextMenuManager/AppConfig.cs @@ -78,7 +78,7 @@ public static string Language public static bool AutoBackup { get => ConfigWriter.GetValue("General", "AutoBackup") != "0"; - set => ConfigWriter.SetValue("General", "AutoBackup", (value ? 1 : 0).ToString()); + set => ConfigWriter.SetValue("General", "AutoBackup", value ? 1 : 0); } public static DateTime LastCheckUpdateTime @@ -99,14 +99,14 @@ public static DateTime LastCheckUpdateTime } set { - ConfigWriter.SetValue("General", "LastCheckUpdateTime", value.ToBinary().ToString()); + ConfigWriter.SetValue("General", "LastCheckUpdateTime", value.ToBinary()); } } public static bool ProtectOpenItem { get => ConfigWriter.GetValue("General", "ProtectOpenItem") != "0"; - set => ConfigWriter.SetValue("General", "ProtectOpenItem", (value ? 1 : 0).ToString()); + set => ConfigWriter.SetValue("General", "ProtectOpenItem", value ? 1 : 0); } public static string EngineUrl @@ -126,19 +126,34 @@ public static string EngineUrl public static bool ShowFilePath { get => ConfigWriter.GetValue("General", "ShowFilePath") == "1"; - set => ConfigWriter.SetValue("General", "ShowFilePath", (value ? 1 : 0).ToString()); + set => ConfigWriter.SetValue("General", "ShowFilePath", value ? 1 : 0); } public static bool WinXSortable { get => ConfigWriter.GetValue("General", "WinXSortable") == "1"; - set => ConfigWriter.SetValue("General", "WinXSortable", (value ? 1 : 0).ToString()); + set => ConfigWriter.SetValue("General", "WinXSortable", value ? 1 : 0); } public static bool OpenMoreRegedit { get => ConfigWriter.GetValue("General", "OpenMoreRegedit") == "1"; - set => ConfigWriter.SetValue("General", "OpenMoreRegedit", (value ? 1 : 0).ToString()); + set => ConfigWriter.SetValue("General", "OpenMoreRegedit", value ? 1 : 0); + } + + public static Version Version + { + get + { + Version version = new Version(); + try { version = new Version(ConfigWriter.GetValue("General", "Version")); } + catch { } + return version; + } + set + { + ConfigWriter.SetValue("General", "Version", value); + } } } } \ No newline at end of file diff --git a/ContextMenuManager/BluePointLilac.Methods/ExternalProgram.cs b/ContextMenuManager/BluePointLilac.Methods/ExternalProgram.cs index c63a836..b64144d 100644 --- a/ContextMenuManager/BluePointLilac.Methods/ExternalProgram.cs +++ b/ContextMenuManager/BluePointLilac.Methods/ExternalProgram.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Win32; +using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; @@ -36,19 +37,24 @@ public static void JumpRegEdit(string regPath, string valueName = null, bool mor Thread.Sleep(50); SendMessage(hTree, WM_KEYDOWN, VK_RIGHT, null); } - else SendMessage(hTree, WM_CHAR, Convert.ToInt16(chr), null); + else + { + SendMessage(hTree, WM_CHAR, Convert.ToInt16(chr), null); + } } - if(!string.IsNullOrEmpty(valueName)) + if(string.IsNullOrEmpty(valueName)) return; + using(RegistryKey key = RegistryEx.GetRegistryKey(regPath)) { - Thread.Sleep(50); - SetForegroundWindow(hList); - SetFocus(hList); - SendMessage(hList, WM_KEYDOWN, VK_HOME, null); - foreach(char chr in Encoding.Default.GetBytes(valueName)) - { - SendMessage(hList, WM_CHAR, Convert.ToInt16(chr), null); - } + if(key?.GetValue(valueName) == null) return; + } + Thread.Sleep(50); + SetForegroundWindow(hList); + SetFocus(hList); + SendMessage(hList, WM_KEYDOWN, VK_HOME, null); + foreach(char chr in Encoding.Default.GetBytes(valueName)) + { + SendMessage(hList, WM_CHAR, Convert.ToInt16(chr), null); } } @@ -118,7 +124,7 @@ public static void OpenNotepadWithText(string text) { using(Process process = Process.Start("notepad.exe")) { - Thread.Sleep(200); + process.WaitForInputIdle(); IntPtr handle = FindWindowEx(process.MainWindowHandle, IntPtr.Zero, "Edit", null); SendMessage(handle, WM_SETTEXT, 0, text); } diff --git a/ContextMenuManager/BluePointLilac.Methods/GuidEx.cs b/ContextMenuManager/BluePointLilac.Methods/GuidEx.cs index f4fb2fa..15fd79b 100644 --- a/ContextMenuManager/BluePointLilac.Methods/GuidEx.cs +++ b/ContextMenuManager/BluePointLilac.Methods/GuidEx.cs @@ -20,11 +20,14 @@ public static bool TryParse(string str, out Guid guid) } } + private static readonly Regex GuidRegex = new Regex(@"[A-F0-9]{8}(\-[A-F0-9]{4}){3}\-[A-F0-9]{12}", RegexOptions.IgnoreCase); + public static bool IsGuid(string str) { if(string.IsNullOrEmpty(str)) return false; - Regex guidRegEx = new Regex(@"[a-fA-F0-9]{8}(\-[a-fA-F0-9]{4}){3}\-[a-fA-F0-9]{12}"); - return guidRegEx.IsMatch(str); + if(str.Length == 38 && str.StartsWith("{") && str.EndsWith("}") && GuidRegex.IsMatch(str)) return true; + if(str.Length == 36 && GuidRegex.IsMatch(str)) return true; + return false; } } } \ No newline at end of file diff --git a/ContextMenuManager/BluePointLilac.Methods/IniWriter.cs b/ContextMenuManager/BluePointLilac.Methods/IniWriter.cs index 7a79dcf..d51d0b4 100644 --- a/ContextMenuManager/BluePointLilac.Methods/IniWriter.cs +++ b/ContextMenuManager/BluePointLilac.Methods/IniWriter.cs @@ -152,6 +152,11 @@ private void SetValue(string section, string key, ref string value, bool isGetVa } } + public void SetValue(string section, string key, object value) + { + SetValue(section, key, value.ToString()); + } + public void SetValue(string section, string key, string value) { SetValue(section, key, ref value, false); diff --git a/ContextMenuManager/Controls/AboutApp.cs b/ContextMenuManager/Controls/AboutApp.cs index 076f795..fd8461d 100644 --- a/ContextMenuManager/Controls/AboutApp.cs +++ b/ContextMenuManager/Controls/AboutApp.cs @@ -279,7 +279,7 @@ public AppSettingBox() MyToolTip.SetToolTip(cmbConfigDir, AppString.Tip.ConfigPath); MyToolTip.SetToolTip(btnConfigDir, AppString.Other.OpenConfigDir); MyToolTip.SetToolTip(btnBackupDir, AppString.Other.OpenBackupDir); - MyToolTip.SetToolTip(lblUpdate, AppString.Tip.CheckUpdate + Environment.NewLine + MyToolTip.SetToolTip(mliUpdate, AppString.Tip.CheckUpdate + Environment.NewLine + AppString.Tip.LastCheckUpdateTime + AppConfig.LastCheckUpdateTime.ToLongDateString()); cmbConfigDir.Items.AddRange(new[] { AppString.Other.AppDataDir, AppString.Other.AppDir }); cmbEngine.Items.AddRange(new[] { "Baidu", "Bing", "Google", "DogeDoge", "Sogou", "360", AppString.Other.CustomEngine }); diff --git a/ContextMenuManager/Controls/RuleItem.cs b/ContextMenuManager/Controls/RuleItem.cs index 1a0130c..e3eaa45 100644 --- a/ContextMenuManager/Controls/RuleItem.cs +++ b/ContextMenuManager/Controls/RuleItem.cs @@ -444,7 +444,7 @@ public int ItemValue } set { - IniWriter.SetValue(Rule.Section, Rule.KeyName, value.ToString()); + IniWriter.SetValue(Rule.Section, Rule.KeyName, value); } } } diff --git a/ContextMenuManager/Controls/ShellExItem.cs b/ContextMenuManager/Controls/ShellExItem.cs index f037882..c25d034 100644 --- a/ContextMenuManager/Controls/ShellExItem.cs +++ b/ContextMenuManager/Controls/ShellExItem.cs @@ -59,7 +59,7 @@ public string RegPath } } - public string ValueName => DefaultValue; + public string ValueName => null; public Guid Guid { get; set; } public string SearchText => Text; public string ItemFilePath => GuidInfo.GetFilePath(Guid); diff --git a/ContextMenuManager/Controls/ShellExecuteDialog.cs b/ContextMenuManager/Controls/ShellExecuteDialog.cs index aaf6525..5219e9f 100644 --- a/ContextMenuManager/Controls/ShellExecuteDialog.cs +++ b/ContextMenuManager/Controls/ShellExecuteDialog.cs @@ -131,7 +131,7 @@ public ShellExecuteCheckBox() { this.Text = "ShellExecute"; this.AutoSize = true; - this.Font = new Font(SystemFonts.DialogFont.FontFamily, 8F); + this.Font = new Font(SystemFonts.DialogFont.FontFamily, 8F / 1F.DpiZoom()); } public string Verb { get; set; } diff --git a/ContextMenuManager/Properties/AssemblyInfo.cs b/ContextMenuManager/Properties/AssemblyInfo.cs index 4a9241f..aad8f43 100644 --- a/ContextMenuManager/Properties/AssemblyInfo.cs +++ b/ContextMenuManager/Properties/AssemblyInfo.cs @@ -11,5 +11,5 @@ [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("35190ec1-2515-488d-a2e9-825d6ff67aa2")] -[assembly: AssemblyVersion("3.0.0.0")] -[assembly: AssemblyFileVersion("3.0.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("3.1.0.0")] +[assembly: AssemblyFileVersion("3.1.0.0")] \ No newline at end of file diff --git a/ContextMenuManager/Properties/Resources/Texts/GuidInfosDic.ini b/ContextMenuManager/Properties/Resources/Texts/GuidInfosDic.ini index 7c51859..3ab5ec4 100644 --- a/ContextMenuManager/Properties/Resources/Texts/GuidInfosDic.ini +++ b/ContextMenuManager/Properties/Resources/Texts/GuidInfosDic.ini @@ -241,6 +241,8 @@ Icon=..\FreeArc.exe [AD392E40-428C-459F-961E-9B147782D099] Text=UltraISO Icon=.\UltraISO.exe +[be86f80b-eb1a-45b4-b4b6-4b12d302b6bc] +Text=AntZip ;----------------杀软------------------ [09A47860-11B0-4DA5-AFA5-26D86198A780] @@ -316,6 +318,7 @@ Text=使用瑞星杀毒 [0bb81440-5f42-4480-a5f7-770a6f439fc8] Text=IObit Malware Fighter Icon=*,3 + ;----------------传输------------------ [53D2405C-48AB-4C8A-8F59-CE0610F13BBC] Text=通过QQ发送到 diff --git a/ContextMenuManager/Updater.cs b/ContextMenuManager/Updater.cs index 1c9c1dc..41df508 100644 --- a/ContextMenuManager/Updater.cs +++ b/ContextMenuManager/Updater.cs @@ -16,11 +16,16 @@ sealed class Updater public static void PeriodicUpdate() { + Version appVersion = new Version(Application.ProductVersion); //如果上次检测更新时间为一个月以前就进行更新操作 - if(AppConfig.LastCheckUpdateTime.AddMonths(1).CompareTo(DateTime.Today) < 0) + bool flag1 = AppConfig.LastCheckUpdateTime.AddMonths(1).CompareTo(DateTime.Today) < 0; + //如果配置文件中的版本号低于程序版本号也进行更新操作 + bool flag2 = appVersion.CompareTo(AppConfig.Version) > 0; + if(flag1 || flag2) { CheckUpdate(); AppConfig.LastCheckUpdateTime = DateTime.Today; + AppConfig.Version = appVersion; } } @@ -35,7 +40,15 @@ public static bool CheckUpdate() private static bool UpdateApp() { IniReader reader = new IniReader(new StringBuilder(GetWebString(UpdateUrl))); - Version version1 = new Version(reader.GetValue("Update", "Version")); + Version version1; + try + { + version1 = new Version(reader.GetValue("Update", "Version")); + } + catch + { + version1 = new Version(Application.ProductVersion); + } Version version2 = new Version(Application.ProductVersion); if(version1.CompareTo(version2) > 0) { diff --git a/Update.ini b/Update.ini index 144c48c..4d8b35b 100644 --- a/Update.ini +++ b/Update.ini @@ -1,4 +1,4 @@ [Update] -Version=3.0.0.0 -Url=https://github.com/BluePointLilac/ContextMenuManager/releases/download/3.0.0.0/ContextMenuManager.zip -Info=【更新描述】\n(1).支持通过GUID添加ShellEx菜单项目;\n(2).添加ShellExecute函数,方便创建更加强大的Shell菜单项目;\n(3).添加WinX菜单创建和排序功能;\n(4).添加IE右键菜单管理和创建功能;\n(5).添加管理和创建右键拖拽菜单项目功能;\n(6).添加了丰富的字典,添加了很多增强菜单;\n(7).整合文件类型管理功能,使管理更加方便;\n(8).添加状态栏实时显示文件路径功能;\n(9).优化程序部分UI,优化部分代码,解决一些已知Bug。 \ No newline at end of file +Version=3.1.0.0 +Url=https://github.com/BluePointLilac/ContextMenuManager/releases/download/3.1.0.0/ContextMenuManager.zip +Info=【更新描述】\n(1).修复已知bug,优化部分代码。 \ No newline at end of file