From a5122b656df03cbbcb1c39078dc72775792af876 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:52:45 +0800 Subject: [PATCH] Bug fix for Dsktop --- v2rayN/ServiceLib/Global.cs | 2 + v2rayN/ServiceLib/Handler/AppHandler.cs | 18 ++- .../Handler/SysProxy/SysProxyHandler.cs | 108 ++++++++++-------- .../Views/OptionSettingWindow.axaml.cs | 11 +- 4 files changed, 74 insertions(+), 65 deletions(-) diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 73108a58bef..8d1cdc2f4d7 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -115,11 +115,13 @@ public class Global }; public static readonly List GeoFilesSources = new() { + "", GeoUrl, @"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/{0}.dat", }; public static readonly List SingboxRulesetSources = new() { + "", SingboxRulesetUrl, @"https://raw.githubusercontent.com/runetfreedom/russia-v2ray-rules-dat/refs/heads/release/sing-box/rule-set-{0}/{1}.srs", }; diff --git a/v2rayN/ServiceLib/Handler/AppHandler.cs b/v2rayN/ServiceLib/Handler/AppHandler.cs index 5f6ab3af5d9..b04870ad984 100644 --- a/v2rayN/ServiceLib/Handler/AppHandler.cs +++ b/v2rayN/ServiceLib/Handler/AppHandler.cs @@ -44,10 +44,6 @@ public bool IsAdministrator #region Init - public AppHandler() - { - } - public bool InitApp() { if (ConfigHandler.LoadConfig(ref _config) != 0) @@ -61,6 +57,13 @@ public bool InitApp() { Environment.SetEnvironmentVariable("DOTNET_EnableWriteXorExecute", "0", EnvironmentVariableTarget.User); } + + SQLiteHelper.Instance.CreateTable(); + SQLiteHelper.Instance.CreateTable(); + SQLiteHelper.Instance.CreateTable(); + SQLiteHelper.Instance.CreateTable(); + SQLiteHelper.Instance.CreateTable(); + SQLiteHelper.Instance.CreateTable(); return true; } @@ -72,13 +75,6 @@ public bool InitComponents() Logging.SaveLog($"{Environment.OSVersion} - {(Environment.Is64BitOperatingSystem ? 64 : 32)}"); Logging.ClearLogs(); - SQLiteHelper.Instance.CreateTable(); - SQLiteHelper.Instance.CreateTable(); - SQLiteHelper.Instance.CreateTable(); - SQLiteHelper.Instance.CreateTable(); - SQLiteHelper.Instance.CreateTable(); - SQLiteHelper.Instance.CreateTable(); - return true; } diff --git a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs index 98220cc03c6..54bfec065b8 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs @@ -17,67 +17,59 @@ public static async Task UpdateSysProxy(Config config, bool forceDisable) { var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http); var portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); - var portPac = AppHandler.Instance.GetLocalPort(EInboundProtocol.pac); if (port <= 0) { return false; } - if (type == ESysProxyType.ForcedChange) + switch (type) { - if (Utils.IsWindows()) - { - var strExceptions = ""; - if (config.systemProxyItem.notProxyLocalAddress) + case ESysProxyType.ForcedChange when Utils.IsWindows(): { - strExceptions = $";{config.constItem.defIEProxyExceptions};{config.systemProxyItem.systemProxyExceptions}"; + GetWindowsProxyString(config, port, portSocks, out var strProxy, out var strExceptions); + ProxySettingWindows.SetProxy(strProxy, strExceptions, 2); + break; } + case ESysProxyType.ForcedChange when Utils.IsLinux(): + await ProxySettingLinux.SetProxy(Global.Loopback, port); + break; - var strProxy = string.Empty; - if (Utils.IsNullOrEmpty(config.systemProxyItem.systemProxyAdvancedProtocol)) - { - strProxy = $"{Global.Loopback}:{port}"; - } - else + case ESysProxyType.ForcedChange: { - strProxy = config.systemProxyItem.systemProxyAdvancedProtocol - .Replace("{ip}", Global.Loopback) - .Replace("{http_port}", port.ToString()) - .Replace("{socks_port}", portSocks.ToString()); + if (Utils.IsOSX()) + { + await ProxySettingOSX.SetProxy(Global.Loopback, port); + } + + break; } - ProxySettingWindows.SetProxy(strProxy, strExceptions, 2); - } - else if (Utils.IsLinux()) - { - await ProxySettingLinux.SetProxy(Global.Loopback, port); - } - else if (Utils.IsOSX()) - { - await ProxySettingOSX.SetProxy(Global.Loopback, port); - } - } - else if (type == ESysProxyType.ForcedClear) - { - if (Utils.IsWindows()) - { + case ESysProxyType.ForcedClear when Utils.IsWindows(): ProxySettingWindows.UnsetProxy(); - } - else if (Utils.IsLinux()) - { + break; + + case ESysProxyType.ForcedClear when Utils.IsLinux(): await ProxySettingLinux.UnsetProxy(); - } - else if (Utils.IsOSX()) - { - await ProxySettingOSX.UnsetProxy(); - } - } - else if (type == ESysProxyType.Pac) - { - PacHandler.Start(Utils.GetConfigPath(), port, portPac); - var strProxy = $"{Global.HttpProtocol}{Global.Loopback}:{portPac}/pac?t={DateTime.Now.Ticks}"; - ProxySettingWindows.SetProxy(strProxy, "", 4); + break; + + case ESysProxyType.ForcedClear: + { + if (Utils.IsOSX()) + { + await ProxySettingOSX.UnsetProxy(); + } + + break; + } + case ESysProxyType.Pac when Utils.IsWindows(): + { + var portPac = AppHandler.Instance.GetLocalPort(EInboundProtocol.pac); + PacHandler.Start(Utils.GetConfigPath(), port, portPac); + var strProxy = $"{Global.HttpProtocol}{Global.Loopback}:{portPac}/pac?t={DateTime.Now.Ticks}"; + ProxySettingWindows.SetProxy(strProxy, "", 4); + break; + } } - if (type != ESysProxyType.Pac) + if (type != ESysProxyType.Pac && Utils.IsWindows()) { PacHandler.Stop(); } @@ -88,5 +80,27 @@ public static async Task UpdateSysProxy(Config config, bool forceDisable) } return true; } + + private static void GetWindowsProxyString(Config config, int port, int portSocks, out string strProxy, out string strExceptions) + { + strExceptions = ""; + if (config.systemProxyItem.notProxyLocalAddress) + { + strExceptions = $";{config.constItem.defIEProxyExceptions};{config.systemProxyItem.systemProxyExceptions}"; + } + + strProxy = string.Empty; + if (Utils.IsNullOrEmpty(config.systemProxyItem.systemProxyAdvancedProtocol)) + { + strProxy = $"{Global.Loopback}:{port}"; + } + else + { + strProxy = config.systemProxyItem.systemProxyAdvancedProtocol + .Replace("{ip}", Global.Loopback) + .Replace("{http_port}", port.ToString()) + .Replace("{socks_port}", portSocks.ToString()); + } + } } } \ No newline at end of file diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs index 2154a27eab1..c21c34012ed 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs @@ -163,13 +163,10 @@ public OptionSettingWindow() this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - //if (Utils.IsWindows()) - //{ - //} - //else - //{ - tabSystemproxy.IsVisible = false; - //} + if (!Utils.IsWindows()) + { + tabSystemproxy.IsVisible = false; + } } private async Task UpdateViewHandler(EViewAction action, object? obj)