From c6caf29b5b832ef5f0fd8e6805f89fc8ea7ac744 Mon Sep 17 00:00:00 2001 From: runetfreedom Date: Mon, 14 Oct 2024 12:50:44 +0300 Subject: [PATCH] Custom geo file source from settings (#5829) Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com> --- v2rayN/ServiceLib/Global.cs | 5 +++++ v2rayN/ServiceLib/Models/ConfigItems.cs | 2 ++ v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 13 ++++++++++++- v2rayN/ServiceLib/Resx/ResUI.resx | 5 ++++- v2rayN/ServiceLib/Services/UpdateService.cs | 6 ++++-- .../ViewModels/OptionSettingViewModel.cs | 3 +++ .../Views/OptionSettingWindow.axaml | 14 ++++++++++++++ .../Views/OptionSettingWindow.axaml.cs | 5 +++++ v2rayN/v2rayN/Views/OptionSettingWindow.xaml | 18 ++++++++++++++++++ .../v2rayN/Views/OptionSettingWindow.xaml.cs | 5 +++++ 10 files changed, 72 insertions(+), 4 deletions(-) diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index d39955dd..2e269ae6 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -114,6 +114,11 @@ @"http://www.msftconnecttest.com/connecttest.txt", }; + public static readonly List GeoFilesSources = new() { + GeoUrl, + @"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/{0}.dat", + }; + 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 bee32971..06e6788a 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -103,6 +103,8 @@ public int trayMenuServersLimit { get; set; } = 20; public bool enableHWA { get; set; } = false; + + public string geoSourceUrl { get; set; } } [Serializable] diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 9a0f92e6..3dd9543d 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -3003,7 +3003,18 @@ namespace ServiceLib.Resx { return ResourceManager.GetString("TbSettingsFontSize", resourceCulture); } } - + + /// + /// Get Geo files source. + /// + public static string TbSettingsGeoFilesSource + { + get + { + return ResourceManager.GetString("TbSettingsGeoFilesSource", resourceCulture); + } + } + /// /// 查找类似 HTTP Port 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 8e4c65fb..65cb3cf1 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1322,9 +1322,12 @@ Host filter - Active + Active Save Interface Layout + + Geo files source + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index 33392fcd..21e1aa2b 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -255,8 +255,8 @@ namespace ServiceLib.Services public async Task UpdateGeoFileAll(Config config, Action updateFunc) { - await UpdateGeoFile("geosite", _config, updateFunc); - await UpdateGeoFile("geoip", _config, updateFunc); + await UpdateGeoFile("geosite", config, updateFunc); + await UpdateGeoFile("geoip", config, updateFunc); _updateFunc?.Invoke(true, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, "geo")); } @@ -450,6 +450,8 @@ namespace ServiceLib.Services { _config = config; _updateFunc = updateFunc; + + var geoUrl = !String.IsNullOrEmpty(config?.guiItem.geoSourceUrl) ? config.guiItem.geoSourceUrl : Global.GeoUrl; var url = string.Format(Global.GeoUrl, geoName); var fileName = Utils.GetTempPath(Utils.GetGuid()); diff --git a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs index 93d61182..0aea70b6 100644 --- a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs @@ -65,6 +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; } #endregion UI @@ -164,6 +165,7 @@ namespace ServiceLib.ViewModels EnableHWA = _config.guiItem.enableHWA; SubConvertUrl = _config.constItem.subConvertUrl; MainGirdOrientation = (int)_config.uiItem.mainGirdOrientation; + GeoFileSourceUrl = _config.guiItem.geoSourceUrl; #endregion UI @@ -316,6 +318,7 @@ namespace ServiceLib.ViewModels _config.guiItem.enableHWA = EnableHWA; _config.constItem.subConvertUrl = SubConvertUrl; _config.uiItem.mainGirdOrientation = (EGirdOrientation)MainGirdOrientation; + _config.guiItem.geoSourceUrl = GeoFileSourceUrl; //systemProxy _config.systemProxyItem.systemProxyExceptions = systemProxyExceptions; diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml index ae63a5e3..aa9ec15b 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml @@ -364,6 +364,7 @@ + @@ -610,6 +611,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 dd52aa92..2ff06d9b 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs @@ -83,6 +83,10 @@ namespace v2rayN.Desktop.Views { cmbSubConvertUrl.Items.Add(it); }); + Global.GeoFilesSources.ForEach(it => + { + cmbGetFilesSourceUrl.Items.Add(it); + }); foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation))) { cmbMainGirdOrientation.Items.Add(it.ToString()); @@ -132,6 +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.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 5b256869..692df521 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml @@ -528,6 +528,7 @@ + @@ -845,6 +846,23 @@ Width="300" Margin="{StaticResource Margin8}" Style="{StaticResource DefComboBox}" /> + + + + diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index cc70ddd0..b67aafeb 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -85,6 +85,10 @@ namespace v2rayN.Views { cmbSubConvertUrl.Items.Add(it); }); + Global.GeoFilesSources.ForEach(it => + { + cmbGetFilesSourceUrl.Items.Add(it); + }); foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation))) { cmbMainGirdOrientation.Items.Add(it.ToString()); @@ -145,6 +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.notProxyLocalAddress, v => v.tognotProxyLocalAddress.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.Text).DisposeWith(disposables);