FtpDirView.cpp
资源名称:FTP总集.rar [点击查看]
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:26k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // FtpDirView.cpp : implementation file
- //
- /*********************************************
- **该文件是属于WolfFTP工程中的。如果有什么问题
- **请联系
- ** tablejiang@21cn.com
- **或者访问
- ** http://wolfftp.51.net
- **以得到最新的支持。
- *********************************************/
- #include "stdafx.h"
- #include "QuickFTP.h"
- #include "FtpDirView.h"
- #include "DirListCtrl.h"
- #include "shlwapi.h"
- #include "InputFileNameDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CFtpDirView
- IMPLEMENT_DYNCREATE(CFtpDirView, CView)
- CFtpDirView::CFtpDirView()
- {
- m_pFtp = NULL ;
- m_bDragging = false ;
- m_pDragImage = NULL ;
- m_nDragIndex = -1;
- }
- CFtpDirView::~CFtpDirView()
- {
- if(m_pDragImage)
- delete m_pDragImage;
- m_pFtp->Logout ( ) ;
- }
- BEGIN_MESSAGE_MAP(CFtpDirView, CView)
- //{{AFX_MSG_MAP(CFtpDirView)
- ON_WM_SIZE()
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- ON_COMMAND(IDR_NEED_CONNECT, OnNeedConnect)
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONUP()
- ON_WM_KEYDOWN()
- ON_WM_CREATE()
- ON_COMMAND(IDR_REMOTE_ABORD, OnRemoteAbord)
- ON_COMMAND(IDR_REMOTE_DELETE, OnRemoteDelete)
- ON_COMMAND(IDR_REMOTE_DOWNLOAD, OnRemoteDownload)
- ON_COMMAND(IDR_REMOTE_EDIT, OnRemoteEdit)
- ON_COMMAND(IDR_REMOTE_MKDIR, OnRemoteMkdir)
- ON_COMMAND(IDR_REMOTE_REFRESH, OnRemoteRefresh)
- ON_COMMAND(ID_SELECT_ALL, OnSelectAll)
- //}}AFX_MSG_MAP
- ON_NOTIFY (LVN_BEGINDRAG, IDC_FTPDIRLIST, OnBeginDrag)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFtpDirView drawing
- void CFtpDirView::OnDraw(CDC* pDC)
- {
- CQuickFTPDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code here
- /*
- CBrush brush ;
- CBrush *pBakBrush ;
- RECT rect ;
- GetClientRect( &rect ) ;
- brush.CreateSolidBrush( RGB(125 , 125 , 125 ) ) ;
- pBakBrush = pDC->SelectObject( &brush ) ;
- rect.bottom = rect.top + 25 ;
- pDC->FillRect( &rect , &brush ) ;
- pDC->SelectObject( pBakBrush ) ;
- brush.DeleteObject () ;
- */
- }
- /////////////////////////////////////////////////////////////////////////////
- // CFtpDirView diagnostics
- #ifdef _DEBUG
- void CFtpDirView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CFtpDirView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- #endif //_DEBUG
- CQuickFTPDoc* CFtpDirView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CQuickFTPDoc)));
- return (CQuickFTPDoc*)m_pDocument;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CFtpDirView message handlers
- void CFtpDirView::OnInitialUpdate()
- {
- CView::OnInitialUpdate();
- // TODO: Add your specialized code here and/or call the base class
- }
- void CFtpDirView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- RECT rect ;
- //set combo box pos .
- if( m_Combo.m_hWnd != NULL )
- {
- GetClientRect( &rect ) ;
- rect.right -= 26 ;
- rect.bottom = 150 ;
- m_Combo.MoveWindow( &rect , TRUE ) ;
- }
- //set bitmap button pos .
- {
- GetClientRect( &rect ) ;
- rect.left = rect.right - 26;
- rect.bottom = rect.top + 20 ;
- m_UpButton.MoveWindow( &rect , TRUE ) ;
- m_UpButton.SizeToContent( ) ;
- }
- //set list pos .
- if( m_ListCtrl.m_hWnd != NULL )
- {
- GetClientRect( &rect ) ;
- rect.top += 22 ;
- m_ListCtrl.MoveWindow( &rect , TRUE ) ;
- }
- }
- LRESULT CFtpDirView::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // TODO: Add your specialized code here and/or call the base class
- switch( message )
- {
- case FTP_SERVER_DIR_LIST_MSG :
- //receive the ftp dir list
- FTPITEM* pFtpItemHead ;
- pFtpItemHead = ( FTPITEM *)wParam ;
- ReceiveDirList( pFtpItemHead ) ;
- break ;
- case FTP_LIST_DBCLICK_MSG :
- //enter the dir item .
- EnterListCurDir( ) ;
- break ;
- case WM_COMMAND :
- HandleCommand( (int)(LOWORD( wParam )) , (HWND)lParam , (UINT)(HIWORD(wParam)) ) ;
- break ;
- case ENABLE_FTP_LIST_MSG:
- switch( wParam )
- {
- case 0 :
- //disable current window
- SetStateDisable( ) ;
- break ;
- case 1:
- //enable current window
- SetStateEnable( ) ;
- break ;
- default:
- break ;
- }
- break ;
- case REFRESH_WND_MSG:
- {
- //refresh current .
- RefreshCurrentDirectory( ) ;
- }
- break ;
- case FTP_LIST_KEY_EVENT_MSG:
- {
- switch( wParam )
- {
- case VK_F5 :
- {
- RefreshCurrentDirectory( ) ;
- }
- break ;
- case VK_F2 :
- {
- RenameSelectItem( ) ;
- }
- break ;
- case VK_DELETE :
- {
- DeleteSelectItem( ) ;
- }
- break ;
- case VK_BACK :
- {
- //enter up directory
- EnterParentDir() ;
- }
- break ;
- case VK_RETURN :
- {
- EnterListCurDir( ) ;
- }
- break ;
- default :
- break ;
- }
- }
- break ;
- case FTP_LIST_RCLK_MSG :
- {
- POINT point ;
- GetCursorPos( &point ) ;
- CMenu PopMenu ;
- PopMenu.LoadMenu( IDR_MAINFRAME ) ;
- CMenu *pPopMenu = PopMenu.GetSubMenu( 2 ) ;
- pPopMenu->EnableMenuItem( IDR_REMOTE_UPLOAD , MF_DISABLED | MF_GRAYED) ;
- pPopMenu->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON , point.x , point.y , this ) ;
- PopMenu.DestroyMenu() ;
- }
- break ;
- default:
- break ;
- }
- return CView::DefWindowProc(message, wParam, lParam);
- }
- void CFtpDirView::OnAppAbout()
- {
- // TODO: Add your command handler code here
- }
- void CFtpDirView::OnNeedConnect()
- {
- // TODO: Add your command handler code here
- }
- void CFtpDirView::HandleCommand(int id, HWND hCtrlWnd, UINT uEvent)
- {
- switch( id )
- {
- case IDC_HISTROYCOMBO:
- switch( uEvent )
- {
- case CBN_SELCHANGE :
- //enter history path .
- char szPath[MAX_PATH] ;
- if( m_Combo.GetSelectText( szPath ) )
- {
- m_pFtp->EnterDirectory( szPath ) ;
- ShowCurrentListDirectory( szPath ) ;
- }
- break ;
- default :
- break ;
- }
- break ;
- case IDC_FTPDIRLIST:
- switch( uEvent )
- {
- case NM_DBLCLK :
- break ;
- default :
- break ;
- }
- break ;
- case IDC_FTPDIRUPBTN:
- switch( uEvent )
- {
- case BN_CLICKED:
- EnterParentDir() ;
- break ;
- default :
- break ;
- }
- break ;
- default :
- break ;
- }
- }
- void CFtpDirView::RefurbishDirList()
- {
- }
- void CFtpDirView::EnterListCurDir()
- {
- int iCount = m_ListCtrl.GetSelectedCount();
- if( iCount > 1 || iCount <= 0)
- return ;
- int iCurSel = m_ListCtrl.GetNextItem( -1 , LVNI_SELECTED ) ;
- LVITEM lci ;
- LVITEM lci2 ;
- char szText[MAX_PATH] ;
- char szText2[MAX_PATH] ;
- szText[0] = 0 ;
- //get the file type .
- lci2.mask = LVIF_INDENT | LVIF_TEXT;
- lci2.pszText = szText2 ;
- lci2.cchTextMax = MAX_PATH ;
- lci2.iItem = iCurSel ;
- lci2.iSubItem = 2 ;
- m_ListCtrl.GetItem( &lci2 ) ;
- //get file name .
- lci.mask = LVIF_INDENT | LVIF_TEXT;
- lci.pszText = szText ;
- lci.cchTextMax = MAX_PATH ;
- lci.iItem = iCurSel ;
- lci.iSubItem = 0 ;
- m_ListCtrl.GetItem( &lci ) ;
- if( strcmp( lci2.pszText , "" )== 0 )
- {
- //if file download it.
- DownLoadFile( lci.pszText , 0 , NULL , iCurSel ) ;
- return ;
- }
- //make the ftp path .
- char strDisplayPath[MAX_PATH] ;
- int iLength = 0 ;
- strcpy( strDisplayPath , m_pFtp->m_CurrentFtpDirectory ) ;
- iLength = strlen( strDisplayPath ) ;
- if( strDisplayPath[iLength - 1 ] != '/' )
- strcat( strDisplayPath , "/" ) ;
- strcat( strDisplayPath , lci.pszText ) ;
- //enter path .
- m_pFtp->EnterDirectory( strDisplayPath ) ;
- //refresh
- ShowCurrentListDirectory( strDisplayPath ) ;
- return ;
- }
- void CFtpDirView::ReceiveDirList(FTPITEM *pFtpItemHead)
- {
- //add file queue to history list.
- //if the path already exist in history list ,
- //we not add it , only select it .
- if( m_HistoryQueue.AddItem( pFtpItemHead , m_pFtp->m_CurrentFtpDirectory ) )
- {
- m_Combo.AddString( m_pFtp->m_CurrentFtpDirectory) ;
- m_Combo.SetCurSel( 0 ) ;
- }
- else
- m_Combo.SetItemSelect( m_pFtp->m_CurrentFtpDirectory ) ;
- RefreshFtpList( pFtpItemHead ) ;
- }
- BOOL CFtpDirView::RefreshFtpList(FTPITEM *pFtpItem)
- {
- //clear list ctrl.
- if( !m_ListCtrl.DelAllItem( ) )
- return false ;
- if( pFtpItem == NULL )
- return false ;
- //add item .
- m_ListCtrl.AddItem( pFtpItem ) ;
- return true ;
- }
- void CFtpDirView::ShowCurrentListDirectory(LPSTR szPath)
- {
- //find the path in history .
- HISTORYINFO * pCurPos = m_HistoryQueue.FindInHistory( szPath ) ;
- if( pCurPos == NULL )
- {
- //if not found , get ftp list.
- RefreshCurrentDirectory() ;
- }
- else
- {
- //if found , use history list.
- RefreshFtpList( pCurPos->pFtpItem ) ;
- }
- //select this path .
- m_Combo.SetItemSelect( szPath ) ;
- }
- void CFtpDirView::EnterParentDir()
- {
- m_pFtp->EnterParentDir( ) ;
- CString strFind ;
- //make path .
- strFind = m_pFtp->m_CurrentFtpDirectory ;
- int pos = strFind.ReverseFind( '/' ) ;
- if( strFind.GetLength( ) > 1 )
- strFind = strFind.Left( pos + 1 ) ;
- char szPath [MAX_PATH ] ;
- strcpy( szPath , (LPCTSTR)strFind );
- //refresh .
- ShowCurrentListDirectory( szPath ) ;
- }
- BOOL CFtpDirView::DisconnectFtp()
- {
- //disconnect with server.
- m_pFtp->Logout ( ) ;
- m_HistoryQueue.DeleteAllItem( ) ;
- m_ListCtrl.DeleteAllItems( ) ;
- m_Combo.DeleteAllItem( ) ;
- return true ;
- }
- BOOL CFtpDirView::ConnectFtp( SITEINFO* pSite )
- {
- //set hwnd info .
- m_HistoryQueue.DeleteAllItem( ) ;
- HWNDINFO hWndInfo ;
- ZeroMemory( &hWndInfo , sizeof( HWNDINFO ) ) ;
- //set window handle .
- hWndInfo.hInfoWnd = m_hDisplayWnd ;
- hWndInfo.hFtpDirListWnd = m_hWnd ;
- m_pFtp->SetSiteInfo( pSite , &hWndInfo) ;
- //get history download file .
- char SaveFileName[MAX_PATH] ;
- sprintf( SaveFileName , "%s%s.QFQ" , m_pFtp->m_SiteInfo.host , m_pFtp->m_SiteInfo.user ) ;
- m_pFtp->m_FileQueue.SetSaveFileName( SaveFileName ) ;
- CQuickFTPDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- //set doc var.
- pDoc->m_pFileQueue = &m_pFtp->m_FileQueue ;
- pDoc->UpdateAllViews( this );
- //start connect.
- m_pFtp->StartFtpCommunication() ;
- RefreshCurrentDirectory( ) ;
- return true ;
- }
- BOOL CFtpDirView::SetStateDisable()
- {
- //disable window
- m_Combo.EnableWindow( FALSE ) ;
- m_ListCtrl.EnableWindow( FALSE ) ;
- m_UpButton.EnableWindow( FALSE ) ;
- return true ;
- }
- BOOL CFtpDirView::SetStateEnable()
- {
- //enable window
- m_Combo.EnableWindow( ) ;
- m_ListCtrl.EnableWindow( ) ;
- m_UpButton.EnableWindow( ) ;
- return true ;
- }
- void CFtpDirView::DownLoadFile(LPSTR szName , BOOL bDir , LPCTSTR LocalPath , int iSelItem )
- {
- FTPFILEINFO FtpFile ;
- ::ZeroMemory( &FtpFile , sizeof( FTPFILEINFO ) ) ;
- //get document .
- CQuickFTPDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- memcpy( &FtpFile.site , &m_pFtp->m_SiteInfo , sizeof( SITEINFO ) ) ;
- strcpy( FtpFile.remotefilename , szName ) ;
- strcpy( FtpFile.remotepath , m_pFtp->m_CurrentFtpDirectory ) ;
- strcpy( FtpFile.localfilename , szName ) ;
- if( LocalPath == NULL )
- strcpy( FtpFile.localpath , pDoc->m_szLocalPath ) ;
- else
- strcpy( FtpFile.localpath , LocalPath ) ;
- FtpFile.bfileput = false ;
- FtpFile.endpos = 0 ;
- FtpFile.startpos = 0 ;
- FtpFile.bIsDirectory = bDir ;
- char szText[MAX_PATH] ;
- m_ListCtrl.GetItemText( iSelItem , 1 , szText , MAX_PATH ) ;
- __int64 iFileSize = _atoi64( szText ) ;
- FtpFile.filesize = iFileSize ;
- m_ListCtrl.GetItemText( iSelItem , 3 , szText , MAX_PATH ) ;
- strcpy( FtpFile.filetime , szText ) ;
- m_pFtp->PutGetFileToServer( &FtpFile ) ;
- //cancel by table 2001 4 2
- pDoc->m_pFileQueue = &m_pFtp->m_FileQueue ;
- pDoc->UpdateAllViews( this ) ;
- }
- void CFtpDirView::AbordAction()
- {
- m_pFtp->StopNowCommand( ) ;
- }
- void CFtpDirView::RefreshCurrentDirectory()
- {
- m_pFtp->ListCurrentDirectory( ) ;
- }
- // this function is called in response to an LVN_BEGINDRAG
- void CFtpDirView::OnBeginDrag (NMHDR* pnmhdr, LRESULT* pResult)
- {
- // save the index of the item being dragged in m_nDragIndex
- m_nDragIndex = ((NM_LISTVIEW *)pnmhdr)->iItem;
- POINT pt;
- pt.x = 8;
- pt.y = 8;
- // Added 2001 3 38
- if(m_pDragImage)
- delete m_pDragImage;
- // create a drag image
- m_pDragImage = m_ListCtrl.CreateDragImage (m_nDragIndex, &pt);
- ASSERT (m_pDragImage);
- // changes the cursor to the drag image (DragMove() is still required in
- // OnMouseMove())
- VERIFY (m_pDragImage->BeginDrag (0, CPoint (8, 8)));
- VERIFY (m_pDragImage->DragEnter (GetDesktopWindow (), ((NM_LISTVIEW *)pnmhdr)->ptAction));
- // set dragging flag
- m_bDragging = TRUE;
- m_hDropItem = NULL;
- m_nDropIndex = -1;
- m_pDropWnd = &m_ListCtrl ;
- // capture all mouse messages
- SetCapture ();
- }
- void CFtpDirView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if (m_bDragging)
- {
- CPoint pt (point);
- ClientToScreen (&pt);
- // move the drag image
- VERIFY (m_pDragImage->DragMove (pt));
- // unlock window updates
- VERIFY (m_pDragImage->DragShowNolock (FALSE));
- // get the CWnd pointer of the window that is under the mouse cursor
- CWnd* pDropWnd = WindowFromPoint (pt);
- ASSERT (pDropWnd);
- // if we drag outside current window
- if (pDropWnd != m_pDropWnd)
- {
- // turn off hilight for drop target in list control
- if (m_nDropIndex != -1)
- {
- CListCtrl* pList = (CListCtrl*)m_pDropWnd;
- VERIFY (pList->SetItemState (m_nDropIndex, 0, LVIS_DROPHILITED));
- // redraw item
- VERIFY (pList->RedrawItems (m_nDropIndex, m_nDropIndex));
- pList->UpdateWindow ();
- m_nDropIndex = -1;
- }
- }
- // save current window pointer
- m_pDropWnd = pDropWnd;
- // convert from screen coordinates to drop target client coordinates
- pDropWnd->ScreenToClient (&pt);
- if( pDropWnd == &m_ListCtrl )
- {
- DestroyCursor( ::SetCursor( LoadCursor( NULL , IDC_NO ) ) ) ;
- CView::OnMouseMove(nFlags, point);
- return ;
- }
- if (pDropWnd->IsKindOf (RUNTIME_CLASS (CListCtrl)))
- {
- UINT uFlags;
- CListCtrl* pList = (CListCtrl*)pDropWnd;
- // turn off hilight for previous drop target
- pList->SetItemState (m_nDropIndex, 0, LVIS_DROPHILITED);
- // redraw previous item
- pList->RedrawItems (m_nDropIndex, m_nDropIndex);
- // get the item that is below cursor
- m_nDropIndex = ((CListCtrl*)pDropWnd)->HitTest (pt, &uFlags);
- if( m_nDropIndex != -1 )
- {
- // highlight it
- pList->SetItemState (m_nDropIndex, LVIS_DROPHILITED, LVIS_DROPHILITED);
- // redraw item
- pList->RedrawItems (m_nDropIndex, m_nDropIndex);
- pList->UpdateWindow ();
- }
- DestroyCursor( ::SetCursor( LoadCursor( NULL , IDC_ARROW ) ) ) ;
- }
- else
- {
- if( pDropWnd->IsKindOf( RUNTIME_CLASS( CDialog ) ) )
- {
- if( ( (CDialog* )pDropWnd )->m_hWnd == m_ListInfo.hGenius )
- {
- DestroyCursor( ::SetCursor( LoadCursor( NULL , IDC_ARROW ) ) ) ;
- }
- else
- {
- DestroyCursor( ::SetCursor( LoadCursor( NULL , IDC_NO ) ) ) ;
- }
- }
- else
- {
- DestroyCursor( ::SetCursor( LoadCursor( NULL , IDC_NO ) ) ) ;
- }
- }
- // lock window updates
- VERIFY (m_pDragImage->DragShowNolock (TRUE));
- }
- CView::OnMouseMove(nFlags, point);
- }
- void CFtpDirView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if (m_bDragging)
- {
- // release mouse capture
- VERIFY (::ReleaseCapture ());
- m_bDragging = FALSE;
- // end dragging
- VERIFY (m_pDragImage->DragLeave (GetDesktopWindow ()));
- m_pDragImage->EndDrag ();
- CPoint pt (point);
- ClientToScreen (&pt);
- // get the CWnd pointer of the window that is under the mouse cursor
- CWnd* pDropWnd = WindowFromPoint (pt);
- ASSERT (pDropWnd);
- if (pDropWnd->IsKindOf (RUNTIME_CLASS ( CListCtrl )))
- {
- CListCtrl* pListWnd = ( CListCtrl*)pDropWnd ;
- pListWnd->SetItemState (m_nDropIndex, 0, LVIS_DROPHILITED);
- pListWnd->RedrawItems (m_nDropIndex, m_nDropIndex);
- if( pDropWnd->m_hWnd == m_ListInfo.hCurJobList ||
- pDropWnd->m_hWnd == m_ListInfo.hLocalList )
- {
- DropItemOnList( (CListCtrl*)pDropWnd );
- }
- if( pDropWnd->m_hWnd == m_ListInfo.hBkJobList )
- {
- AddSelectToBkTransmitQueue( ) ;
- }
- }
- if( pDropWnd->IsKindOf( RUNTIME_CLASS( CDialog ) ) )
- {
- if( pDropWnd->m_hWnd == m_ListInfo.hGenius )
- {
- ::PostMessage( m_ListInfo.hGenius , GENIUS_WND_SPLIT_MSG , 0 , 0 ) ;
- AddSelectToBkTransmitQueue( ) ;
- }
- }
- }
- CView::OnLButtonUp(nFlags, point);
- }
- BOOL CFtpDirView::DropItemOnList(CListCtrl* pDropWnd)
- {
- // unhilite the drop target
- pDropWnd->SetItemState (m_nDropIndex, 0, LVIS_DROPHILITED);
- char szLabel[MAX_PATH];
- LV_ITEM lvi;
- ZeroMemory (&lvi, sizeof (LV_ITEM));
- lvi.iItem = m_nDropIndex;
- lvi.mask = LVIF_TEXT;
- lvi.pszText = szLabel;
- lvi.cchTextMax = MAX_PATH ;
- // get item that was dragged
- if( !pDropWnd->GetItem( &lvi ) )
- {
- return DownLoadSelectItem ( NULL ) ;
- }
- char szPath[MAX_PATH] ;
- CQuickFTPDoc* pDoc = GetDocument( ) ;
- strcpy( szPath , pDoc->m_szLocalPath ) ;
- int iLength = strlen( szPath ) ;
- if( szPath[iLength-1] != '\' )
- {
- szPath[iLength] = '\' ;
- szPath[iLength+1] = ' ' ;
- }
- strcat( szPath , lvi.pszText ) ;
- if( PathIsDirectory( szPath ) )
- {
- DownLoadSelectItem( szPath ) ;
- }
- else
- {
- DownLoadSelectItem( NULL ) ;
- }
- return true ;
- }
- BOOL CFtpDirView::DownLoadSelectItem( LPCTSTR LocalPath )
- {
- UINT i, uSelectedCount = m_ListCtrl.GetSelectedCount();
- int nItem = -1;
- if( !m_pFtp->IsConnect() )
- return false ;
- // download all of the selected items.
- if (uSelectedCount > 0)
- {
- for (i=0;i < uSelectedCount;i++)
- {
- nItem = m_ListCtrl.GetNextItem(nItem, LVNI_SELECTED);
- ASSERT(nItem != -1);
- LVITEM lci ;
- LVITEM lci2 ;
- char szText[MAX_PATH] ;
- char szText2[MAX_PATH] ;
- szText[0] = 0 ;
- lci2.mask = LVIF_INDENT | LVIF_TEXT;
- lci2.pszText = szText2 ;
- lci2.cchTextMax = MAX_PATH ;
- lci2.iItem = nItem ;
- lci2.iSubItem = 2 ;
- m_ListCtrl.GetItem( &lci2 ) ;
- lci.mask = LVIF_INDENT | LVIF_TEXT;
- lci.pszText = szText ;
- lci.cchTextMax = MAX_PATH ;
- lci.iItem = nItem ;
- lci.iSubItem = 0 ;
- m_ListCtrl.GetItem( &lci ) ;
- if( strcmp( lci2.pszText , "" ) == 0 )
- {
- DownLoadFile( lci.pszText , 0 , LocalPath , nItem ) ;
- }
- else
- {
- DownLoadFile( lci.pszText , 1 , LocalPath , nItem ) ;
- }
- }
- }
- return true ;
- }
- void CFtpDirView::DeleteSelectItem()
- {
- UINT i, uSelectedCount = m_ListCtrl.GetSelectedCount();
- int nItem = -1;
- if( !m_pFtp->IsConnect() )
- return ;
- // download all of the selected items.
- if (uSelectedCount > 0)
- {
- for (i=0;i < uSelectedCount;i++)
- {
- nItem = m_ListCtrl.GetNextItem(nItem, LVNI_SELECTED);
- ASSERT(nItem != -1);
- LVITEM lci ;
- LVITEM lci2 ;
- char szText[MAX_PATH] ;
- char szText2[MAX_PATH] ;
- szText[0] = 0 ;
- lci2.mask = LVIF_INDENT | LVIF_TEXT;
- lci2.pszText = szText2 ;
- lci2.cchTextMax = MAX_PATH ;
- lci2.iItem = nItem ;
- lci2.iSubItem = 2 ;
- m_ListCtrl.GetItem( &lci2 ) ;
- lci.mask = LVIF_INDENT | LVIF_TEXT;
- lci.pszText = szText ;
- lci.cchTextMax = MAX_PATH ;
- lci.iItem = nItem ;
- lci.iSubItem = 0 ;
- m_ListCtrl.GetItem( &lci ) ;
- if( strcmp( lci2.pszText , "" ) == 0 )
- {
- DelectItem( lci.pszText , 0 ) ;
- }
- else
- {
- DelectItem( lci.pszText , 1 ) ;
- }
- }
- }
- return ;
- }
- void CFtpDirView::DelectItem(LPSTR szName, BOOL bDir)
- {
- FTPFILEINFO FtpFile ;
- ::ZeroMemory( &FtpFile , sizeof( FTPFILEINFO ) ) ;
- //get document .
- CQuickFTPDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- memcpy( &FtpFile.site , &m_pFtp->m_SiteInfo , sizeof( SITEINFO ) ) ;
- strcpy( FtpFile.remotefilename , szName ) ;
- strcpy( FtpFile.remotepath , m_pFtp->m_CurrentFtpDirectory ) ;
- strcpy( FtpFile.localfilename , szName ) ;
- strcpy( FtpFile.localpath , pDoc->m_szLocalPath ) ;
- FtpFile.bfileput = false ;
- FtpFile.endpos = 0 ;
- FtpFile.startpos = 0 ;
- FtpFile.bIsDirectory = bDir ;
- m_pFtp->DeleteFile( &FtpFile ) ;
- //cancel by table 2001 4 2
- //pDoc->m_pFileQueue = m_pFtp->m_pFileTransmitQueue ;
- }
- BOOL CFtpDirView::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: Add your specialized code here and/or call the base class
- /*
- switch( pMsg->message )
- {
- case WM_KEYDOWN :
- {
- switch( pMsg->wParam )
- {
- case VK_DELETE :
- TRACE( "press delete!" ) ;
- break ;
- case VK_RETURN :
- TRACE( "Press return !" ) ;
- break ;
- default :
- break ;
- }
- }
- break ;
- default :
- break ;
- }
- */
- return CView::PreTranslateMessage(pMsg);
- }
- void CFtpDirView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- switch( nChar )
- {
- case VK_F2 :
- break ;
- default :
- break ;
- }
- CView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CFtpDirView::RenameSelectItem()
- {
- UINT uSelectedCount ;
- int nItem = -1;
- char szPath[MAX_PATH] ;
- CFileManageLib fileman ;
- uSelectedCount = m_ListCtrl.GetSelectedCount( ) ;
- if( uSelectedCount != 1 )
- return ;
- strcpy( szPath , m_pFtp->m_CurrentFtpDirectory ) ;
- int iLength = strlen( szPath );
- if( szPath[iLength-1] != '/' )
- {
- szPath[iLength] = '/';
- szPath[iLength+1] = ' ' ;
- }
- char szText[MAX_PATH] ;
- szText[0] = ' ';
- int iCurSel = m_ListCtrl.GetNextItem( nItem , LVNI_SELECTED ) ;
- m_ListCtrl.GetItemText( iCurSel , 0 , szText , MAX_PATH ) ;
- CInputFileNameDlg dlg ;
- dlg.m_strName = szText ;
- if( dlg.DoModal() == IDOK )
- {
- char szDes[MAX_PATH] ;
- char szSrc[MAX_PATH] ;
- sprintf( szDes , "%s%s" , szPath , dlg.m_strName ) ;
- sprintf( szSrc , "%s%s" , szPath , szText ) ;
- m_pFtp->RenameFile( szSrc , szDes ) ;
- }
- RefreshCurrentDirectory( ) ;
- }
- BOOL CFtpDirView::EditSelectItem()
- {
- UINT uSelectedCount = m_ListCtrl.GetSelectedCount( ) ;
- if( uSelectedCount != 1 )
- return false ;
- return true ;
- }
- BOOL CFtpDirView::AddSelectToBkTransmitQueue( )
- {
- UINT i, uSelectedCount = m_ListCtrl.GetSelectedCount();
- int nItem = -1;
- if( !m_pFtp->IsConnect() )
- return false ;
- // download all of the selected items.
- if (uSelectedCount > 0)
- {
- for (i=0;i < uSelectedCount;i++)
- {
- nItem = m_ListCtrl.GetNextItem(nItem, LVNI_SELECTED);
- ASSERT(nItem != -1);
- LVITEM lci ;
- LVITEM lci2 ;
- char szText[MAX_PATH] ;
- char szText2[MAX_PATH] ;
- szText[0] = 0 ;
- lci2.mask = LVIF_INDENT | LVIF_TEXT;
- lci2.pszText = szText2 ;
- lci2.cchTextMax = MAX_PATH ;
- lci2.iItem = nItem ;
- lci2.iSubItem = 2 ;
- m_ListCtrl.GetItem( &lci2 ) ;
- lci.mask = LVIF_INDENT | LVIF_TEXT;
- lci.pszText = szText ;
- lci.cchTextMax = MAX_PATH ;
- lci.iItem = nItem ;
- lci.iSubItem = 0 ;
- m_ListCtrl.GetItem( &lci ) ;
- if( strcmp( lci2.pszText , "" ) == 0 )
- {
- AddItemToBkQueue( lci.pszText , 0 , nItem ) ;
- }
- else
- {
- AddItemToBkQueue( lci.pszText , 1 , nItem ) ;
- }
- }
- }
- return true ;
- }
- BOOL CFtpDirView::AddItemToBkQueue(LPSTR szName , BOOL bDir , int iSelItem )
- {
- FTPFILEINFO FtpFile ;
- ::ZeroMemory( &FtpFile , sizeof( FTPFILEINFO ) ) ;
- //get document .
- CQuickFTPDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- memcpy( &FtpFile.site , &m_pFtp->m_SiteInfo , sizeof( SITEINFO ) ) ;
- strcpy( FtpFile.remotefilename , szName ) ;
- strcpy( FtpFile.remotepath , m_pFtp->m_CurrentFtpDirectory ) ;
- strcpy( FtpFile.localfilename , szName ) ;
- strcpy( FtpFile.localpath , pDoc->m_szLocalPath ) ;
- FtpFile.bfileput = false ;
- FtpFile.endpos = 0 ;
- FtpFile.startpos = 0 ;
- FtpFile.bIsDirectory = bDir ;
- char szText[MAX_PATH] ;
- m_ListCtrl.GetItemText( iSelItem , 1 , szText , MAX_PATH ) ;
- __int64 iFileSize = _atoi64( szText ) ;
- FtpFile.filesize = iFileSize ;
- m_ListCtrl.GetItemText( iSelItem , 3 , szText , MAX_PATH ) ;
- strcpy( FtpFile.filetime , szText ) ;
- return m_pBkTransmitDlg->AddToBkQueue( &FtpFile ) ;
- }
- int CFtpDirView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- // TODO: Add your specialized creation code here
- RECT rect ;
- GetClientRect( &rect ) ;
- rect.right -= 26 ;
- rect.bottom = 150 ;
- m_Combo.Create( WS_CHILD | WS_VISIBLE |WS_VSCROLL | WS_TABSTOP | CBS_DROPDOWNLIST
- , rect , this , IDC_HISTROYCOMBO ) ;
- GetClientRect( &rect ) ;
- rect.left = rect.right -26 ;
- rect.bottom = rect.top + 20 ;
- m_UpButton.Create( NULL , WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW ,
- rect , this , IDC_FTPDIRUPBTN ) ;
- m_UpButton.LoadBitmaps( IDB_BITMAP_UP , IDB_BITMAP_DOWN , IDB_BITMAP_FOCUS , IDB_BITMAP_DISABLE ) ;
- // m_UpButton.AutoLoad( IDC_FTPDIRUPBTN , this ) ;
- m_UpButton.SizeToContent( ) ;
- GetClientRect( &rect ) ;
- rect.top += 25 ;
- //rect.bottom -= 30 ;
- m_ListCtrl.Create( WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SHOWSELALWAYS ,
- rect , this , IDC_FTPDIRLIST ) ;
- m_ListCtrl.m_hParentWnd = m_hWnd ;
- return 0;
- }
- void CFtpDirView::OnRemoteAbord()
- {
- // TODO: Add your command handler code here
- }
- void CFtpDirView::OnRemoteDelete()
- {
- // TODO: Add your command handler code here
- DeleteSelectItem( ) ;
- }
- void CFtpDirView::OnRemoteDownload()
- {
- // TODO: Add your command handler code here
- DownLoadSelectItem( NULL ) ;
- }
- void CFtpDirView::OnRemoteEdit()
- {
- // TODO: Add your command handler code here
- EditSelectItem( ) ;
- }
- void CFtpDirView::OnRemoteMkdir()
- {
- // TODO: Add your command handler code here
- if( !m_pFtp->IsConnect( ) )
- return ;
- CInputFileNameDlg dlg ;
- dlg.m_strName = "新建目录" ;
- if( dlg.DoModal( ) == IDOK )
- {
- m_pFtp->CreateDirectory( dlg.m_strName ) ;
- }
- }
- void CFtpDirView::OnRemoteRefresh()
- {
- // TODO: Add your command handler code here
- RefreshCurrentDirectory( ) ;
- }
- void CFtpDirView::OnSelectAll()
- {
- // TODO: Add your command handler code here
- m_ListCtrl.SelectAllItem( ) ;
- }