mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-30 01:34:08 +00:00
fix: tighten Unix platform handling
Adds Linux and macOS platform guards so the analyzer can narrow calls through Utils.IsLinux() and Utils.IsMacOS(). Marks the Linux/macOS autostart and system proxy helpers with explicit platform attributes. Updates Utils.GetSystemHosts() to read /etc/hosts on Linux and macOS while keeping the existing Windows hosts and hosts.ics merge behavior.
This commit is contained in:
parent
06796e474a
commit
25c7c69886
4 changed files with 27 additions and 6 deletions
|
|
@ -863,6 +863,8 @@ public class Utils
|
|||
}
|
||||
|
||||
public static Dictionary<string, string> GetSystemHosts()
|
||||
{
|
||||
if (IsWindows())
|
||||
{
|
||||
var hosts = GetSystemHosts(@"C:\Windows\System32\drivers\etc\hosts");
|
||||
var hostsIcs = GetSystemHosts(@"C:\Windows\System32\drivers\etc\hosts.ics");
|
||||
|
|
@ -875,6 +877,14 @@ public class Utils
|
|||
return hosts;
|
||||
}
|
||||
|
||||
if (IsLinux() || IsMacOS())
|
||||
{
|
||||
return GetSystemHosts("/etc/hosts");
|
||||
}
|
||||
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public static async Task<string?> GetCliWrapOutput(string filePath, string? arg)
|
||||
{
|
||||
return await GetCliWrapOutput(filePath, arg != null ? new List<string>() { arg } : null);
|
||||
|
|
@ -1117,8 +1127,10 @@ public class Utils
|
|||
[SupportedOSPlatformGuard("windows")]
|
||||
public static bool IsWindows() => OperatingSystem.IsWindows();
|
||||
|
||||
[SupportedOSPlatformGuard("linux")]
|
||||
public static bool IsLinux() => OperatingSystem.IsLinux();
|
||||
|
||||
[SupportedOSPlatformGuard("macos")]
|
||||
public static bool IsMacOS() => OperatingSystem.IsMacOS();
|
||||
|
||||
[UnsupportedOSPlatformGuard("windows")]
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ public static class AutoStartupHandler
|
|||
|
||||
#region Linux
|
||||
|
||||
[SupportedOSPlatform("linux")]
|
||||
private static async Task ClearTaskLinux()
|
||||
{
|
||||
try
|
||||
|
|
@ -140,6 +141,7 @@ public static class AutoStartupHandler
|
|||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
[SupportedOSPlatform("linux")]
|
||||
private static async Task SetTaskLinux()
|
||||
{
|
||||
try
|
||||
|
|
@ -160,6 +162,7 @@ public static class AutoStartupHandler
|
|||
}
|
||||
}
|
||||
|
||||
[SupportedOSPlatform("linux")]
|
||||
private static string GetHomePathLinux()
|
||||
{
|
||||
var homePath = Path.Combine(Utils.GetHomePath(), ".config", "autostart", $"{Global.AppName}.desktop");
|
||||
|
|
@ -171,6 +174,7 @@ public static class AutoStartupHandler
|
|||
|
||||
#region macOS
|
||||
|
||||
[SupportedOSPlatform("macos")]
|
||||
private static async Task ClearTaskOSX()
|
||||
{
|
||||
try
|
||||
|
|
@ -190,6 +194,7 @@ public static class AutoStartupHandler
|
|||
}
|
||||
}
|
||||
|
||||
[SupportedOSPlatform("macos")]
|
||||
private static async Task SetTaskOSX()
|
||||
{
|
||||
try
|
||||
|
|
@ -207,6 +212,7 @@ public static class AutoStartupHandler
|
|||
}
|
||||
}
|
||||
|
||||
[SupportedOSPlatform("macos")]
|
||||
private static string GetLaunchAgentPathMacOS()
|
||||
{
|
||||
var homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
|
|
@ -215,6 +221,7 @@ public static class AutoStartupHandler
|
|||
return launchAgentPath;
|
||||
}
|
||||
|
||||
[SupportedOSPlatform("macos")]
|
||||
private static string GenerateLaunchAgentPlist()
|
||||
{
|
||||
var exePath = Utils.GetExePath();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
namespace ServiceLib.Handler.SysProxy;
|
||||
|
||||
[SupportedOSPlatform("linux")]
|
||||
public static class ProxySettingLinux
|
||||
{
|
||||
private static readonly string _proxySetFileName = $"{Global.ProxySetLinuxShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
namespace ServiceLib.Handler.SysProxy;
|
||||
|
||||
[SupportedOSPlatform("macos")]
|
||||
public static class ProxySettingOSX
|
||||
{
|
||||
private static readonly string _proxySetFileName = $"{Global.ProxySetOSXShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
||||
|
|
|
|||
Loading…
Reference in a new issue