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
|
|
@ -864,15 +864,25 @@ public class Utils
|
||||||
|
|
||||||
public static Dictionary<string, string> GetSystemHosts()
|
public static Dictionary<string, string> GetSystemHosts()
|
||||||
{
|
{
|
||||||
var hosts = GetSystemHosts(@"C:\Windows\System32\drivers\etc\hosts");
|
if (IsWindows())
|
||||||
var hostsIcs = GetSystemHosts(@"C:\Windows\System32\drivers\etc\hosts.ics");
|
|
||||||
|
|
||||||
foreach (var (key, value) in hostsIcs)
|
|
||||||
{
|
{
|
||||||
hosts[key] = value;
|
var hosts = GetSystemHosts(@"C:\Windows\System32\drivers\etc\hosts");
|
||||||
|
var hostsIcs = GetSystemHosts(@"C:\Windows\System32\drivers\etc\hosts.ics");
|
||||||
|
|
||||||
|
foreach (var (key, value) in hostsIcs)
|
||||||
|
{
|
||||||
|
hosts[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hosts;
|
if (IsLinux() || IsMacOS())
|
||||||
|
{
|
||||||
|
return GetSystemHosts("/etc/hosts");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Dictionary<string, string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<string?> GetCliWrapOutput(string filePath, string? arg)
|
public static async Task<string?> GetCliWrapOutput(string filePath, string? arg)
|
||||||
|
|
@ -1117,8 +1127,10 @@ public class Utils
|
||||||
[SupportedOSPlatformGuard("windows")]
|
[SupportedOSPlatformGuard("windows")]
|
||||||
public static bool IsWindows() => OperatingSystem.IsWindows();
|
public static bool IsWindows() => OperatingSystem.IsWindows();
|
||||||
|
|
||||||
|
[SupportedOSPlatformGuard("linux")]
|
||||||
public static bool IsLinux() => OperatingSystem.IsLinux();
|
public static bool IsLinux() => OperatingSystem.IsLinux();
|
||||||
|
|
||||||
|
[SupportedOSPlatformGuard("macos")]
|
||||||
public static bool IsMacOS() => OperatingSystem.IsMacOS();
|
public static bool IsMacOS() => OperatingSystem.IsMacOS();
|
||||||
|
|
||||||
[UnsupportedOSPlatformGuard("windows")]
|
[UnsupportedOSPlatformGuard("windows")]
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ public static class AutoStartupHandler
|
||||||
|
|
||||||
#region Linux
|
#region Linux
|
||||||
|
|
||||||
|
[SupportedOSPlatform("linux")]
|
||||||
private static async Task ClearTaskLinux()
|
private static async Task ClearTaskLinux()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -140,6 +141,7 @@ public static class AutoStartupHandler
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SupportedOSPlatform("linux")]
|
||||||
private static async Task SetTaskLinux()
|
private static async Task SetTaskLinux()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -160,6 +162,7 @@ public static class AutoStartupHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SupportedOSPlatform("linux")]
|
||||||
private static string GetHomePathLinux()
|
private static string GetHomePathLinux()
|
||||||
{
|
{
|
||||||
var homePath = Path.Combine(Utils.GetHomePath(), ".config", "autostart", $"{Global.AppName}.desktop");
|
var homePath = Path.Combine(Utils.GetHomePath(), ".config", "autostart", $"{Global.AppName}.desktop");
|
||||||
|
|
@ -171,6 +174,7 @@ public static class AutoStartupHandler
|
||||||
|
|
||||||
#region macOS
|
#region macOS
|
||||||
|
|
||||||
|
[SupportedOSPlatform("macos")]
|
||||||
private static async Task ClearTaskOSX()
|
private static async Task ClearTaskOSX()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -190,6 +194,7 @@ public static class AutoStartupHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SupportedOSPlatform("macos")]
|
||||||
private static async Task SetTaskOSX()
|
private static async Task SetTaskOSX()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -207,6 +212,7 @@ public static class AutoStartupHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SupportedOSPlatform("macos")]
|
||||||
private static string GetLaunchAgentPathMacOS()
|
private static string GetLaunchAgentPathMacOS()
|
||||||
{
|
{
|
||||||
var homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
var homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||||
|
|
@ -215,6 +221,7 @@ public static class AutoStartupHandler
|
||||||
return launchAgentPath;
|
return launchAgentPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SupportedOSPlatform("macos")]
|
||||||
private static string GenerateLaunchAgentPlist()
|
private static string GenerateLaunchAgentPlist()
|
||||||
{
|
{
|
||||||
var exePath = Utils.GetExePath();
|
var exePath = Utils.GetExePath();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
namespace ServiceLib.Handler.SysProxy;
|
namespace ServiceLib.Handler.SysProxy;
|
||||||
|
|
||||||
|
[SupportedOSPlatform("linux")]
|
||||||
public static class ProxySettingLinux
|
public static class ProxySettingLinux
|
||||||
{
|
{
|
||||||
private static readonly string _proxySetFileName = $"{Global.ProxySetLinuxShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
private static readonly string _proxySetFileName = $"{Global.ProxySetLinuxShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
namespace ServiceLib.Handler.SysProxy;
|
namespace ServiceLib.Handler.SysProxy;
|
||||||
|
|
||||||
|
[SupportedOSPlatform("macos")]
|
||||||
public static class ProxySettingOSX
|
public static class ProxySettingOSX
|
||||||
{
|
{
|
||||||
private static readonly string _proxySetFileName = $"{Global.ProxySetOSXShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
private static readonly string _proxySetFileName = $"{Global.ProxySetOSXShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue