From 4f05b93d63ed5d1eec588a4ff7101fa43cf52ec8 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 3 Nov 2024 13:44:12 +0800 Subject: [PATCH] Bug fix MainModule FileName only exists in Win32. --- v2rayN/AmazTool/UpgradeApp.cs | 10 ++++----- v2rayN/ServiceLib/Handler/CoreHandler.cs | 22 ------------------- .../ViewModels/MainWindowViewModel.cs | 2 +- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/v2rayN/AmazTool/UpgradeApp.cs b/v2rayN/AmazTool/UpgradeApp.cs index 31de6a6d..852f18da 100644 --- a/v2rayN/AmazTool/UpgradeApp.cs +++ b/v2rayN/AmazTool/UpgradeApp.cs @@ -22,12 +22,12 @@ namespace AmazTool Console.WriteLine("Try to end the process(尝试结束进程)."); try { - var path = GetPath(V2rayN); - Console.WriteLine(path); var existing = Process.GetProcessesByName(V2rayN); - var pp = existing.FirstOrDefault(p => p.MainModule?.FileName != null && p.MainModule?.FileName.Contains(path) == true); - pp?.Kill(); - pp?.WaitForExit(1000); + foreach (var pp in existing) + { + pp?.Kill(); + pp?.WaitForExit(1000); + } } catch (Exception ex) { diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index 8f230a18..acb91c20 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -108,13 +108,11 @@ namespace ServiceLib.Handler { try { - bool hasProc = false; if (_process != null) { await KillProcess(_process); _process.Dispose(); _process = null; - hasProc = true; } if (_processPre != null) @@ -122,26 +120,6 @@ namespace ServiceLib.Handler await KillProcess(_processPre); _processPre.Dispose(); _processPre = null; - hasProc = true; - } - - if (!hasProc) - { - var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(); - foreach (var it in coreInfo) - { - if (it.CoreType == ECoreType.v2rayN) - { - continue; - } - foreach (var name in it.CoreExes) - { - var path = Utils.GetBinPath(Utils.GetExeName(name), it.CoreType.ToString()); - var existing = Process.GetProcessesByName(name); - var pp = existing.FirstOrDefault(p => p.MainModule?.FileName != null && p.MainModule?.FileName.Contains(path) == true); - await KillProcess(pp); - } - } } } catch (Exception ex) diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 5fc22623..dc0b6bfe 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -289,7 +289,7 @@ namespace ServiceLib.ViewModels await ProfileExHandler.Instance.SaveTo(); await StatisticsHandler.Instance.SaveTo(); StatisticsHandler.Instance.Close(); - CoreHandler.Instance.CoreStop(); + await CoreHandler.Instance.CoreStop(); Logging.SaveLog("MyAppExit End"); }