From a2679e009dfe48911fe0ba9f547187c94de58ddc Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 21 Mar 2022 20:20:29 +0800 Subject: [PATCH] refactor some code --- v2rayN/v2rayN/Forms/AddServerForm.cs | 16 ++++++----- v2rayN/v2rayN/Handler/ConfigHandler.cs | 2 +- v2rayN/v2rayN/Handler/LazyConfig.cs | 31 +++++++++++++++++++++ v2rayN/v2rayN/Handler/MainFormHandler.cs | 2 +- v2rayN/v2rayN/Handler/V2rayConfigHandler.cs | 2 +- v2rayN/v2rayN/Handler/V2rayHandler.cs | 6 +--- v2rayN/v2rayN/Mode/Config.cs | 25 +---------------- v2rayN/v2rayN/Resx/ResUI.Designer.cs | 2 +- v2rayN/v2rayN/Resx/ResUI.resx | 2 +- v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 2 +- 10 files changed, 48 insertions(+), 42 deletions(-) diff --git a/v2rayN/v2rayN/Forms/AddServerForm.cs b/v2rayN/v2rayN/Forms/AddServerForm.cs index e623929a..ef8a9d9c 100644 --- a/v2rayN/v2rayN/Forms/AddServerForm.cs +++ b/v2rayN/v2rayN/Forms/AddServerForm.cs @@ -16,13 +16,7 @@ namespace v2rayN.Forms private void AddServerForm_Load(object sender, EventArgs e) { this.Text = (eConfigType).ToString(); - - cmbSecurity.Items.AddRange(Global.vmessSecuritys.ToArray()); - cmbSecurity3.Items.AddRange(config.GetShadowsocksSecuritys().ToArray()); - - cmbFlow5.Items.AddRange(Global.xtlsFlows.ToArray()); - cmbFlow6.Items.AddRange(Global.xtlsFlows.ToArray()); - + cmbCoreType.Items.AddRange(Global.coreTypes.ToArray()); cmbCoreType.Items.Add(string.Empty); @@ -31,12 +25,16 @@ namespace v2rayN.Forms case EConfigType.Vmess: panVmess.Dock = DockStyle.Fill; panVmess.Visible = true; + + cmbSecurity.Items.AddRange(Global.vmessSecuritys.ToArray()); break; case EConfigType.Shadowsocks: panSs.Dock = DockStyle.Fill; panSs.Visible = true; panTran.Visible = false; this.Height = this.Height - panTran.Height; + + cmbSecurity3.Items.AddRange(LazyConfig.Instance.GetShadowsocksSecuritys().ToArray()); break; case EConfigType.Socks: panSocks.Dock = DockStyle.Fill; @@ -48,11 +46,15 @@ namespace v2rayN.Forms panVless.Dock = DockStyle.Fill; panVless.Visible = true; transportControl.AllowXtls = true; + + cmbFlow5.Items.AddRange(Global.xtlsFlows.ToArray()); break; case EConfigType.Trojan: panTrojan.Dock = DockStyle.Fill; panTrojan.Visible = true; transportControl.AllowXtls = true; + + cmbFlow6.Items.AddRange(Global.xtlsFlows.ToArray()); break; } diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 631f2bc3..0cf56c5c 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -488,7 +488,7 @@ namespace v2rayN.Handler vmessItem.id = vmessItem.id.TrimEx(); vmessItem.security = vmessItem.security.TrimEx(); - if (!config.GetShadowsocksSecuritys().Contains(vmessItem.security)) + if (!LazyConfig.Instance.GetShadowsocksSecuritys().Contains(vmessItem.security)) { return -1; } diff --git a/v2rayN/v2rayN/Handler/LazyConfig.cs b/v2rayN/v2rayN/Handler/LazyConfig.cs index 976c8970..d1be5442 100644 --- a/v2rayN/v2rayN/Handler/LazyConfig.cs +++ b/v2rayN/v2rayN/Handler/LazyConfig.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using v2rayN.Mode; +using System.Linq; namespace v2rayN.Handler { @@ -20,5 +22,34 @@ namespace v2rayN.Handler { return _config; } + + public List GetShadowsocksSecuritys() + { + if (GetCoreType(null, EConfigType.Shadowsocks) == ECoreType.v2fly) + { + return Global.ssSecuritys; + } + + return Global.ssSecuritysInXray; + } + + public ECoreType GetCoreType(VmessItem vmessItem, EConfigType eConfigType) + { + if (vmessItem != null && vmessItem.coreType != null) + { + return (ECoreType)vmessItem.coreType; + } + + if (_config.coreTypeItem == null) + { + return ECoreType.Xray; + } + var item = _config.coreTypeItem.FirstOrDefault(it => it.configType == eConfigType); + if (item == null) + { + return ECoreType.Xray; + } + return item.coreType; + } } } diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs index 7da72180..c7dc4337 100644 --- a/v2rayN/v2rayN/Handler/MainFormHandler.cs +++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs @@ -53,7 +53,7 @@ namespace v2rayN.Handler if (!Utils.IsNullOrEmpty(item.customIcon) && File.Exists(item.customIcon)) { graphics.FillRectangle(drawBrush, new Rectangle(0, 0, width, height)); - graphics.DrawImage(new Bitmap(item.customIcon), 0, 0); + graphics.DrawImage(new Bitmap(item.customIcon), 0, 0, width, height); customIcon = true; } } diff --git a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs index 1e299c9e..9e213992 100644 --- a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs @@ -400,7 +400,7 @@ namespace v2rayN.Handler serversItem.address = node.address; serversItem.port = node.port; serversItem.password = node.id; - if (config.GetShadowsocksSecuritys().Contains(node.security)) + if (LazyConfig.Instance.GetShadowsocksSecuritys().Contains(node.security)) { serversItem.method = node.security; } diff --git a/v2rayN/v2rayN/Handler/V2rayHandler.cs b/v2rayN/v2rayN/Handler/V2rayHandler.cs index 1d81a90a..7db95a8a 100644 --- a/v2rayN/v2rayN/Handler/V2rayHandler.cs +++ b/v2rayN/v2rayN/Handler/V2rayHandler.cs @@ -332,11 +332,7 @@ namespace v2rayN.Handler { return; } - var coreType = config.GetCoreType(item.configType); - if (item.coreType != null) - { - coreType = (ECoreType)item.coreType; - } + var coreType = LazyConfig.Instance.GetCoreType(item, item.configType); if (coreType == ECoreType.v2fly) { diff --git a/v2rayN/v2rayN/Mode/Config.cs b/v2rayN/v2rayN/Mode/Config.cs index f158768b..f7b00755 100644 --- a/v2rayN/v2rayN/Mode/Config.cs +++ b/v2rayN/v2rayN/Mode/Config.cs @@ -256,16 +256,6 @@ namespace v2rayN.Mode return vmess.FirstOrDefault(it => it.indexId == id); } - public List GetShadowsocksSecuritys() - { - if (GetCoreType(EConfigType.Shadowsocks) == ECoreType.v2fly) - { - return Global.ssSecuritys; - } - - return Global.ssSecuritysInXray; - } - public bool IsActiveNode(VmessItem item) { if (!Utils.IsNullOrEmpty(item.indexId) && item.indexId == indexId) @@ -285,19 +275,6 @@ namespace v2rayN.Mode return groupItem.Where(it => it.id == groupId).FirstOrDefault()?.remarks; } - public ECoreType GetCoreType(EConfigType eConfigType) - { - if (coreTypeItem == null) - { - return ECoreType.Xray; - } - var item = coreTypeItem.FirstOrDefault(it => it.configType == eConfigType); - if (item == null) - { - return ECoreType.Xray; - } - return item.coreType; - } #endregion } @@ -358,7 +335,7 @@ namespace v2rayN.Mode break; default: summary += string.Format("{0}", remarks); - break; + break; } return summary; } diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index 892684b2..e202e71b 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -115,7 +115,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Note that custom configuration relies entirely on your own configuration and does not work with all settings. The system agent is available when the socks port is equal to the port in the settings in the custom configuration inbound. 的本地化字符串。 + /// 查找类似 Note that custom configuration relies entirely on your own configuration and does not work with all settings. If you want to use the system proxy, please modify the listening port manually. 的本地化字符串。 /// internal static string CustomServerTips { get { diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index 81b80999..6077e7eb 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -130,7 +130,7 @@ configuration format is incorrect - Note that custom configuration relies entirely on your own configuration and does not work with all settings. The system agent is available when the socks port is equal to the port in the settings in the custom configuration inbound. + Note that custom configuration relies entirely on your own configuration and does not work with all settings. If you want to use the system proxy, please modify the listening port manually. Downloading... diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index 986200aa..6ad22fc8 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -130,7 +130,7 @@ 配置格式不正确 - 注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。在自定义配置inbound中有socks port等于设置中的port时,系统代理才可用 + 注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。如需使用系统代理请手工修改监听端口。 下载开始...