www.pudn.com > NetPaw.rar > DownloadFile.h
#pragma once
#include "httpsocket.h"
#include "atltypes.h"
#include "timer.h"
#include "netpawdoc.h"
class CMainFrame;
class CNetPawView;
// each CDownloadFile object represents a downloading file,
// with several socket connections in it
class CDownloadFile : public CFile
{
public:
CDownloadFile( DLFILEITEM_S *pstDlFileIt );
virtual ~CDownloadFile(void);
protected:
// because multi-threads will write the file,
// it's important to set operation lock
CCriticalSection m_csFileAccess;
// file length and received bytes,
// should protected by file LOCK
CCriticalSection m_csDataAccess;
volatile LONGLONG m_nFileLength;
volatile LONGLONG m_nBytesReceived;
volatile LONGLONG m_dwRecvBytesOld;
volatile long m_nStoppedSockets;
// all client socket are managed in a list, need protect
list m_lstSocket;
BOOL m_bStopDownld;
BOOL m_bRestart;
CString m_sFileName;
CMediaTimer m_obTimer;
double m_dUsedTime;
public:
HWND m_hFrameWnd;
CHttpSocket* m_pSnifferSock;
CString m_sDownloadUrl;
CString m_sReferer;
CString m_sWebInfo;
long m_nConnections;
protected:
void MassConnect();
void AssignTask(void);
BOOL ReAssignTask(CHttpSocket* pSocket);
int GetLeftSegments( list& lstUndone );
SEGMENT_S* GetMinOffset(list& lstUndone);
LONGLONG GetMaxBound(list& lstUndone);
public:
LONGLONG GetFileLength()
{
return m_nFileLength;
}
CString GetFileName()
{
return m_sFileName;
}
void CloseFile(void)
{
// lock the file and close
CSingleLock sl(&m_csFileAccess);
sl.Lock();
if( m_hFile != CFile::hFileNull )
{
CFile::Close();
}
}
// write received data
void Write(char *pBuffer, DWORD dwBytes, LONGLONG nOffset);
// socket notifying methods
void NotifyConnected(CHttpSocket *pSocket);
void NotifyFileLen(LONGLONG nFileLen);
void NotifyRcvData(CHttpSocket *pSocket, char *pBuffer, DWORD dwBytesRcvd);
void NotifyFinished(CHttpSocket* pSocket);
void Stop(void);
void CloseSockets(void);
void Destroy(void);
void AddSocket(void);
void DeleteSocket(CHttpSocket *pSocket);
void CloseSocket(CHttpSocket* pSocket);
void GetPerfData(PERFITEM_S* pstPerfIT);
CHttpSocket* GetSlowSocket(void);
void DrawDownldFile(CDC* pDC, CRect& rectDC, CNetPawView *pView);
BOOL IsStopDownld(void);
BOOL IsStopped(void);
BOOL IsFinished(void);
SOCKET GetSnifferSock(void);
void DelSniffSocket(void);
void Start(HWND hMainWnd = NULL);
void Restart(HWND hMainWnd);
void NewSocket(SEGMENT_S *pstSeg);
BOOL ParseFileName();
void SaveDlFileData(CFile *pFile);
void NotifyStatus(int nCode, LPVOID pParam = NULL);
};