[#] 修复微信寻找路径时的 bug #282

This commit is contained in:
huiyadanli 2022-01-22 23:48:41 +08:00
parent 5a54a21391
commit 3a3e5306e7
4 changed files with 60 additions and 26 deletions

View File

@ -1,5 +1,7 @@
using RevokeMsgPatcher.Model; using RevokeMsgPatcher.Model;
using RevokeMsgPatcher.Utils; using RevokeMsgPatcher.Utils;
using System;
using System.Collections.Generic;
namespace RevokeMsgPatcher.Modifier namespace RevokeMsgPatcher.Modifier
{ {
@ -16,20 +18,28 @@ namespace RevokeMsgPatcher.Modifier
/// <returns></returns> /// <returns></returns>
public override string FindInstallPath() public override string FindInstallPath()
{ {
string installPath = PathUtil.FindInstallPathFromRegistry("QQLite"); try
if (!IsAllFilesExist(installPath))
{ {
foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\QQLite")) string installPath = PathUtil.FindInstallPathFromRegistry("QQLite");
if (!IsAllFilesExist(installPath))
{ {
if (IsAllFilesExist(defaultPath)) List<string> 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; return null;
} }

View File

@ -1,5 +1,7 @@
using RevokeMsgPatcher.Model; using RevokeMsgPatcher.Model;
using RevokeMsgPatcher.Utils; using RevokeMsgPatcher.Utils;
using System;
using System.Collections.Generic;
namespace RevokeMsgPatcher.Modifier namespace RevokeMsgPatcher.Modifier
{ {
@ -16,20 +18,28 @@ namespace RevokeMsgPatcher.Modifier
/// <returns></returns> /// <returns></returns>
public override string FindInstallPath() public override string FindInstallPath()
{ {
string installPath = PathUtil.FindInstallPathFromRegistry("{052CFB79-9D62-42E3-8A15-DE66C2C97C3E}"); try
if (!IsAllFilesExist(installPath))
{ {
foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\QQ")) string installPath = PathUtil.FindInstallPathFromRegistry("{052CFB79-9D62-42E3-8A15-DE66C2C97C3E}");
if (!IsAllFilesExist(installPath))
{ {
if (IsAllFilesExist(defaultPath)) List<string> 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; return null;
} }

View File

@ -1,5 +1,7 @@
using RevokeMsgPatcher.Model; using RevokeMsgPatcher.Model;
using RevokeMsgPatcher.Utils; using RevokeMsgPatcher.Utils;
using System;
using System.Collections.Generic;
using System.IO; using System.IO;
namespace RevokeMsgPatcher.Modifier namespace RevokeMsgPatcher.Modifier
@ -18,22 +20,30 @@ namespace RevokeMsgPatcher.Modifier
/// <returns></returns> /// <returns></returns>
public override string FindInstallPath() public override string FindInstallPath()
{ {
string installPath = PathUtil.FindInstallPathFromRegistry("Wechat"); try
string realPath = GetRealInstallPath(installPath);
if (string.IsNullOrEmpty(realPath))
{ {
foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\Wechat")) string installPath = PathUtil.FindInstallPathFromRegistry("Wechat");
string realPath = GetRealInstallPath(installPath);
if (string.IsNullOrEmpty(realPath))
{ {
realPath = GetRealInstallPath(defaultPath); List<string> defaultPathList = PathUtil.GetDefaultInstallPaths(@"Tencent\QQ");
if (!string.IsNullOrEmpty(realPath)) 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; return null;
} }
@ -45,6 +55,10 @@ namespace RevokeMsgPatcher.Modifier
/// <returns></returns> /// <returns></returns>
private string GetRealInstallPath(string basePath) private string GetRealInstallPath(string basePath)
{ {
if (basePath == null)
{
return null;
}
if (IsAllFilesExist(basePath)) if (IsAllFilesExist(basePath))
{ {
return basePath; return basePath;

View File

@ -61,7 +61,7 @@ namespace RevokeMsgPatcher
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message + "\n" + ex.StackTrace.Trim(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
#endif #endif
} }
@ -69,12 +69,12 @@ namespace RevokeMsgPatcher
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) 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) 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);
} }
} }
} }