From 17bfe74ecf64d8d7bbc8c0e6f798f9d70def5899 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 11 Feb 2023 19:34:15 +0800 Subject: [PATCH] Add routing sort --- v2rayN/v2rayN/Base/DownloaderHelper.cs | 2 +- v2rayN/v2rayN/Handler/ConfigHandler.cs | 19 ++++++++++++------- v2rayN/v2rayN/Handler/LazyConfig.cs | 2 +- v2rayN/v2rayN/Mode/Config.cs | 4 ++-- v2rayN/v2rayN/Mode/RoutingItem.cs | 1 + .../ViewModels/RoutingSettingViewModel.cs | 1 + v2rayN/v2rayN/Views/MsgView.xaml.cs | 2 +- .../Views/RoutingRuleSettingWindow.xaml | 18 ++++++++++++++++++ .../Views/RoutingRuleSettingWindow.xaml.cs | 1 + v2rayN/v2rayN/Views/RoutingSettingWindow.xaml | 10 +++++++--- 10 files changed, 45 insertions(+), 15 deletions(-) diff --git a/v2rayN/v2rayN/Base/DownloaderHelper.cs b/v2rayN/v2rayN/Base/DownloaderHelper.cs index 6e2d91bd..86ceac99 100644 --- a/v2rayN/v2rayN/Base/DownloaderHelper.cs +++ b/v2rayN/v2rayN/Base/DownloaderHelper.cs @@ -132,7 +132,7 @@ namespace v2rayN.Base await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token); } - + downloadOpt = null; } diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index b218c45c..e83c30f9 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -43,7 +43,7 @@ namespace v2rayN.Handler if (config == null) { config = new Config - { + { }; } if (config.coreBasicItem == null) @@ -92,7 +92,7 @@ namespace v2rayN.Handler { enableRoutingAdvanced = true }; - } + } //路由规则 if (Utils.IsNullOrEmpty(config.routingBasicItem.domainStrategy)) { @@ -158,7 +158,7 @@ namespace v2rayN.Handler if (Utils.IsNullOrEmpty(config.uiItem.currentLanguage)) { config.uiItem.currentLanguage = Global.Languages[0]; - } + } if (config.constItem == null) { @@ -310,7 +310,7 @@ namespace v2rayN.Handler SqliteHelper.Instance.Replace(routing); } - config = Utils.FromJson(Utils.ToJson(configOld)); + config = Utils.FromJson(Utils.ToJson(configOld)); if (config.coreBasicItem == null) { @@ -320,8 +320,8 @@ namespace v2rayN.Handler loglevel = configOld.loglevel, muxEnabled = configOld.muxEnabled, }; - } - + } + if (config.routingBasicItem == null) { config.routingBasicItem = new() @@ -1509,13 +1509,16 @@ namespace v2rayN.Handler public static int InitBuiltinRouting(ref Config config, bool blImportAdvancedRules = false) { - if (blImportAdvancedRules || LazyConfig.Instance.RoutingItems().Count <= 0) + var items = LazyConfig.Instance.RoutingItems(); + if (blImportAdvancedRules || items.Count <= 0) { + var maxSort = items.Max(t => t.sort); //Bypass the mainland var item2 = new RoutingItem() { remarks = "绕过大陆(Whitelist)", url = string.Empty, + sort = maxSort + 1, }; AddBatchRoutingRules(ref item2, Utils.GetEmbedText(Global.CustomRoutingFileName + "white")); @@ -1524,6 +1527,7 @@ namespace v2rayN.Handler { remarks = "黑名单(Blacklist)", url = string.Empty, + sort = maxSort + 2, }; AddBatchRoutingRules(ref item3, Utils.GetEmbedText(Global.CustomRoutingFileName + "black")); @@ -1532,6 +1536,7 @@ namespace v2rayN.Handler { remarks = "全局(Global)", url = string.Empty, + sort = maxSort + 3, }; AddBatchRoutingRules(ref item1, Utils.GetEmbedText(Global.CustomRoutingFileName + "global")); diff --git a/v2rayN/v2rayN/Handler/LazyConfig.cs b/v2rayN/v2rayN/Handler/LazyConfig.cs index 20bc299d..19ba0526 100644 --- a/v2rayN/v2rayN/Handler/LazyConfig.cs +++ b/v2rayN/v2rayN/Handler/LazyConfig.cs @@ -139,7 +139,7 @@ namespace v2rayN.Handler public List RoutingItems() { - return SqliteHelper.Instance.Table().Where(it => it.locked == false).ToList(); + return SqliteHelper.Instance.Table().Where(it => it.locked == false).OrderBy(t => t.sort).ToList(); } public RoutingItem GetRoutingItem(string id) { diff --git a/v2rayN/v2rayN/Mode/Config.cs b/v2rayN/v2rayN/Mode/Config.cs index c141052f..25c7d52b 100644 --- a/v2rayN/v2rayN/Mode/Config.cs +++ b/v2rayN/v2rayN/Mode/Config.cs @@ -7,9 +7,9 @@ public class Config { #region property - + public string indexId { get; set; } - + public string remoteDNS { get; set; } /// /// Outbound Freedom domainStrategy diff --git a/v2rayN/v2rayN/Mode/RoutingItem.cs b/v2rayN/v2rayN/Mode/RoutingItem.cs index 8aae1ac4..5780ddc5 100644 --- a/v2rayN/v2rayN/Mode/RoutingItem.cs +++ b/v2rayN/v2rayN/Mode/RoutingItem.cs @@ -15,6 +15,7 @@ namespace v2rayN.Mode public bool locked { get; set; } public string customIcon { get; set; } public string domainStrategy { get; set; } + public int sort { get; set; } } } diff --git a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs index 233f0c44..39dd1fbf 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs @@ -176,6 +176,7 @@ namespace v2rayN.ViewModels remarks = item.remarks, url = item.url, customIcon = item.customIcon, + sort = item.sort, }; _routingItems.Add(it); } diff --git a/v2rayN/v2rayN/Views/MsgView.xaml.cs b/v2rayN/v2rayN/Views/MsgView.xaml.cs index ef28a95f..d3d866bb 100644 --- a/v2rayN/v2rayN/Views/MsgView.xaml.cs +++ b/v2rayN/v2rayN/Views/MsgView.xaml.cs @@ -94,7 +94,7 @@ namespace v2rayN.Views private void menuMsgViewClear_Click(object sender, System.Windows.RoutedEventArgs e) { ClearMsg(); - } + } private void cmbMsgFilter_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { _config.uiItem.mainMsgFilter = cmbMsgFilter.Text.TrimEx(); diff --git a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml index 9a0c1ad8..f0d44ae4 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml @@ -92,6 +92,7 @@ + @@ -177,6 +178,23 @@ Content="{x:Static resx:ResUI.TbBrowse}" Style="{StaticResource DefButton}" /> + + + diff --git a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs index 791b450a..ec3d9428 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs @@ -33,6 +33,7 @@ namespace v2rayN.Views this.Bind(ViewModel, vm => vm.SelectedRouting.domainStrategy, v => v.cmbdomainStrategy.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedRouting.url, v => v.txtUrl.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedRouting.customIcon, v => v.txtCustomIcon.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SelectedRouting.sort, v => v.txtSort.Text).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.RuleAddCmd, v => v.menuRuleAdd).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ImportRulesFromFileCmd, v => v.menuImportRulesFromFile).DisposeWith(disposables); diff --git a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml index a2eae352..d4233bbe 100644 --- a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml @@ -197,15 +197,19 @@ Binding="{Binding remarks}" Header="{x:Static resx:ResUI.LvAlias}" /> +