From 65f14705fea63bb45d684a4e31e4c145c2fce7ce Mon Sep 17 00:00:00 2001 From: runetfreedom Date: Tue, 15 Oct 2024 03:08:37 +0300 Subject: [PATCH] Fix broken TUN if custom geo file is selected --- v2rayN/ServiceLib/Global.cs | 10 ++++++++++ v2rayN/ServiceLib/Models/ConfigItems.cs | 2 +- .../Services/CoreConfig/CoreConfigSingboxService.cs | 6 +++++- v2rayN/ServiceLib/Services/UpdateService.cs | 7 ++++--- v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs | 6 +++--- v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml | 2 +- .../v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs | 6 +++--- v2rayN/v2rayN/Views/OptionSettingWindow.xaml | 4 ++-- v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs | 6 +++--- 9 files changed, 32 insertions(+), 17 deletions(-) diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 2e269ae6..f444251e 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -114,11 +114,21 @@ @"http://www.msftconnecttest.com/connecttest.txt", }; + public static readonly List GeoSourceNames = new() { + "", //Default + "Russia", + }; + 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", + }; + 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..1fff5613 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -140,7 +140,7 @@ { public string defIEProxyExceptions { get; set; } public string subConvertUrl { get; set; } = string.Empty; - public string? geoSourceUrl { get; set; } + public int geoSource { get; set; } = 0; } [Serializable] diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs index 3e8dc82a..923de645 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 geoUrl = Global.SingboxRulesetSources.Count <= _config.constItem.geoSource + ? Global.SingboxRulesetUrl + : Global.SingboxRulesetSources[_config.constItem.geoSource]; + customRuleset = new() { type = "remote", format = "binary", tag = item, - url = string.Format(Global.SingboxRulesetUrl, item.StartsWith(geosite) ? geosite : geoip, item), + url = string.Format(geoUrl, 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 d821d1db..9fff1668 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -451,10 +451,11 @@ namespace ServiceLib.Services _config = config; _updateFunc = updateFunc; - var geoUrl = string.IsNullOrEmpty(config?.constItem.geoSourceUrl) + var geoIndex = config?.constItem.geoSource ?? 0; + var geoUrl = Global.GeoFilesSources.Count <= geoIndex ? Global.GeoUrl - : config.constItem.geoSourceUrl; - var url = string.Format(Global.GeoUrl, geoName); + : Global.GeoFilesSources[geoIndex]; + 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..ac2ff14e 100644 --- a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs @@ -65,7 +65,7 @@ namespace ServiceLib.ViewModels [Reactive] public bool EnableHWA { get; set; } [Reactive] public string SubConvertUrl { get; set; } [Reactive] public int MainGirdOrientation { get; set; } - [Reactive] public string GeoFileSourceUrl { get; set; } + [Reactive] public int GeoFileSource { get; set; } #endregion UI @@ -165,7 +165,7 @@ namespace ServiceLib.ViewModels EnableHWA = _config.guiItem.enableHWA; SubConvertUrl = _config.constItem.subConvertUrl; MainGirdOrientation = (int)_config.uiItem.mainGirdOrientation; - GeoFileSourceUrl = _config.constItem.geoSourceUrl; + GeoFileSource = _config.constItem.geoSource; #endregion UI @@ -318,7 +318,7 @@ namespace ServiceLib.ViewModels _config.guiItem.enableHWA = EnableHWA; _config.constItem.subConvertUrl = SubConvertUrl; _config.uiItem.mainGirdOrientation = (EGirdOrientation)MainGirdOrientation; - _config.constItem.geoSourceUrl = GeoFileSourceUrl; + _config.constItem.geoSource = GeoFileSource; //systemProxy _config.systemProxyItem.systemProxyExceptions = systemProxyExceptions; diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml index a183fdf5..87395694 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml @@ -619,7 +619,7 @@ Classes="Margin8" Text="{x:Static resx:ResUI.TbSettingsGeoFilesSource}" /> + Global.GeoSourceNames.ForEach(it => { - cmbGetFilesSourceUrl.Items.Add(it); + cmbGetFilesSource.Items.Add(it); }); foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation))) { @@ -136,7 +136,7 @@ namespace v2rayN.Desktop.Views this.Bind(ViewModel, vm => vm.SpeedPingTestUrl, v => v.cmbSpeedPingTestUrl.SelectedValue).DisposeWith(disposables); 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.GeoFileSource, v => v.cmbGetFilesSource.SelectedIndex).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..fb2548d9 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml @@ -855,12 +855,12 @@ Style="{StaticResource ToolbarTextBlock}" Text="{x:Static resx:ResUI.TbSettingsGeoFilesSource}" /> diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index b67aafeb..39092410 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -85,9 +85,9 @@ namespace v2rayN.Views { cmbSubConvertUrl.Items.Add(it); }); - Global.GeoFilesSources.ForEach(it => + Global.GeoSourceNames.ForEach(it => { - cmbGetFilesSourceUrl.Items.Add(it); + cmbGetFilesSource.Items.Add(it); }); foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation))) { @@ -149,7 +149,7 @@ namespace v2rayN.Views this.Bind(ViewModel, vm => vm.EnableHWA, v => v.togEnableHWA.IsChecked).DisposeWith(disposables); 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.GeoFileSource, v => v.cmbGetFilesSource.SelectedIndex).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);