From 8285688ec97f9df099d86d2e1be7cb375e00bbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E4=BB=99=E5=A5=B3?= Date: Sun, 19 Feb 2023 18:51:08 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E5=BD=93=E8=BF=87=E6=BB=A4=E5=99=A8?= =?UTF-8?q?=E6=98=AF=E6=97=A0=E6=95=88=E7=9A=84=E6=AD=A3=E5=88=99=E6=97=B6?= =?UTF-8?q?,=20=E4=BC=9A=E8=BE=93=E5=87=BA=E5=A4=A7=E9=87=8F=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v2rayN/v2rayN/Views/MsgView.xaml.cs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/v2rayN/v2rayN/Views/MsgView.xaml.cs b/v2rayN/v2rayN/Views/MsgView.xaml.cs index d3d866bb..8e999939 100644 --- a/v2rayN/v2rayN/Views/MsgView.xaml.cs +++ b/v2rayN/v2rayN/Views/MsgView.xaml.cs @@ -11,6 +11,10 @@ namespace v2rayN.Views public partial class MsgView { private static Config _config; + + private string lastMsgFilter; + private bool lastMsgFilterNotAvailable; + public MsgView() { InitializeComponent(); @@ -28,29 +32,39 @@ namespace v2rayN.Views void DelegateAppendText(string msg) { - Dispatcher.BeginInvoke(new Action(AppendText), DispatcherPriority.Send, msg); + Dispatcher.BeginInvoke(AppendText, DispatcherPriority.Send, msg); } public void AppendText(string msg) { - if (msg.Equals(Global.CommandClearMsg)) + if (msg == Global.CommandClearMsg) { ClearMsg(); return; } - if (!togAutoRefresh.IsChecked.Value) + if (togAutoRefresh.IsChecked == false) { return; } + var MsgFilter = cmbMsgFilter.Text.TrimEx(); - if (!Utils.IsNullOrEmpty(MsgFilter)) + if (MsgFilter != lastMsgFilter) lastMsgFilterNotAvailable = false; + if (!string.IsNullOrEmpty(MsgFilter) && !lastMsgFilterNotAvailable) { - if (!Regex.IsMatch(msg, MsgFilter)) + try { - return; + if (!Regex.IsMatch(msg, MsgFilter)) // 如果不是正则表达式会异常 + { + return; + } + } + catch (Exception) + { + lastMsgFilterNotAvailable = true; } } - + lastMsgFilter = MsgFilter; + ShowMsg(msg); } From ee61363c318426dd771c674837bc08c01106e81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E4=BB=99=E5=A5=B3?= Date: Sun, 19 Feb 2023 19:06:35 +0800 Subject: [PATCH 2/3] update --- v2rayN/v2rayN/Base/StringEx.cs | 2 +- v2rayN/v2rayN/Views/AddServerWindow.xaml.cs | 63 +++++++++---------- .../Views/GlobalHotkeySettingWindow.xaml.cs | 14 ++--- v2rayN/v2rayN/Views/MainWindow.xaml | 1 + v2rayN/v2rayN/Views/MainWindow.xaml.cs | 19 +++--- .../v2rayN/Views/OptionSettingWindow.xaml.cs | 7 +-- 6 files changed, 50 insertions(+), 56 deletions(-) diff --git a/v2rayN/v2rayN/Base/StringEx.cs b/v2rayN/v2rayN/Base/StringEx.cs index 9aca7060..1aad19d5 100644 --- a/v2rayN/v2rayN/Base/StringEx.cs +++ b/v2rayN/v2rayN/Base/StringEx.cs @@ -42,7 +42,7 @@ namespace v2rayN.Base } } - public static string TrimEx(this string value) + public static string TrimEx(this string? value) { return value == null ? string.Empty : value.Trim(); } diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs index c92125ec..ebdb124e 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs @@ -185,12 +185,12 @@ namespace v2rayN.Views return; } - if (network.Equals(Global.DefaultNetwork)) + if (network == Global.DefaultNetwork) { cmbHeaderType.Items.Add(Global.None); cmbHeaderType.Items.Add(Global.TcpHeaderHttp); } - else if (network.Equals("kcp") || network.Equals("quic")) + else if (network is "kcp" or "quic") { cmbHeaderType.Items.Add(Global.None); Global.kcpHeaderTypes.ForEach(it => @@ -198,7 +198,7 @@ namespace v2rayN.Views cmbHeaderType.Items.Add(it); }); } - else if (network.Equals("grpc")) + else if (network == "grpc") { cmbHeaderType.Items.Add(Global.GrpcgunMode); cmbHeaderType.Items.Add(Global.GrpcmultiMode); @@ -222,37 +222,34 @@ namespace v2rayN.Views tipPath.Text = tipHeaderType.Text = string.Empty; - if (network.Equals(Global.DefaultNetwork)) + switch (network) { - tipRequestHost.Text = ResUI.TransportRequestHostTip1; - tipHeaderType.Text = ResUI.TransportHeaderTypeTip1; - } - else if (network.Equals("kcp")) - { - tipHeaderType.Text = ResUI.TransportHeaderTypeTip2; - tipPath.Text = ResUI.TransportPathTip5; - } - else if (network.Equals("ws")) - { - tipRequestHost.Text = ResUI.TransportRequestHostTip2; - tipPath.Text = ResUI.TransportPathTip1; - } - else if (network.Equals("h2")) - { - tipRequestHost.Text = ResUI.TransportRequestHostTip3; - tipPath.Text = ResUI.TransportPathTip2; - } - else if (network.Equals("quic")) - { - tipRequestHost.Text = ResUI.TransportRequestHostTip4; - tipPath.Text = ResUI.TransportPathTip3; - tipHeaderType.Text = ResUI.TransportHeaderTypeTip3; - } - else if (network.Equals("grpc")) - { - tipPath.Text = ResUI.TransportPathTip4; - tipHeaderType.Text = ResUI.TransportHeaderTypeTip4; - labHeaderType.Visibility = Visibility.Hidden; + case Global.DefaultNetwork: + tipRequestHost.Text = ResUI.TransportRequestHostTip1; + tipHeaderType.Text = ResUI.TransportHeaderTypeTip1; + break; + case "kcp": + tipHeaderType.Text = ResUI.TransportHeaderTypeTip2; + tipPath.Text = ResUI.TransportPathTip5; + break; + case "ws": + tipRequestHost.Text = ResUI.TransportRequestHostTip2; + tipPath.Text = ResUI.TransportPathTip1; + break; + case "h2": + tipRequestHost.Text = ResUI.TransportRequestHostTip3; + tipPath.Text = ResUI.TransportPathTip2; + break; + case "quic": + tipRequestHost.Text = ResUI.TransportRequestHostTip4; + tipPath.Text = ResUI.TransportPathTip3; + tipHeaderType.Text = ResUI.TransportHeaderTypeTip3; + break; + case "grpc": + tipPath.Text = ResUI.TransportPathTip4; + tipHeaderType.Text = ResUI.TransportHeaderTypeTip4; + labHeaderType.Visibility = Visibility.Hidden; + break; } } diff --git a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs index 8cab7b5f..ef92e71f 100644 --- a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs @@ -85,19 +85,19 @@ namespace v2rayN.Views if (item.Control) { - keys += $"{Forms.Keys.Control.ToString()} + "; + keys += $"{Forms.Keys.Control} + "; } if (item.Alt) { - keys += $"{Forms.Keys.Alt.ToString()} + "; + keys += $"{Forms.Keys.Alt} + "; } if (item.Shift) { - keys += $"{Forms.Keys.Shift.ToString()} + "; + keys += $"{Forms.Keys.Shift} + "; } if (item.KeyCode != null) { - keys += $"{item.KeyCode.ToString()}"; + keys += $"{item.KeyCode}"; } SetText($"txtGlobalHotkey{k}", keys); @@ -148,11 +148,11 @@ namespace v2rayN.Views { foreach (UIElement element in gridText.Children) { - if (element is TextBox) + if (element is TextBox box) { - if (((TextBox)element).Name == name) + if (box.Name == name) { - ((TextBox)element).Text = txt; + box.Text = txt; } } } diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index 8edac082..6af8d92f 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -359,6 +359,7 @@ Margin="4,0" materialDesign:HintAssist.Hint="{x:Static resx:ResUI.MsgServerTitle}" materialDesign:TextFieldAssist.HasClearButton="True" + VerticalContentAlignment="Center" Style="{StaticResource DefTextBox}" /> diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index b6a75966..deb67f17 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -197,13 +197,13 @@ namespace v2rayN.Views { if (action == "AdjustMainLvColWidth") { - Application.Current.Dispatcher.Invoke((Action)(() => + Application.Current.Dispatcher.Invoke(() => { foreach (var it in lstProfiles.Columns) { it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto); } - })); + }); } else if (action == "ProfilesFocus") { @@ -355,7 +355,7 @@ namespace v2rayN.Views } else { - if (e.Key == Key.Enter || e.Key == Key.Return) + if (e.Key is Key.Enter or Key.Return) { ViewModel?.SetDefaultServer(); } @@ -471,9 +471,8 @@ namespace v2rayN.Views } private void MenuItem_Click(object sender, RoutedEventArgs e) { - if (sender is MenuItem) + if (sender is MenuItem item) { - MenuItem item = (MenuItem)sender; Utils.ProcessStart(item.Tag.ToString()); } } @@ -482,7 +481,7 @@ namespace v2rayN.Views #endregion #region Drag and Drop - private Point startPoint = new Point(); + private Point startPoint = new(); private int startIndex = -1; private string formatData = "ProfileItemModel"; @@ -523,8 +522,7 @@ namespace v2rayN.Views Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)) { // Get the dragged Item - var listView = sender as DataGrid; - if (listView == null) return; + if (sender is not DataGrid listView) return; var listViewItem = FindAnchestor((DependencyObject)e.OriginalSource); if (listViewItem == null) return; // Abort // Find the data behind the ListViewItem @@ -532,7 +530,7 @@ namespace v2rayN.Views if (item == null) return; // Abort // Initialize the drag & drop operation startIndex = lstProfiles.SelectedIndex; - DataObject dragData = new DataObject(formatData, item); + DataObject dragData = new(formatData, item); DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Copy | DragDropEffects.Move); } } @@ -550,8 +548,7 @@ namespace v2rayN.Views if (e.Data.GetDataPresent(formatData) && sender == e.Source) { // Get the drop Item destination - var listView = sender as DataGrid; - if (listView == null) return; + if (sender is not DataGrid listView) return; var listViewItem = FindAnchestor((DependencyObject)e.OriginalSource); if (listViewItem == null) { diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index 8c8505bf..c891cd2a 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -76,13 +76,12 @@ namespace v2rayN.Views //fill fonts try { - var dir = new DirectoryInfo(Utils.GetFontsPath()); - var files = dir.GetFiles("*.ttf"); + var files = Directory.GetFiles(Utils.GetFontsPath(), "*.ttf"); var culture = _config.uiItem.currentLanguage.Equals(Global.Languages[0]) ? "zh-cn" : "en-us"; var culture2 = "en-us"; - foreach (var it in files) + foreach (var ttf in files) { - var families = Fonts.GetFontFamilies(Utils.GetFontsPath(it.Name)); + var families = Fonts.GetFontFamilies(Utils.GetFontsPath(ttf)); foreach (FontFamily family in families) { var typefaces = family.GetTypefaces(); From 2bd4088d4074b68cc92debef4bf6c5cb1c14bb8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E4=BB=99=E5=A5=B3?= Date: Sun, 19 Feb 2023 19:15:02 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BD=BF=E7=94=A8=3D=3D=E6=9B=BF=E4=BB=A3s?= =?UTF-8?q?tring.Equals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v2rayN/PacLib/PacHandler.cs | 6 +++--- v2rayN/v2rayN/Handler/CoreConfigHandler.cs | 14 +++++++------- v2rayN/v2rayN/Handler/TunHandler.cs | 2 +- v2rayN/v2rayN/Tool/Utils.cs | 4 ++-- v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs | 4 ++-- .../v2rayN/ViewModels/RoutingSettingViewModel.cs | 2 +- v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/v2rayN/PacLib/PacHandler.cs b/v2rayN/PacLib/PacHandler.cs index ee95d4e1..819a94a8 100644 --- a/v2rayN/PacLib/PacHandler.cs +++ b/v2rayN/PacLib/PacHandler.cs @@ -20,9 +20,9 @@ public class PacHandler public static void Start(string configPath, int httpPort, int pacPort) { - if (configPath.Equals(_configPath) - && httpPort.Equals(_httpPort) - && pacPort.Equals(_pacPort) + if (configPath == _configPath + && httpPort == _httpPort + && pacPort == _pacPort && _isRunning) { _needRestart = false; diff --git a/v2rayN/v2rayN/Handler/CoreConfigHandler.cs b/v2rayN/v2rayN/Handler/CoreConfigHandler.cs index b0d18e31..c5e345f0 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigHandler.cs @@ -613,12 +613,12 @@ namespace v2rayN.Handler mtu = config.kcpItem.mtu, tti = config.kcpItem.tti }; - if (iobound.Equals("out")) + if (iobound == "out") { kcpSettings.uplinkCapacity = config.kcpItem.uplinkCapacity; kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity; } - else if (iobound.Equals("in")) + else if (iobound == "in") { kcpSettings.uplinkCapacity = config.kcpItem.downlinkCapacity; ; kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity; @@ -724,7 +724,7 @@ namespace v2rayN.Handler break; default: //tcp - if (node.headerType.Equals(Global.TcpHeaderHttp)) + if (node.headerType == Global.TcpHeaderHttp) { TcpSettings tcpSettings = new() { @@ -734,7 +734,7 @@ namespace v2rayN.Handler } }; - if (iobound.Equals("out")) + if (iobound == "out") { //request Host string request = Utils.GetEmbedText(Global.v2raySampleHttprequestFileName); @@ -753,7 +753,7 @@ namespace v2rayN.Handler request = request.Replace("$requestPath$", $"\"{pathHttp}\""); tcpSettings.header.request = Utils.FromJson(request); } - else if (iobound.Equals("in")) + else if (iobound == "in") { //string response = Utils.GetEmbedText(Global.v2raySampleHttpresponseFileName); //tcpSettings.header.response = Utils.FromJson(response); @@ -1184,7 +1184,7 @@ namespace v2rayN.Handler && outbound.streamSettings.tcpSettings.header != null && !Utils.IsNullOrEmpty(outbound.streamSettings.tcpSettings.header.type)) { - if (outbound.streamSettings.tcpSettings.header.type.Equals(Global.TcpHeaderHttp)) + if (outbound.streamSettings.tcpSettings.header.type == Global.TcpHeaderHttp) { profileItem.headerType = outbound.streamSettings.tcpSettings.header.type; string request = Convert.ToString(outbound.streamSettings.tcpSettings.header.request); @@ -1322,7 +1322,7 @@ namespace v2rayN.Handler && inbound.streamSettings.tcpSettings.header != null && !Utils.IsNullOrEmpty(inbound.streamSettings.tcpSettings.header.type)) { - if (inbound.streamSettings.tcpSettings.header.type.Equals(Global.TcpHeaderHttp)) + if (inbound.streamSettings.tcpSettings.header.type == Global.TcpHeaderHttp) { profileItem.headerType = inbound.streamSettings.tcpSettings.header.type; string request = Convert.ToString(inbound.streamSettings.tcpSettings.header.request); diff --git a/v2rayN/v2rayN/Handler/TunHandler.cs b/v2rayN/v2rayN/Handler/TunHandler.cs index c0a1de04..0ce373c6 100644 --- a/v2rayN/v2rayN/Handler/TunHandler.cs +++ b/v2rayN/v2rayN/Handler/TunHandler.cs @@ -45,7 +45,7 @@ namespace v2rayN.Base { var socksPort = LazyConfig.Instance.GetLocalPort(Global.InboundSocks); - if (socksPort.Equals(_socksPort) + if (socksPort == _socksPort && _process != null && !_process.HasExited) { diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs index 6f4e5e69..4cc1b7c1 100644 --- a/v2rayN/v2rayN/Tool/Utils.cs +++ b/v2rayN/v2rayN/Tool/Utils.cs @@ -489,7 +489,7 @@ namespace v2rayN { return true; } - if (text.Equals("null")) + if (text == "null") { return true; } @@ -636,7 +636,7 @@ namespace v2rayN string value = RegReadValue(Global.AutoRunRegPath, Global.AutoRunName, ""); string exePath = GetExePath(); - if (value?.Equals(exePath) == true || value?.Equals($"\"{exePath}\"") == true) + if (value == exePath || value == $"\"{exePath}\"") { return true; } diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index 79be3452..adf4d067 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -788,7 +788,7 @@ namespace v2rayN.ViewModels var item = new ComboItem() { ID = it.indexId, Text = name }; _servers.Add(item); - if (_config.indexId.Equals(it.indexId)) + if (_config.indexId == it.indexId) { SelectedServer = item; } @@ -1456,7 +1456,7 @@ namespace v2rayN.ViewModels foreach (var item in routings) { _routingItems.Add(item); - if (item.id.Equals(_config.routingBasicItem.routingIndexId)) + if (item.id == _config.routingBasicItem.routingIndexId) { SelectedRouting = item; } diff --git a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs index 39dd1fbf..01b27ff2 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs @@ -163,7 +163,7 @@ namespace v2rayN.ViewModels foreach (var item in routings) { bool def = false; - if (item.id.Equals(_config.routingBasicItem.routingIndexId)) + if (item.id == _config.routingBasicItem.routingIndexId) { def = true; } diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index c891cd2a..71141622 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -77,7 +77,7 @@ namespace v2rayN.Views try { var files = Directory.GetFiles(Utils.GetFontsPath(), "*.ttf"); - var culture = _config.uiItem.currentLanguage.Equals(Global.Languages[0]) ? "zh-cn" : "en-us"; + var culture = _config.uiItem.currentLanguage == Global.Languages[0] ? "zh-cn" : "en-us"; var culture2 = "en-us"; foreach (var ttf in files) {