修改了结束exe程序的位置
This commit is contained in:
34
Form1.cs
34
Form1.cs
@@ -42,11 +42,11 @@ namespace CheckDownload
|
||||
// 阿里云OSS访问密钥Secret
|
||||
private const string OssAccessKeySecret = "7ClQns3wz6psmIp9T2OfuEn3tpzrCK";
|
||||
// 123盘鉴权密钥
|
||||
private const string OneDriveAuthKey = "6SwdpWdSJuJRSh";
|
||||
private const string OneDriveAuthKey = "ZhwG3LxOtGJwM3ym";
|
||||
// 123盘UID
|
||||
private const string OneDriveUid = "1826795402";
|
||||
private const string OneDriveUid = "1850250683";
|
||||
// 123盘路径(不包含域名)- 修改此处即可同时生效于主备域名
|
||||
private const string OneDrivePath = "/1826795402/KeyAuth";
|
||||
private const string OneDrivePath = "/1850250683/SuWin";
|
||||
// 123盘主域名
|
||||
private const string OneDriveMainDomain = "vip.123pan.cn";
|
||||
// 123盘备用域名
|
||||
@@ -520,12 +520,6 @@ namespace CheckDownload
|
||||
/// <returns>下载成功返回true,否则返回false</returns>
|
||||
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 fileName = Path.GetFileName(filePath);
|
||||
string truncatedFileName = TruncateString(fileName, 10);
|
||||
@@ -1623,12 +1617,22 @@ namespace CheckDownload
|
||||
return ext == ".db" || ext == ".db3";
|
||||
}
|
||||
|
||||
private void KillProcessIfRunning(string exeRelativePath)
|
||||
private void KillProcessIfRunning(string exePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
string exeName = Path.GetFileNameWithoutExtension(exeRelativePath);
|
||||
string targetExeDir = Path.GetDirectoryName(Path.Combine(_baseDirectory, exeRelativePath));
|
||||
string exeName = Path.GetFileNameWithoutExtension(exePath);
|
||||
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))
|
||||
{
|
||||
@@ -1729,6 +1733,12 @@ namespace CheckDownload
|
||||
{
|
||||
try
|
||||
{
|
||||
// 如果目标文件是.exe文件,先检查并kill掉可能正在运行的进程
|
||||
if (Path.GetExtension(targetPath).Equals(".exe", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
KillProcessIfRunning(targetPath);
|
||||
}
|
||||
|
||||
// 确保目标目录存在
|
||||
string targetDir = Path.GetDirectoryName(targetPath);
|
||||
if (!Directory.Exists(targetDir))
|
||||
|
Reference in New Issue
Block a user