refactor some code

This commit is contained in:
2dust 2022-03-21 20:20:29 +08:00
parent 78d6bcd57a
commit a2679e009d
10 changed files with 48 additions and 42 deletions

View file

@ -17,12 +17,6 @@ namespace v2rayN.Forms
{
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;
}

View file

@ -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;
}

View file

@ -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<string> 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;
}
}
}

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -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)
{

View file

@ -256,16 +256,6 @@ namespace v2rayN.Mode
return vmess.FirstOrDefault(it => it.indexId == id);
}
public List<string> 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
}

View file

@ -115,7 +115,7 @@ namespace v2rayN.Resx {
}
/// <summary>
/// 查找类似 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. 的本地化字符串。
/// </summary>
internal static string CustomServerTips {
get {

View file

@ -130,7 +130,7 @@
<value> configuration format is incorrect</value>
</data>
<data name="CustomServerTips" xml:space="preserve">
<value>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.</value>
<value>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.</value>
</data>
<data name="Downloading" xml:space="preserve">
<value>Downloading...</value>

View file

@ -130,7 +130,7 @@
<value>配置格式不正确</value>
</data>
<data name="CustomServerTips" xml:space="preserve">
<value>注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。在自定义配置inbound中有socks port等于设置中的port时系统代理才可用</value>
<value>注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。如需使用系统代理请手工修改监听端口。</value>
</data>
<data name="Downloading" xml:space="preserve">
<value>下载开始...</value>