Add routing sort

This commit is contained in:
2dust 2023-02-11 19:34:15 +08:00
parent b77827df90
commit 17bfe74ecf
10 changed files with 45 additions and 15 deletions

View file

@ -132,7 +132,7 @@ namespace v2rayN.Base
await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token); await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token);
} }
downloadOpt = null; downloadOpt = null;
} }

View file

@ -43,7 +43,7 @@ namespace v2rayN.Handler
if (config == null) if (config == null)
{ {
config = new Config config = new Config
{ {
}; };
} }
if (config.coreBasicItem == null) if (config.coreBasicItem == null)
@ -92,7 +92,7 @@ namespace v2rayN.Handler
{ {
enableRoutingAdvanced = true enableRoutingAdvanced = true
}; };
} }
//路由规则 //路由规则
if (Utils.IsNullOrEmpty(config.routingBasicItem.domainStrategy)) if (Utils.IsNullOrEmpty(config.routingBasicItem.domainStrategy))
{ {
@ -158,7 +158,7 @@ namespace v2rayN.Handler
if (Utils.IsNullOrEmpty(config.uiItem.currentLanguage)) if (Utils.IsNullOrEmpty(config.uiItem.currentLanguage))
{ {
config.uiItem.currentLanguage = Global.Languages[0]; config.uiItem.currentLanguage = Global.Languages[0];
} }
if (config.constItem == null) if (config.constItem == null)
{ {
@ -310,7 +310,7 @@ namespace v2rayN.Handler
SqliteHelper.Instance.Replace(routing); SqliteHelper.Instance.Replace(routing);
} }
config = Utils.FromJson<Config>(Utils.ToJson(configOld)); config = Utils.FromJson<Config>(Utils.ToJson(configOld));
if (config.coreBasicItem == null) if (config.coreBasicItem == null)
{ {
@ -320,8 +320,8 @@ namespace v2rayN.Handler
loglevel = configOld.loglevel, loglevel = configOld.loglevel,
muxEnabled = configOld.muxEnabled, muxEnabled = configOld.muxEnabled,
}; };
} }
if (config.routingBasicItem == null) if (config.routingBasicItem == null)
{ {
config.routingBasicItem = new() config.routingBasicItem = new()
@ -1509,13 +1509,16 @@ namespace v2rayN.Handler
public static int InitBuiltinRouting(ref Config config, bool blImportAdvancedRules = false) 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 //Bypass the mainland
var item2 = new RoutingItem() var item2 = new RoutingItem()
{ {
remarks = "绕过大陆(Whitelist)", remarks = "绕过大陆(Whitelist)",
url = string.Empty, url = string.Empty,
sort = maxSort + 1,
}; };
AddBatchRoutingRules(ref item2, Utils.GetEmbedText(Global.CustomRoutingFileName + "white")); AddBatchRoutingRules(ref item2, Utils.GetEmbedText(Global.CustomRoutingFileName + "white"));
@ -1524,6 +1527,7 @@ namespace v2rayN.Handler
{ {
remarks = "黑名单(Blacklist)", remarks = "黑名单(Blacklist)",
url = string.Empty, url = string.Empty,
sort = maxSort + 2,
}; };
AddBatchRoutingRules(ref item3, Utils.GetEmbedText(Global.CustomRoutingFileName + "black")); AddBatchRoutingRules(ref item3, Utils.GetEmbedText(Global.CustomRoutingFileName + "black"));
@ -1532,6 +1536,7 @@ namespace v2rayN.Handler
{ {
remarks = "全局(Global)", remarks = "全局(Global)",
url = string.Empty, url = string.Empty,
sort = maxSort + 3,
}; };
AddBatchRoutingRules(ref item1, Utils.GetEmbedText(Global.CustomRoutingFileName + "global")); AddBatchRoutingRules(ref item1, Utils.GetEmbedText(Global.CustomRoutingFileName + "global"));

View file

@ -139,7 +139,7 @@ namespace v2rayN.Handler
public List<RoutingItem> RoutingItems() public List<RoutingItem> RoutingItems()
{ {
return SqliteHelper.Instance.Table<RoutingItem>().Where(it => it.locked == false).ToList(); return SqliteHelper.Instance.Table<RoutingItem>().Where(it => it.locked == false).OrderBy(t => t.sort).ToList();
} }
public RoutingItem GetRoutingItem(string id) public RoutingItem GetRoutingItem(string id)
{ {

View file

@ -7,9 +7,9 @@
public class Config public class Config
{ {
#region property #region property
public string indexId { get; set; } public string indexId { get; set; }
public string remoteDNS { get; set; } public string remoteDNS { get; set; }
/// <summary> /// <summary>
/// Outbound Freedom domainStrategy /// Outbound Freedom domainStrategy

View file

@ -15,6 +15,7 @@ namespace v2rayN.Mode
public bool locked { get; set; } public bool locked { get; set; }
public string customIcon { get; set; } public string customIcon { get; set; }
public string domainStrategy { get; set; } public string domainStrategy { get; set; }
public int sort { get; set; }
} }
} }

View file

@ -176,6 +176,7 @@ namespace v2rayN.ViewModels
remarks = item.remarks, remarks = item.remarks,
url = item.url, url = item.url,
customIcon = item.customIcon, customIcon = item.customIcon,
sort = item.sort,
}; };
_routingItems.Add(it); _routingItems.Add(it);
} }

View file

@ -94,7 +94,7 @@ namespace v2rayN.Views
private void menuMsgViewClear_Click(object sender, System.Windows.RoutedEventArgs e) private void menuMsgViewClear_Click(object sender, System.Windows.RoutedEventArgs e)
{ {
ClearMsg(); ClearMsg();
} }
private void cmbMsgFilter_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) private void cmbMsgFilter_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{ {
_config.uiItem.mainMsgFilter = cmbMsgFilter.Text.TrimEx(); _config.uiItem.mainMsgFilter = cmbMsgFilter.Text.TrimEx();

View file

@ -92,6 +92,7 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
@ -177,6 +178,23 @@
Content="{x:Static resx:ResUI.TbBrowse}" Content="{x:Static resx:ResUI.TbBrowse}"
Style="{StaticResource DefButton}" /> Style="{StaticResource DefButton}" />
<TextBlock
Grid.Row="4"
Grid.Column="0"
Margin="4"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.LvSort}" />
<TextBox
x:Name="txtSort"
Grid.Row="4"
Grid.Column="1"
Width="200"
Margin="4"
HorizontalAlignment="Left"
AcceptsReturn="True"
Style="{StaticResource DefTextBox}" />
</Grid> </Grid>
<TabControl x:Name="tabAdvanced"> <TabControl x:Name="tabAdvanced">

View file

@ -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.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.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.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.RuleAddCmd, v => v.menuRuleAdd).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ImportRulesFromFileCmd, v => v.menuImportRulesFromFile).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ImportRulesFromFileCmd, v => v.menuImportRulesFromFile).DisposeWith(disposables);

View file

@ -197,15 +197,19 @@
Binding="{Binding remarks}" Binding="{Binding remarks}"
Header="{x:Static resx:ResUI.LvAlias}" /> Header="{x:Static resx:ResUI.LvAlias}" />
<DataGridTextColumn <DataGridTextColumn
Width="70" Width="60"
Binding="{Binding ruleNum}" Binding="{Binding ruleNum}"
Header="{x:Static resx:ResUI.LvCount}" /> Header="{x:Static resx:ResUI.LvCount}" />
<DataGridTextColumn <DataGridTextColumn
Width="280" Width="60"
Binding="{Binding sort}"
Header="{x:Static resx:ResUI.LvSort}" />
<DataGridTextColumn
Width="260"
Binding="{Binding url}" Binding="{Binding url}"
Header="{x:Static resx:ResUI.LvUrl}" /> Header="{x:Static resx:ResUI.LvUrl}" />
<DataGridTextColumn <DataGridTextColumn
Width="280" Width="260"
Binding="{Binding customIcon}" Binding="{Binding customIcon}"
Header="{x:Static resx:ResUI.LvCustomIcon}" /> Header="{x:Static resx:ResUI.LvCustomIcon}" />
</DataGrid.Columns> </DataGrid.Columns>