⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftplistctrl.cpp

📁 一个支持FTP,SFTP的客户端程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		while (selpos)
		{
			int nItem = GetNextSelectedItem(selpos);
			int index=m_IndexMapping[nItem];
			ASSERT(index!=m_pDirectory->num);
			if (m_pDirectory->direntry[index].dir)
			{
				MessageBeep(MB_ICONEXCLAMATION);
				return;
			}
		}
		selpos = GetFirstSelectedItemPosition();
	}
	while (selpos)
	{
		int nItem = GetNextSelectedItem(selpos);
		int index=m_IndexMapping[nItem];
		ASSERT(index!=m_pDirectory->num);
		if (m_pDirectory->direntry[index].dir)
		{
			t_folder folder;
			folder.path = m_pDirectory->path;
			folder.subdir = m_pDirectory->direntry[index].name;
			m_PathsToVisit.push_back(folder);
			pMainFrame->m_pCommandQueue->SetLock(TRUE);
		}
		else
			pMainFrame->AddQueueItem(TRUE, m_pDirectory->direntry[index].name, "", "", m_pDirectory->path, FALSE, m_transferuser, m_transferpass);
	}
	if (!m_PathsToVisit.empty())
	{
		m_nFolderDownloadStart = FALSE;
		m_PathsVisited.push_front(m_pDirectory->path);
		m_nBatchAction = 1;
		DoNextStep();
	}
}

void CFtpListCtrl::OnFtpcontextDelete() 
{
	BOOL bDontAsk = FALSE;

	/* After displaying the confirmation dialog, jump back to the start of the function.
	 * This is required since a new/changed directory listing could have been displayed 
	 * while the dialog was open.
	 */
  ondelete_recheck:

	CMainFrame *pMainFrame = DYNAMIC_DOWNCAST(CMainFrame, GetParentFrame());
	if (pMainFrame->m_pCommandQueue->IsLocked())
		return;
	if (!m_pDirectory || m_nBatchAction || 
		!m_PathsToVisit.empty() || !m_PathsVisited.empty())
		return;

	POSITION selpos = GetFirstSelectedItemPosition();
	if (!selpos)
		return;
	
	BOOL dir = FALSE;
	BOOL file = FALSE;
	int count = 0;

	while (selpos)
	{
		int nItem = GetNextSelectedItem(selpos);
		int index = m_IndexMapping[nItem];
		if (index == m_pDirectory->num)
			continue;
		count++;
		if (m_pDirectory->direntry[index].dir)
			dir = TRUE;
		else
			file = TRUE;
	}

	if (count == 1)
	{
		if (pMainFrame->m_pCommandQueue->IsBusy())
		{
			MessageBeep(MB_ICONEXCLAMATION);
			return;
		}
		POSITION selpos = GetFirstSelectedItemPosition();
		ASSERT(selpos);
		int nItem = GetNextSelectedItem(selpos);
		int index = m_IndexMapping[nItem];
		if (index == m_pDirectory->num)
		{
			ASSERT(selpos);
			nItem = GetNextSelectedItem(selpos);
			index = m_IndexMapping[nItem];
		}
		if (index < 0 || index >= m_pDirectory->num)
		{
			MessageBeep(MB_ICONEXCLAMATION);
			return;
		}

		if (!bDontAsk)
		{
			CString str;
			str.Format(IDS_QUESTION_DELETEFILE, m_pDirectory->direntry[index].name);
			int res = AfxMessageBox(str, MB_YESNO|MB_ICONQUESTION);
			if (res == IDYES)
			{
				bDontAsk = TRUE;

				// Jump back to the start of the function
				goto ondelete_recheck;
			}
		}
		else
		{
			if (m_pDirectory->direntry[index].dir && !m_pDirectory->direntry[index].bLink)
			{
				t_folder folder;
				folder.path = m_pDirectory->path;
				folder.subdir = m_pDirectory->direntry[index].name;
				m_PathsToVisit.push_back(folder);
				pMainFrame->m_pCommandQueue->SetLock(TRUE);
			}
			else
				pMainFrame->m_pCommandQueue->Delete(m_pDirectory->direntry[index].name, m_pDirectory->path);
		}		
	}
	else if (count>1)
	{
		if (pMainFrame->m_pCommandQueue->IsBusy())
		{
			MessageBeep(MB_ICONEXCLAMATION);
			return;
		}

		if (!bDontAsk)
		{
			int res = IDNO;
			CString str;
			if (dir&&(!file))
			{
				str.Format(IDS_QUESTION_DELETEDIRS, count);
				res = AfxMessageBox(str, MB_YESNO|MB_ICONQUESTION);
			}
			else if (dir&&file)
			{
				str.Format(IDS_QUESTION_DELETEFILESANDDIRS, count);
				res = AfxMessageBox(str, MB_YESNO|MB_ICONQUESTION);
			}
			else
			{
				str.Format(IDS_QUESTION_DELETEFILES, count);
				res = AfxMessageBox(str, MB_YESNO|MB_ICONQUESTION);
			}
			if (res == IDYES)
			{
				bDontAsk = TRUE;
				
				// Jump back to the start of the function
				goto ondelete_recheck;
			}
		}
		else
		{
			selpos = GetFirstSelectedItemPosition();
			ASSERT(selpos);
			while (selpos)
			{
				count++;
				int nItem = GetNextSelectedItem(selpos);
				int index = m_IndexMapping[nItem];
				if (index==m_pDirectory->num)
					continue;
				if (m_pDirectory->direntry[index].dir && !m_pDirectory->direntry[index].bLink)
				{
					t_folder folder;
					folder.path = m_pDirectory->path;
					folder.subdir = m_pDirectory->direntry[index].name;
					m_PathsToVisit.push_back(folder);
					pMainFrame->m_pCommandQueue->SetLock(TRUE);
				}
				else
					pMainFrame->m_pCommandQueue->Delete(m_pDirectory->direntry[index].name,m_pDirectory->path);
			}
		}
	}
	if (!m_PathsToVisit.empty())
	{
		m_PathsVisited.push_front(m_pDirectory->path);
		m_nBatchAction = 2;
		DoNextStep();
	}
}

void CFtpListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if (nChar==46)
		OnFtpcontextDelete();
	else if (nChar==VK_F2)
	{
		CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
		if (pMainFrame->m_pCommandQueue->IsLocked())
			return;

		// To Use F2 as hot Key to get EditCtrl on the ListView it must have 
		// the Style LVS_EDITLABELS
		ASSERT( GetStyle() & LVS_EDITLABELS );
		// don't do an Edit Label when the multiple Items are selected
		if( GetSelectedCount( ) == 1 )
		{
			UINT nListSelectedItem = GetSelectedItem();
			VERIFY( EditLabel( nListSelectedItem ) != NULL );
		}
		else
			CListCtrl::OnKeyDown( nChar, nRepCnt, nFlags );
	}
		
	CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CFtpListCtrl::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult) 
{
	*pResult = 0;

	CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
	if (pMainFrame->m_pCommandQueue->IsBusy())
	{
		POSITION selpos = GetFirstSelectedItemPosition();
		while (selpos)
		{
			int nItem = GetNextSelectedItem(selpos);
			int index = m_IndexMapping[nItem];
			ASSERT(index!=m_pDirectory->num);
			if (m_pDirectory->direntry[index].dir)
				return;
		}
	}
	if (pMainFrame->m_pCommandQueue->IsLocked())
		return;

	POSITION selpos = GetFirstSelectedItemPosition();
	while (selpos)
	{
		int nItem = GetNextSelectedItem(selpos);
		if (!nItem)
			return;
	}
	EnsureVisible(((LPNMLISTVIEW)pNMHDR)->iItem, FALSE);
	
	//Let the main window handle the rest
	pMainFrame->OnBegindrag(this, ((LPNMLISTVIEW)pNMHDR)->ptAction);
}

void CFtpListCtrl::OnDragEnd(int target, CPoint point)
{
	DragLeave(NULL);

	m_transferuser = m_transferpass = "";
	if (target == 1)
		OnFtpcontextAddtoqueue();
	else if (!target)
		OnFtpcontextDownload();
	else if (target == 2 || target == 3)
	{
		if (!m_pDirectory)
			return;
		
		CMainFrame *pMainFrame = DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
		if (pMainFrame->m_pCommandQueue->IsLocked())
			return;
		if (m_nBatchAction || !m_PathsToVisit.empty() || !m_PathsVisited.empty())
			return;
		
		if (pMainFrame->m_pCommandQueue->IsBusy())
		{
			MessageBeep(MB_ICONEXCLAMATION);
			return;
		}

		CServerPath path = m_pDirectory->path;
		CServerPath newPath = path;

		if (target == 2)
		{
			ScreenToClient(&point);
			int nHitItem = HitTest(point);
			if (nHitItem == -1)
				return;
			
			if (nHitItem > 0 && nHitItem < (int)m_IndexMapping.size() && !m_pDirectory->direntry[m_IndexMapping[nHitItem]].dir)
				return;
			
			POSITION selpos = GetFirstSelectedItemPosition();
			while (selpos)
			{
				int nItem = GetNextSelectedItem(selpos);
				if (nItem == nHitItem)
					return;
			}

			if (!nHitItem)
			{
				if (!path.HasParent())
					return;
				newPath = path.GetParent();
			}
			else
				newPath.AddSubdir(m_pDirectory->direntry[m_IndexMapping[nHitItem]].name);
		}
		else
		{
			newPath = reinterpret_cast<CFtpTreeCtrl *>(pMainFrame->GetFtpTreePane()->GetTreeCtrl())->GetDropTarget();
			if (newPath.IsEmpty())
				return;
		}

		POSITION selpos = GetFirstSelectedItemPosition();
		while (selpos)
		{
			int nItem = GetNextSelectedItem(selpos);
			if (nItem < 1 || nItem >= (int)m_IndexMapping.size())
				continue;
			int nIndex = m_IndexMapping[nItem];
			if (nIndex < 0 || nIndex >= m_pDirectory->num)
				continue;
			pMainFrame->m_pCommandQueue->Rename(m_pDirectory->direntry[nIndex].name, m_pDirectory->direntry[nIndex].name, path, newPath);
		}
	}
}

void CFtpListCtrl::OnDropFiles(HDROP hDropInfo) 
{
	//End of a file drag&drop operation
	CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
	if (!GetItemCount())
	{
		DragFinish(hDropInfo);
		return;
	}
	int dropcount=DragQueryFile(hDropInfo,0xFFFFFFFF,0,0);
	for (int i=0;i<dropcount;i++)
	{
		int len=DragQueryFile(hDropInfo,i,0,0)+1;
		LPTSTR name=new TCHAR[len];
		DragQueryFile(hDropInfo,i,name,len);
		CFileStatus64 status;
		GetStatus64(name, status);
		CString name2=name;
		if (status.m_attribute&0x10)
		{
			CString filename=name;
			if (filename.ReverseFind('\\')!=-1)
				filename=filename.Right(filename.GetLength()-filename.ReverseFind('\\')-1);
			pMainFrame->UploadDir(name2 + _T("\\*.*"), filename + _T("\\"), TRUE);
		}
		else
		{
			ASSERT(name2.ReverseFind('\\')!=-1);
			CString filename=name2.Mid(name2.ReverseFind('\\')+1);
			CString path=name2.Left(name2.ReverseFind('\\'));
			pMainFrame->AddQueueItem(FALSE,filename,"",path,m_pDirectory->path,TRUE);
		}
		delete [] name;
	}
	pMainFrame->TransferQueue(2);
	DragFinish(hDropInfo);

}

void CFtpListCtrl::OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult) 
{
	CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
	*pResult=TRUE;
	if (pMainFrame->m_pCommandQueue->IsLocked())
		return;
	if (pMainFrame->m_pCommandQueue->IsBusy())
		return;
	if (!pDispInfo->item.iItem)
		return;
	*pResult = 0;
	CEdit *pEdit=GetEditControl();
	if (pEdit)
		pEdit->LimitText( 255 );
	
}

void CFtpListCtrl::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
	if (pDispInfo->item.pszText)
	{
		CString newname = pDispInfo->item.pszText;
		newname = newname.Left(255);
		if ((newname.Find('/')!=-1)||(newname.Find('\\')!=-1)||
			(newname.Find(':')!=-1)||(newname.Find('*')!=-1)||
			(newname.Find('?')!=-1)||(newname.Find('"')!=-1)||
			(newname.Find('<')!=-1)||(newname.Find('>')!=-1)||
			(newname.Find('|')!=-1))
		{
			AfxMessageBox(IDS_ERRORMSG_FILENAMEINVALID, MB_ICONEXCLAMATION);
			*pResult = FALSE;
			return;
		}
		CMainFrame *pMainFrame = DYNAMIC_DOWNCAST(CMainFrame, GetParentFrame());
		pMainFrame->m_pCommandQueue->Rename(m_pDirectory->direntry[m_IndexMapping[pDispInfo->item.iItem]].name, newname, m_pDirectory->path);
	}
	*pResult = FALSE;
}

#define VK_A		65
BOOL CFtpListCtrl::PreTranslateMessage(MSG* pMsg) 
{
	// If edit control is visible in tree view control, sending a
	// WM_KEYDOWN message to the edit control will dismiss the edit
	// control.  When ENTER key was sent to the edit control, the parent
	// window of the tree view control is responsible for updating the
	// item's label in TVN_ENDLABELEDIT notification code.
	if ( pMsg->message == WM_KEYDOWN )
	{
		CEdit* edit = GetEditControl();
		if (edit)
		{
			if( GetKeyState( VK_CONTROL )&128 && pMsg->wParam == VK_A )
			{
				edit->SetSel(0, -1);
				return TRUE;
			}
			if( pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_CONTROL || pMsg->wParam == VK_INSERT || pMsg->wParam == VK_SHIFT )
			{
				edit->SendMessage(WM_KEYDOWN, pMsg->wParam, pMsg->lParam);
				return TRUE;
			}
		}
		else
		{
			if( GetKeyState( VK_CONTROL )&128 && pMsg->wParam == VK_A )
			{
				m_bUpdating = TRUE;
				if (GetItemCount())
					SetItemState(0,GetItemCount()==1?LVIS_SELECTED:0,LVIS_SELECTED);
				for (int i=1;i<GetItemCount();i++)
					SetItemState(i,LVIS_SELECTED,LVIS_SELECTED);
				m_bUpdating = FALSE;

				UpdateStatusBar();
				return TRUE;
			}
			else if (pMsg->wParam==VK_RETURN)
			{
				CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
				if (pMainFrame->m_pCommandQueue->IsLocked())
					return TRUE;
				if (m_nBatchAction || !m_PathsToVisit.empty() || !m_PathsVisited.empty())
					return TRUE;

				POSITION selpos = GetFirstSelectedItemPosition();
				BOOL bOpen=TRUE;
				int openindex=-1;
				if (selpos)
				{
					int nItem = GetNextSelectedItem(selpos);
					int index=openindex=m_IndexMapping[nItem];
					if (index!=m_pDirectory->num && !m_pDirectory->direntry[index].dir)
					{
						bOpen=FALSE;
						pMainFrame->AddQueueItem(TRUE,m_pDirectory->direntry[index].name,"","",m_pDirectory->path,TRUE);
						openindex=-1;
					}
				}
				else
					return TRUE;
				while (selpos)
				{
					bOpen=FALSE;
					int nItem = GetNextSelectedItem(selpos);
					int index=m_IndexMapping[nItem];
					if (index==m_pDirectory->num)
						continue;
					if (m_pDirectory->direntry[index].dir)
					{
						t_folder folder;
						folder.path = m_pDirectory->path;
						folder.subdir = m_pDirectory->direntry[index].name;
						m_PathsToVisit.push_back(folder);
						pMainFrame->m_pCommandQueue->SetLock(TRUE);
					}
					else
						pMainFrame->AddQueueItem(TRUE,m_pDirectory->direntry[index].name,"","",m_pDirectory->path,TRUE,m_transferuser,m_transferpass);
				}
				if (bOpen)
				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -