📄 ssnetworkcontrol.cs
字号:
namespace Imps.Client.Pc.Options
{
using Imps.Client;
using Imps.Client.Base;
using Imps.Client.CommLayer;
using Imps.Client.Core;
using Imps.Client.Pc;
using Imps.Client.Pc.Controls;
using Imps.Client.Pc.Utils;
using Imps.Client.Resource;
using Imps.Client.Utils;
using Imps.Utils;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
public class SsNetworkControl : OptionsControlBase, IConnectionConfigation
{
private IFrameworkWindow _frameworkWnd;
private string bkHttpProxyPort = string.Empty;
private string bkHttpProxyServerAddress = string.Empty;
private XButton btnTestHttpProxy;
private XButton btnTestSocks;
private XButton btnTestTcp;
private CheckBox chkConnLog;
private CheckBox chkUseDirect;
private CheckBox chkUseHttpProxy;
private CheckBox chkUseSocks;
private IContainer components;
private XLabel ctlConnectionType;
private XButton ctlExamine;
private XComboBox ctlHttpProxyType;
private XLabel ctlPromptHttpSetting;
private const int DefaultHttpPort = 80;
private const int DefaultSocksPort = 0x438;
private GroupBox gbConnStatus;
private GroupBox gbNetworkConfig;
private XLabel lbDirectly;
private XLabel lbHttpPassword;
private XLabel lbHttpProxyPort;
private XLabel lbHttpProxyServer;
private XLabel lbHttpUser;
private XLabel lbSocksPassword;
private XLabel lbSocksPort;
private XLabel lbSocksServer;
private XLabel lbSocksUser;
private System.Windows.Forms.Timer MyTimer;
private PictureBox pbConnStatus;
private XTextBox txtHttpProxyPassword;
private XTextBox txtHttpProxyPort;
private XTextBox txtHttpProxyServerAdress;
private XTextBox txtHttpProxyUserName;
private XTextBox txtSockServerAddress;
private XTextBox txtSocksPassword;
private XTextBox txtSocksPort;
private XTextBox txtSocksUserName;
public SsNetworkControl(IFrameworkWindow iFrameworkWin)
{
base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
this._frameworkWnd = iFrameworkWin;
this.InitializeComponent();
this.SetControlsText();
this.SetLimitation();
this.AppendModifiedEvent();
}
private void AppendModifiedEvent()
{
this.chkConnLog.CheckedChanged += new EventHandler(this.ConfigChanged);
this.txtHttpProxyServerAdress.TextChanged += new EventHandler(this.ConfigChanged);
this.txtHttpProxyPort.TextChanged += new EventHandler(this.ConfigChanged);
this.txtHttpProxyUserName.TextChanged += new EventHandler(this.ConfigChanged);
this.txtHttpProxyPassword.TextChanged += new EventHandler(this.ConfigChanged);
this.txtSockServerAddress.TextChanged += new EventHandler(this.ConfigChanged);
this.txtSocksPort.TextChanged += new EventHandler(this.ConfigChanged);
this.txtSocksUserName.TextChanged += new EventHandler(this.ConfigChanged);
this.txtSocksPassword.TextChanged += new EventHandler(this.ConfigChanged);
}
private void btnTestDirect_Click(object sender, EventArgs e)
{
this.TestConnection(ConnectionType.Direct);
}
private void btnTestHttpProxy_Click(object sender, EventArgs e)
{
this.TestConnection(ConnectionType.HttpProxy);
}
private void btnTestSocks_Click(object sender, EventArgs e)
{
this.TestConnection(ConnectionType.SocksProxy);
}
private bool CheckHttpProxyCfg()
{
this.txtHttpProxyServerAdress.Text = this.txtHttpProxyServerAdress.Text.Trim();
this.txtHttpProxyPort.Text = this.txtHttpProxyPort.Text.Trim();
this.txtHttpProxyUserName.Text = this.txtHttpProxyUserName.Text.Trim();
this.txtHttpProxyPassword.Text = this.txtHttpProxyPassword.Text;
if (((UseHttpProxyTypeItem) this.ctlHttpProxyType.SelectedItem).ProxyType == UseHttpProxyType.UseIeProxySetting)
{
return true;
}
if (string.IsNullOrEmpty(this.txtHttpProxyServerAdress.Text))
{
BalloonHelper.ShowInputErrorBallon(this.txtHttpProxyServerAdress, "您尚未设置HTTP服务器地址!", StringTable.Options.TitleInvalidInput);
this.txtHttpProxyServerAdress.Focus();
return false;
}
if (IsValidProxy(this.txtHttpProxyServerAdress.Text.Trim()))
{
int result = 0;
int.TryParse(this.txtHttpProxyPort.Text, out result);
if (result > 0)
{
return true;
}
BalloonHelper.ShowInputErrorBallon(this.txtHttpProxyPort, "HTTP代理服务端口号不正确!", StringTable.Options.TitleInvalidInput);
this.txtHttpProxyPort.Focus();
this.txtHttpProxyPort.SelectAll();
return false;
}
BalloonHelper.ShowInputErrorBallon(this.txtHttpProxyServerAdress, "HTTP代理服务器地址不正确!", StringTable.Options.TitleInvalidInput);
this.txtHttpProxyServerAdress.Focus();
this.txtHttpProxyServerAdress.SelectAll();
return false;
}
private bool CheckPort(string port)
{
int num;
if (!int.TryParse(port, out num))
{
return false;
}
return ((num > 0) && (num <= 0xffff));
}
private bool CheckSocksCfg()
{
this.txtSockServerAddress.Text = this.txtSockServerAddress.Text.Trim();
this.txtSocksPort.Text = this.txtSocksPort.Text.Trim();
this.txtSocksUserName.Text = this.txtSocksUserName.Text.Trim();
this.txtSocksPassword.Text = this.txtSocksPassword.Text;
if (string.IsNullOrEmpty(this.txtSockServerAddress.Text))
{
this._frameworkWnd.UnifiedMessageBox.ShowError(base.FindForm(), StringTable.NetworkSettingOption.SocksProxyHostEmpty);
this.txtSockServerAddress.Focus();
return false;
}
if (IsValidProxy(this.txtSockServerAddress.Text.Trim()))
{
int result = 0;
int.TryParse(this.txtSocksPort.Text, out result);
if (result > 0)
{
return true;
}
this._frameworkWnd.UnifiedMessageBox.ShowError(base.FindForm(), StringTable.NetworkSettingOption.SocksProxyPortError);
this.txtSocksPort.Focus();
this.txtSocksPort.SelectAll();
return false;
}
this._frameworkWnd.UnifiedMessageBox.ShowError(base.FindForm(), StringTable.NetworkSettingOption.SocksProxyHostError);
this.txtSockServerAddress.Focus();
this.txtSockServerAddress.SelectAll();
return false;
}
public override bool CheckUserInput()
{
if (this.chkUseSocks.Checked && !this.CheckSocksCfg())
{
return false;
}
if (this.chkUseHttpProxy.Checked && !this.CheckHttpProxyCfg())
{
return false;
}
if ((!this.chkUseDirect.Checked && !this.chkUseSocks.Checked) && !this.chkUseHttpProxy.Checked)
{
this._frameworkWnd.UnifiedMessageBox.ShowError(base.FindForm(), StringTable.ClientCommLayerString.NotSelectConnectionTypeError);
return false;
}
if (!this.chkUseDirect.Checked && !this.chkUseHttpProxy.Checked)
{
this._frameworkWnd.UnifiedMessageBox.ShowError(base.FindForm(), StringTable.ClientCommLayerString.OnSelectSocksConnectionTypeError);
return false;
}
return true;
}
private void chkDirect_CheckedChanged(object sender, EventArgs e)
{
this.SupportTcpInputBoxes();
base.Modified = true;
}
private void chkHttpProxy_CheckedChanged(object sender, EventArgs e)
{
this.SupportHttpProxyInputBox();
base.Modified = true;
}
private void chkIEProxy_CheckedChanged(object sender, EventArgs e)
{
}
private void chkSocks_CheckedChanged(object sender, EventArgs e)
{
this.SupportSocksProxyInputBoxes();
base.Modified = true;
}
private void chkUseTcp_CheckedChanged(object sender, EventArgs e)
{
base.Modified = true;
this.btnTestTcp.Enabled = this.chkUseDirect.Checked;
}
public IConnectionConfigation CloneConfigation()
{
return ConnectionConfigation.Clone(this);
}
private void ConfigChanged(object sender, EventArgs e)
{
base.Modified = true;
}
private void ctlExamine_Click(object sender, EventArgs e)
{
if (this.UpdateData(true))
{
new NetworkDetectForm().ShowDialog(this);
}
}
private void ctlHttpProxyType_DropDown(object sender, EventArgs e)
{
this.StopTimer();
}
private void ctlHttpProxyType_DropDownClosed(object sender, EventArgs e)
{
this.StartTimer();
}
private void ctlHttpProxyType_SelectedIndexChanged(object sender, EventArgs e)
{
this.ConfigChanged(sender, e);
this.UpdateJustTime();
this.SupportHttpProxyInputBox();
this.ctlPromptHttpSetting.Text = UseHttpProxyTypeText.GetDescription(this.CurrentUseHttpProxyType);
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.gbConnStatus = new GroupBox();
this.ctlConnectionType = new XLabel();
this.ctlExamine = new XButton();
this.chkConnLog = new CheckBox();
this.pbConnStatus = new PictureBox();
this.gbNetworkConfig = new GroupBox();
this.ctlHttpProxyType = new XComboBox();
this.chkUseSocks = new CheckBox();
this.chkUseDirect = new CheckBox();
this.chkUseHttpProxy = new CheckBox();
this.lbHttpProxyPort = new XLabel();
this.lbSocksPort = new XLabel();
this.txtHttpProxyPort = new XTextBox();
this.btnTestHttpProxy = new XButton();
this.txtHttpProxyPassword = new XTextBox();
this.lbHttpPassword = new XLabel();
this.txtHttpProxyUserName = new XTextBox();
this.lbHttpUser = new XLabel();
this.txtHttpProxyServerAdress = new XTextBox();
this.lbHttpProxyServer = new XLabel();
this.btnTestSocks = new XButton();
this.txtSocksPassword = new XTextBox();
this.lbSocksPassword = new XLabel();
this.txtSocksUserName = new XTextBox();
this.lbSocksUser = new XLabel();
this.txtSockServerAddress = new XTextBox();
this.txtSocksPort = new XTextBox();
this.lbSocksServer = new XLabel();
this.btnTestTcp = new XButton();
this.lbDirectly = new XLabel();
this.ctlPromptHttpSetting = new XLabel();
XLabel label = new XLabel();
XLabel label2 = new XLabel();
XLabel label3 = new XLabel();
this.gbConnStatus.SuspendLayout();
((ISupportInitialize) this.pbConnStatus).BeginInit();
this.gbNetworkConfig.SuspendLayout();
base.SuspendLayout();
label.BorderColor = Color.Empty;
label.BorderStyle = BorderStyle.Fixed3D;
label.ButtonBorderStyle = ButtonBorderStyle.None;
label.Location = new Point(0x57, 0x9f);
label.Name = "lbLine";
label.Size = new Size(0x109, 2);
label.TabIndex = 3;
label2.BorderColor = Color.Empty;
label2.BorderStyle = BorderStyle.Fixed3D;
label2.ButtonBorderStyle = ButtonBorderStyle.None;
label2.Location = new Point(0x61, 0xce);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -