From 3b929af0042a85c98d27f18999227b2b3a3b547d Mon Sep 17 00:00:00 2001 From: huiyadanli Date: Sun, 26 Dec 2021 22:37:19 +0800 Subject: [PATCH] =?UTF-8?q?[+]=20=E5=A4=84=E7=90=86=E5=BE=AE=E4=BF=A1=203.?= =?UTF-8?q?5.0.4=20=E8=B7=AF=E5=BE=84=E6=94=B9=E5=8F=98=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20#253?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RevokeMsgPatcher/Modifier/WechatModifier.cs | 33 +++++++++++++++++++-- RevokeMsgPatcher/Utils/PathUtil.cs | 10 +++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/RevokeMsgPatcher/Modifier/WechatModifier.cs b/RevokeMsgPatcher/Modifier/WechatModifier.cs index ace78e8..690baaa 100644 --- a/RevokeMsgPatcher/Modifier/WechatModifier.cs +++ b/RevokeMsgPatcher/Modifier/WechatModifier.cs @@ -1,5 +1,6 @@ using RevokeMsgPatcher.Model; using RevokeMsgPatcher.Utils; +using System.IO; namespace RevokeMsgPatcher.Modifier { @@ -18,11 +19,13 @@ namespace RevokeMsgPatcher.Modifier public override string FindInstallPath() { string installPath = PathUtil.FindInstallPathFromRegistry("Wechat"); - if (!IsAllFilesExist(installPath)) + string realPath = GetRealInstallPath(installPath); + if (string.IsNullOrEmpty(realPath)) { foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\Wechat")) { - if (IsAllFilesExist(defaultPath)) + realPath = GetRealInstallPath(defaultPath); + if (!string.IsNullOrEmpty(realPath)) { return defaultPath; } @@ -30,11 +33,35 @@ namespace RevokeMsgPatcher.Modifier } else { - return installPath; + return realPath; } return null; } + /// + /// 微信 3.5.0.4 改变了目录结构 + /// + /// + /// + private string GetRealInstallPath(string basePath) + { + if (IsAllFilesExist(basePath)) + { + return basePath; + } + DirectoryInfo[] directories = new DirectoryInfo(basePath).GetDirectories(); + PathUtil.SortByLastWriteTimeDesc(ref directories); // 按修改时间倒序 + foreach (DirectoryInfo folder in directories) + { + if (IsAllFilesExist(folder.FullName)) + { + return folder.FullName; + } + } + return null; + } + + /// /// 获取整个APP的当前版本 /// diff --git a/RevokeMsgPatcher/Utils/PathUtil.cs b/RevokeMsgPatcher/Utils/PathUtil.cs index 61c547c..b5d885a 100644 --- a/RevokeMsgPatcher/Utils/PathUtil.cs +++ b/RevokeMsgPatcher/Utils/PathUtil.cs @@ -77,5 +77,15 @@ namespace RevokeMsgPatcher.Utils } return list; } + + /// + /// 按文件夹修改时间倒序 + /// + /// + public static void SortByLastWriteTimeDesc(ref DirectoryInfo[] dirs) + { + Array.Sort(dirs, delegate (DirectoryInfo x, DirectoryInfo y) { return y.LastWriteTime.CompareTo(x.LastWriteTime); }); + } + } }