Storage.h
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:2k
源码类别:
P2P编程
开发平台:
Visual C++
- // StorageEx.h: interface for the CStorageEx class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_STORAGEEX_H__EB7826B8_4D91_41DF_80BB_927B7396622C__INCLUDED_)
- #define AFX_STORAGEEX_H__EB7826B8_4D91_41DF_80BB_927B7396622C__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "FileInfo.h"
- class CDownloaderFeedback;
- class CSizeEx
- {
- public :
- CSizeEx(const BLONG x, const BLONG y)
- {
- cx = x;
- cy = y;
- }
- CSizeEx()
- {
- cx = cy = 0;
- }
- BLONG cx;
- BLONG cy;
- };
- class CStorageEx
- {
- class CRange
- {
- public:
- CRange(BLONG lbeg, BLONG lend, string strFileName)
- {
- m_lbeg = lbeg;
- m_lend = lend;
- m_strFileName = strFileName;
- }
- BLONG m_lbeg;
- BLONG m_lend;
- string m_strFileName;
- };
- public:
- CStorageEx();
- virtual ~CStorageEx();
- bool Create(CDownloaderFeedback* pMain, vector<CFileInfo>& vFiles,
- HANDLE hevDone, long lMaxFilesOpen = 0, bool bLockFiles = true, bool bLockWhileReading = false);
- void Close();
- void GetUnNeededRanges(const vector<CSize>& vUnNeededFileInxs, vector<CSizeEx>& vUnNeededRanges) const;
- BLONG GetTotalLength();
- void SetReadOnly();
- bool was_preallocated(BLONG lPos, BLONG lLength);
- bool flush();
- void top_off();
- bool write(char *pBuf, BLONG lPos, BLONG lAmount);
- bool read(char *pBuf, BLONG lPos, BLONG lAmount, bool bFlushFirst = false);
- bool GetFilesRange(vector<long>& vRangeHoles, vector<long>& vFileOffset, long lPieceLen);
- private:
- bool _intervals(BLONG lPos, BLONG lAmount, vector<CRange>& v);
- FILE* _get_file_handle(string strFileName, bool bForWrite);
- FILE* _open(string strFileName, string strMode);
- void _close(string strFileName);
- void _lock_file(string strFileName, FILE* pfile);
- void _unlock_file(string strFileName, FILE* pfile);
- static time_t getfiletime(string strFileName);
- HANDLE m_hevDone;
- CDownloaderFeedback* m_pMain;
- bool m_bLockFiles;
- bool m_bLockWhileReading;
- bool m_bMaxFilesOpen;
- long m_lMaxFilesOpen;
- BLONG m_lTotalLength;
- vector<string> m_vHandleBuffer;
- vector<CRange> m_vRange;
- map<string, BLONG> m_mTops;
- map<string, BLONG> m_mSizes;
- map<string, time_t> m_mTimes;
- map<string, FILE*> m_mHandles;
- map<string, bool> m_mWHandles;
- };
- class CStorage : public CStorageEx
- {
- };
- #endif // !defined(AFX_STORAGEEX_H__EB7826B8_4D91_41DF_80BB_927B7396622C__INCLUDED_)