From 3a3e5306e717e0d82be6a4c93e8af1bdac4f397a Mon Sep 17 00:00:00 2001 From: huiyadanli Date: Sat, 22 Jan 2022 23:48:41 +0800 Subject: [PATCH] =?UTF-8?q?[#]=20=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=AF=BB=E6=89=BE=E8=B7=AF=E5=BE=84=E6=97=B6=E7=9A=84=20bug=20?= =?UTF-8?q?#282?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RevokeMsgPatcher/Modifier/QQLiteModifier.cs | 24 +++++++++++----- RevokeMsgPatcher/Modifier/QQModifier.cs | 24 +++++++++++----- RevokeMsgPatcher/Modifier/WechatModifier.cs | 32 +++++++++++++++------ RevokeMsgPatcher/Program.cs | 6 ++-- 4 files changed, 60 insertions(+), 26 deletions(-) diff --git a/RevokeMsgPatcher/Modifier/QQLiteModifier.cs b/RevokeMsgPatcher/Modifier/QQLiteModifier.cs index 45af711..1ef039e 100644 --- a/RevokeMsgPatcher/Modifier/QQLiteModifier.cs +++ b/RevokeMsgPatcher/Modifier/QQLiteModifier.cs @@ -1,5 +1,7 @@ using RevokeMsgPatcher.Model; using RevokeMsgPatcher.Utils; +using System; +using System.Collections.Generic; namespace RevokeMsgPatcher.Modifier { @@ -16,20 +18,28 @@ namespace RevokeMsgPatcher.Modifier /// public override string FindInstallPath() { - string installPath = PathUtil.FindInstallPathFromRegistry("QQLite"); - if (!IsAllFilesExist(installPath)) + try { - foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\QQLite")) + string installPath = PathUtil.FindInstallPathFromRegistry("QQLite"); + if (!IsAllFilesExist(installPath)) { - if (IsAllFilesExist(defaultPath)) + List defaultPathList = PathUtil.GetDefaultInstallPaths(@"Tencent\QQLite"); + foreach (string defaultPath in defaultPathList) { - return defaultPath; + if (IsAllFilesExist(defaultPath)) + { + return defaultPath; + } } } + else + { + return installPath; + } } - else + catch (Exception e) { - return installPath; + Console.WriteLine(e.Message); } return null; } diff --git a/RevokeMsgPatcher/Modifier/QQModifier.cs b/RevokeMsgPatcher/Modifier/QQModifier.cs index e52dde8..b82958b 100644 --- a/RevokeMsgPatcher/Modifier/QQModifier.cs +++ b/RevokeMsgPatcher/Modifier/QQModifier.cs @@ -1,5 +1,7 @@ using RevokeMsgPatcher.Model; using RevokeMsgPatcher.Utils; +using System; +using System.Collections.Generic; namespace RevokeMsgPatcher.Modifier { @@ -16,20 +18,28 @@ namespace RevokeMsgPatcher.Modifier /// public override string FindInstallPath() { - string installPath = PathUtil.FindInstallPathFromRegistry("{052CFB79-9D62-42E3-8A15-DE66C2C97C3E}"); - if (!IsAllFilesExist(installPath)) + try { - foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\QQ")) + string installPath = PathUtil.FindInstallPathFromRegistry("{052CFB79-9D62-42E3-8A15-DE66C2C97C3E}"); + if (!IsAllFilesExist(installPath)) { - if (IsAllFilesExist(defaultPath)) + List defaultPathList = PathUtil.GetDefaultInstallPaths(@"Tencent\QQ"); + foreach (string defaultPath in defaultPathList) { - return defaultPath; + if (IsAllFilesExist(defaultPath)) + { + return defaultPath; + } } } + else + { + return installPath; + } } - else + catch (Exception e) { - return installPath; + Console.WriteLine(e.Message); } return null; } diff --git a/RevokeMsgPatcher/Modifier/WechatModifier.cs b/RevokeMsgPatcher/Modifier/WechatModifier.cs index 690baaa..1a92ad7 100644 --- a/RevokeMsgPatcher/Modifier/WechatModifier.cs +++ b/RevokeMsgPatcher/Modifier/WechatModifier.cs @@ -1,5 +1,7 @@ using RevokeMsgPatcher.Model; using RevokeMsgPatcher.Utils; +using System; +using System.Collections.Generic; using System.IO; namespace RevokeMsgPatcher.Modifier @@ -18,22 +20,30 @@ namespace RevokeMsgPatcher.Modifier /// public override string FindInstallPath() { - string installPath = PathUtil.FindInstallPathFromRegistry("Wechat"); - string realPath = GetRealInstallPath(installPath); - if (string.IsNullOrEmpty(realPath)) + try { - foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\Wechat")) + string installPath = PathUtil.FindInstallPathFromRegistry("Wechat"); + string realPath = GetRealInstallPath(installPath); + if (string.IsNullOrEmpty(realPath)) { - realPath = GetRealInstallPath(defaultPath); - if (!string.IsNullOrEmpty(realPath)) + List defaultPathList = PathUtil.GetDefaultInstallPaths(@"Tencent\QQ"); + foreach (string defaultPath in defaultPathList) { - return defaultPath; + realPath = GetRealInstallPath(defaultPath); + if (!string.IsNullOrEmpty(realPath)) + { + return defaultPath; + } } } + else + { + return realPath; + } } - else + catch (Exception e) { - return realPath; + Console.WriteLine(e.Message); } return null; } @@ -45,6 +55,10 @@ namespace RevokeMsgPatcher.Modifier /// private string GetRealInstallPath(string basePath) { + if (basePath == null) + { + return null; + } if (IsAllFilesExist(basePath)) { return basePath; diff --git a/RevokeMsgPatcher/Program.cs b/RevokeMsgPatcher/Program.cs index 5046c55..58667bb 100644 --- a/RevokeMsgPatcher/Program.cs +++ b/RevokeMsgPatcher/Program.cs @@ -61,7 +61,7 @@ namespace RevokeMsgPatcher } catch (Exception ex) { - MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message + "\n" + ex.StackTrace.Trim(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endif } @@ -69,12 +69,12 @@ namespace RevokeMsgPatcher static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { - MessageBox.Show(e.Exception.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(e.Exception.Message + "\n" + e.Exception.StackTrace.Trim(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { - MessageBox.Show((e.ExceptionObject as Exception).Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show((e.ExceptionObject as Exception).Message + "\n" + (e.ExceptionObject as Exception).StackTrace.Trim(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }