[+] 处理微信 3.5.0.4 路径改变的问题 #253

This commit is contained in:
huiyadanli 2021-12-26 22:37:19 +08:00
parent c503984745
commit 3b929af004
2 changed files with 40 additions and 3 deletions

View File

@ -1,5 +1,6 @@
using RevokeMsgPatcher.Model; using RevokeMsgPatcher.Model;
using RevokeMsgPatcher.Utils; using RevokeMsgPatcher.Utils;
using System.IO;
namespace RevokeMsgPatcher.Modifier namespace RevokeMsgPatcher.Modifier
{ {
@ -18,11 +19,13 @@ namespace RevokeMsgPatcher.Modifier
public override string FindInstallPath() public override string FindInstallPath()
{ {
string installPath = PathUtil.FindInstallPathFromRegistry("Wechat"); string installPath = PathUtil.FindInstallPathFromRegistry("Wechat");
if (!IsAllFilesExist(installPath)) string realPath = GetRealInstallPath(installPath);
if (string.IsNullOrEmpty(realPath))
{ {
foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\Wechat")) foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\Wechat"))
{ {
if (IsAllFilesExist(defaultPath)) realPath = GetRealInstallPath(defaultPath);
if (!string.IsNullOrEmpty(realPath))
{ {
return defaultPath; return defaultPath;
} }
@ -30,11 +33,35 @@ namespace RevokeMsgPatcher.Modifier
} }
else else
{ {
return installPath; return realPath;
} }
return null; return null;
} }
/// <summary>
/// 微信 3.5.0.4 改变了目录结构
/// </summary>
/// <param name="basePath"></param>
/// <returns></returns>
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;
}
/// <summary> /// <summary>
/// 获取整个APP的当前版本 /// 获取整个APP的当前版本
/// </summary> /// </summary>

View File

@ -77,5 +77,15 @@ namespace RevokeMsgPatcher.Utils
} }
return list; return list;
} }
/// <summary>
/// 按文件夹修改时间倒序
/// </summary>
/// <param name="dirs"></param>
public static void SortByLastWriteTimeDesc(ref DirectoryInfo[] dirs)
{
Array.Sort(dirs, delegate (DirectoryInfo x, DirectoryInfo y) { return y.LastWriteTime.CompareTo(x.LastWriteTime); });
}
} }
} }