From 6f3e4b36823b579964b990548703cc552a77ce95 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 26 Aug 2024 18:45:41 +0800 Subject: [PATCH] Adding OSPlatform Processing --- v2rayN/ServiceLib/Common/Utils.cs | 13 +++++++++++++ v2rayN/ServiceLib/Handler/CoreHandler.cs | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index 1f90e0cb..968de934 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -5,6 +5,7 @@ using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; using System.Reflection; +using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; @@ -703,6 +704,18 @@ namespace ServiceLib.Common return systemHosts; } + public static string GetExeName(string name) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return $"{name}.exe"; + } + else + { + return name; + } + } + #endregion 杂项 #region TempPath diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index 6eddc956..78185563 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -116,7 +116,7 @@ namespace ServiceLib.Handler foreach (Process p in existing) { string? path = p.MainModule?.FileName; - if (path == $"{Utils.GetBinPath(vName, it.coreType.ToString())}.exe") + if (path == Utils.GetExeName(Utils.GetBinPath(vName, it.coreType.ToString()))) { KillProcess(p); } @@ -151,7 +151,7 @@ namespace ServiceLib.Handler string fileName = string.Empty; foreach (string name in coreInfo.coreExes) { - string vName = $"{name}.exe"; + string vName = Utils.GetExeName(name); vName = Utils.GetBinPath(vName, coreInfo.coreType.ToString()); if (File.Exists(vName)) {