📄 queuectrl.cpp
字号:
{
ASSERT(lpParameter);
CQueueData *pQueueData = reinterpret_cast<CQueueData *>(lpParameter);
CString file = pQueueData->transferFile.localfile;
CFileStatus64 status;
if (!GetStatus64(pQueueData->transferFile.localfile, status))
{
CloseHandle((HANDLE)pQueueData->retrycount);
delete pQueueData;
}
LPTSTR str;
if (pQueueData->nOpen==1)
{
/* CString cmdLine;
if (file.Find( _T(" ") )!=-1)
file=_T("\"") + file + _T("\"");
PROCESS_INFORMATION ProcessInformation;
STARTUPINFO startupinfo={0};
startupinfo.cb=sizeof(startupinfo);
str=new TCHAR[file.GetLength()+1];
_tcscpy(str, file);
if (CreateProcess(0, str, 0, 0, 0, 0, 0, 0, &startupinfo, &ProcessInformation))
{
CloseHandle(ProcessInformation.hThread);
HANDLE handles[2];
handles[0]=(HANDLE)reinterpret_cast<CQueueData *>(pTransferFile->lpParam)->retrycount;
handles[1]=ProcessInformation.hProcess;
int res=WaitForMultipleObjects(2, handles, FALSE, INFINITE);
if (res==(WAIT_OBJECT_0+1) || res==(WAIT_ABANDONED_0+1))
{
CFileStatus64 statusnew;
if (GetStatus64(pTransferFile->localfile, statusnew))
{
if (statusnew.m_mtime!=status.m_mtime || statusnew.m_size!=status.m_size || statusnew.m_attribute!=status.m_attribute)
{
delete [] str;
CloseHandle((HANDLE)reinterpret_cast<CQueueData *>(pTransferFile->lpParam)->retrycount);
if (!AfxGetMainWnd()->PostMessage(WM_APP + 10, reinterpret_cast<WPARAM>(pTransferFile), 0))
{
delete reinterpret_cast<CQueueData*>(pTransferFile->lpParam);
delete pTransferFile;
DeleteFile(pTransferFile->localfile);
}
return 0;
}
else
DeleteFile(pTransferFile->localfile);
}
else
DeleteFile(pTransferFile->localfile);
}
}
else
{
CString str;
str.Format(IDS_ERRORMSG_VIEWEDIT_CANTOPENFILE, pTransferFile->localfile);
AfxMessageBox(str, MB_ICONEXCLAMATION, 0);
DeleteFile(pTransferFile->localfile);
}*/
}
else if (pQueueData->nOpen == 2)
{
int pos=file.ReverseFind('.');
if (pos!=-1)
{
CString fext=file.Mid(pos+1);
fext.MakeLower();
//Parse the file associations
CString CustomAssociations = COptions::GetOption(OPTION_VIEWEDITCUSTOM);
CString ext;
CString prog;
BOOL bDoExt=TRUE;
while (CustomAssociations!="")
{
int pos=CustomAssociations.Find( _T(";") );
if (bDoExt)
{
if (!pos || pos==-1 || pos==CustomAssociations.GetLength()-1)
break;
ext+=CustomAssociations.Left(pos);
CustomAssociations=CustomAssociations.Mid(pos+1);
if (CustomAssociations.Left(1)== _T(" "))
{
ext+=_T(";");
CustomAssociations=CustomAssociations.Mid(1);
}
else
bDoExt=FALSE;
}
else
{
if (!pos || pos==CustomAssociations.GetLength()-1)
break;
if (pos!=-1)
{
prog += CustomAssociations.Left(pos);
CustomAssociations=CustomAssociations.Mid(pos+1);
}
else
{
prog = CustomAssociations;
CustomAssociations="";
}
if (CustomAssociations.Left(1)== _T(" "))
{
prog+=_T(";");
CustomAssociations=CustomAssociations.Mid(1);
if (CustomAssociations!="")
continue;
}
ext.MakeLower();
if (fext==ext)
{ //We've found a file aassociation for this extension
CString cmdLine;
if (file.Find( _T(" ") )!=-1)
file=_T("\"") + file + _T("\"");
cmdLine=prog + _T(" ") + file;
PROCESS_INFORMATION ProcessInformation;
STARTUPINFO startupinfo={0};
startupinfo.cb=sizeof(startupinfo);
LPTSTR str=new TCHAR[cmdLine.GetLength()+1];
_tcscpy(str, cmdLine);
if (CreateProcess(0, str, 0, 0, 0, 0, 0, 0, &startupinfo, &ProcessInformation))
{
CloseHandle(ProcessInformation.hThread);
HANDLE handles[2];
handles[0] = (HANDLE)pQueueData->retrycount;
handles[1] = ProcessInformation.hProcess;
int res = WaitForMultipleObjects(2, handles, FALSE, INFINITE);
if (res==(WAIT_OBJECT_0+1) || res==(WAIT_ABANDONED_0+1))
{
CFileStatus64 statusnew;
if (GetStatus64(pQueueData->transferFile.localfile, statusnew))
{
if (statusnew.m_mtime!=status.m_mtime || statusnew.m_size!=status.m_size || statusnew.m_attribute!=status.m_attribute)
{
delete [] str;
CloseHandle((HANDLE)pQueueData->retrycount);
if (!AfxGetMainWnd()->PostMessage(WM_APP + 10, (WPARAM)pQueueData, 0))
{
DeleteFile(pQueueData->transferFile.localfile);
delete pQueueData;
}
CloseHandle(ProcessInformation.hProcess);
return 0;
}
else
DeleteFile(pQueueData->transferFile.localfile);
}
else
DeleteFile(pQueueData->transferFile.localfile);
}
CloseHandle(ProcessInformation.hProcess);
}
else
{
CString str;
str.Format(IDS_ERRORMSG_VIEWEDIT_CANTSTARTPROGRAM, prog, pQueueData->transferFile.localfile);
AfxMessageBox(str, MB_ICONEXCLAMATION, 0);
DeleteFile(pQueueData->transferFile.localfile);
}
delete [] str;
CloseHandle((HANDLE)pQueueData->retrycount);
delete pQueueData;
return 0;
}
ext="";
prog="";
bDoExt=TRUE;
}
}
}
//File has no extension or custom file association could not be found
CString defprog=COptions::GetOption(OPTION_VIEWEDITDEFAULT);
if (defprog=="")
{
AfxMessageBox(IDS_ERRORMSG_VIEWEDIT_NODEFPROG, MB_ICONEXCLAMATION);
CloseHandle((HANDLE)pQueueData->retrycount);
delete pQueueData;
return 0;
}
CString cmdLine;
if (file.Find( _T(" ") )!=-1)
file=_T("\"") + file + _T("\"");
cmdLine=defprog + _T(" ") + file;
PROCESS_INFORMATION ProcessInformation;
STARTUPINFO startupinfo={0};
startupinfo.cb=sizeof(startupinfo);
str=new TCHAR[cmdLine.GetLength()+1];
_tcscpy(str, cmdLine);
if (CreateProcess(0, str, 0, 0, 0, 0, 0, 0, &startupinfo, &ProcessInformation))
{
CloseHandle(ProcessInformation.hThread);
HANDLE handles[2];
handles[0] = (HANDLE)pQueueData->retrycount;
handles[1] = ProcessInformation.hProcess;
int res=WaitForMultipleObjects(2, handles, FALSE, INFINITE);
if (res==(WAIT_OBJECT_0+1) || res==(WAIT_ABANDONED_0+1))
{
CFileStatus64 statusnew;
if (GetStatus64(pQueueData->transferFile.localfile, statusnew))
{
if (statusnew.m_mtime!=status.m_mtime || statusnew.m_size!=status.m_size || statusnew.m_attribute!=status.m_attribute)
{
delete [] str;
CloseHandle((HANDLE)pQueueData->retrycount);
if (!AfxGetMainWnd()->PostMessage(WM_APP, reinterpret_cast<WPARAM>(pQueueData), 0))
{
DeleteFile(pQueueData->transferFile.localfile);
delete pQueueData;
}
CloseHandle(ProcessInformation.hProcess);
return 0;
}
else
DeleteFile(pQueueData->transferFile.localfile);
}
else
DeleteFile(pQueueData->transferFile.localfile);
}
CloseHandle(ProcessInformation.hProcess);
}
else
{
CString str;
str.Format(IDS_ERRORMSG_VIEWEDIT_CANTSTARTPROGRAM, defprog, pQueueData->transferFile.localfile);
AfxMessageBox(str, MB_ICONEXCLAMATION, 0);
DeleteFile(pQueueData->transferFile.localfile);
}
}
CloseHandle((HANDLE)pQueueData->retrycount);
delete pQueueData;
delete [] str;
return 0;
}
LRESULT CQueueCtrl::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
if (message>=(WM_APP + 10) && message<(WM_APP + 10 + m_TransferApiArray.size()))
{
ASSERT(Validate());
int nApiIndex = message - WM_APP - 10;
t_TransferApi api = m_TransferApiArray[nApiIndex];
switch(FZ_MSG_ID(wParam))
{
case FZ_MSG_SOCKETSTATUS:
switch(FZ_MSG_PARAM(wParam))
{
case FZ_SOCKETSTATUS_RECV:
pMainFrame->m_RecvLed.Ping(100);
break;
case FZ_SOCKETSTATUS_SEND:
pMainFrame->m_SendLed.Ping(100);
break;
}
break;
case FZ_MSG_LISTDATA:
{
t_directory *pDir=(t_directory *)lParam;
if (pDir)
{
CServerPath path=((CFtpListCtrl *)pMainFrame->GetFtpPane()->GetListCtrl())->GetCurrentDirectory();
if (path==pDir->path)
{
pMainFrame->GetFtpPane()->List(pDir);
pMainFrame->GetFtpTreePane()->List(pDir);
}
else
delete pDir;
}
}
break;
case FZ_MSG_REPLY:
//Find api which has sent this message
if (api.bActive && !m_bQuit)
ProcessReply(lParam, nApiIndex);
break;
case FZ_MSG_SECURESERVER:
//if (m_pSecureIconCtrl)
// m_pSecureIconCtrl->ShowWindow(FZ_MSG_PARAM(wParam)?SW_SHOW:SW_HIDE);
break;
case FZ_MSG_ASYNCREQUEST:
if (!m_bQuit)
{
if (FZ_MSG_PARAM(wParam) == FZ_ASYNCREQUEST_OVERWRITE)
{
COverwriteRequestData *pData=(COverwriteRequestData *)lParam;
for (t_QueueVector::iterator iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
{
if (!iter->bActive)
break;
if (iter->pTransferApi == api.pTransferApi)
{
if (iter->bTransferStarted && iter->transferFile.nType != 1)
if (api.pTransferApi->IsValid()) //Make sure data.pFileZillaApi still exists
{
api.pTransferApi->SetAsyncRequestResult(FILEEXISTS_RESUME, pData);
return TRUE;
}
break;
}
}
}
CAsyncRequestQueue::ProcessRequest(reinterpret_cast<CAsyncRequestData *>(lParam), api.pTransferApi, TRUE);
break;
}
case FZ_MSG_STATUS:
{
t_ffam_statusmessage *pStatus=(t_ffam_statusmessage *)lParam;
if (pStatus)
{
pMainFrame->GetStatusPane()->ShowStatus(pStatus->status, pStatus->type);
if (pStatus->post)
delete pStatus;
else
ASSERT(FALSE);
break;
}
}
break;
case FZ_MSG_TRANSFERSTATUS:
{
t_ffam_transferstatus *pStatus=(t_ffam_transferstatus *)lParam;
if (api.bActive && !m_bQuit)
{
if (!SetProgress(api.pTransferApi, pStatus))
delete pStatus;
}
else
delete pStatus;
}
break;
case FZ_MSG_QUITCOMPLETE:
if (m_bQuit)
{
m_nQuitCount--;
if (!m_nQuitCount)
VERIFY(AfxGetMainWnd()->PostMessage(WM_CLOSE));
}
break;
}
return TRUE;
}
return CListCtrl::DefWindowProc(message, wParam, lParam);
}
void CQueueCtrl::OnTimer(UINT nIDEvent)
{
if (nIDEvent==m_nTimerID)
{
for (UINT i=0; i<m_TransferApiArray.size(); i++)
{
t_TransferApi api=m_TransferApiArray[i];
if (!api.bActive && api.pLastActiveTime)
{
CTimeSpan span = CTime::GetCurrentTime() - *api.pLastActiveTime;
if (span.GetTotalSeconds()>30)
{
api.pTransferApi->Disconnect();
delete api.pLastActiveTime;
api.pLastActiveTime=0;
m_TransferApiArray[i]=api;
}
}
}
int nApiIndex=-1;
int res;
do
{
res = TransferNextFile(nApiIndex);
if (res==-1)
ProcessReply(FZ_REPLY_ERROR, nApiIndex);
else if (res==-2)
ProcessReply(FZ_REPLY_ERROR|FZ_REPLY_CRITICALERROR, nApiIndex);
} while (res==1);
return;
}
CListCtrl::OnTimer(nIDEvent);
}
void WINAPI DrawItemColumn (HDC hdc, LPCTSTR szText, LPRECT prcClip, int nAlign = 0, BOOL bDontMeasure = FALSE);
///////////////////////////////////////////////////////////////////////////////
// DrawListViewItem()
//
// Parameters
//
// Purpose
//
// Return Value
//
void CQueueCtrl::DrawItem (LPDRAWITEMSTRUCT pDIS)
{
TCHAR szBuffer[512];
LV_ITEM lvi;
int cxImage = 0, cyImage = 0;
UINT uFirstColWidth;
RECT rcClip;
int iColumn = 1;
UINT uiFlags = ILD_TRANSPARENT;
// Get the item image to be displayed
lvi.mask = LVIF_IMAGE | LVIF_STATE | LVIF_TEXT;
lvi.iItem = pDIS->itemID;
lvi.iSubItem = 0;
lvi.pszText = szBuffer;
lvi.cchTextMax = 512;
ListView_GetItem (pDIS->hwndItem, &lvi);
int oldTextColor = -1;
int oldBkColor = -1;
// Check to see if this item is selected
if (pDIS->itemState & ODS_SELECTED)
{
// Set the text background and foreground colors
if (GetFocus() == this)
{
oldTextColor = ::SetTextColor(pDIS->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
oldBkColor = ::SetBkColor(pDIS->hDC, GetSysColor(COLOR_HIGHLIGHT));
}
else
{
oldTextColor = ::SetTextColor(pDIS->hDC, GetSysColor(COLOR_WINDOWTEXT));
oldBkColor = ::SetBkColor(pDIS->hDC, GetSysColor(COLOR_INACTIVEBORDER));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -