//Download by http://www.NewXing.com // HttpDownload.h: interface for the HttpDownload class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_HTTPDOWNLOAD_H__F5CAC8FE_99D6_482E_966B_487D4E515329__INCLUDED_) #define AFX_HTTPDOWNLOAD_H__F5CAC8FE_99D6_482E_966B_487D4E515329__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include ///////////////////////////////////////////////////// ////////////////////////////////////////////////////// ///MY CODES STARTS HERE/////////////////////////////// ////////////////////////////////////////////////////// //#include //#include #ifndef MultiThreadDataClassH #define MultiThreadDataClassH #endif typedef struct FromToImpl{ DWORD from; DWORD to; }m_fromTo; typedef struct InforImpl{ CString server; CString object; CString savePath; //文件保存路径 DWORD fileSize; //文件大小 int threadCnt; //线程数 DWORD downloadSize;//已经下载文件大小 FromToImpl *fromToImpl; }m_inforImpl; typedef struct NewTask{ CString server; CString object; UINT port; UINT threadCnt; CString savepath; }NewTask; UINT threadFun(LPVOID lparam);//函数声明 #define DEFAULT_HTTP_PORT 80 #define PER_GETLEN 1024 // HTTP STATUS CODE分类 // const UINT HTTP_OK = 0; // const UINT HTTP_ERROR = 1; // const UINT HTTP_REDIRECT = 2; // const UINT HTTP_FAIL = 3; // 发送请求 const UINT SENDREQUEST_SUCCESS = 0; // 成功 const UINT SENDREQUEST_ERROR = 1; // 一般网络错误,可以重试 const UINT SENDREQUEST_STOP = 2; // 中途停止(用户中断) (不用重试) const UINT SENDREQUEST_FAIL = 3; // 失败 (不用重试) class HttpDownload { public: //bool realDownload(DWORD pos ,DWORD len,int index,CSocket sock); HttpDownload(); virtual ~HttpDownload(); void Initial(int n); void FreeMemory(); //释放内存 void SetStop(bool m_bstop);//通过参数stop确定是否停止 void CreateThread(); BOOL StartHttpTask(NewTask task); UINT SendRequest(BOOL bHead = false); bool Download(int index); CTime GetTime(LPCTSTR lpszTime); UINT GetInfo(LPCTSTR lpszHeader, DWORD &dwContentLength, DWORD &dwStatusCode, CTime &TimeLastModified); CString GetLine(char* lpData, int& ndx); int GetHeadLength(char* lpData); BOOL ParseURL(CString str); bool GetInfofromTemp(CString filename); void GetInfofromDevision(); void CreateInforImpl(CString str); bool CreateNewFile(CString fileName, DWORD size); bool WriteInfoToFile(); bool WriteToFile(CString filePath,DWORD pos ,char *buffer , int len); //CTypedPtrList m_lsTask; //DOWNLOADSTATE m_state; //BOOL m_bTerminate[4]; CSocket m_pSocket;//套结字 CString m_strServer;//服务器地址 CString m_strObject;//远端路径 CString m_strSavePath;//文件本地保存地址 CString m_strTempSavePath;//临时文件保存地址 CString m_strHead;//。。。 CString m_strReferer; //产生请求的初始资源 CString m_strDownloadUrl;//重定向后的下载路径!!!!! CTime m_TimeLastModified;//上次修改时间 BOOL m_bSupportResume; //是否支持断点续传 BOOL m_bResume; //是否曾经下过 BOOL m_bFileLocked; //临时文件是否被占用 BOOL m_bIsUseFile; BOOL m_bStop; BOOL m_bAddSize; UINT m_nPort;//端口号 FILE *globalFile; //CCriticalSection m_cs; DWORD m_dwDownloadSize;//已经下载文件的大小 DWORD m_dwFileSize;//要下载的文件的大小 int m_dwThreadCnt;//线程数 LONG m_index; int runningThreadCnt;//正在运行的线程数 FromToImpl *fromToImpl; InforImpl inforImpl; //waston int nComplete; NewTask TaskInfo; //waston ///////////////////////////////////////////////////// //MY CODES ENDS HERE///////////////////////////////// ///////////////////////////////////////////////////// }; #endif // !defined(AFX_HTTPDOWNLOAD_H__F5CAC8FE_99D6_482E_966B_487D4E515329__INCLUDED_)