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

📄 queuectrl.cpp

📁 一个支持FTP,SFTP的客户端程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
										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))
		{
			delete [] str;
			str = NULL;
			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))
			{
				CloseHandle(ProcessInformation.hProcess);
				Sleep(500);

				// Check if the file is still open
				while (1)
				{
					HANDLE hFileHandle = CreateFile(pQueueData->transferFile.localfile, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
					if (hFileHandle == INVALID_HANDLE_VALUE)
					{
						int error = GetLastError();
						if (error != ERROR_SHARING_VIOLATION)
							break;
					}
					else
					{
						CloseHandle(hFileHandle);
						break;
					}

					res = WaitForSingleObject((HANDLE)pQueueData->retrycount, 1000);
					if (res != WAIT_TIMEOUT)
					{
						CloseHandle((HANDLE)pQueueData->retrycount);
						DeleteFile(pQueueData->transferFile.localfile);
						delete pQueueData;
						return 0;
					}
				}
				CFileStatus64 statusnew;
				if (GetStatus64(pQueueData->transferFile.localfile, statusnew))
				{
					if ((statusnew.m_has_mtime && status.m_has_mtime && statusnew.m_mtime != status.m_mtime) || statusnew.m_attribute!=status.m_attribute)
					{
						CloseHandle((HANDLE)pQueueData->retrycount);
						
						if (!AfxGetApp()->m_pMainWnd->PostMessage(WM_APP, reinterpret_cast<WPARAM>(pQueueData), 0))
						{
							DeleteFile(pQueueData->transferFile.localfile);
							delete pQueueData;
						}
						
						return 0;
					}
					else
						DeleteFile(pQueueData->transferFile.localfile);
				}
				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)
				break;

			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)
						continue;

					if (iter->bTransferStarted && !iter->bTriedAutoResume && iter->transferFile.nType != 1)
						if (api.pTransferApi->IsValid()) //Make sure data.pFileZillaApi still exists
						{
							iter->bTriedAutoResume = TRUE;
							api.pTransferApi->SetAsyncRequestResult(FILEEXISTS_RESUME_ASKONFAIL, 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)
				{
					if (pMainFrame)
						pMainFrame->GetStatusPane()->ShowStatus(pStatus->status, pStatus->type);
					if (pStatus->post)
						delete pStatus;
					else
					{
						ASSERT(FALSE);
					}
				}
			}
			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_PTR 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));
		}
		
		// Also add the ILD_BLEND50 so the images come out selected 
		uiFlags |= ILD_BLEND50; 
	} 
	else 
	{ 
		// Set the text background and foreground colors to the standard window colors 
		oldTextColor = ::SetTextColor (pDIS->hDC, GetSysColor(COLOR_WINDOWTEXT)); 
		oldBkColor = ::SetBkColor (pDIS->hDC, GetSysColor(COLOR_WINDOW)); 
	} 

	// Get the image list and draw the image 
/*	ImageList_Draw (g_hImages, 
		lvi.iImage, 
		pDIS->hDC, 
		pDIS->rcItem.left, 
		pDIS->rcItem.top, 
		uiFlags); 
	// Find out how big the image we just drew was 
	ImageList_GetIconSize (g_hImages, &cxImage, &cyImage); 
*/	
	// Calculate the width of the first column after the image width. If 
	// There was no image, then cxImage will be zero. 

	int nIndex;
	BOOL bStatusLine = FALSE;
	if (pDIS->itemID < static_cast<unsigned int>(m_nActiveCount * 2))
	{
		nIndex = pDIS->itemID / 2;
		bStatusLine = pDIS->itemID % 2;
	}
	else
		nIndex = pDIS->itemID - m_nActiveCount;
	
	if (bStatusLine)
	{
		CDC *pDC=GetDC();
		HDC hDC=pDC->GetSafeHdc();
		HGDIOBJ hOldBrush=SelectObject(hDC, GetCurrentObject(pDIS->hDC, OBJ_BRUSH));
		HGDIOBJ hOldFont=SelectObject(hDC, GetCurrentObject(pDIS->hDC, OBJ_FONT));
		DrawStatusLine(hDC, pDIS->rcItem, pDIS->itemID);
		SelectObject(hDC, hOldBrush);
		SelectObject(hDC, hOldFont);
		ReleaseDC(pDC);
	}
	else
	{
		uFirstColWidth = GetColumnWidth(0) - cxImage; 
		
		// Set up the new clipping rect for the first column text and draw it 
		rcClip.left = pDIS->rcItem.left + cxImage; 
		rcClip.right = pDIS->rcItem.left + GetColumnWidth(0); 
		rcClip.top = pDIS->rcItem.top; 
		rcClip.bottom = pDIS->rcItem.bottom; 
		
		DrawItemColumn (pDIS->hDC, szBuffer, &rcClip); 
		szBuffer[0] = 0; 
		
		SetTextAlign(pDIS->hDC, TA_RIGHT);
		lvi.mask = LVIF_TEXT; 
		lvi.iSubItem++; 
		ListView_GetItem (pDIS->hwndItem, &lvi); 
		rcClip.left = rcClip.right; 
		rcClip.right = rcClip.left + GetColumnWidth(1); 
		DrawItemColumn(pDIS->hDC, szBuffer, &rcClip, 2); 
		szBuffer[0] = 0; 
		
		SetTextAlign(pDIS->hDC, TA_LEFT);
		rcClip.left = rcClip.right; 
		rcClip.right = rcClip.left + GetColumnWidth(2); 
		lvi.iSubItem++; 
		ListView_GetItem (pDIS->hwndItem, &lvi); 
		DrawItemColumn(pDIS->hDC, szBuffer, &rcClip, 1); 
		szBuffer[0] = 0; 
		
		rcClip.left = rcClip.right; 
		rcClip.right = rcClip.left + GetColumnWidth(3); 
		lvi.iSubItem++; 
		ListView_GetItem (pDIS->hwndItem, &lvi); 
		DrawItemColumn(pDIS->hDC, szBuffer, &rcClip); 
		szBuffer[0] = 0; 
		
		rcClip.left = rcClip.right; 
		rcClip.right = rcClip.left + GetColumnWidth(4); 
		lvi.iSubItem++; 
		ListView_GetItem (pDIS->hwndItem, &lvi); 
		DrawItemColumn(pDIS->hDC, szBuffer, &rcClip); 
		szBuffer[0] = 0; 
		
		rcClip.left = rcClip.right; 
		rcClip.right = rcClip.left + GetColumnWidth(5); 
		lvi.iSubItem++; 
		ListView_GetItem (pDIS->hwndItem, &lvi); 
		DrawItemColumn(pDIS->hDC, szBuffer, &rcClip); 
		szBuffer[0] = 0; 
	}

	// If we changed the colors for the selected item, undo it 
	
	// Set the text background and foreground colors 
	if (oldTextColor != -1)
		::SetTextColor (pDIS->hDC, oldTextColor);
	if (oldBkColor != -1)
		::SetBkColor (pDIS->hDC, oldBkColor);
	
	// If the item is focused, now draw a focus rect around the entire row 
	if (pDIS->itemState & ODS_FOCUS && GetFocus() == this) 
	{ 
		// Adjust the left edge to exclude the image 
		rcClip = pDIS->rcItem; 
		rcClip.left += cxImage; 
		
		// Draw the focus rect 
		DrawFocusRect (pDIS->hDC, &rcClip); 
	} 
}

BOOL WINAPI CalcStringEllipsi

⌨️ 快捷键说明

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