00001
00002
00003
00004
00005
00006 #if !defined(AFX_VMSBTDOWNLOADMANAGER_H__8322A330_304D_470C_BCD6_15403F57E210__INCLUDED_)
00007 #define AFX_VMSBTDOWNLOADMANAGER_H__8322A330_304D_470C_BCD6_15403F57E210__INCLUDED_
00008
00009 #if _MSC_VER > 1000
00010 #pragma once
00011 #endif
00012
00013 #include "Bittorrent\fdmbtsupp\vmsBtDownload.h"
00014 #include "fsTicksMgr.h"
00015 #include "vmsDownloadMgrEx.h"
00016
00017 #define BTDF_LAUNCH_WHEN_DONE 1
00018 #define BTDF_LAUNCH_WHEN_DONE_NO_CONFIRM (1 << 1)
00019 #define BTDF_GENERATE_DESC_FILE (1 << 2)
00020 #define BTDF_RESERVE_DISK_SPACE (1 << 3)
00021 #define BTDF_IGNORE_ALL_RESTRICTIONS (1 << 4)
00022 #define BTDF_DISABLE_SEEDING (1 << 5)
00023
00024 enum vmsBtDownloadManagerEvent
00025 {
00026 BTDME_CHECKING_FILES,
00027 BTDME_ALLOCATING,
00028 BTDME_DOWNLOAD_STARTED,
00029 BTDME_DOWNLOADING,
00030 BTDME_DOWNLOAD_STOPPED_OR_DONE,
00031 BTDME_ALLOCATION_FAILED,
00032 BTDME_SEEDING,
00033 };
00034
00035 typedef DWORD (*fntBtDownloadManagerEventHandler)(class vmsBtDownloadManager*, vmsBtDownloadManagerEvent, DWORD, LPVOID);
00036
00037 enum vmsBtDownloadStateEx
00038 {
00039 BTDSE_QUEUED = BTDS_QUEUED,
00040 BTDSE_CHECKING_FILES = BTDS_CHECKING_FILES,
00041 BTDSE_CONNECTING_TRACKER = BTDS_CONNECTING_TRACKER,
00042 BTDSE_DOWNLOADING = BTDS_DOWNLOADING,
00043 BTDSE_FINISHED = BTDS_FINISHED,
00044 BTDSE_SEEDING = BTDS_SEEDING,
00045 BTDSE_ALLOCATING = BTDS_ALLOCATING,
00046 BTDSE_STOPPED,
00047 };
00048
00049 class vmsBtDownloadManager
00050 {
00051 public:
00052 fsString get_RootFolderName();
00053 UINT64 get_SplittedByteCountAtBeginningOfFile();
00054 void GetSectionsInfo (std::vector <vmsSectionInfo> &v);
00055 int get_CurrentTaskProgress();
00056 std::wstring get_FileNameW(int nIndex);
00057 void StopSeeding();
00058 void EnableSeeding(BOOL bEnable);
00059 BOOL IsStoppedByUser();
00060 BOOL LoadState(LPBYTE lpBuffer, LPDWORD pdwSize, WORD wVer);
00061 BOOL SaveState(LPBYTE pb, LPDWORD pdwSize);
00062 int get_ConnectionCount();
00063 void UseDetailedLog(BOOL bUse);
00064 UINT GetTrafficLimit();
00065 void LimitTraffic(UINT uLimit);
00066 void StopDownloading();
00067 fsInternetResult StartDownloading();
00068 BOOL DeleteFile();
00069 fsInternetResult SetToRestartState();
00070 fsInternetResult RestartDownloading();
00071 BOOL IsBtDownloadRunning();
00072 BOOL IsCantStart();
00073 BOOL MoveToFolder(LPCSTR pszPath);
00074 UINT GetSpeed();
00075 int GetDownloadingSectionCount();
00076 void GetSectionInfo(int nIndex, vmsSectionInfo *sect);
00077 BOOL IsDownloading();
00078 UINT64 GetDownloadedBytesCount();
00079 UINT64 GetTotalFilesSize();
00080 int GetNumberOfSections();
00081 BOOL IsRunning();
00082 BOOL IsDone();
00083 float GetPercentDone();
00084 fsString get_OutputFilePathName();
00085 vmsBtDownload* get_BtDownload();
00086 int get_NextAnnounceInterval();
00087 vmsBtDownloadPeerInfoList* get_PeerInfoList();
00088 void get_PeersStat (int *pnPeersConnected, int *pnSeedsTotal, int *pnLeechersTotal, int *pnSeedsConnected);
00089 UINT64 get_WastedByteCount();
00090 double get_ShareRating();
00091 UINT64 get_TotalUploadedByteCount();
00092 fsString m_strTrackerStatus;
00093 fsString get_CurrentTracker();
00094 int get_PieceSize();
00095 int get_PieceCount();
00096 int get_FilePercentDone(int nIndex);
00097 UINT64 get_FileSize(int nIndex);
00098 fsString get_FileName(int nIndex);
00099 fsString get_TorrentComment();
00100 void set_TrackerLogin(LPCSTR pszUser, LPCSTR pszPassword);
00101 void disable_Flags(DWORD dw);
00102 void enable_Flags(DWORD dw);
00103 DWORD get_Flags();
00104 fsString get_URL();
00105 void get_TrackerLogin (fsString &strUser, fsString &strPassword);
00106 LPCSTR get_TorrentUrl();
00107 fsString get_InfoHash();
00108 void SetEventsHandler (fntBtDownloadManagerEventHandler pfn, LPVOID pData);
00109 LPCSTR get_OutputPath();
00110 fsString get_OutputFilePathName (int nIndex);
00111 int get_FileCount();
00112 UINT GetUploadSpeed();
00113 fsString get_TorrentName();
00114 vmsBtDownloadStateEx get_State();
00115 BOOL CreateByTorrentFile (LPCSTR pszTorrentFile, LPCSTR pszOutputPath, LPCSTR pszTorrentUrl);
00116 void DeleteBtDownload();
00117
00118 vmsBtDownloadManager();
00119 virtual ~vmsBtDownloadManager();
00120
00121 protected:
00122 void SaveBtDownloadState_Pieces();
00123 LONG m_nUsingBtDownload;
00124 static DWORD WINAPI _threadCheckStartSeeding (LPVOID lp);
00125 void RemoveBtDownloadDirectory();
00126 void RecursiveRemoveDirectory (LPCWSTR pwszPath);
00127 BOOL IsDownloadStatCanBeRead ();
00128 void PostCreateTorrentObject();
00129 DWORD RaiseEvent(vmsBtDownloadManagerEvent ev, DWORD dw = 0);
00130 void SaveBtDownloadState_FileProgress();
00131 void SaveBtDownloadState();
00132 void StopThread();
00133 static DWORD WINAPI _threadBtDownloadManager(LPVOID lp);
00134 BOOL m_bStoppedByUser;
00135 bool m_bThreadRunning, m_bThreadDoJob, m_bThreadNeedStop;
00136 void ProcessFilePathMacroses(CString &str);
00137 BOOL CreateBtDownload();
00138
00139 vmsBtFile* m_pTorrent;
00140 vmsBtDownload *m_pDownload;
00141
00142 fntBtDownloadManagerEventHandler m_pfnEvHandler;
00143 LPVOID m_lpEvParam;
00144
00145 UINT m_uLowSpeedMaxTime;
00146 UINT m_uTrafficLimit;
00147
00148 struct _inc_BtDownloadInfo
00149 {
00150 float *pfProgress;
00151 fsTicksMgr timeLastDataStatAccess;
00152 LPBYTE pbFastResumeData; DWORD dwFastResumeDataSize;
00153 fsString strOutputPath;
00154 fsString strTrackerUser, strTrackerPassword;
00155 fsString strTorrentUrl;
00156 DWORD dwFlags;
00157 fsString strCurrentTracker;
00158 UINT64 nUploadedBytes;
00159 double fShareRating;
00160 UINT64 nWastedBytes;
00161 float fPercentDone;
00162 BOOL bDone;
00163 std::vector <bool> vPieces;
00164 UINT64 nDownloadedBytes;
00165 };
00166 _inc_BtDownloadInfo m_info;
00167 };
00168
00169 #endif