Browse Source

'int' convert to 'enum ListenerType'

pull/567/head
YFdyh000 5 years ago
parent
commit
a6fcf53b10
  1. 28
      v2rayN/v2rayN/Forms/MainForm.cs
  2. 6
      v2rayN/v2rayN/Forms/OptionSettingForm.cs
  3. 2
      v2rayN/v2rayN/Handler/MainFormHandler.cs
  4. 35
      v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs
  5. 6
      v2rayN/v2rayN/Mode/Config.cs

28
v2rayN/v2rayN/Forms/MainForm.cs

@ -334,10 +334,12 @@ namespace v2rayN.Forms
toolSslSocksPort.Text = $"{Global.Loopback}:{config.inbound[0].localPort}";
if (config.listenerType != 0)
if (config.listenerType != (int)ListenerType.noHttpProxy)
{
toolSslHttpPort.Text = $"{Global.Loopback}:{Global.httpPort}";
if (config.listenerType % 2 == 0)
if (config.listenerType == ListenerType.GlobalPac ||
config.listenerType == ListenerType.PacOpenAndClear ||
config.listenerType == ListenerType.PacOpenOnly)
{
if (PACServerHandle.IsRunning)
{
@ -1133,41 +1135,41 @@ namespace v2rayN.Forms
private void menuNotEnabledHttp_Click(object sender, EventArgs e)
{
SetListenerType(0);
SetListenerType(ListenerType.noHttpProxy);
}
private void menuGlobal_Click(object sender, EventArgs e)
{
SetListenerType(1);
SetListenerType(ListenerType.GlobalHttp);
}
private void menuGlobalPAC_Click(object sender, EventArgs e)
{
SetListenerType(2);
SetListenerType(ListenerType.GlobalPac);
}
private void menuKeep_Click(object sender, EventArgs e)
{
SetListenerType(3);
SetListenerType(ListenerType.HttpOpenAndClear);
}
private void menuKeepPAC_Click(object sender, EventArgs e)
{
SetListenerType(4);
SetListenerType(ListenerType.PacOpenAndClear);
}
private void menuKeepNothing_Click(object sender, EventArgs e)
{
SetListenerType(5);
SetListenerType(ListenerType.HttpOpenOnly);
}
private void menuKeepPACNothing_Click(object sender, EventArgs e)
{
SetListenerType(6);
SetListenerType(ListenerType.PacOpenOnly);
}
private void SetListenerType(int type)
private void SetListenerType(ListenerType type)
{
config.listenerType = type;
ChangePACButtonStatus(type);
}
private void ChangePACButtonStatus(int type)
private void ChangePACButtonStatus(ListenerType type)
{
if (type != 0)
if (type != ListenerType.noHttpProxy)
{
HttpProxyHandle.RestartHttpAgent(config, false);
}
@ -1179,7 +1181,7 @@ namespace v2rayN.Forms
for (int k = 0; k < menuSysAgentMode.DropDownItems.Count; k++)
{
ToolStripMenuItem item = ((ToolStripMenuItem)menuSysAgentMode.DropDownItems[k]);
item.Checked = (type == k);
item.Checked = ((int)type == k);
}
ConfigHandler.SaveConfig(ref config, false);

6
v2rayN/v2rayN/Forms/OptionSettingForm.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Windows.Forms;
using v2rayN.Handler;
using v2rayN.Base;
using v2rayN.HttpProxyHandler;
namespace v2rayN.Forms
{
@ -67,7 +68,7 @@ namespace v2rayN.Forms
//remoteDNS
txtremoteDNS.Text = config.remoteDNS;
cmblistenerType.SelectedIndex = config.listenerType;
cmblistenerType.SelectedIndex = (int)config.listenerType;
}
/// <summary>
@ -262,7 +263,8 @@ namespace v2rayN.Forms
//remoteDNS
config.remoteDNS = txtremoteDNS.Text.TrimEx();
config.listenerType = cmblistenerType.SelectedIndex;
config.listenerType = (ListenerType)Enum.ToObject(typeof(ListenerType), cmblistenerType.SelectedIndex);
return 0;
}

2
v2rayN/v2rayN/Handler/MainFormHandler.cs

@ -32,7 +32,7 @@ namespace v2rayN.Handler
try
{
Color color = ColorTranslator.FromHtml("#3399CC");
int index = config.listenerType;
int index = (int)config.listenerType;
if (index > 0)
{
color = (new Color[] { Color.Red, Color.Purple, Color.DarkGreen, Color.Orange, Color.DarkSlateBlue, Color.RoyalBlue })[index - 1];

35
v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs

@ -3,6 +3,19 @@ using v2rayN.Mode;
namespace v2rayN.HttpProxyHandler
{
/// <summary>
/// 系统代理(http)模式
/// </summary>
public enum ListenerType
{
noHttpProxy = 0,
GlobalHttp = 1,
GlobalPac = 2,
HttpOpenAndClear = 3,
PacOpenAndClear = 4,
HttpOpenOnly = 5,
PacOpenOnly = 6
}
/// <summary>
/// 系统代理(http)总处理
/// 启动privoxy提供http协议
@ -12,29 +25,29 @@ namespace v2rayN.HttpProxyHandler
{
private static bool Update(Config config, bool forceDisable)
{
int type = config.listenerType;
ListenerType type = config.listenerType;
if (forceDisable)
{
type = 0;
type = ListenerType.noHttpProxy;
}
try
{
if (type != 0)
if (type != ListenerType.noHttpProxy)
{
int port = Global.httpPort;
if (port <= 0)
{
return false;
}
if (type == 1)
if (type == ListenerType.GlobalHttp)
{
//PACServerHandle.Stop();
//ProxySetting.SetProxy($"{Global.Loopback}:{port}", Global.IEProxyExceptions, 2);
SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}");
}
else if (type == 2)
else if (type == ListenerType.GlobalPac)
{
string pacUrl = GetPacUrl();
//ProxySetting.SetProxy(pacUrl, "", 4);
@ -42,24 +55,24 @@ namespace v2rayN.HttpProxyHandler
//PACServerHandle.Stop();
PACServerHandle.Init(config);
}
else if (type == 3)
else if (type == ListenerType.HttpOpenAndClear)
{
//PACServerHandle.Stop();
SysProxyHandle.ResetIEProxy();
}
else if (type == 4)
else if (type == ListenerType.PacOpenAndClear)
{
string pacUrl = GetPacUrl();
SysProxyHandle.ResetIEProxy();
//PACServerHandle.Stop();
PACServerHandle.Init(config);
}
else if (type == 5)
else if (type == ListenerType.HttpOpenOnly)
{
//PACServerHandle.Stop();
//SysProxyHandle.ResetIEProxy();
}
else if (type == 6)
else if (type == ListenerType.PacOpenOnly)
{
string pacUrl = GetPacUrl();
//SysProxyHandle.ResetIEProxy();
@ -114,7 +127,7 @@ namespace v2rayN.HttpProxyHandler
{
try
{
if (config.listenerType != 5 && config.listenerType != 6)
if (config.listenerType != ListenerType.HttpOpenOnly && config.listenerType != ListenerType.PacOpenOnly)
{
Update(config, true);
}
@ -138,7 +151,7 @@ namespace v2rayN.HttpProxyHandler
public static void RestartHttpAgent(Config config, bool forced)
{
bool isRestart = false;
if (config.listenerType == 0)
if (config.listenerType == ListenerType.noHttpProxy)
{
// 关闭http proxy时,直接返回
return;

6
v2rayN/v2rayN/Mode/Config.cs

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using v2rayN.Base;
using v2rayN.HttpProxyHandler;
namespace v2rayN.Mode
{
@ -107,9 +109,9 @@ namespace v2rayN.Mode
}
/// <summary>
/// 监听状态 0-not 1-http 2-PAC
/// 监听状态
/// </summary>
public int listenerType
public ListenerType listenerType
{
get; set;
}

Loading…
Cancel
Save