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); }); + } + } }