📄 mainform.cs
字号:
this.rmMwd.Text = "创建文件夹";
this.rmMwd.Click += new System.EventHandler(this.rmMwd_Click);
//
// rmRwd
//
this.rmRwd.Index = 2;
this.rmRwd.Text = "删除文件夹";
this.rmRwd.Click += new System.EventHandler(this.rmRwd_Click);
//
// rmDelete
//
this.rmDelete.Index = 3;
this.rmDelete.Text = "删除文件";
this.rmDelete.Click += new System.EventHandler(this.rmDelete_Click);
//
// rmFlush
//
this.rmFlush.Index = 4;
this.rmFlush.Text = "刷新";
this.rmFlush.Click += new System.EventHandler(this.rmFlush_Click);
//
// menuItem9
//
this.menuItem9.Index = 5;
this.menuItem9.Text = "-";
//
// rmCnd
//
this.rmCnd.Index = 6;
this.rmCnd.Text = "修改文件目录";
this.rmCnd.Click += new System.EventHandler(this.rmCnd_Click);
//
// rmCnf
//
this.rmCnf.Index = 7;
this.rmCnf.Text = "修改文件名";
this.rmCnf.Click += new System.EventHandler(this.rmCnf_Click);
//
// mainstatusBar
//
this.mainstatusBar.Location = new System.Drawing.Point(0, 607);
this.mainstatusBar.Name = "mainstatusBar";
this.mainstatusBar.ShowPanels = true;
this.mainstatusBar.Size = new System.Drawing.Size(800, 22);
this.mainstatusBar.TabIndex = 0;
this.mainstatusBar.Text = "statusBar1";
//
// toolBar1
//
this.toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
this.toolBar1.DropDownArrows = true;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(800, 42);
this.toolBar1.TabIndex = 1;
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 2;
this.label1.Text = "服务器IP:";
//
// tbIP
//
this.tbIP.Location = new System.Drawing.Point(80, 8);
this.tbIP.Name = "tbIP";
this.tbIP.Size = new System.Drawing.Size(120, 21);
this.tbIP.TabIndex = 3;
this.tbIP.Text = "192.168.0.235";
//
// label2
//
this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.Location = new System.Drawing.Point(208, 8);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 16);
this.label2.TabIndex = 4;
this.label2.Text = "端口:";
//
// tbPort
//
this.tbPort.Location = new System.Drawing.Point(248, 8);
this.tbPort.Name = "tbPort";
this.tbPort.Size = new System.Drawing.Size(64, 21);
this.tbPort.TabIndex = 5;
this.tbPort.Text = "8900";
//
// label3
//
this.label3.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label3.Location = new System.Drawing.Point(320, 8);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 16);
this.label3.TabIndex = 6;
this.label3.Text = "帐号:";
//
// tbAccount
//
this.tbAccount.Location = new System.Drawing.Point(360, 8);
this.tbAccount.Name = "tbAccount";
this.tbAccount.Size = new System.Drawing.Size(104, 21);
this.tbAccount.TabIndex = 7;
this.tbAccount.Text = "张景亮";
//
// label4
//
this.label4.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label4.Location = new System.Drawing.Point(472, 8);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(48, 16);
this.label4.TabIndex = 8;
this.label4.Text = "密码:";
//
// tbPwd
//
this.tbPwd.Location = new System.Drawing.Point(512, 8);
this.tbPwd.Name = "tbPwd";
this.tbPwd.PasswordChar = '*';
this.tbPwd.TabIndex = 9;
this.tbPwd.Text = "123";
//
// btn_Connect
//
this.btn_Connect.Location = new System.Drawing.Point(632, 8);
this.btn_Connect.Name = "btn_Connect";
this.btn_Connect.TabIndex = 10;
this.btn_Connect.Text = "连 接";
this.btn_Connect.Click += new System.EventHandler(this.btn_Connect_Click);
//
// btn_Terminate
//
this.btn_Terminate.Location = new System.Drawing.Point(720, 8);
this.btn_Terminate.Name = "btn_Terminate";
this.btn_Terminate.TabIndex = 11;
this.btn_Terminate.Text = "断 开";
this.btn_Terminate.Click += new System.EventHandler(this.btn_Terminate_Click);
//
// Acitve_Timer
//
this.Acitve_Timer.Interval = 15000;
this.Acitve_Timer.Tick += new System.EventHandler(this.Acitve_Timer_Tick);
//
// columnHeader1
//
this.columnHeader1.Text = "名称";
this.columnHeader1.Width = 150;
//
// columnHeader2
//
this.columnHeader2.Text = "大小";
this.columnHeader2.Width = 100;
//
// columnHeader3
//
this.columnHeader3.Text = "类型";
//
// columnHeader4
//
this.columnHeader4.Text = "最后访问时间";
this.columnHeader4.Width = 150;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(800, 433);
this.Controls.Add(this.btn_Terminate);
this.Controls.Add(this.btn_Connect);
this.Controls.Add(this.tbPwd);
this.Controls.Add(this.label4);
this.Controls.Add(this.tbAccount);
this.Controls.Add(this.label3);
this.Controls.Add(this.tbPort);
this.Controls.Add(this.label2);
this.Controls.Add(this.tbIP);
this.Controls.Add(this.label1);
this.Controls.Add(this.mainpanel);
this.Controls.Add(this.toolBar1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.MainMenu;
this.Name = "MainForm";
this.Text = "CodeManager v1.0";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.MainForm_Load);
this.mainpanel.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
private void MainForm_Load(object sender, System.EventArgs e)
{
//管理线程
Thread manager = new Thread( new ThreadStart( ThreadManager ) );
manager.IsBackground = true;
manager.Start();
}
//管理线程
public void ThreadManager()
{
while(true)
{
Thread.Sleep(5000);
try
{
if (!m_Enable)
continue;
//测试网络连接
//启动接收数据线程
if (null == threadrecv)
{
nRebuild = 0;
threadrecv = new Thread( new ThreadStart( ThreadRecvCMSG_Packet ) );
threadrecv.IsBackground = true;
threadrecv.Start();
}
else if (!threadrecv.IsAlive || nRebuild > 20)
{
nRebuild = 0;
try{threadrecv.Abort();}
catch{}
threadrecv = new Thread( new ThreadStart( ThreadRecvCMSG_Packet ) );
threadrecv.IsBackground = true;
threadrecv.Start();
System.GC.Collect();
}
// Get a stream object for reading and writing
for(int i = 0 ; i< array_file.Count; i ++)
{
//NetworkStream stream =((CSock_File)cmsg_array_file[i]). m_sock.GetStream();
CFile_Trans cf = (CFile_Trans)array_file[i];
//活动测试
if (!cf.m_Enable)
{
logs("socket 关闭");
cf.close();
cf = null;
array_file.RemoveAt(i);
break;
}
}
}
catch{}
}
}
public void ThreadRecvCMSG_Packet()
{
Int32 i;
byte []tmp = null;
//init param
int nTotal;
int nCmd;
int nSeq;
MemoryStream ms = null;
NetworkStream stream = null;
while(true)
{
if (!m_Enable)
break;
Thread.Sleep(50);
try
{
stream = m_sock.GetStream();
}
catch(InvalidOperationException ioep)
{
m_Enable = false;
logs(String.Format("(ThreadRecvCMSG_Packet_sockstream)Source:{0},TargetSite{1},Message{2}", ioep.Source, ioep.TargetSite, ioep.Message));
ioep=null;break;
}
catch(Exception ep)
{
logs(String.Format("(ThreadRecvCMSG_Packet_sockstream)Source:{0},TargetSite{1},Message{2}", ep.Source, ep.TargetSite, ep.Message));
ep=null;continue;
}
if (null == stream)
continue;
try
{
if (!stream.DataAvailable)
continue;
logs("recv data!");
tmp = new byte[1024];
if ((i = stream.Read(tmp, 0, tmp.Length)) > 4)
{
if (null == ms)
ms = new MemoryStream();
else
ms.Position = ms.Length;
ms.Write(tmp, 0, i);
}
stream.Flush();
if (ms.Length > 12)
{
tmp = new byte[12];
ms.Position = 0;
if ((i = ms.Read(tmp, 0, 12)) == 12)
{
nTotal = BitConverter.ToInt32(defcmd.b2b(tmp, 0, 4), 0);
nCmd = BitConverter.ToInt32(defcmd.b2b(tmp, 4, 4), 0);
nSeq = BitConverter.ToInt32(defcmd.b2b(tmp, 8, 4), 0);
if (ms.Length >= (nTotal - 12))
tmp = new byte[nTotal - 12];
if ((i = ms.Read(tmp, 0, nTotal - 12))> 0)
{
ParseCMSG_Cmd(nCmd, nSeq, tmp);
ms.Close();
ms = null;
}
}
}
}
catch(ArgumentOutOfRangeException aore)
{
nRebuild ++;
logs(String.Format("(ThreadRecvCMSG_Packet)Source:{0},TargetSite{1},Message{2}", aore.Source, aore.TargetSite, aore.Message));
aore = null;
}
catch(IOException ioe)
{
nRebuild ++;
logs(String.Format("(ThreadRecvCMSG_Packet)Source:{0},TargetSite{1},Message{2}", ioe.Source, ioe.TargetSite, ioe.Message));
ioe = null;
}
catch(Exception ep)
{
nRebuild ++;
logs(String.Format("(ThreadRecvCMSG_Packet)Source:{0},TargetSite{1},Message{2}", ep.Source, ep.TargetSite, ep.Message));
ep = null;
}
}
}
/// <summary>
/// 解释发送包
/// </summary>
/// <param name="cmd">包指令</param>
/// <param name="Packet">包体</param>
/// <returns>返回</returns>
public bool ParseCMSG_SendPacket(int cmd, byte [] Packet)
{
try
{
NetworkStream stream = null;
try
{
stream = m_sock.GetStream();
}
catch(InvalidOperationException ioep)
{
m_Enable = false;
m_sock.Close();
m_sock = null;
logs(String.Format("(ParseCMSG_SendPacket_sockstream)Source:{0},TargetSite{1},Message{2}", ioep.Source, ioep.TargetSite, ioep.Message));
ioep=null;
MessageBox.Show("连接已断开!");
return false;
}
catch(Exception ep)
{
logs(String.Format("(ParseCMSG_SendPacket_sockstream)Source:{0},TargetSite{1},Message{2}", ep.Source, ep.TargetSite, ep.Message));
ep=null;
}
if (null == stream)
return false;
byte [] bTmp = null;
switch(cmd)
{
case defcmd.CONNECT:
MemoryStream ms = new MemoryStream();
//打包帐号
bTmp = Encoding.GetEncoding(936).GetBytes(String.Format("{0}\n", m_sAccount));
ms.Write(bTmp, 0, bTmp.Length);
String szTimestamp = DateTime.Now.ToString("MMddHHmmss");
//打包AuthenticatorSource
bTmp = Encoding.GetEncoding(936).GetBytes(String.Format("{0}000000000{1}000000000{2}", m_sAccount, m_sPwd, szTimestamp));
// This is one implementation of the abstract class MD5.
MD5 md5 = new MD5CryptoServiceProvider();
bTmp = md5.ComputeHash(bTmp);
ms.Write(bTmp, 0, bTmp.Length);
ms.WriteByte(10);
//打包版本号
ms.WriteByte(defcmd.Version);
//打包时间
bTmp = Encoding.GetEncoding(936).GetBytes(szTimestamp);
ms.Write(bTmp, 0, bTmp.Length);
///组装包头
bTmp = new byte[12+ms.Length];
Buffer.BlockCopy(BitConverter.GetBytes(bTmp.Length), 0, bTmp, 0, 4);
//命令类型
Buffer.BlockCopy(BitConverter.GetBytes(defcmd.CONNECT), 0, bTmp, 4, 4);
//seq
Buffer.BlockCopy(BitConverter.GetBytes(0), 0, bTmp, 8, 4);
//请求认证
Buffer.BlockCopy(ms.ToArray(), 0, bTmp, 12, (int)ms.Length);
stream.Write(bTmp, 0, bTmp.Length);
ms.Close();
//等待回复信息
stream.Flush();
MainForm.logs("send data!CONNECT");
break;
case defcmd.ACTIION_TEST:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -