亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? downloadthread.cpp

?? FTP客戶端
?? CPP
字號:
/****************************************************************/
/*																*/
/*  DownloadThread.cpp											*/
/*																*/
/*  Implementation of the CDownloadThread class.				*/
/*	This class downloads a file from a FTP server in a seperate	*/
/*  thread. It sends a notification when finished/aborted.		*/
/*																*/
/*  Programmed by Pablo van der Meer							*/
/*  Copyright Pablo Software Solutions 2002						*/
/*	http://www.pablovandermeer.nl								*/
/*																*/
/*  Last updated: 15 may 2002									*/
/*																*/
/****************************************************************/


#include "stdafx.h"
#include "DownloadThread.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

IMPLEMENT_DYNCREATE(CDownloadThread, CWinThread)

CDownloadThread::CDownloadThread()
{
	m_bAutoDelete = FALSE;
	m_dwFileLength = 0;
	m_bTransferFailed = FALSE;
	m_bDirectoryCreated  = FALSE;

	m_nConnectionTimeout = 3000;
	m_pFtpConnection = NULL;
	m_nRetries = 1;
	m_nRetryDelay = 10;
	m_nPort = 21;
	m_bUsePASVMode = FALSE;
	
    // kill event starts out in the signaled state
    m_hEventKill = CreateEvent(NULL, TRUE, FALSE, NULL);
    m_hEventDead = CreateEvent(NULL, TRUE, FALSE, NULL);

	// default to binary transfer
	m_dwTransferType = FTP_TRANSFER_TYPE_BINARY;
}


CDownloadThread::~CDownloadThread()
{
	CloseHandle(m_hEventKill);
	CloseHandle(m_hEventDead);
}


/********************************************************************/
/*																	*/
/* Function name : InitInstance										*/
/* Description   : Initialize this instance of the thread.			*/
/*				   In this case it's actually the place where		*/
/*				   everything takes place.							*/
/*																	*/
/********************************************************************/
BOOL CDownloadThread::InitInstance()
{
	if (WaitForSingleObject(m_hEventKill, 0) != WAIT_TIMEOUT)
	{
		// aborted by user
		m_strResult = "\"" + m_strRemoteName + "\" download cancelled.";

		// Let the main thread know we are finished
		::PostMessage(m_pTransferManager->m_hWnd, WM_DOWNLOAD_FINISHED, (WPARAM)this, 0);

		// event is signaled
		return FALSE;
	}
	
	PostDownloadStatus("Initializing");

	// set animation to 'Downloading'
	m_ProgressDlg.m_nAnimationID = IDR_AVI1;
	
	// create dummy window as parent for the progress dialog
	if (!m_wndDummy.CreateEx(0, AfxRegisterWndClass(0), "CDownload Dummy Window",
			WS_OVERLAPPED, 0, 0, 0, 0, NULL, NULL))
		return FALSE;

	// Create the progress dialog box.
	if (!m_ProgressDlg.Create(&m_wndDummy, m_hEventKill))
		return FALSE;
	
	// wait until dialog is created
	WaitForProgressDialog();

	// when reducing the timeout connection, the internet connection speed is faster.
	if (m_nConnectionTimeout) 
	{
		m_InternetSession.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, m_nConnectionTimeout);
		m_InternetSession.SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, m_nConnectionTimeout);
		m_InternetSession.SetOption(INTERNET_OPTION_SEND_TIMEOUT, m_nConnectionTimeout);
	}

	// catch all exceptions
	try	
	{	
		// start receiving file 
		DownloadFile(m_strRemoteName, m_strLocalName);
	}
	catch(char *pszError)
	{ 		
		m_strResult = pszError; 		
	}
	catch (CFileException * pEx)
	{ 	
		// file can't be opened
		m_strResult.Format("File Error %d %s", pEx->m_cause, pEx->m_strFileName); 		
	}
	catch (CInternetException* pEx)
	{
		// internet exception
		m_strResult.Format("Internet Exception Error %d", pEx->m_dwError);
		if (pEx->m_dwError == ERROR_INTERNET_EXTENDED_ERROR)
		{
			char szBuffer[1024];
			DWORD dwBufferLength = 1024;
			DWORD dwError = 0;
			::InternetGetLastResponseInfo(&dwError, szBuffer, &dwBufferLength);
			m_strResult += szBuffer;
		}
	}
	// fix error message
	m_strResult.Replace('\n', ' ');
	m_strResult.Remove('\r');

	if (!m_strResult.IsEmpty())
	{
		// exception was thrown
		m_bTransferFailed = TRUE;
	}
	else
	if (WaitForSingleObject(m_hEventKill, 0) != WAIT_TIMEOUT)
	{
		// aborted by user
		m_strResult = "\"" + m_strRemoteName + "\" download cancelled.";
	}
	else 
	{
		if (m_bDirectoryCreated)
		{
			// successfull created folder
			m_strResult = "\"" + m_strLocalName + "\" folder successfully created.";
		}
		else
		{
			// successfull downloaded file
			m_strResult = "\"" + m_strRemoteName + "\" successfully downloaded.";
		}
	}

	// Let the main thread know we are done
	::PostMessage(m_pTransferManager->m_hWnd, WM_DOWNLOAD_FINISHED, (WPARAM)this, 0);

	// avoid entering standard message loop by returning FALSE
    return FALSE;
}


/********************************************************************/
/*																	*/
/* Function name : ExitInstance										*/
/* Description   : Perform any per-thread cleanup here.				*/
/*																	*/
/********************************************************************/
int CDownloadThread::ExitInstance()
{
	if (m_pFtpConnection)
	{
		m_pFtpConnection->Close();

		// delete ftp connection
		delete m_pFtpConnection;
		m_pFtpConnection = NULL;
	}

	// Close this session
	m_InternetSession.Close();

    m_ProgressDlg.DestroyWindow();

	m_wndDummy.DestroyWindow();
	
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CDownloadThread, CWinThread)
	//{{AFX_MSG_MAP(CDownloadThread)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/********************************************************************/
/*																	*/
/* Function name : KillThread										*/
/* Description   : With this public member you can kill this thread	*/
/*				   for the outside.									*/
/*																	*/
/********************************************************************/
void CDownloadThread::KillThread()
{
    // reset the m_hEventKill which signals the thread to shutdown
    VERIFY(SetEvent(m_hEventKill));

	DWORD dwResult;
	// make sure it is running
	while (dwResult = ResumeThread() > 1)
	{
		if (dwResult == 0xFFFFFFFF)
			break;
	}

    // allow thread to run at higher priority during kill process
    SetThreadPriority(THREAD_PRIORITY_ABOVE_NORMAL);
    WaitForSingleObject(m_hEventDead, INFINITE);
    WaitForSingleObject(m_hThread, INFINITE);

    // now delete CWinThread object since it's no longer necessary
    delete this;
}


/********************************************************************/
/*																	*/
/* Function name : Delete											*/
/* Description   : Called when thread is destructed.				*/
/*																	*/
/********************************************************************/
void CDownloadThread::Delete()
{
    // calling the base here won't do anything but it is a good habit
	CWinThread::Delete();

	// acknowledge receipt of kill notification
	VERIFY(SetEvent(m_hEventDead));
}


/********************************************************************/
/*																	*/
/* Function name : DownloadFile										*/
/* Description   : This is where the real downloading takes place.	*/
/*																	*/
/********************************************************************/
void CDownloadThread::DownloadFile(CString &source, CString &dest)
{
	m_ProgressDlg.SetWindowTitle("Receiving " + source);
	m_ProgressDlg.SetPos(0);
	m_ProgressDlg.SetSecondStatus("");

	// only a directory name was specified
	if (dest.Right(1) == "\\")
	{
		// try to create directory structure
		CreateLocalDirectory(dest);

		m_bDirectoryCreated = TRUE;
		return;
	}

	PostDownloadStatus("Connecting");

	// try x times to connect
	int nRetries = m_nRetries;
	while (nRetries > 0)
	{
		nRetries--;
		try
		{
			// Create new ftp connection to retrieve file
			wsprintf(m_szStatus, "Connecting to %s (Attempt %d of %d)", m_strServerName, m_nRetries - nRetries, m_nRetries); 
			m_ProgressDlg.SetStatus(m_szStatus);

			DoEvents();
			
			// Connect to FTP Server
			m_pFtpConnection = m_InternetSession.GetFtpConnection(m_strServerName, m_strUserName, m_strPassword, m_nPort, m_bUsePASVMode);
			nRetries = 0;
		}
		catch (CInternetException* pEx)
		{
			m_pFtpConnection = NULL;

			// catch errors from WinINet
			pEx->GetErrorMessage(m_szStatus, sizeof(m_szStatus));
			pEx->Delete();

			if (nRetries > 0)
			{
				wsprintf(m_szStatus, "Failed to connect to %s (Attempt %d of %d)", m_strServerName, m_nRetries - nRetries, m_nRetries); 
				m_ProgressDlg.SetStatus(m_szStatus);
				
				wsprintf(m_szStatus, "Retrying after %d seconds...", m_nRetryDelay); 
				m_ProgressDlg.SetSecondStatus(m_szStatus);

				// wait for m_nRetryDelay seconds, while m_hEventKill is not signaled
				if (WaitWithMessageLoop(m_hEventKill, m_nRetryDelay * 1000) == TRUE)
				{
					// user canceled download
					throw m_szStatus; 
				}
				PostDownloadStatus("Retrying");
				m_ProgressDlg.SetSecondStatus("");
			}
			else
			{
				throw m_szStatus; 
			}
		}
	}

	// split folder and file (if complete path is given)
	int nPos = source.ReverseFind('/');
	if (nPos != -1)
	{
		m_strCurrentDirectory = source.Left(nPos+1);
		source = source.Mid(nPos+1);
	}

	// set current directory
	if (!m_pFtpConnection->SetCurrentDirectory(m_strCurrentDirectory))
	{
		DWORD dwLength = 255, dwError;
		CString strInfo;
		InternetGetLastResponseInfo(&dwError, strInfo.GetBuffer(dwLength), &dwLength);
		strInfo.ReleaseBuffer();
		strInfo.Remove('\n');
		strInfo.Remove('\r');

		wsprintf(m_szStatus, "%s", strInfo);
		throw m_szStatus; 
	}


	lstrcpy(m_szStatus, source); 
	// Show source file name
	m_ProgressDlg.SetStatus(m_szStatus);
	// Show destination file name
	m_ProgressDlg.SetSecondStatus("to: " + dest);

	// open destination file
	if (m_File.Open(dest, CFile::modeCreate | CFile::modeWrite, NULL) == FALSE)
	{
		wsprintf(m_szStatus, "Unable to create file %s", dest); 
		throw m_szStatus; 
	}
	
	wsprintf(m_szStatus, "Opening %s", source); 
	m_ProgressDlg.SetStatus(m_szStatus);

	CInternetFile* pInternetFile = m_pFtpConnection->OpenFile(source, GENERIC_READ, m_dwTransferType);
	if (!pInternetFile)
	{
		wsprintf(m_szStatus, "Unable to open remote file %s", source); 
		throw m_szStatus; 
	}
	
	PostDownloadStatus("Downloading");

	// set max to 100%
	m_ProgressDlg.SetUpper(100);

	char buffer[BUF_SIZE];
	unsigned int nRead = BUF_SIZE;
	unsigned int nTotalRead = 0;
	while (nRead == BUF_SIZE && (WaitForSingleObject(m_hEventKill, 0) == WAIT_TIMEOUT))
	{
		// read remote data into buffer
		nRead = pInternetFile->Read(buffer, BUF_SIZE);
		// write buffer to data file
		m_File.Write(buffer, nRead);
		nTotalRead += nRead;
		wsprintf(m_szStatus, "%s (%d of %d  bytes transferred)", source, nTotalRead, m_dwFileLength); 	
		m_ProgressDlg.SetStatus(m_szStatus);

		if (m_dwFileLength > 0)
		{
			int nPos = (nTotalRead*100)/m_dwFileLength;
			m_ProgressDlg.SetPos(nPos);
		}
		else
		{
			m_ProgressDlg.SetPos(0);
		}
	}

	// close the file
	m_File.Close();

	// close internet file
	pInternetFile->Close();

	delete pInternetFile;
	
	// close FTP connection
	wsprintf(m_szStatus, "Closing connection to %s", m_strServerName); 
	m_ProgressDlg.SetStatus(m_szStatus);

	PostDownloadStatus("Finished");
}


/********************************************************************/
/*																	*/
/* Function name : GetLastError										*/
/* Description   : Get last error string.							*/
/*																	*/
/********************************************************************/
CString CDownloadThread::GetLastError()
{
	return m_strResult;
}


/********************************************************************/
/*																	*/
/* Function name : CreateLocalDirectory								*/
/* Description   : Create directory tree.							*/
/*																	*/
/********************************************************************/
BOOL CDownloadThread::CreateLocalDirectory(LPCTSTR lpszDirectory)
{
	CString strResult = lpszDirectory;
	
	CString strDir;
	BOOL bResult;
	// create directory structure one part at a time
	while (strResult != "")
	{
		strDir += strResult.Left(strResult.Find("\\")+1);
		strResult = strResult.Mid(strResult.Find("\\")+1);
		bResult = CreateDirectory(strDir, 0);
	}
	return bResult;
}


/********************************************************************/
/*																	*/
/* Function name : WaitForProgressDialog							*/
/* Description   : If the thread has just started, it may not have	*/
/*				   had time yet to initialize the dialog window.	*/
/*																	*/
/********************************************************************/
void CDownloadThread::WaitForProgressDialog()
{
	if(m_ProgressDlg.m_hWnd == NULL)
	{
		while(m_ProgressDlg.m_hWnd == NULL)
		{
			DoEvents();
		}
	}
	if(!::IsWindow(m_ProgressDlg.m_hWnd))
	{
		while(!::IsWindow(m_ProgressDlg.m_hWnd))
		{
			DoEvents();
		}
	}
}


/********************************************************************/
/*																	*/
/* Function name : PostDownloadStatus								*/
/* Description   : Post status to Transfer Manager.					*/
/*																	*/
/********************************************************************/
void CDownloadThread::PostDownloadStatus(LPCTSTR lpszStatus)
{
	int nLength = lstrlen(lpszStatus);
	// dynamically allocate memory for status message (receiver will delete it!)
	LPSTR lpszData = new char[nLength+1];
	lstrcpy(lpszData, lpszStatus);
	::PostMessage(m_pTransferManager->m_hWnd, WM_FTP_STATUS, (WPARAM)this, (LPARAM)lpszData);
}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产品国语在线不卡| 岛国精品一区二区| 欧美日韩国产综合久久| 夜夜揉揉日日人人青青一国产精品| 成人午夜av电影| 1000部国产精品成人观看| 91天堂素人约啪| 午夜免费久久看| 日韩一区二区三区四区| 久久 天天综合| 亚洲国产精品传媒在线观看| 91蝌蚪国产九色| 夜夜精品视频一区二区 | 91精品国产综合久久蜜臀| 午夜精品成人在线| 欧美www视频| 菠萝蜜视频在线观看一区| 又紧又大又爽精品一区二区| 91精品欧美一区二区三区综合在 | 亚洲一区二区三区四区中文字幕| 欧美日韩一区二区三区高清| 色婷婷狠狠综合| 亚洲成人免费看| 久久久久亚洲综合| 一本色道久久综合亚洲91| 青青草原综合久久大伊人精品| 国产日韩精品一区二区三区 | 欧美一级淫片007| 国产一区二区在线电影| 亚洲黄色录像片| 久久精品人人做人人爽97| 日本久久精品电影| 激情偷乱视频一区二区三区| 国产精品久久久久影院| 91精品国产综合久久精品图片| 国产99精品国产| 日韩精品成人一区二区三区| 国产精品网站在线| 日韩一区二区视频| 色偷偷一区二区三区| 精品亚洲国内自在自线福利| 一区二区三区四区精品在线视频| 欧美va亚洲va在线观看蝴蝶网| 91蝌蚪porny九色| 国产成人啪免费观看软件| 五月天精品一区二区三区| 中文一区在线播放| 日韩视频免费观看高清完整版| 色妞www精品视频| 国产精品一区二区三区乱码 | 亚洲精品中文字幕乱码三区| 久久亚洲影视婷婷| 欧美日韩国产精品自在自线| av一区二区三区| 国产一区二区三区久久悠悠色av| 午夜精品一区二区三区电影天堂| 亚洲人xxxx| 中文字幕一区日韩精品欧美| 国产亚洲精品超碰| 欧美一二三四在线| 欧美日韩亚洲综合一区二区三区| 91在线小视频| 久久久99久久| 日韩免费在线观看| 欧美精品少妇一区二区三区 | 欧美日韩高清一区二区三区| 色综合天天综合色综合av| 国产乱子伦视频一区二区三区 | 午夜欧美一区二区三区在线播放 | 一区二区三区鲁丝不卡| 欧美激情一二三区| 国产偷国产偷亚洲高清人白洁| 日韩免费视频一区二区| 91精品国产综合久久精品图片| 欧美日韩一区精品| 在线精品视频免费播放| 一本色道久久综合亚洲aⅴ蜜桃 | 精品噜噜噜噜久久久久久久久试看| 欧美日韩久久久| 欧美日韩综合在线| 欧美美女网站色| 欧美高清视频一二三区 | 91蜜桃传媒精品久久久一区二区| 国产成人精品一区二区三区网站观看| 国产主播一区二区三区| 国产又黄又大久久| 国产精品香蕉一区二区三区| 成人动漫av在线| 91色乱码一区二区三区| 91日韩精品一区| 欧美日韩视频在线第一区 | 精品一区二区国语对白| 国产一区二区三区蝌蚪| 成人aa视频在线观看| 日本高清免费不卡视频| 欧美日韩电影在线播放| 午夜精品一区在线观看| 日韩福利视频网| 韩国女主播一区二区三区| 国产精品18久久久久久vr| 成人一级片网址| 91久久免费观看| 欧美一区二区三区精品| 久久亚洲综合av| 亚洲日穴在线视频| 亚洲va韩国va欧美va| 精品亚洲porn| 波多野结衣视频一区| 在线视频国内自拍亚洲视频| 欧美一级二级三级乱码| 国产精品天干天干在观线| 1024亚洲合集| 美国十次了思思久久精品导航| 国产91精品一区二区麻豆亚洲| 99国产精品国产精品毛片| 欧美美女网站色| 国产三级三级三级精品8ⅰ区| 国产精品国产三级国产普通话三级 | 亚洲最大成人网4388xx| 日韩不卡一区二区三区| 国产不卡高清在线观看视频| 欧美日韩一区三区| 欧美精彩视频一区二区三区| 亚洲一区二区在线免费观看视频| 蜜桃91丨九色丨蝌蚪91桃色| bt7086福利一区国产| 欧美一卡2卡3卡4卡| 日韩美女精品在线| 日本成人在线网站| av在线免费不卡| 欧美电视剧在线观看完整版| 亚洲图片欧美激情| 精品一区免费av| 欧美日韩色一区| 国产精品国产自产拍高清av| 久久精品国产精品亚洲精品| 91同城在线观看| 中文字幕久久午夜不卡| 日韩1区2区日韩1区2区| 91久久国产综合久久| 久久精品日韩一区二区三区| 免播放器亚洲一区| 欧美色视频在线| 国产精品看片你懂得| 国产一区美女在线| 日韩欧美一区中文| 亚洲v精品v日韩v欧美v专区 | 色哟哟一区二区三区| 中文子幕无线码一区tr| 国内久久精品视频| 欧美一区二区三区视频免费播放| 亚洲精品久久嫩草网站秘色| 岛国一区二区在线观看| 久久色在线视频| 九九**精品视频免费播放| 欧美一区二区三区四区五区 | 亚洲一区二区中文在线| 99久久国产综合精品女不卡| 久久精品视频一区二区| 精品一区二区av| 久久综合狠狠综合久久激情| 免费在线观看日韩欧美| 91麻豆精品国产综合久久久久久 | 欧美亚洲综合另类| 最新国产の精品合集bt伙计| 国产盗摄视频一区二区三区| 久久精品欧美一区二区三区不卡| 麻豆精品一区二区三区| 欧美一级夜夜爽| 蜜臀a∨国产成人精品| 91麻豆精品国产91久久久久久久久| 五月婷婷综合激情| 欧美嫩在线观看| 美女国产一区二区三区| 日韩你懂的电影在线观看| 激情六月婷婷久久| 久久久久久久性| 国产成人精品午夜视频免费| 中文字幕欧美日韩一区| 99re8在线精品视频免费播放| 日韩毛片视频在线看| 欧洲精品在线观看| 午夜精品久久久久久久久久久| 欧美日韩五月天| 精品一二三四区| 中文av字幕一区| 在线日韩一区二区| 日韩精品亚洲专区| 精品日韩一区二区三区| 国产福利一区在线观看| 国产精品久久久久影院老司| 欧美在线你懂的| 人人超碰91尤物精品国产| 久久网站最新地址| 成人动漫av在线| 日韩高清一区二区| 国产精品三级电影| 欧美三级电影在线看| 国产美女主播视频一区| 一区二区中文字幕在线|