mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-18 06:34:42 +03:00
58d2641559
* deps: bump ZXing.Net.Bindings.SkiaSharp from 0.16.14 to 0.16.22 Patch update to the latest stable release on the 0.16.x line. No breaking changes, no public API changes - purely internal fixes. Verified by a full Release build of v2rayN.sln on .NET 10; no new warnings or errors are introduced. * chore: remove NoWarn and fix .NET 10 build warnings Removes the repository-level NoWarn suppression from Directory.Build.props and addresses the warnings that surface on top of the .NET 10 migration in #9179, keeping Debug, Release, and cross-platform publishes warning-free without suppressing warnings globally. Changes: - Removes <NoWarn>CA1031;CS1591;NU1507;CA1416;IDE0058;IDE0053;IDE0200</NoWarn> from Directory.Build.props. - Annotates Windows-only APIs with [SupportedOSPlatform] and [SupportedOSPlatformGuard] so CA1416 accepts that the Windows surface is gated behind Utils.IsWindows() / Utils.IsNonWindows(). - Splits Utils.SetUnixFileMode into a cross-platform wrapper and a private [UnsupportedOSPlatform("windows")] implementation so File.SetUnixFileMode never reaches the analyzer on Windows builds. - Adds a parameterless constructor to MessageBoxDialog so Avalonia's runtime XAML loader (AVLN3001) can instantiate the dialog. - Moves the WPF high-DPI configuration from app.manifest to <ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode> in v2rayN.csproj, fixing WFO0003. - Adds global using System.Runtime.Versioning; to ServiceLib and v2rayN.Desktop so the platform attributes are usable project-wide. * test: make cycle dependency tests locale-independent Accept the localized Russian cycle dependency diagnostic in CoreConfigContextBuilderTests so the assertions pass when tests run under a Russian UI culture. * 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.
100 lines
3.5 KiB
C#
100 lines
3.5 KiB
C#
namespace ServiceLib.Handler.SysProxy;
|
|
|
|
public static class SysProxyHandler
|
|
{
|
|
private static readonly string _tag = "SysProxyHandler";
|
|
|
|
public static async Task<bool> UpdateSysProxy(Config config, bool forceDisable)
|
|
{
|
|
var type = config.SystemProxyItem.SysProxyType;
|
|
|
|
if (forceDisable && type != ESysProxyType.Unchanged)
|
|
{
|
|
type = ESysProxyType.ForcedClear;
|
|
}
|
|
|
|
try
|
|
{
|
|
var port = AppManager.Instance.GetLocalPort(EInboundProtocol.socks);
|
|
var exceptions = config.SystemProxyItem.SystemProxyExceptions.Replace(" ", "");
|
|
if (port <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
switch (type)
|
|
{
|
|
case ESysProxyType.ForcedChange when Utils.IsWindows():
|
|
{
|
|
GetWindowsProxyString(config, port, out var strProxy, out var strExceptions);
|
|
ProxySettingWindows.SetProxy(strProxy, strExceptions, 2);
|
|
break;
|
|
}
|
|
case ESysProxyType.ForcedChange when Utils.IsLinux():
|
|
await ProxySettingLinux.SetProxy(Global.Loopback, port, exceptions);
|
|
break;
|
|
|
|
case ESysProxyType.ForcedChange when Utils.IsMacOS():
|
|
await ProxySettingOSX.SetProxy(Global.Loopback, port, exceptions);
|
|
break;
|
|
|
|
case ESysProxyType.ForcedClear when Utils.IsWindows():
|
|
ProxySettingWindows.UnsetProxy();
|
|
break;
|
|
|
|
case ESysProxyType.ForcedClear when Utils.IsLinux():
|
|
await ProxySettingLinux.UnsetProxy();
|
|
break;
|
|
|
|
case ESysProxyType.ForcedClear when Utils.IsMacOS():
|
|
await ProxySettingOSX.UnsetProxy();
|
|
break;
|
|
|
|
case ESysProxyType.Pac when Utils.IsWindows():
|
|
await SetWindowsProxyPac(port);
|
|
break;
|
|
}
|
|
|
|
if (type != ESysProxyType.Pac && Utils.IsWindows())
|
|
{
|
|
PacManager.Instance.Stop();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logging.SaveLog(_tag, ex);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private static void GetWindowsProxyString(Config config, int port, out string strProxy, out string strExceptions)
|
|
{
|
|
strExceptions = config.SystemProxyItem.SystemProxyExceptions.Replace(" ", "");
|
|
if (config.SystemProxyItem.NotProxyLocalAddress)
|
|
{
|
|
strExceptions = $"<local>;{strExceptions}";
|
|
}
|
|
|
|
strProxy = string.Empty;
|
|
if (config.SystemProxyItem.SystemProxyAdvancedProtocol.IsNullOrEmpty())
|
|
{
|
|
strProxy = $"{Global.Loopback}:{port}";
|
|
}
|
|
else
|
|
{
|
|
strProxy = config.SystemProxyItem.SystemProxyAdvancedProtocol
|
|
.Replace("{ip}", Global.Loopback)
|
|
.Replace("{http_port}", port.ToString())
|
|
.Replace("{socks_port}", port.ToString());
|
|
}
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
private static async Task SetWindowsProxyPac(int port)
|
|
{
|
|
var portPac = AppManager.Instance.GetLocalPort(EInboundProtocol.pac);
|
|
await PacManager.Instance.StartAsync(port, portPac);
|
|
var strProxy = $"{Global.HttpProtocol}{Global.Loopback}:{portPac}/pac?t={DateTime.Now.Ticks}";
|
|
ProxySettingWindows.SetProxy(strProxy, "", 4);
|
|
}
|
|
}
|