📄 mainform.cs
字号:
using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Xml;
using System.Text;
using System.Data;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
namespace CodeManager
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
/// <summary>
/// 文件列表类
/// </summary>
class Fnode
{
public Fnode(int nImage, string sName)
{
m_nImage = nImage;
m_sName = sName;
}
public int m_nImage;
public String m_sName;
}
//消息函数定义
[DllImport("user32.DLL", EntryPoint="SendMessage")]
public static extern int SendMessage(int hwnd, int msg, int wparam, int lparam);
public const int WM_UPDATELIST = 0x0401;
//系统定义
private System.Windows.Forms.MainMenu MainMenu;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.Panel mainpanel;
private System.Windows.Forms.StatusBar mainstatusBar;
private System.Windows.Forms.TreeView FiletreeView;
private System.Windows.Forms.Splitter mainsplitter;
private System.Windows.Forms.ListView FilelistView;
private System.Windows.Forms.Splitter buttomsplitter;
public bool m_Enable;
public TcpClient m_sock;
private String m_sPath;
private String m_sPath_tmp;
private String m_sLocalPath;
private Thread threadrecv=null;
private short nRebuild;
public Queue FileQueue;
private ArrayList array_file = null;
//配置参数
public static String cfFile="config.xml";
public String m_sIP;
public String m_sPort1;
public String m_sPort2;
public String m_sAccount;
public String m_sPwd;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.ListBox MsgBox;
private System.Windows.Forms.ContextMenu RightMenu_Tree;
private System.Windows.Forms.ImageList TreeimageList;
private System.Windows.Forms.MenuItem rmList;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem rmMwd;
private System.Windows.Forms.MenuItem rmRwd;
private System.Windows.Forms.MenuItem rmDelete;
private System.Windows.Forms.MenuItem rmCnd;
private System.Windows.Forms.MenuItem rmCnf;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button btn_Connect;
private System.Windows.Forms.Button btn_Terminate;
private System.Windows.Forms.TextBox tbIP;
private System.Windows.Forms.TextBox tbPort;
private System.Windows.Forms.TextBox tbAccount;
private System.Windows.Forms.TextBox tbPwd;
private System.Windows.Forms.Timer Acitve_Timer;
private System.Windows.Forms.MenuItem mFile;
private System.Windows.Forms.MenuItem mHelp;
private System.Windows.Forms.MenuItem smAbout;
private System.Windows.Forms.MenuItem smExit;
private System.Windows.Forms.MenuItem smConfig;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem rmFlush;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.ComponentModel.IContainer components;
public MainForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
if (!initparam())
TraceMsg("初始化参数失败");
tbIP.Text = m_sIP;
tbPort.Text = m_sPort1;
tbAccount.Text = m_sAccount;
tbPwd.Text = m_sPwd;
m_sock = null;
m_Enable = false;
Queue myQ = new Queue();
// Creates a synchronized wrapper around the Queue.
FileQueue = Queue.Synchronized( myQ );
// Create a file thread list
array_file = new ArrayList();
m_sPath = "/";
//init local file system
m_sLocalPath = "";
getlogical();
}
private bool initparam()
{
try
{
XmlDocument doc = new XmlDocument();
if (!File.Exists(Directory.GetCurrentDirectory() +"/"+ MainForm.cfFile))
{
doc.Load("<?xml version=\"1.0\" encoding=\"UTF-8\"?><config></config>");
doc.Save(Directory.GetCurrentDirectory() + "/" + MainForm.cfFile);
return false;
}
doc.Load(Directory.GetCurrentDirectory() +"/"+ MainForm.cfFile);
XmlNodeList xnl = doc.GetElementsByTagName("config");
if ( xnl.Count > 0)
{
XmlNodeList xnlhost = doc.GetElementsByTagName("host");
if ( xnlhost.Count > 0)
{
m_sIP = xnlhost.Item(0).Attributes["ip"].InnerText;
m_sPort1 = xnlhost.Item(0).Attributes["port1"].InnerText;
m_sPort2 = xnlhost.Item(0).Attributes["port2"].InnerText;
}
XmlNodeList xnlAccount = doc.GetElementsByTagName("account");
if (xnlAccount.Count > 0)
{
m_sAccount = xnlAccount.Item(0).InnerText;
}
XmlNodeList xnlPwd = doc.GetElementsByTagName("pwd");
if (xnlPwd.Count > 0)
{
m_sPwd = xnlPwd.Item(0).InnerText;
}
}
}
catch(XmlException xmlep)
{
logs(String.Format("(initparam)Source:{0},TargetSite{1},Message{2}", xmlep.Source, xmlep.TargetSite, xmlep.Message));
xmlep = null;
}
return true;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
this.MainMenu = new System.Windows.Forms.MainMenu();
this.mFile = new System.Windows.Forms.MenuItem();
this.smConfig = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.smExit = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.mHelp = new System.Windows.Forms.MenuItem();
this.smAbout = new System.Windows.Forms.MenuItem();
this.mainpanel = new System.Windows.Forms.Panel();
this.FilelistView = new System.Windows.Forms.ListView();
this.TreeimageList = new System.Windows.Forms.ImageList(this.components);
this.buttomsplitter = new System.Windows.Forms.Splitter();
this.MsgBox = new System.Windows.Forms.ListBox();
this.mainsplitter = new System.Windows.Forms.Splitter();
this.FiletreeView = new System.Windows.Forms.TreeView();
this.RightMenu_Tree = new System.Windows.Forms.ContextMenu();
this.rmList = new System.Windows.Forms.MenuItem();
this.rmMwd = new System.Windows.Forms.MenuItem();
this.rmRwd = new System.Windows.Forms.MenuItem();
this.rmDelete = new System.Windows.Forms.MenuItem();
this.rmFlush = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.rmCnd = new System.Windows.Forms.MenuItem();
this.rmCnf = new System.Windows.Forms.MenuItem();
this.mainstatusBar = new System.Windows.Forms.StatusBar();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.label1 = new System.Windows.Forms.Label();
this.tbIP = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.tbPort = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.tbAccount = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.tbPwd = new System.Windows.Forms.TextBox();
this.btn_Connect = new System.Windows.Forms.Button();
this.btn_Terminate = new System.Windows.Forms.Button();
this.Acitve_Timer = new System.Windows.Forms.Timer(this.components);
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.mainpanel.SuspendLayout();
this.SuspendLayout();
//
// MainMenu
//
this.MainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mFile,
this.menuItem6,
this.mHelp});
//
// mFile
//
this.mFile.Index = 0;
this.mFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.smConfig,
this.menuItem7,
this.smExit});
this.mFile.Text = "文件(&F)";
//
// smConfig
//
this.smConfig.Index = 0;
this.smConfig.Text = "配置";
this.smConfig.Click += new System.EventHandler(this.smConfig_Click);
//
// menuItem7
//
this.menuItem7.Index = 1;
this.menuItem7.Text = "-";
//
// smExit
//
this.smExit.Index = 2;
this.smExit.Text = "退出(&X)";
this.smExit.Click += new System.EventHandler(this.smExit_Click);
//
// menuItem6
//
this.menuItem6.Index = 1;
this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2,
this.menuItem3,
this.menuItem4});
this.menuItem6.Text = "编辑";
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "复制";
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "粘贴";
//
// menuItem3
//
this.menuItem3.Index = 2;
this.menuItem3.Text = "剪切";
//
// menuItem4
//
this.menuItem4.Index = 3;
this.menuItem4.Text = "删除";
//
// mHelp
//
this.mHelp.Index = 2;
this.mHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.smAbout});
this.mHelp.Text = "帮助(&H)";
//
// smAbout
//
this.smAbout.Index = 0;
this.smAbout.Text = "关于CodeManager";
//
// mainpanel
//
this.mainpanel.Controls.Add(this.FilelistView);
this.mainpanel.Controls.Add(this.buttomsplitter);
this.mainpanel.Controls.Add(this.MsgBox);
this.mainpanel.Controls.Add(this.mainsplitter);
this.mainpanel.Controls.Add(this.FiletreeView);
this.mainpanel.Controls.Add(this.mainstatusBar);
this.mainpanel.Dock = System.Windows.Forms.DockStyle.Top;
this.mainpanel.Location = new System.Drawing.Point(0, 42);
this.mainpanel.Name = "mainpanel";
this.mainpanel.Size = new System.Drawing.Size(800, 629);
this.mainpanel.TabIndex = 0;
//
// FilelistView
//
this.FilelistView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4});
this.FilelistView.Dock = System.Windows.Forms.DockStyle.Fill;
this.FilelistView.FullRowSelect = true;
this.FilelistView.Location = new System.Drawing.Point(315, 0);
this.FilelistView.MultiSelect = false;
this.FilelistView.Name = "FilelistView";
this.FilelistView.Size = new System.Drawing.Size(485, 408);
this.FilelistView.SmallImageList = this.TreeimageList;
this.FilelistView.StateImageList = this.TreeimageList;
this.FilelistView.TabIndex = 4;
this.FilelistView.View = System.Windows.Forms.View.Details;
this.FilelistView.DoubleClick += new System.EventHandler(this.FilelistView_DoubleClick);
//
// TreeimageList
//
this.TreeimageList.ImageSize = new System.Drawing.Size(16, 16);
this.TreeimageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("TreeimageList.ImageStream")));
this.TreeimageList.TransparentColor = System.Drawing.Color.Transparent;
//
// buttomsplitter
//
this.buttomsplitter.Dock = System.Windows.Forms.DockStyle.Bottom;
this.buttomsplitter.Location = new System.Drawing.Point(315, 408);
this.buttomsplitter.Name = "buttomsplitter";
this.buttomsplitter.Size = new System.Drawing.Size(485, 3);
this.buttomsplitter.TabIndex = 5;
this.buttomsplitter.TabStop = false;
//
// MsgBox
//
this.MsgBox.Dock = System.Windows.Forms.DockStyle.Bottom;
this.MsgBox.ItemHeight = 12;
this.MsgBox.Location = new System.Drawing.Point(315, 411);
this.MsgBox.Name = "MsgBox";
this.MsgBox.Size = new System.Drawing.Size(485, 196);
this.MsgBox.TabIndex = 1;
//
// mainsplitter
//
this.mainsplitter.Location = new System.Drawing.Point(312, 0);
this.mainsplitter.Name = "mainsplitter";
this.mainsplitter.Size = new System.Drawing.Size(3, 607);
this.mainsplitter.TabIndex = 1;
this.mainsplitter.TabStop = false;
//
// FiletreeView
//
this.FiletreeView.ContextMenu = this.RightMenu_Tree;
this.FiletreeView.Dock = System.Windows.Forms.DockStyle.Left;
this.FiletreeView.ImageList = this.TreeimageList;
this.FiletreeView.Location = new System.Drawing.Point(0, 0);
this.FiletreeView.Name = "FiletreeView";
this.FiletreeView.Size = new System.Drawing.Size(312, 607);
this.FiletreeView.TabIndex = 3;
this.FiletreeView.DoubleClick += new System.EventHandler(this.FiletreeView_DoubleClick);
//
// RightMenu_Tree
//
this.RightMenu_Tree.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.rmList,
this.rmMwd,
this.rmRwd,
this.rmDelete,
this.rmFlush,
this.menuItem9,
this.rmCnd,
this.rmCnf});
//
// rmList
//
this.rmList.Index = 0;
this.rmList.Text = "显示目录";
this.rmList.Click += new System.EventHandler(this.rmList_Click);
//
// rmMwd
//
this.rmMwd.Index = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -