Merge pull request #3315 from ilyfairy/master

修复了一些问题
pull/3336/head
2dust 2023-02-19 20:23:38 +08:00 committed by GitHub
commit 22641a1da0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 88 additions and 80 deletions

View File

@ -20,9 +20,9 @@ public class PacHandler
public static void Start(string configPath, int httpPort, int pacPort) public static void Start(string configPath, int httpPort, int pacPort)
{ {
if (configPath.Equals(_configPath) if (configPath == _configPath
&& httpPort.Equals(_httpPort) && httpPort == _httpPort
&& pacPort.Equals(_pacPort) && pacPort == _pacPort
&& _isRunning) && _isRunning)
{ {
_needRestart = false; _needRestart = false;

View File

@ -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(); return value == null ? string.Empty : value.Trim();
} }

View File

@ -613,12 +613,12 @@ namespace v2rayN.Handler
mtu = config.kcpItem.mtu, mtu = config.kcpItem.mtu,
tti = config.kcpItem.tti tti = config.kcpItem.tti
}; };
if (iobound.Equals("out")) if (iobound == "out")
{ {
kcpSettings.uplinkCapacity = config.kcpItem.uplinkCapacity; kcpSettings.uplinkCapacity = config.kcpItem.uplinkCapacity;
kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity; kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity;
} }
else if (iobound.Equals("in")) else if (iobound == "in")
{ {
kcpSettings.uplinkCapacity = config.kcpItem.downlinkCapacity; ; kcpSettings.uplinkCapacity = config.kcpItem.downlinkCapacity; ;
kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity; kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity;
@ -724,7 +724,7 @@ namespace v2rayN.Handler
break; break;
default: default:
//tcp //tcp
if (node.headerType.Equals(Global.TcpHeaderHttp)) if (node.headerType == Global.TcpHeaderHttp)
{ {
TcpSettings tcpSettings = new() TcpSettings tcpSettings = new()
{ {
@ -734,7 +734,7 @@ namespace v2rayN.Handler
} }
}; };
if (iobound.Equals("out")) if (iobound == "out")
{ {
//request Host //request Host
string request = Utils.GetEmbedText(Global.v2raySampleHttprequestFileName); string request = Utils.GetEmbedText(Global.v2raySampleHttprequestFileName);
@ -753,7 +753,7 @@ namespace v2rayN.Handler
request = request.Replace("$requestPath$", $"\"{pathHttp}\""); request = request.Replace("$requestPath$", $"\"{pathHttp}\"");
tcpSettings.header.request = Utils.FromJson<object>(request); tcpSettings.header.request = Utils.FromJson<object>(request);
} }
else if (iobound.Equals("in")) else if (iobound == "in")
{ {
//string response = Utils.GetEmbedText(Global.v2raySampleHttpresponseFileName); //string response = Utils.GetEmbedText(Global.v2raySampleHttpresponseFileName);
//tcpSettings.header.response = Utils.FromJson<object>(response); //tcpSettings.header.response = Utils.FromJson<object>(response);
@ -1184,7 +1184,7 @@ namespace v2rayN.Handler
&& outbound.streamSettings.tcpSettings.header != null && outbound.streamSettings.tcpSettings.header != null
&& !Utils.IsNullOrEmpty(outbound.streamSettings.tcpSettings.header.type)) && !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; profileItem.headerType = outbound.streamSettings.tcpSettings.header.type;
string request = Convert.ToString(outbound.streamSettings.tcpSettings.header.request); string request = Convert.ToString(outbound.streamSettings.tcpSettings.header.request);
@ -1322,7 +1322,7 @@ namespace v2rayN.Handler
&& inbound.streamSettings.tcpSettings.header != null && inbound.streamSettings.tcpSettings.header != null
&& !Utils.IsNullOrEmpty(inbound.streamSettings.tcpSettings.header.type)) && !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; profileItem.headerType = inbound.streamSettings.tcpSettings.header.type;
string request = Convert.ToString(inbound.streamSettings.tcpSettings.header.request); string request = Convert.ToString(inbound.streamSettings.tcpSettings.header.request);

View File

@ -45,7 +45,7 @@ namespace v2rayN.Base
{ {
var socksPort = LazyConfig.Instance.GetLocalPort(Global.InboundSocks); var socksPort = LazyConfig.Instance.GetLocalPort(Global.InboundSocks);
if (socksPort.Equals(_socksPort) if (socksPort == _socksPort
&& _process != null && _process != null
&& !_process.HasExited) && !_process.HasExited)
{ {

View File

@ -489,7 +489,7 @@ namespace v2rayN
{ {
return true; return true;
} }
if (text.Equals("null")) if (text == "null")
{ {
return true; return true;
} }
@ -636,7 +636,7 @@ namespace v2rayN
string value = RegReadValue(Global.AutoRunRegPath, Global.AutoRunName, ""); string value = RegReadValue(Global.AutoRunRegPath, Global.AutoRunName, "");
string exePath = GetExePath(); string exePath = GetExePath();
if (value?.Equals(exePath) == true || value?.Equals($"\"{exePath}\"") == true) if (value == exePath || value == $"\"{exePath}\"")
{ {
return true; return true;
} }

View File

@ -788,7 +788,7 @@ namespace v2rayN.ViewModels
var item = new ComboItem() { ID = it.indexId, Text = name }; var item = new ComboItem() { ID = it.indexId, Text = name };
_servers.Add(item); _servers.Add(item);
if (_config.indexId.Equals(it.indexId)) if (_config.indexId == it.indexId)
{ {
SelectedServer = item; SelectedServer = item;
} }
@ -1456,7 +1456,7 @@ namespace v2rayN.ViewModels
foreach (var item in routings) foreach (var item in routings)
{ {
_routingItems.Add(item); _routingItems.Add(item);
if (item.id.Equals(_config.routingBasicItem.routingIndexId)) if (item.id == _config.routingBasicItem.routingIndexId)
{ {
SelectedRouting = item; SelectedRouting = item;
} }

View File

@ -163,7 +163,7 @@ namespace v2rayN.ViewModels
foreach (var item in routings) foreach (var item in routings)
{ {
bool def = false; bool def = false;
if (item.id.Equals(_config.routingBasicItem.routingIndexId)) if (item.id == _config.routingBasicItem.routingIndexId)
{ {
def = true; def = true;
} }

View File

@ -185,12 +185,12 @@ namespace v2rayN.Views
return; return;
} }
if (network.Equals(Global.DefaultNetwork)) if (network == Global.DefaultNetwork)
{ {
cmbHeaderType.Items.Add(Global.None); cmbHeaderType.Items.Add(Global.None);
cmbHeaderType.Items.Add(Global.TcpHeaderHttp); 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); cmbHeaderType.Items.Add(Global.None);
Global.kcpHeaderTypes.ForEach(it => Global.kcpHeaderTypes.ForEach(it =>
@ -198,7 +198,7 @@ namespace v2rayN.Views
cmbHeaderType.Items.Add(it); cmbHeaderType.Items.Add(it);
}); });
} }
else if (network.Equals("grpc")) else if (network == "grpc")
{ {
cmbHeaderType.Items.Add(Global.GrpcgunMode); cmbHeaderType.Items.Add(Global.GrpcgunMode);
cmbHeaderType.Items.Add(Global.GrpcmultiMode); cmbHeaderType.Items.Add(Global.GrpcmultiMode);
@ -222,37 +222,34 @@ namespace v2rayN.Views
tipPath.Text = tipPath.Text =
tipHeaderType.Text = string.Empty; tipHeaderType.Text = string.Empty;
if (network.Equals(Global.DefaultNetwork)) switch (network)
{ {
tipRequestHost.Text = ResUI.TransportRequestHostTip1; case Global.DefaultNetwork:
tipHeaderType.Text = ResUI.TransportHeaderTypeTip1; tipRequestHost.Text = ResUI.TransportRequestHostTip1;
} tipHeaderType.Text = ResUI.TransportHeaderTypeTip1;
else if (network.Equals("kcp")) break;
{ case "kcp":
tipHeaderType.Text = ResUI.TransportHeaderTypeTip2; tipHeaderType.Text = ResUI.TransportHeaderTypeTip2;
tipPath.Text = ResUI.TransportPathTip5; tipPath.Text = ResUI.TransportPathTip5;
} break;
else if (network.Equals("ws")) case "ws":
{ tipRequestHost.Text = ResUI.TransportRequestHostTip2;
tipRequestHost.Text = ResUI.TransportRequestHostTip2; tipPath.Text = ResUI.TransportPathTip1;
tipPath.Text = ResUI.TransportPathTip1; break;
} case "h2":
else if (network.Equals("h2")) tipRequestHost.Text = ResUI.TransportRequestHostTip3;
{ tipPath.Text = ResUI.TransportPathTip2;
tipRequestHost.Text = ResUI.TransportRequestHostTip3; break;
tipPath.Text = ResUI.TransportPathTip2; case "quic":
} tipRequestHost.Text = ResUI.TransportRequestHostTip4;
else if (network.Equals("quic")) tipPath.Text = ResUI.TransportPathTip3;
{ tipHeaderType.Text = ResUI.TransportHeaderTypeTip3;
tipRequestHost.Text = ResUI.TransportRequestHostTip4; break;
tipPath.Text = ResUI.TransportPathTip3; case "grpc":
tipHeaderType.Text = ResUI.TransportHeaderTypeTip3; tipPath.Text = ResUI.TransportPathTip4;
} tipHeaderType.Text = ResUI.TransportHeaderTypeTip4;
else if (network.Equals("grpc")) labHeaderType.Visibility = Visibility.Hidden;
{ break;
tipPath.Text = ResUI.TransportPathTip4;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip4;
labHeaderType.Visibility = Visibility.Hidden;
} }
} }

View File

@ -85,19 +85,19 @@ namespace v2rayN.Views
if (item.Control) if (item.Control)
{ {
keys += $"{Forms.Keys.Control.ToString()} + "; keys += $"{Forms.Keys.Control} + ";
} }
if (item.Alt) if (item.Alt)
{ {
keys += $"{Forms.Keys.Alt.ToString()} + "; keys += $"{Forms.Keys.Alt} + ";
} }
if (item.Shift) if (item.Shift)
{ {
keys += $"{Forms.Keys.Shift.ToString()} + "; keys += $"{Forms.Keys.Shift} + ";
} }
if (item.KeyCode != null) if (item.KeyCode != null)
{ {
keys += $"{item.KeyCode.ToString()}"; keys += $"{item.KeyCode}";
} }
SetText($"txtGlobalHotkey{k}", keys); SetText($"txtGlobalHotkey{k}", keys);
@ -148,11 +148,11 @@ namespace v2rayN.Views
{ {
foreach (UIElement element in gridText.Children) 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;
} }
} }
} }

View File

@ -359,6 +359,7 @@
Margin="4,0" Margin="4,0"
materialDesign:HintAssist.Hint="{x:Static resx:ResUI.MsgServerTitle}" materialDesign:HintAssist.Hint="{x:Static resx:ResUI.MsgServerTitle}"
materialDesign:TextFieldAssist.HasClearButton="True" materialDesign:TextFieldAssist.HasClearButton="True"
VerticalContentAlignment="Center"
Style="{StaticResource DefTextBox}" /> Style="{StaticResource DefTextBox}" />
</WrapPanel> </WrapPanel>

View File

@ -197,13 +197,13 @@ namespace v2rayN.Views
{ {
if (action == "AdjustMainLvColWidth") if (action == "AdjustMainLvColWidth")
{ {
Application.Current.Dispatcher.Invoke((Action)(() => Application.Current.Dispatcher.Invoke(() =>
{ {
foreach (var it in lstProfiles.Columns) foreach (var it in lstProfiles.Columns)
{ {
it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto); it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto);
} }
})); });
} }
else if (action == "ProfilesFocus") else if (action == "ProfilesFocus")
{ {
@ -355,7 +355,7 @@ namespace v2rayN.Views
} }
else else
{ {
if (e.Key == Key.Enter || e.Key == Key.Return) if (e.Key is Key.Enter or Key.Return)
{ {
ViewModel?.SetDefaultServer(); ViewModel?.SetDefaultServer();
} }
@ -471,9 +471,8 @@ namespace v2rayN.Views
} }
private void MenuItem_Click(object sender, RoutedEventArgs e) 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()); Utils.ProcessStart(item.Tag.ToString());
} }
} }
@ -482,7 +481,7 @@ namespace v2rayN.Views
#endregion #endregion
#region Drag and Drop #region Drag and Drop
private Point startPoint = new Point(); private Point startPoint = new();
private int startIndex = -1; private int startIndex = -1;
private string formatData = "ProfileItemModel"; private string formatData = "ProfileItemModel";
@ -523,8 +522,7 @@ namespace v2rayN.Views
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)) Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
{ {
// Get the dragged Item // Get the dragged Item
var listView = sender as DataGrid; if (sender is not DataGrid listView) return;
if (listView == null) return;
var listViewItem = FindAnchestor<DataGridRow>((DependencyObject)e.OriginalSource); var listViewItem = FindAnchestor<DataGridRow>((DependencyObject)e.OriginalSource);
if (listViewItem == null) return; // Abort if (listViewItem == null) return; // Abort
// Find the data behind the ListViewItem // Find the data behind the ListViewItem
@ -532,7 +530,7 @@ namespace v2rayN.Views
if (item == null) return; // Abort if (item == null) return; // Abort
// Initialize the drag & drop operation // Initialize the drag & drop operation
startIndex = lstProfiles.SelectedIndex; startIndex = lstProfiles.SelectedIndex;
DataObject dragData = new DataObject(formatData, item); DataObject dragData = new(formatData, item);
DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Copy | DragDropEffects.Move); DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Copy | DragDropEffects.Move);
} }
} }
@ -550,8 +548,7 @@ namespace v2rayN.Views
if (e.Data.GetDataPresent(formatData) && sender == e.Source) if (e.Data.GetDataPresent(formatData) && sender == e.Source)
{ {
// Get the drop Item destination // Get the drop Item destination
var listView = sender as DataGrid; if (sender is not DataGrid listView) return;
if (listView == null) return;
var listViewItem = FindAnchestor<DataGridRow>((DependencyObject)e.OriginalSource); var listViewItem = FindAnchestor<DataGridRow>((DependencyObject)e.OriginalSource);
if (listViewItem == null) if (listViewItem == null)
{ {

View File

@ -11,6 +11,10 @@ namespace v2rayN.Views
public partial class MsgView public partial class MsgView
{ {
private static Config _config; private static Config _config;
private string lastMsgFilter;
private bool lastMsgFilterNotAvailable;
public MsgView() public MsgView()
{ {
InitializeComponent(); InitializeComponent();
@ -28,29 +32,39 @@ namespace v2rayN.Views
void DelegateAppendText(string msg) void DelegateAppendText(string msg)
{ {
Dispatcher.BeginInvoke(new Action<string>(AppendText), DispatcherPriority.Send, msg); Dispatcher.BeginInvoke(AppendText, DispatcherPriority.Send, msg);
} }
public void AppendText(string msg) public void AppendText(string msg)
{ {
if (msg.Equals(Global.CommandClearMsg)) if (msg == Global.CommandClearMsg)
{ {
ClearMsg(); ClearMsg();
return; return;
} }
if (!togAutoRefresh.IsChecked.Value) if (togAutoRefresh.IsChecked == false)
{ {
return; return;
} }
var MsgFilter = cmbMsgFilter.Text.TrimEx(); 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); ShowMsg(msg);
} }

View File

@ -76,13 +76,12 @@ namespace v2rayN.Views
//fill fonts //fill fonts
try try
{ {
var dir = new DirectoryInfo(Utils.GetFontsPath()); var files = Directory.GetFiles(Utils.GetFontsPath(), "*.ttf");
var files = dir.GetFiles("*.ttf"); var culture = _config.uiItem.currentLanguage == Global.Languages[0] ? "zh-cn" : "en-us";
var culture = _config.uiItem.currentLanguage.Equals(Global.Languages[0]) ? "zh-cn" : "en-us";
var culture2 = "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) foreach (FontFamily family in families)
{ {
var typefaces = family.GetTypefaces(); var typefaces = family.GetTypefaces();