- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
FileSource.cpp
资源名称:anywhere.zip [点击查看]
上传用户:zhenhuadz
上传日期:2007-01-07
资源大小:1511k
文件大小:14k
源码类别:
远程控制编程
开发平台:
Visual C++
- // FileSource.cpp : implementation file
- //
- #include "stdafx.h"
- #include "anywhere.h"
- #include "FileSource.h"
- #include "anywheredoc.h"
- #include "common.h"//可考虑不要
- #include "thread1.h"//线程
- #include "searchdlg.h"
- //#include "shadowwnd.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CFileSource
- IMPLEMENT_DYNCREATE(CFileSource, CFormView)
- CFileSource::CFileSource()
- : CFormView(CFileSource::IDD)
- {
- //{{AFX_DATA_INIT(CFileSource)
- //}}AFX_DATA_INIT
- bDrv=FALSE;
- remotedir="";
- }
- CFileSource::~CFileSource()
- {
- }
- void CFileSource::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CFileSource)
- DDX_Control(pDX, IDC_REMOTEDIR, m_cRemotedir);
- DDX_Control(pDX, IDC_REFRESH, m_refresh);
- DDX_Control(pDX, IDC_SEARCH, m_btsearch);
- DDX_Control(pDX, IDC_UPLOAD, m_btupload);
- DDX_Control(pDX, IDC_RUN, m_btrun);
- DDX_Control(pDX, IDC_DOWN, m_btdown);
- DDX_Control(pDX, IDC_DELETE, m_btdel);
- DDX_Control(pDX, IDC_REMOTE, m_remote);
- DDX_Control(pDX, IDC_LOCAL, m_local);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CFileSource, CFormView)
- //{{AFX_MSG_MAP(CFileSource)
- ON_WM_SIZE()
- ON_WM_CREATE()
- ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
- ON_NOTIFY(NM_DBLCLK, IDC_REMOTE, OnDblclkRemote)
- ON_BN_CLICKED(IDC_SEARCH, OnSearch)
- ON_BN_CLICKED(IDC_DOWN, OnDown)
- ON_MESSAGE(WM_SETACTIVE,OnSetActive)
- ON_NOTIFY(NM_DBLCLK, IDC_LOCAL, OnDblclkLocal)
- ON_BN_CLICKED(IDC_UPLOAD, OnUpload)
- ON_BN_CLICKED(IDC_RUN, OnRun)
- ON_BN_CLICKED(IDC_DELETE, OnDelete)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFileSource diagnostics
- #ifdef _DEBUG
- void CFileSource::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CFileSource::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CFileSource message handlers
- void CFileSource::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
- m_ImageList.Create(IDB_LIST_DIR,16,1,RGB(0,255,0));
- m_remote.SetImageList(&m_ImageList,LVSIL_SMALL);
- CRect rect;
- GetClientRect(&rect);
- m_remote.InsertColumn(0, "名字", LVCFMT_LEFT,rect.Width()/4);
- m_remote.InsertColumn(1, "大小", LVCFMT_LEFT, rect.Width()/6);
- m_local.Initialize();//DisplayTree(NULL,TRUE);
- //EnableButton();
- }
- void CFileSource::OnSize(UINT nType, int cx, int cy)
- {
- CFormView::OnSize(nType, cx, cy);
- //int rate=4/5;
- CFormView::ShowScrollBar(SB_VERT,FALSE);
- CFormView::ShowScrollBar(SB_HORZ,FALSE);
- if (GetSafeHwnd())
- {
- if (m_local.GetSafeHwnd())
- {
- CRect rect(0,0,cx/2,cy*7/8);
- m_local.MoveWindow(&rect);
- }
- if (m_remote.GetSafeHwnd())
- {
- CRect rect2(cx/2,cy/15,cx,cy*7/8);
- m_remote.MoveWindow(&rect2);
- }
- if (m_cRemotedir.GetSafeHwnd())
- {
- m_cRemotedir.MoveWindow(cx/2,0,cx,cy/15,TRUE);
- }
- if (m_btupload.GetSafeHwnd())
- {
- //CRect rc1(cx/20,cy*8/9,cx/5,cy*17/18);
- //m_btupload.MoveWindow(&rc1,TRUE);
- m_btupload.MoveWindow(cx/54,cy*9/10,cx/9,cy/13,TRUE);
- }
- if (m_btdown.GetSafeHwnd())
- {
- //CRect rc2(cx/4+cx/40,cy*8/9,cx/3,cy*17/18);
- //m_btdown.MoveWindow(&rc2,TRUE);
- m_btdown.MoveWindow(cx*8/54,cy*9/10,cx/9,cy/13,TRUE);
- }
- if (m_btrun.GetSafeHwnd())
- {
- m_btrun.MoveWindow(cx*15/54,cy*9/10,cx/9,cy/13,TRUE);
- }
- if (m_btdel.GetSafeHwnd())
- {
- m_btdel.MoveWindow(cx*22/54,cy*9/10,cx/9,cy/13,TRUE);
- }
- if (m_btsearch.GetSafeHwnd())
- {
- m_btsearch.MoveWindow(cx*29/54,cy*9/10,cx/9,cy/13,TRUE);
- }
- if (m_refresh.GetSafeHwnd())
- {
- m_refresh.MoveWindow(cx*36/54,cy*9/10,cx/9,cy/13,TRUE);
- }
- }
- }
- void CFileSource::AddFile(CObList &filelist)
- {
- CAnywhereDoc *pDoc=(CAnywhereDoc *)GetDocument();
- POSITION filelist_pos;
- if (!filelist.IsEmpty()) {
- filelist_pos=filelist.GetHeadPosition();
- }
- else return;
- POSITION pos;
- int num=0;
- while ((pos=filelist_pos)!=NULL)
- {
- filelist.GetNext(pos);
- if (pos) {
- //pDoc->filetype *pfile=(pDoc->filetype *)
- //CString file=(char *)filelist.GetAt(pos);
- filetype * pfile=(filetype*)filelist.GetAt(pos);
- CString file=pfile->filename;
- CString length=pfile->filelength;
- if (file.Right(1)=="*") {
- file=file.Left(file.GetLength()-1);
- m_remote.InsertItem(num,file,1);
- }
- else
- m_remote.InsertItem(num,file,3);
- m_remote.SetItemText(num,1,length);
- }
- num++;
- filelist_pos=pos;
- //else {
- //msglist_pos=Msglist.GetTailPosition();
- // return TRUE;//没找到
- //}
- }
- }
- void CFileSource::message(CString text)
- {
- CString order=text.Left(8);
- text=text.Right(text.GetLength()-8);
- if (order=="LISTFILE") {
- CAnywhereDoc *pDoc=(CAnywhereDoc *)GetDocument();
- m_remote.DeleteAllItems();
- AddDrv();
- BOOL bFinished=FALSE;
- int pos,pos1;
- CString text1;
- int num=0;
- while (!bFinished) {
- if ((pos=text.Find("/"))!=-1)
- {
- text1=text.Left(pos);//为名字+长度(目录无长度)
- if (text1.Right(1)=="*")
- {
- m_remote.InsertItem(num,text1.Left(text1.GetLength()-1),1);//名字为目录
- m_remote.SetItemData(num,1);//为目录
- }
- else {
- pos1=text1.Find("?");
- m_remote.InsertItem(num,text1.Left(pos1),3);//插入名字
- text1=text1.Right(text1.GetLength()-pos1-1);//长度
- m_remote.SetItemText(num,1,text1);
- m_remote.SetItemData(num,0);//为文件
- }
- text=text.Right(text.GetLength()-pos-1);
- }
- else bFinished=true;
- num++;
- }
- m_cRemotedir.SetWindowText(remotedir);
- }//end if
- }
- int CFileSource::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFormView::OnCreate(lpCreateStruct) == -1)
- return -1;
- return 0;
- }
- void CFileSource::OnRefresh()
- {
- if (!linkrc.bConnected) return;
- DWORD ThreadId;
- if (remotedir.IsEmpty()) return;
- CString filename="LISTFILE"+remotedir;
- strcpy(linkrc.sbuf,filename);
- linkrc.m_hWnd=m_hMainWnd;
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- }
- void CFileSource::OnDblclkRemote(NMHDR* pNMHDR, LRESULT* pResult)
- {
- DWORD ThreadId;
- int i =m_remote.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
- int dir=(int)m_remote.GetItemData(i);
- if (dir==0) return;
- else if (dir==1) {
- CString tmp=m_remote.GetItemText(i,0);
- if (tmp.Right(2)=="..") {
- char * str=remotedir.GetBuffer(remotedir.GetLength());
- for (int j=strlen(str)-1;j>=0;j--)
- {
- if (str[j]=='\') {str[j]=0;break;}
- }
- remotedir.ReleaseBuffer();
- if (remotedir.Right(1)==":") remotedir+="\";
- }
- else if (remotedir.Right(1)=="\") remotedir+=tmp;
- else remotedir=remotedir+"\"+tmp;
- }
- else if (dir==2) {
- remotedir=m_remote.GetItemText(i,0);}
- //if (remotedir.Right(2)=="..")
- // remotedir=olddir;
- CString filename="LISTFILE"+remotedir;
- strcpy(linkrc.sbuf,filename);
- linkrc.m_hWnd=m_hMainWnd;
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- *pResult = 0;
- }
- void CFileSource::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
- {
- if (!bDrv) AddDrv();
- //EnableButton();
- CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
- }
- void CFileSource::OnSearch()
- {
- if (!linkrc.bConnected) return;
- CSearchDlg sehdlg;
- sehdlg.DoModal();
- /*if (IDOK==sehdlg.DoModal())
- {
- DWORD ThreadId;
- CString filename="FINDFILE"+sehdlg.filename;
- strcpy(linkrc.sbuf,filename);
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- }
- */
- }
- void CFileSource::AddDrv()
- {
- CAnywhereDoc *pDoc=(CAnywhereDoc *)GetDocument();
- CString tmpdrv=pDoc->m_sys[8];
- if (tmpdrv.IsEmpty()) return;
- int num=0;
- while (!tmpdrv.IsEmpty())
- {
- CString tmp=tmpdrv.Left(3);
- tmpdrv=tmpdrv.Right(tmpdrv.GetLength()-3);
- m_remote.InsertItem(num,tmp);
- m_remote.SetItemData(num,2);//为驱动器
- num++;
- }
- bDrv=TRUE;
- }
- void CFileSource::OnDown()
- {
- if (!linkrc.bConnected) return;
- CString filename=m_local.GetFullPath(m_local.GetSelectedItem());
- int i=m_remote.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
- int j;
- if ((i==-1) || (filename.IsEmpty())) {
- CString sErrmsg,caption;
- sErrmsg.LoadString(IDS_WRONG_ACTION);
- caption.LoadString(IDS_CAPTION);
- MessageBox(sErrmsg,caption,MB_OK);
- return ;
- }//错误的操作
- if ((j=m_remote.GetItemData(i))!=0) return;//选定下载的那个文件
- CString ask,caption;
- ask.LoadString(IDS_DOWN_ASK);
- caption.LoadString(IDS_CAPTION);
- ask=ask+m_remote.GetItemText(i,0);
- if (IDYES==MessageBox(ask,caption,MB_YESNO)) {
- if (remotedir.Right(1)!="\") remotedir+="\";
- filename=filename+m_remote.GetItemText(i,0);//存到本地机的路径
- CString remote_file="GETFILE*"+remotedir+m_remote.GetItemText(i,0);
- DWORD ThreadId;
- strcpy(linkrc.sbuf,remote_file);
- strcpy(linkrc.rbuf,filename);
- linkrc.m_hWnd=GetSafeHwnd();
- hSend=CreateThread(NULL,0,GetFileThread,&linkrc,0,&ThreadId);
- m_btdown.EnableWindow(FALSE);}
- }
- LRESULT CFileSource::OnSetActive(WPARAM wParam,LPARAM lParam)
- {
- if (!(BOOL)wParam) {
- /*CString sErrmsg,caption;
- sErrmsg.LoadString(IDS_GETFILE_FAILED);
- caption.LoadString(IDS_CAPTION);
- MessageBox(sErrmsg,caption,MB_OK);
- return 0;*/
- m_btdown.EnableWindow(TRUE);
- m_btupload.EnableWindow(TRUE);
- return 0;
- }//getfile失败
- CString text=*(CString *)lParam;
- CString order=text.Left(8);
- text=text.Right(text.GetLength()-8);
- m_btdown.EnableWindow(TRUE);
- m_btupload.EnableWindow(TRUE);
- if (order=="GETFILE*")
- {
- CString sSucmsg,caption;
- sSucmsg.LoadString(IDS_GETFILE_OK);
- sSucmsg+=text;
- caption.LoadString(IDS_CAPTION);
- MessageBox(sSucmsg,caption,MB_OK);
- return 1;
- }//成功
- if (order=="PUTFILE*")
- {
- CString sSucmsg,caption;
- sSucmsg.LoadString(IDS_PUTFILE_OK);
- sSucmsg+=text;
- caption.LoadString(IDS_CAPTION);
- MessageBox(sSucmsg,caption,MB_OK);
- return 1;
- }
- if (order=="RUNFILE*")
- {
- CString sSucmsg,caption;
- sSucmsg.LoadString(IDS_RUN_OK);
- caption.LoadString(IDS_CAPTION);
- sSucmsg+=text;
- MessageBox(sSucmsg,caption,MB_OK);
- return 1;
- }
- if (order=="DELFILE*")
- {
- CString sSucmsg,caption;
- sSucmsg.LoadString(IDS_DEL_OK);
- caption.LoadString(IDS_CAPTION);
- sSucmsg+=text;
- MessageBox(sSucmsg,caption,MB_OK);
- return 1;
- }
- return 1;
- }
- void CFileSource::OnDblclkLocal(NMHDR* pNMHDR, LRESULT* pResult)
- {
- HTREEITEM hti=m_local.GetSelectedItem();
- CString filename=m_local.GetFullPath(hti);
- if (GetFileAttributes(filename)==FILE_ATTRIBUTE_DIRECTORY)
- return ;
- else
- ShellExecute(GetSafeHwnd(),NULL,filename,NULL,NULL,SW_SHOWNORMAL);
- *pResult = 0;
- }
- void CFileSource::OnUpload()
- {
- if (!linkrc.bConnected) return;
- CString filepath=m_local.GetFullPath(m_local.GetSelectedItem());
- //本地文件
- CString filename=m_local.GetItemText(m_local.GetSelectedItem());
- //欲存为的远端文件名
- //int i=m_remote.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
- if ((remotedir.IsEmpty()) || (filename.IsEmpty())) {
- CString sErrmsg,caption;
- sErrmsg.LoadString(IDS_WRONG_ACTION);
- caption.LoadString(IDS_CAPTION);
- MessageBox(sErrmsg,caption,MB_OK);
- return ;
- }//错误的操作
- //if return;//如果当前目录为空返回
- CString ask,caption;
- ask.LoadString(IDS_UPLOAD_ASK);
- caption.LoadString(IDS_CAPTION);
- ask=ask+filepath;
- if (IDYES==MessageBox(ask,caption,MB_YESNO)) {
- if (remotedir.Right(1)!="\") remotedir+="\";
- //filename=remotedir+filename;
- CString remote_file="PUTFILE*"+remotedir+filename;
- DWORD ThreadId;
- strcpy(linkrc.sbuf,remote_file);
- strcpy(linkrc.rbuf,filepath);
- linkrc.m_hWnd=GetSafeHwnd();
- hSend=CreateThread(NULL,0,PutFileThread,&linkrc,0,&ThreadId);
- m_btupload.EnableWindow(FALSE);}
- //int j;
- //if ((j=m_remote.GetItemData(i))!=1) return;
- }
- void CFileSource::OnRun()
- {
- if (!linkrc.bConnected) return;
- int i=m_remote.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
- if (i==-1) return;
- int j=m_remote.GetItemData(i);
- if (j!=0) return;
- CString sAskmsg;
- sAskmsg.LoadString(IDS_RUN_ASK);
- if (remotedir.Right(1)!="\") remotedir+="\";
- CString filename=remotedir+m_remote.GetItemText(i,0);
- sAskmsg=sAskmsg+filename;
- CString caption;
- caption.LoadString(IDS_CAPTION);
- if (IDYES==MessageBox(sAskmsg,caption,MB_YESNO))
- {
- DWORD ThreadId;
- filename="RUNFILE*"+filename;
- strcpy(linkrc.sbuf,filename);
- strcpy(linkrc.rbuf,filename);
- linkrc.m_hWnd=GetSafeHwnd();
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- }
- }
- void CFileSource::OnDelete()
- {
- if (!linkrc.bConnected) return;
- int i=m_remote.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
- if (i==-1) return;
- int j=m_remote.GetItemData(i);
- if (j!=0) return;
- CString sAskmsg;
- sAskmsg.LoadString(IDS_DEL_ASK);
- if (remotedir.Right(1)!="\") remotedir+="\";
- CString filename=remotedir+m_remote.GetItemText(i,0);
- sAskmsg=sAskmsg+filename;
- CString caption;
- caption.LoadString(IDS_CAPTION);
- if (IDYES==MessageBox(sAskmsg,caption,MB_YESNO))
- {
- DWORD ThreadId;
- filename="DELFILE*"+filename;
- strcpy(linkrc.sbuf,filename);
- strcpy(linkrc.rbuf,filename);
- linkrc.m_hWnd=GetSafeHwnd();
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- }
- }
- void CFileSource::EnableButton()
- {
- if (!linkrc.bConnected) {
- m_btdel.EnableWindow(FALSE);
- m_btrun.EnableWindow(FALSE);
- m_btsearch.EnableWindow(FALSE);
- m_btupload.EnableWindow(FALSE);
- m_btdown.EnableWindow(FALSE);
- m_refresh.EnableWindow(FALSE);
- }
- else {
- m_btdel.EnableWindow(TRUE);
- m_btrun.EnableWindow(TRUE);
- m_btsearch.EnableWindow(TRUE);
- m_btupload.EnableWindow(TRUE);
- m_btdown.EnableWindow(TRUE);
- m_refresh.EnableWindow(TRUE);
- }
- }