From eebb6735aab35ff358ddeb217ef952ca65d4737e Mon Sep 17 00:00:00 2001 From: runetfreedom Date: Tue, 15 Oct 2024 08:28:51 +0300 Subject: [PATCH] Add sing-box srs custom url support for fix TUN (#5835) Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com> --- v2rayN/ServiceLib/Global.cs | 5 +++++ v2rayN/ServiceLib/Models/ConfigItems.cs | 1 + v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 13 ++++++++++++- v2rayN/ServiceLib/Resx/ResUI.resx | 2 ++ .../CoreConfig/CoreConfigSingboxService.cs | 6 +++++- v2rayN/ServiceLib/Services/UpdateService.cs | 2 +- .../ViewModels/OptionSettingViewModel.cs | 3 +++ .../Views/OptionSettingWindow.axaml | 14 ++++++++++++++ .../Views/OptionSettingWindow.axaml.cs | 5 +++++ v2rayN/v2rayN/Views/OptionSettingWindow.xaml | 17 +++++++++++++++++ v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs | 5 +++++ 11 files changed, 70 insertions(+), 3 deletions(-) diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 2e269ae6..73108a58 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -119,6 +119,11 @@ @"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", + }; + public static readonly Dictionary UserAgentTexts = new() { {"chrome","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36" }, diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs index e4bbe112..ff282ab1 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -141,6 +141,7 @@ public string defIEProxyExceptions { get; set; } public string subConvertUrl { get; set; } = string.Empty; public string? geoSourceUrl { get; set; } + public string? srsSourceUrl { get; set; } } [Serializable] diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index f219d43b..15f1d568 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -3012,7 +3012,18 @@ namespace ServiceLib.Resx { return ResourceManager.GetString("TbSettingsGeoFilesSource", resourceCulture); } } - + + /// + /// 查找类似 Sing-box srs files source (optional) 的本地化字符串。 + /// + public static string TbSettingsSrsFilesSource + { + get + { + return ResourceManager.GetString("TbSettingsSrsFilesSource", resourceCulture); + } + } + /// /// 查找类似 HTTP Port 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 5d0f1a44..95053d3a 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1330,6 +1330,8 @@ Geo files source (optional) + + Sing-box srs files source (optional) UpgradeApp does not exist diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs index 3e8dc82a..b0fbf800 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs @@ -1367,12 +1367,16 @@ namespace ServiceLib.Services.CoreConfig } else { + var srsUrl = string.IsNullOrEmpty(_config.constItem.srsSourceUrl) + ? Global.SingboxRulesetUrl + : _config.constItem.srsSourceUrl; + customRuleset = new() { type = "remote", format = "binary", tag = item, - url = string.Format(Global.SingboxRulesetUrl, item.StartsWith(geosite) ? geosite : geoip, item), + url = string.Format(srsUrl, item.StartsWith(geosite) ? geosite : geoip, item), download_detour = Global.ProxyTag }; } diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index 8e9e54e4..f25548ce 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -454,7 +454,7 @@ namespace ServiceLib.Services var geoUrl = string.IsNullOrEmpty(config?.constItem.geoSourceUrl) ? Global.GeoUrl : config.constItem.geoSourceUrl; - var url = string.Format(Global.GeoUrl, geoName); + var url = string.Format(geoUrl, geoName); var fileName = Utils.GetTempPath(Utils.GetGuid()); DownloadService downloadHandle = new(); diff --git a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs index ef6f6735..d3b79f35 100644 --- a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs @@ -66,6 +66,7 @@ namespace ServiceLib.ViewModels [Reactive] public string SubConvertUrl { get; set; } [Reactive] public int MainGirdOrientation { get; set; } [Reactive] public string GeoFileSourceUrl { get; set; } + [Reactive] public string SrsFileSourceUrl { get; set; } #endregion UI @@ -166,6 +167,7 @@ namespace ServiceLib.ViewModels SubConvertUrl = _config.constItem.subConvertUrl; MainGirdOrientation = (int)_config.uiItem.mainGirdOrientation; GeoFileSourceUrl = _config.constItem.geoSourceUrl; + SrsFileSourceUrl = _config.constItem.srsSourceUrl; #endregion UI @@ -319,6 +321,7 @@ namespace ServiceLib.ViewModels _config.constItem.subConvertUrl = SubConvertUrl; _config.uiItem.mainGirdOrientation = (EGirdOrientation)MainGirdOrientation; _config.constItem.geoSourceUrl = GeoFileSourceUrl; + _config.constItem.srsSourceUrl = SrsFileSourceUrl; //systemProxy _config.systemProxyItem.systemProxyExceptions = systemProxyExceptions; diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml index a183fdf5..92e13a93 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml @@ -365,6 +365,7 @@ + @@ -624,6 +625,19 @@ Grid.Column="1" Width="300" Classes="Margin8" /> + + + diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs index 2ff06d9b..2154a27e 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs @@ -87,6 +87,10 @@ namespace v2rayN.Desktop.Views { cmbGetFilesSourceUrl.Items.Add(it); }); + Global.SingboxRulesetSources.ForEach(it => + { + cmbSrsFilesSourceUrl.Items.Add(it); + }); foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation))) { cmbMainGirdOrientation.Items.Add(it.ToString()); @@ -137,6 +141,7 @@ namespace v2rayN.Desktop.Views this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.GeoFileSourceUrl, v => v.cmbGetFilesSourceUrl.SelectedValue).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SrsFileSourceUrl, v => v.cmbSrsFilesSourceUrl.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.notProxyLocalAddress, v => v.tognotProxyLocalAddress.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.SelectedValue).DisposeWith(disposables); diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml index e1754326..24c351e3 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml @@ -529,6 +529,7 @@ + @@ -862,6 +863,22 @@ Margin="{StaticResource Margin8}" IsEditable="True" Style="{StaticResource DefComboBox}" /> + + + diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index b67aafeb..7e364d3c 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -89,6 +89,10 @@ namespace v2rayN.Views { cmbGetFilesSourceUrl.Items.Add(it); }); + Global.SingboxRulesetSources.ForEach(it => + { + cmbSrsFilesSourceUrl.Items.Add(it); + }); foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation))) { cmbMainGirdOrientation.Items.Add(it.ToString()); @@ -150,6 +154,7 @@ namespace v2rayN.Views this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.GeoFileSourceUrl, v => v.cmbGetFilesSourceUrl.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SrsFileSourceUrl, v => v.cmbSrsFilesSourceUrl.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.notProxyLocalAddress, v => v.tognotProxyLocalAddress.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.Text).DisposeWith(disposables);