NeoXUpdater.cs
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
public static class AlgoUpdater
{
/// <summary>
/// 杀掉 algomatch.exe(若存在),然后将当前目录的 NeoX.dll 复制到 AlgoMatch\NeoX.dll。
/// 复制失败则抛出异常。
/// </summary>
public static void UpdateNeoX()
{
// 1. 杀掉 algomatch.exe
foreach (Process p in Process.GetProcessesByName("AlgoMatch"))
{
try
{
p.Kill(); // 强制结束
p.WaitForExit(5000); // 最多等待 5 秒
}
catch (Exception ex)
{
// 若杀进程失败,可记录日志或继续(不影响复制)
Console.WriteLine($"Warning: 结束进程失败: {ex.Message}");
}
}
// 2. 构造路径
string currentDir = AppDomain.CurrentDomain.BaseDirectory;
string sourceFile = Path.Combine(currentDir, "NeoX.dll");
string targetDir = Path.Combine(currentDir, "AlgoMatch");
string targetFile = Path.Combine(targetDir, "NeoX.dll");
// 3. 检查源文件
if (!File.Exists(sourceFile))
{
MessageBox.Show("The source file NeoX.dll does not exist. \r\nFile:" + sourceFile);
return;
}
// 4. 确保目标目录存在
Directory.CreateDirectory(targetDir);
// 5. 复制(可覆盖)
try
{
File.Copy(sourceFile, targetFile, overwrite: true);
}
catch (Exception ex)
{
MessageBox.Show("Failed to copy NeoX.dll to the AlgoMatch directory. \r\nException:" + ex);
}
}
}