📄 mainform.cs
字号:
}
private void rmList_Click(object sender, System.EventArgs e)
{
ParseCMSG_SendPacket(defcmd.PWD, Encoding.GetEncoding(936).GetBytes("print work path\n"));
//ParseCMSG_SendPacket(defcmd.RND, Encoding.GetEncoding(936).GetBytes(DateTime.Now.ToString("yyyyMMdd")));
}
protected override void WndProc(ref Message m)
{
// TODO: 添加 MainForm.WndProc 实现
if (m.Msg == WM_UPDATELIST)
{
FileTreeFull();
return;
}
base.WndProc (ref m);
}
private void FiletreeView_DoubleClick(object sender, System.EventArgs e)
{
TreeNode tn = FiletreeView.SelectedNode;
if ( 0 == tn.ImageIndex)
{
m_sPath_tmp = m_sPath.Substring(0, m_sPath.LastIndexOf("/"));
if (m_sPath_tmp == "")
m_sPath_tmp = "/";
ParseCMSG_SendPacket(defcmd.CWD, Encoding.GetEncoding(936).GetBytes(m_sPath_tmp+"\n"));
}
else if (1 == tn.ImageIndex)
{
if (m_sPath == "/")
m_sPath_tmp = "/"+tn.Text;
else
m_sPath_tmp = m_sPath+"/"+tn.Text;
ParseCMSG_SendPacket(defcmd.CWD, Encoding.GetEncoding(936).GetBytes(m_sPath_tmp+"\n"));
}
else if (2 == tn.ImageIndex)
{
CFile_Trans cft = new CFile_Trans(this, m_sPath, m_sLocalPath, tn.Text, 2);
cft.threadproc = new Thread( new ThreadStart( cft.DoTrans ) );
cft.threadproc.IsBackground = true;
cft.threadproc.Start();
logs("trace file socket start.");
array_file.Add(cft);
}
}
private void btn_Connect_Click(object sender, System.EventArgs e)
{
// check box
if ( "" == tbIP.Text )
{
MessageBox.Show("服务器IP不能为空!");
return;
}
else if ( "" == tbPort.Text )
{
MessageBox.Show("服务器PORT不能为空!");
return;
}
else if ( "" == tbAccount.Text )
{
MessageBox.Show("帐号不能为空!");
return;
}
else if ( "" == tbPwd.Text )
{
MessageBox.Show("密码不能为空!");
return;
}
IPAddress hostIPAddress = IPAddress.Parse(tbIP.Text);
try
{
NetworkStream stream = null;
for ( short n = 0; n < 10; n++)
{
try
{
if (m_sock == null)
{
m_sock = new TcpClient();
m_sock.Connect(hostIPAddress, Int32.Parse(tbPort.Text));
}
stream = m_sock.GetStream();
if (null != stream)
break;
}
catch
{Thread.Sleep(1000);continue;}
}
ParseCMSG_SendPacket(defcmd.CONNECT, null);
/*
MemoryStream ms = new MemoryStream();
byte [] bTmp = null;
//打包帐号
bTmp = Encoding.GetEncoding(936).GetBytes(String.Format("{0}\n", tbAccount.Text));
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}", tbAccount.Text, tbPwd.Text, 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];
Buffer.BlockCopy(BitConverter.GetBytes(12+ms.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);
//请求认证
stream.Write(bTmp, 0, bTmp.Length);
bTmp = ms.ToArray();
stream.Write(bTmp, 0, bTmp.Length);
ms.Close();
//等待回复信息
stream.Flush();
//*/
Int32 i;
byte [] tmp = new byte[4];
if ((i = stream.Read(tmp, 0, tmp.Length)) == 4)
{
int nTotal = BitConverter.ToInt32(tmp, 0);
stream.Flush();
tmp = new byte[BitConverter.ToInt32(tmp, 0)-4];
if ((i = stream.Read(tmp, 0, tmp.Length)) == tmp.Length)
{
int nCmd = BitConverter.ToInt32(tmp, 0);
int nSeq = BitConverter.ToInt32(tmp, 4);
ParseCMSG_Cmd(nCmd, nSeq, defcmd.b2b(tmp, 8, tmp.Length-8));
}
}
/*
Int32 i;
byte []buf = new byte[12];
byte []tmp = new byte[4];
stream.Read(buf, 0, 12);
int nTotal = BitConverter.ToInt32(defcmd.b2b(buf, 0, 4), 0);
int nCmd = BitConverter.ToInt32(defcmd.b2b(buf, 4, 4), 0);
int nSeq = BitConverter.ToInt32(defcmd.b2b(buf, 8, 4), 0);
buf = new byte[nTotal - 12];
if ((i = stream.Read(buf, 0, nTotal - 12))> 0)
ParseCMSG_Cmd(nCmd, nSeq, buf);
m_sAccount = tbAccount.Text;
//*/
}
catch(Exception ep)
{
logs("[btn_Connect_Click]error:" + ep.Message);
return;
}
}
private void btn_Terminate_Click(object sender, System.EventArgs e)
{
try
{
m_Enable = false;
m_sock.GetStream().Close();
m_sock.Close();
m_sock = null;
Acitve_Timer.Enabled = false;
threadrecv.Abort();
}
finally
{
TraceMsg("断开网络连路!");
}
}
private void rmMwd_Click(object sender, System.EventArgs e)
{
FrmConnect fc = new FrmConnect(this);
fc.ShowDialog();
fc = null;
}
private void rmCnd_Click(object sender, System.EventArgs e)
{
Frmcn fc = null;
try
{
TreeNode tn = FiletreeView.SelectedNode;
if (null == tn)
{
MessageBox.Show("没有选定项!");
return;
}
if ( 1 == tn.ImageIndex)
{
fc = new Frmcn(this, 1, tn.Text);
fc.ShowDialog();
fc = null;
}
else
{
MessageBox.Show("此项为非文件夹,请重新选择!");
}
}
catch(Exception ep)
{logs("[rmCnd_Click]"+ep.Message);}
}
private void rmRwd_Click(object sender, System.EventArgs e)
{
try
{
TreeNode tn = FiletreeView.SelectedNode;
if (null == tn)
{
MessageBox.Show("没有选定项!");
return;
}
if ( 1 == tn.ImageIndex)
{
ParseCMSG_SendPacket(defcmd.RMD, Encoding.GetEncoding(936).GetBytes(tn.Text+"\n"));
}
else
{
MessageBox.Show("此项为非文件夹,请重新选择!");
}
}
catch(Exception ep)
{logs("[rmRwd_Click]"+ep.Message);}
}
private void rmDelete_Click(object sender, System.EventArgs e)
{
try
{
TreeNode tn = FiletreeView.SelectedNode;
if (null == tn)
{
MessageBox.Show("没有选定项!");
return;
}
if ( 2 == tn.ImageIndex)
{
ParseCMSG_SendPacket(defcmd.DELE, Encoding.GetEncoding(936).GetBytes(tn.Text+"\n"));
}
else
{
MessageBox.Show("此项为非文件,请重新选择!");
}
}
catch(Exception ep)
{logs("[rmDelete_Click]"+ep.Message);}
}
private void rmCnf_Click(object sender, System.EventArgs e)
{
Frmcn fc = null;
try
{
TreeNode tn = FiletreeView.SelectedNode;
if (null == tn)
{
MessageBox.Show("没有选定项!");
return;
}
if ( 1 == tn.ImageIndex)
{
fc = new Frmcn(this, 1, tn.Text);
fc.ShowDialog();
fc = null;
}
else if( 2 == tn.ImageIndex)
{
fc = new Frmcn(this, 2, tn.Text);
fc.ShowDialog();
fc = null;
}
else
{
MessageBox.Show("此项为非文件夹或文件夹,请重新选择!");
}
}
catch(Exception ep)
{logs("[rmCnd_Click]"+ep.Message);}
}
private void Acitve_Timer_Tick(object sender, System.EventArgs e)
{
ParseCMSG_SendPacket(defcmd.ACTIION_TEST, Encoding.GetEncoding(936).GetBytes("Active_Test\n"));
}
//显示逻辑分区
private void getlogical()
{
//清空listview
FilelistView.Items.Clear();
String [] logicdriver = Directory.GetLogicalDrives();
for ( short nIndex = 0 ; nIndex < logicdriver.Length; nIndex ++)
FilelistView.Items.Add(logicdriver[nIndex], 3);
}
//显示本地目录
private bool showpath(String szPath)
{
if ( ':' == szPath[szPath.Length-1] )
{
getlogical();
return true;
}
try
{
DirectoryInfo di = new DirectoryInfo(szPath);
FileSystemInfo[] dirs = di.GetFileSystemInfos();
//显示上级目录
FilelistView.Items.Clear();
FilelistView.Items.Add("上一级", 0);
Type dtype = Type.GetType("System.IO.DirectoryInfo");
ListViewItem lvt = null;
string [] lvtsub = new string[4];
foreach (FileSystemInfo fsi in dirs)
{
if (fsi.GetType().Equals(dtype))
{
lvtsub[0] = fsi.Name;
lvtsub[1] = "";
lvtsub[2] = "文件夹";
lvtsub[3] = fsi.LastAccessTime.ToString("yyyy-MM-dd HH:mm");
lvt = new ListViewItem(lvtsub, 1);
FilelistView.Items.Add(lvt);
}
else
{
lvtsub[0] = fsi.Name;
lvtsub[1] = ((FileInfo)fsi).Length.ToString("0 Byte");
lvtsub[2] = "文件";
lvtsub[3] = fsi.LastAccessTime.ToString("yyyy-MM-dd HH:mm");
lvt = new ListViewItem(lvtsub, 2);
FilelistView.Items.Add(lvt);
}
}
return true;
}
catch(ArgumentNullException anep)
{
logs("[showpath]文件夹不存在"+anep.Message);
return false;
}
catch(Exception ep)
{
logs("[showpath]"+ep.Message);
return false;
}
}
private void FilelistView_DoubleClick(object sender, System.EventArgs e)
{
try
{
ListViewItem lvt = FilelistView.Items[FilelistView.SelectedIndices[0]];
if ( 0 == lvt.ImageIndex) //上一级
{
m_sLocalPath = m_sLocalPath.Substring(0, m_sLocalPath.LastIndexOf(@"\"));
}
else if ( 1 == lvt.ImageIndex) //选定文件夹
{
m_sLocalPath = m_sLocalPath+"\\"+lvt.Text;
}
else if ( 2 == lvt.ImageIndex) //选定文件
{
CFile_Trans cft = new CFile_Trans(this, m_sPath, m_sLocalPath, lvt.Text, 1);
cft.threadproc = new Thread( new ThreadStart( cft.DoTrans ) );
cft.threadproc.IsBackground = true;
cft.threadproc.Start();
logs("trace file socket start.");
array_file.Add(cft);
}
else if ( 3 == lvt.ImageIndex) //选定逻辑盘
{
m_sLocalPath = lvt.Text;
}
if (!showpath(m_sLocalPath))
m_sLocalPath = m_sLocalPath.Substring(0, m_sLocalPath.LastIndexOf(@"\"));
}
catch(Exception ep)
{logs("[FilelistView_DoubleClick]"+ep.Message);}
}
private void smExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void smConfig_Click(object sender, System.EventArgs e)
{
Config cfg = new Config();
cfg.ShowDialog();
cfg = null;
}
private void rmFlush_Click(object sender, System.EventArgs e)
{
ParseCMSG_SendPacket(defcmd.FLALL, Encoding.GetEncoding(936).GetBytes("LIST\n"));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -