From 54c16cad7d8d3a35e6db22212331c6813791c42a Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Tue, 27 Aug 2024 19:44:50 +0800
Subject: [PATCH] Adding OSPlatform Processing
---
v2rayN/ServiceLib/Common/Utils.cs | 31 +++++-----------------
v2rayN/ServiceLib/Handler/LazyConfig.cs | 2 +-
v2rayN/ServiceLib/Handler/UpdateHandler.cs | 4 +--
3 files changed, 10 insertions(+), 27 deletions(-)
diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs
index a0b5b790..463e6f4b 100644
--- a/v2rayN/ServiceLib/Common/Utils.cs
+++ b/v2rayN/ServiceLib/Common/Utils.cs
@@ -495,29 +495,6 @@ namespace ServiceLib.Common
#region 测速
- ///
- /// 取得本机 IP Address
- ///
- ///
- //public static List GetHostIPAddress()
- //{
- // List lstIPAddress = new List();
- // try
- // {
- // IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
- // foreach (IPAddress ipa in IpEntry.AddressList)
- // {
- // if (ipa.AddressFamily == AddressFamily.InterNetwork)
- // lstIPAddress.Add(ipa.ToString());
- // }
- // }
- // catch (Exception ex)
- // {
- // SaveLog(ex.Message, ex);
- // }
- // return lstIPAddress;
- //}
-
public static void SetSecurityProtocol(bool enableSecurityProtocolTls13)
{
if (enableSecurityProtocolTls13)
@@ -708,7 +685,7 @@ namespace ServiceLib.Common
public static string GetExeName(string name)
{
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if (IsWindows())
{
return $"{name}.exe";
}
@@ -718,6 +695,12 @@ namespace ServiceLib.Common
}
}
+ public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+
+ public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
+
+ public static bool IsOSX() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+
#endregion 杂项
#region TempPath
diff --git a/v2rayN/ServiceLib/Handler/LazyConfig.cs b/v2rayN/ServiceLib/Handler/LazyConfig.cs
index 0902642d..2fba1116 100644
--- a/v2rayN/ServiceLib/Handler/LazyConfig.cs
+++ b/v2rayN/ServiceLib/Handler/LazyConfig.cs
@@ -54,7 +54,7 @@ namespace ServiceLib.Handler
public void AddProcess(IntPtr processHandle)
{
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if (Utils.IsWindows())
{
_processJob ??= new();
_processJob?.AddProcess(processHandle);
diff --git a/v2rayN/ServiceLib/Handler/UpdateHandler.cs b/v2rayN/ServiceLib/Handler/UpdateHandler.cs
index af9209c8..b50f2cbd 100644
--- a/v2rayN/ServiceLib/Handler/UpdateHandler.cs
+++ b/v2rayN/ServiceLib/Handler/UpdateHandler.cs
@@ -444,7 +444,7 @@ namespace ServiceLib.Handler
private string? GetUrlFromCore(CoreInfo? coreInfo)
{
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if (Utils.IsWindows())
{
return RuntimeInformation.ProcessArchitecture switch
{
@@ -454,7 +454,7 @@ namespace ServiceLib.Handler
_ => null,
};
}
- else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+ else if (Utils.IsLinux())
{
return RuntimeInformation.ProcessArchitecture switch
{