修改了结束exe程序的位置

This commit is contained in:
2025-07-18 17:22:23 +08:00
parent 9b790fe9e0
commit 848de6f3fa

View File

@@ -42,11 +42,11 @@ namespace CheckDownload
// 阿里云OSS访问密钥Secret // 阿里云OSS访问密钥Secret
private const string OssAccessKeySecret = "7ClQns3wz6psmIp9T2OfuEn3tpzrCK"; private const string OssAccessKeySecret = "7ClQns3wz6psmIp9T2OfuEn3tpzrCK";
// 123盘鉴权密钥 // 123盘鉴权密钥
private const string OneDriveAuthKey = "6SwdpWdSJuJRSh"; private const string OneDriveAuthKey = "ZhwG3LxOtGJwM3ym";
// 123盘UID // 123盘UID
private const string OneDriveUid = "1826795402"; private const string OneDriveUid = "1850250683";
// 123盘路径不包含域名- 修改此处即可同时生效于主备域名 // 123盘路径不包含域名- 修改此处即可同时生效于主备域名
private const string OneDrivePath = "/1826795402/KeyAuth"; private const string OneDrivePath = "/1850250683/SuWin";
// 123盘主域名 // 123盘主域名
private const string OneDriveMainDomain = "vip.123pan.cn"; private const string OneDriveMainDomain = "vip.123pan.cn";
// 123盘备用域名 // 123盘备用域名
@@ -520,12 +520,6 @@ namespace CheckDownload
/// <returns>下载成功返回true否则返回false</returns> /// <returns>下载成功返回true否则返回false</returns>
private async Task<bool> AttemptDownloadAsync(string filePath, string expectedMd5) private async Task<bool> AttemptDownloadAsync(string filePath, string expectedMd5)
{ {
// kill exe if running
if (Path.GetExtension(filePath).Equals(".exe", StringComparison.OrdinalIgnoreCase))
{
KillProcessIfRunning(filePath);
}
string tempFilePath = Path.Combine(_tempDirectory, filePath); string tempFilePath = Path.Combine(_tempDirectory, filePath);
string fileName = Path.GetFileName(filePath); string fileName = Path.GetFileName(filePath);
string truncatedFileName = TruncateString(fileName, 10); string truncatedFileName = TruncateString(fileName, 10);
@@ -1623,12 +1617,22 @@ namespace CheckDownload
return ext == ".db" || ext == ".db3"; return ext == ".db" || ext == ".db3";
} }
private void KillProcessIfRunning(string exeRelativePath) private void KillProcessIfRunning(string exePath)
{ {
try try
{ {
string exeName = Path.GetFileNameWithoutExtension(exeRelativePath); string exeName = Path.GetFileNameWithoutExtension(exePath);
string targetExeDir = Path.GetDirectoryName(Path.Combine(_baseDirectory, exeRelativePath)); string targetExeDir;
// 判断是否为完整路径
if (Path.IsPathRooted(exePath))
{
targetExeDir = Path.GetDirectoryName(exePath);
}
else
{
targetExeDir = Path.GetDirectoryName(Path.Combine(_baseDirectory, exePath));
}
foreach (var proc in Process.GetProcessesByName(exeName)) foreach (var proc in Process.GetProcessesByName(exeName))
{ {
@@ -1729,6 +1733,12 @@ namespace CheckDownload
{ {
try try
{ {
// 如果目标文件是.exe文件先检查并kill掉可能正在运行的进程
if (Path.GetExtension(targetPath).Equals(".exe", StringComparison.OrdinalIgnoreCase))
{
KillProcessIfRunning(targetPath);
}
// 确保目标目录存在 // 确保目标目录存在
string targetDir = Path.GetDirectoryName(targetPath); string targetDir = Path.GetDirectoryName(targetPath);
if (!Directory.Exists(targetDir)) if (!Directory.Exists(targetDir))