mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 11:59:13 +00:00
Use enum
This commit is contained in:
parent
4301415b4c
commit
c53d9c118a
12 changed files with 31 additions and 66 deletions
8
v2rayN/ServiceLib/Enums/ERuleType.cs
Normal file
8
v2rayN/ServiceLib/Enums/ERuleType.cs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
namespace ServiceLib.Enums;
|
||||||
|
|
||||||
|
public enum ERuleType
|
||||||
|
{
|
||||||
|
ALL = 0,
|
||||||
|
Routing = 1,
|
||||||
|
DNS = 2,
|
||||||
|
}
|
|
@ -87,8 +87,6 @@ public class Global
|
||||||
public const string SingboxFinalResolverTag = "final_resolver";
|
public const string SingboxFinalResolverTag = "final_resolver";
|
||||||
public const string SingboxHostsDNSTag = "hosts_dns";
|
public const string SingboxHostsDNSTag = "hosts_dns";
|
||||||
public const string SingboxFakeDNSTag = "fake_dns";
|
public const string SingboxFakeDNSTag = "fake_dns";
|
||||||
public const string RoutingRuleType = "Routing";
|
|
||||||
public const string DNSRuleType = "DNS";
|
|
||||||
|
|
||||||
public static readonly List<string> IEProxyProtocols =
|
public static readonly List<string> IEProxyProtocols =
|
||||||
[
|
[
|
||||||
|
@ -473,12 +471,6 @@ public class Global
|
||||||
"tcp,udp"
|
"tcp,udp"
|
||||||
];
|
];
|
||||||
|
|
||||||
public static readonly List<string> RuleTypes =
|
|
||||||
[
|
|
||||||
RoutingRuleType,
|
|
||||||
DNSRuleType
|
|
||||||
];
|
|
||||||
|
|
||||||
public static readonly List<string> destOverrideProtocols =
|
public static readonly List<string> destOverrideProtocols =
|
||||||
[
|
[
|
||||||
"http",
|
"http",
|
||||||
|
|
|
@ -15,5 +15,5 @@ public class RulesItem
|
||||||
public List<string>? Process { get; set; }
|
public List<string>? Process { get; set; }
|
||||||
public bool Enabled { get; set; } = true;
|
public bool Enabled { get; set; } = true;
|
||||||
public string? Remarks { get; set; }
|
public string? Remarks { get; set; }
|
||||||
public List<string>? RuleTypes { get; set; }
|
public ERuleType? RuleType { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,7 +253,7 @@ public partial class CoreConfigSingboxService
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((item.RuleTypes?.Count ?? 0) > 0 && !item.RuleTypes.Contains(Global.DNSRuleType))
|
if (item.RuleType == ERuleType.Routing)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ public partial class CoreConfigSingboxService
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((item1.RuleTypes?.Count ?? 0) > 0 && !item1.RuleTypes.Contains(Global.RoutingRuleType))
|
if (item1.RuleType == ERuleType.DNS)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ public partial class CoreConfigV2rayService
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((item.RuleTypes?.Count ?? 0) > 0 && !item.RuleTypes.Contains(Global.DNSRuleType))
|
if (item.RuleType == ERuleType.Routing)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public partial class CoreConfigV2rayService
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((item.RuleTypes?.Count ?? 0) > 0 && !item.RuleTypes.Contains(Global.RoutingRuleType))
|
if (item.RuleType == ERuleType.DNS)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,8 @@ public class RoutingRuleDetailsViewModel : MyReactiveObject
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public string Process { get; set; }
|
public string Process { get; set; }
|
||||||
|
|
||||||
public IList<string> Types { get; set; }
|
[Reactive]
|
||||||
|
public string? RuleType { get; set; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public bool AutoSort { get; set; }
|
public bool AutoSort { get; set; }
|
||||||
|
@ -53,11 +54,7 @@ public class RoutingRuleDetailsViewModel : MyReactiveObject
|
||||||
Domain = Utils.List2String(SelectedSource.Domain, true);
|
Domain = Utils.List2String(SelectedSource.Domain, true);
|
||||||
IP = Utils.List2String(SelectedSource.Ip, true);
|
IP = Utils.List2String(SelectedSource.Ip, true);
|
||||||
Process = Utils.List2String(SelectedSource.Process, true);
|
Process = Utils.List2String(SelectedSource.Process, true);
|
||||||
Types = SelectedSource.RuleTypes?.ToList();
|
RuleType = SelectedSource.RuleType?.ToString();
|
||||||
if (Types == null || Types.Count == 0)
|
|
||||||
{
|
|
||||||
Types = Global.RuleTypes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SaveRulesAsync()
|
private async Task SaveRulesAsync()
|
||||||
|
@ -80,7 +77,7 @@ public class RoutingRuleDetailsViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
SelectedSource.Protocol = ProtocolItems?.ToList();
|
SelectedSource.Protocol = ProtocolItems?.ToList();
|
||||||
SelectedSource.InboundTag = InboundTagItems?.ToList();
|
SelectedSource.InboundTag = InboundTagItems?.ToList();
|
||||||
SelectedSource.RuleTypes = Types?.ToList();
|
SelectedSource.RuleType = RuleType.IsNullOrEmpty() ? null : (ERuleType)Enum.Parse(typeof(ERuleType), RuleType);
|
||||||
|
|
||||||
var hasRule = SelectedSource.Domain?.Count > 0
|
var hasRule = SelectedSource.Domain?.Count > 0
|
||||||
|| SelectedSource.Ip?.Count > 0
|
|| SelectedSource.Ip?.Count > 0
|
||||||
|
|
|
@ -45,12 +45,12 @@
|
||||||
Margin="{StaticResource Margin4}"
|
Margin="{StaticResource Margin4}"
|
||||||
HorizontalAlignment="Left"
|
HorizontalAlignment="Left"
|
||||||
VerticalAlignment="Center" />
|
VerticalAlignment="Center" />
|
||||||
<ListBox
|
<ComboBox
|
||||||
x:Name="clbRuleTypes"
|
x:Name="cmbRuleType"
|
||||||
|
Width="300"
|
||||||
Margin="{StaticResource Margin4}"
|
Margin="{StaticResource Margin4}"
|
||||||
HorizontalAlignment="Left"
|
MaxDropDownHeight="1000" />
|
||||||
SelectionMode="Multiple,Toggle"
|
|
||||||
Theme="{DynamicResource CardCheckGroupListBox}" />
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
|
|
@ -28,16 +28,7 @@ public partial class RoutingRuleDetailsWindow : WindowBase<RoutingRuleDetailsVie
|
||||||
clbProtocol.ItemsSource = Global.RuleProtocols;
|
clbProtocol.ItemsSource = Global.RuleProtocols;
|
||||||
clbInboundTag.ItemsSource = Global.InboundTags;
|
clbInboundTag.ItemsSource = Global.InboundTags;
|
||||||
cmbNetwork.ItemsSource = Global.RuleNetworks;
|
cmbNetwork.ItemsSource = Global.RuleNetworks;
|
||||||
|
cmbRuleType.ItemsSource = Utils.GetEnumNames<ERuleType>();
|
||||||
clbRuleTypes.SelectionChanged += ClbRuleTypes_SelectionChanged;
|
|
||||||
clbRuleTypes.ItemsSource = Global.RuleTypes;
|
|
||||||
if (ViewModel.Types != null)
|
|
||||||
{
|
|
||||||
foreach (var it in ViewModel.Types)
|
|
||||||
{
|
|
||||||
clbRuleTypes.SelectedItems.Add(it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rulesItem.Id.IsNullOrEmpty())
|
if (!rulesItem.Id.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
|
@ -62,6 +53,7 @@ public partial class RoutingRuleDetailsWindow : WindowBase<RoutingRuleDetailsVie
|
||||||
this.Bind(ViewModel, vm => vm.IP, v => v.txtIP.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.IP, v => v.txtIP.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.Process, v => v.txtProcess.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.Process, v => v.txtProcess.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.AutoSort, v => v.chkAutoSort.IsChecked).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.AutoSort, v => v.chkAutoSort.IsChecked).DisposeWith(disposables);
|
||||||
|
this.Bind(ViewModel, vm => vm.RuleType, v => v.cmbRuleType.SelectedValue).DisposeWith(disposables);
|
||||||
|
|
||||||
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
|
||||||
});
|
});
|
||||||
|
@ -118,12 +110,4 @@ public partial class RoutingRuleDetailsWindow : WindowBase<RoutingRuleDetailsVie
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClbRuleTypes_SelectionChanged(object? sender, SelectionChangedEventArgs e)
|
|
||||||
{
|
|
||||||
if (ViewModel != null)
|
|
||||||
{
|
|
||||||
ViewModel.Types = clbRuleTypes.SelectedItems.Cast<string>().ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,12 +60,12 @@
|
||||||
Margin="{StaticResource Margin4}"
|
Margin="{StaticResource Margin4}"
|
||||||
HorizontalAlignment="Left"
|
HorizontalAlignment="Left"
|
||||||
VerticalAlignment="Center" />
|
VerticalAlignment="Center" />
|
||||||
<ListBox
|
<ComboBox
|
||||||
x:Name="clbRuleTypes"
|
x:Name="cmbRuleType"
|
||||||
|
Width="200"
|
||||||
Margin="{StaticResource Margin4}"
|
Margin="{StaticResource Margin4}"
|
||||||
HorizontalAlignment="Left"
|
MaxDropDownHeight="1000"
|
||||||
FontSize="{DynamicResource StdFontSize}"
|
Style="{StaticResource DefComboBox}" />
|
||||||
Style="{StaticResource MaterialDesignFilterChipPrimaryListBox}" />
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
|
|
@ -21,16 +21,7 @@ public partial class RoutingRuleDetailsWindow
|
||||||
clbProtocol.ItemsSource = Global.RuleProtocols;
|
clbProtocol.ItemsSource = Global.RuleProtocols;
|
||||||
clbInboundTag.ItemsSource = Global.InboundTags;
|
clbInboundTag.ItemsSource = Global.InboundTags;
|
||||||
cmbNetwork.ItemsSource = Global.RuleNetworks;
|
cmbNetwork.ItemsSource = Global.RuleNetworks;
|
||||||
|
cmbRuleType.ItemsSource = Utils.GetEnumNames<ERuleType>();
|
||||||
clbRuleTypes.SelectionChanged += ClbRuleTypes_SelectionChanged;
|
|
||||||
clbRuleTypes.ItemsSource = Global.RuleTypes;
|
|
||||||
if (ViewModel.Types != null)
|
|
||||||
{
|
|
||||||
foreach (var it in ViewModel.Types)
|
|
||||||
{
|
|
||||||
clbRuleTypes.SelectedItems.Add(it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rulesItem.Id.IsNullOrEmpty())
|
if (!rulesItem.Id.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
|
@ -55,6 +46,7 @@ public partial class RoutingRuleDetailsWindow
|
||||||
this.Bind(ViewModel, vm => vm.IP, v => v.txtIP.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.IP, v => v.txtIP.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.Process, v => v.txtProcess.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.Process, v => v.txtProcess.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.AutoSort, v => v.chkAutoSort.IsChecked).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.AutoSort, v => v.chkAutoSort.IsChecked).DisposeWith(disposables);
|
||||||
|
this.Bind(ViewModel, vm => vm.RuleType, v => v.cmbRuleType.Text).DisposeWith(disposables);
|
||||||
|
|
||||||
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
|
||||||
});
|
});
|
||||||
|
@ -111,12 +103,4 @@ public partial class RoutingRuleDetailsWindow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClbRuleTypes_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
|
||||||
{
|
|
||||||
if (ViewModel != null)
|
|
||||||
{
|
|
||||||
ViewModel.Types = clbRuleTypes.SelectedItems.Cast<string>().ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue