修复虚拟网卡添加路由错误,和增加自动更新

This commit is contained in:
snltty
2024-07-18 10:25:58 +08:00
parent a923720124
commit 2024e1ee3d
5 changed files with 51 additions and 58 deletions

View File

@@ -18,7 +18,6 @@ namespace linker.service
protected override void OnStart(string[] _args)
{
OpenExe();
OpenExeTray();
CheckMainProcess();
}
protected override void OnStop()
@@ -29,7 +28,6 @@ namespace linker.service
}
private Process proc;
private Process procTray;
private void CheckMainProcess()
{
@@ -105,65 +103,11 @@ namespace linker.service
}
}
private bool OpenExeTray()
{
try
{
string filename = Process.GetCurrentProcess().MainModule.FileName;
string dir = Path.GetDirectoryName(filename);
procTray = Process.Start(new ProcessStartInfo()
{
WorkingDirectory = dir,
FileName = Path.Combine(dir, $"{mainExeName}.tray.win.exe"),
Arguments = "--task=1",
Verb = "runas",
});
return true;
}
catch (Exception)
{
try
{
procTray.Kill();
procTray.Dispose();
}
catch (Exception)
{
}
procTray = null;
}
return false;
}
private void KillExeTray()
{
try
{
procTray?.Close();
procTray?.Dispose();
foreach (var item in Process.GetProcessesByName($"{mainExeName}.tray.win"))
{
item.Kill();
}
}
catch (Exception)
{
}
finally
{
procTray = null;
}
}
public void RestartService()
{
try
{
KillExe();
KillExeTray();
Environment.Exit(1);
}
catch (Exception)