00001
00002
00003
00004
00005
00006 #if !defined(AFX_FSDOWNLOADSMGR_H__49230334_5704_46DF_95BA_2F7535E427DE__INCLUDED_)
00007 #define AFX_FSDOWNLOADSMGR_H__49230334_5704_46DF_95BA_2F7535E427DE__INCLUDED_
00008
00009 #if _MSC_VER > 1000
00010 #pragma once
00011 #endif
00012
00013 #include "list.h"
00014 #include "array.h"
00015 #include "fsDownloadMgr.h"
00016 #include "vmsObject.h"
00017 #include "fsDownloadRegSaver.h"
00018 #include "vmsFileRecentList.h"
00019
00020 #ifndef FDM_DLDR__RAWCODEONLY
00021 #endif
00022
00023 #ifndef FDM_DLDR__RAWCODEONLY
00024 #include "fsIECatchMgr.h"
00025 #include "fsDownloadsHistoryMgr.h"
00026 #endif
00027 #include "fsArchiveRebuilder.h"
00028 #include "vmsStringRecentList.h"
00029 #include "fsDownload.h"
00030
00031 enum fsDownloadsMgrEvent
00032 {
00033 DME_DOWNLOAD_STATE_CHANGED,
00034 DME_DOWNLOADEREVENTRECEIVED,
00035 DME_EVENTDESCRIPRIONRECEIVED,
00036 DME_DOWNLOADWILLBEDELETED,
00037 DME_DOWNLOADWASDELETEDFROMLIST,
00038 DME_DOWNLOADFILEWILLBEDELETED,
00039 DME_NOACTIVEDOWNLOADS,
00040 DME_REDIRECTED,
00041 DME_DLDSAUTOSTARTMDFD,
00042 DME_FILEUPDATED,
00043 DME_DOWNLOADSTOPPEDORDONE,
00044 DME_SECTIONSTARTED,
00045 DME_SECTIONDOWNLOADING,
00046 DME_DLMGRTHREADSTARTING,
00047 DME_BEFOREDOWNLOADING,
00048 DME_DLDADDEDTODELETED,
00049 DME_DLDREMOVEDFROMDELETED,
00050 DME_DLDWILLBEFULLYDELETED,
00051 DME_DLDRESTORED,
00052 DME_RECADDEDTOHISTORY,
00053 DME_RECDELETEDFROMHISTORY,
00054 DME_HISTORYCLEARED,
00055 DME_CREATEDLDDIALOG,
00056 DME_CLOSEDLDDIALOG,
00057 DME_UPDATEDLDDIALOG,
00058 DME_DLDAUTODELETED,
00059 DME_BEGINDELETEMANYDOWNLOADS,
00060 DME_ENDDELETEMANYDOWNLOADS,
00061 DME_RECYCLEBINCONTENTCHANGED,
00062 DME_BTDLD_STAT_CHANGED,
00063 };
00064
00065 enum fsTUM
00066 {
00067 TUM_LIGHT = 0,
00068 TUM_MEDIUM = 1,
00069 TUM_HEAVY = 2
00070 };
00071
00072 struct fsTrafficUsageMode
00073 {
00074 UINT uMaxConns;
00075 UINT uMaxConnsPS;
00076 UINT uMaxDlds;
00077 UINT uTrafficLimit;
00078 };
00079
00080 enum fsDeleteDownloadReaction
00081 {
00082 DDR_ASK = 0,
00083 DDR_FROMLISTONLY = 1,
00084 DDR_WITHFILE = 2
00085 };
00086
00087 struct fsServerConnections
00088 {
00089 CString strName;
00090 UINT cConns;
00091 };
00092
00093 const UINT MAX_SUMMS = 24*60*(60/5);
00094
00095 enum fsConnectionType
00096 {
00097 CT_MODEM_14_4,
00098 CT_MODEM_28_8,
00099 CT_MODEM_33_6,
00100 CT_MODEM_56_ISDN,
00101 CT_DUAL_ISDN,
00102 CT_CABLE_DSL_256,
00103 CT_CABLE_DSL_300,
00104 CT_CABLE_DSL_512,
00105 CT_T1,
00106 CT_LAN_10,
00107 CT_UNKNOWN
00108 };
00109
00110 enum fsTUMManage
00111 {
00112 TM_OFF,
00113 TM_DECREASEBYONELEVEL,
00114 TM_SETTOLIGHT
00115 };
00116
00117 #define DLMGRFILE_CURRENT_VERSION (1)
00118 #define DLMGRFILE_SIG "FDM Dl Mgr SI"
00119 struct fsStateInfoFileHdr
00120 {
00121 char szSig [sizeof (DLMGRFILE_SIG) + 1];
00122 WORD wVer;
00123
00124 fsStateInfoFileHdr ()
00125 {
00126 strcpy (szSig, DLMGRFILE_SIG);
00127 wVer = DLMGRFILE_CURRENT_VERSION;
00128 }
00129 };
00130
00131 class fsDownloadsMgr
00132 {
00133 friend class CDownloaderProperties_ListPage;
00134 friend class CPrg_Data;
00135 public:
00136 BOOL AllowStartNewDownloads();
00137 vmsDownloadSmartPtr get_HighestPriorityDownload();
00138 void AddEvent (vmsDownloadSmartPtr dld, LPCSTR pszEvent, fsDownloadMgr_EventDescType enType = EDT_RESPONSE_S);
00139 void DownloadStateChanged (vmsDownloadSmartPtr dld);
00140
00141
00142 int IsSuchUrlExistsAlready(vmsDownloadSmartPtr dld);
00143
00144 void set_HighestPriorityDownload (vmsDownloadSmartPtr dld);
00145
00146 vmsDownloadSmartPtr FindDownloadByBtDownload (vmsBtDownload* pDld);
00147 vmsDownloadSmartPtr GetDownloadByBtDownloadMgr (vmsBtDownloadManager *pMgr);
00148
00149 void AttachToBtSession();
00150
00151 static void GetEventColors (fsDownloadMgr_EventDescType enType, COLORREF &clrText, COLORREF &clrBg, int &iImage);
00152
00153 BOOL DeleteGroupsDownloads (vmsDownloadsGroupSmartPtr pGroup, BOOL bInclSubgroups);
00154
00155 void ReorderDownloads (DLDS_LIST_REF vDlds, DLDS_LIST_REF vReqOrder, bool bDldsSorted = false);
00156
00157 void MoveDownloads (DLDS_LIST_REF vDlds, vmsDownloadSmartPtr pDldPosition, bool bUp);
00158
00159 void LastFilesDownloaded_Clear();
00160
00161 const vmsFileRecentList* get_LastFilesDownloaded () const;
00162
00163 UINT GetNextDownloadID();
00164
00165 BOOL GenerateDescriptionFile (vmsDownloadSmartPtr dld);
00166
00167 void ApplyAER (fsAlreadyExistReaction enAER);
00168
00169 void Shutdown();
00170
00171 void LaunchDownload (vmsDownloadSmartPtr dld, UINT nWaitForConfirmation = 0);
00172
00173 void Initialize();
00174
00175 void MoveDownloadToEndOfList (vmsDownloadSmartPtr dld);
00176 #ifndef FDM_DLDR__RAWCODEONLY
00177 fsDownloadsHistoryMgr m_histmgr;
00178 #endif
00179
00180 BOOL IsRestoringNow();
00181
00182 BOOL PerformVirusCheck (vmsDownloadSmartPtr dld, BOOL bCheckExtReqs, BOOL bWaitDone);
00183
00184 int RestoreDownloads (DLDS_LIST &vDlds);
00185
00186 int GetDeletedDownloadIndex (vmsDownloadSmartPtr dld);
00187
00188 BOOL IsDeletingDeletedNow();
00189
00190 int DeleteDeletedDownloads (DLDS_LIST &vDlds, BOOL bNoCancel = FALSE);
00191
00192 void ClearDeleted();
00193
00194 void ReadDeletedSettings();
00195
00196 vmsDownloadSmartPtr Get_DeletedDownload (int iIndex);
00197
00198 int Get_DeletedDownloadCount();
00199
00200 void Apply_MirrParameters (vmsDownloadSmartPtr dld);
00201 void ReadMirrParameters();
00202
00203 void Apply_MirrParameters();
00204
00205 void StartDownloads(DLDS_LIST &vpDlds, BOOL bByUser = FALSE);
00206
00207 void StopDownloads(DLDS_LIST &vDlds, BOOL bByUser = FALSE);
00208
00209 void ProcessDownloads();
00210
00211 static void Download_CloneSettings (vmsDownloadSmartPtr dst, vmsDownloadSmartPtr src);
00212
00213 void UseDetailedLog (BOOL b);
00214
00215 BOOL IsDeletingNow();
00216 fsTUMManage GetTUMManage();
00217 void SetTUMManage (fsTUMManage enManage);
00218 #ifndef FDM_DLDR__RAWCODEONLY
00219
00220 void AttachToIECatchMgr (fsIECatchMgr* mgr);
00221 #endif
00222
00223 int GetRunningDownloadCount();
00224
00225 void ApplyTrafficLimit();
00226
00227 void ReadSettings();
00228
00229 void ApplyConnectionType(fsConnectionType enCT);
00230
00231 void SaveSettings();
00232
00233 void UnlockList();
00234 void LockList ();
00235
00236 void RebuildServerList(BOOL bUpdateSiteList = TRUE);
00237
00238 void AllowStartNewDownloads (BOOL bAllow);
00239
00240 vmsDownloadSmartPtr GetDownloadByID (UINT nID);
00241
00242 BOOL IsRunning();
00243
00244 BOOL IsSummarySpeedWasLessThan (UINT uSpeed, UINT uTimeInterval);
00245
00246 void StopAllDownloads(BOOL bByUser);
00247 void StartAllDownloads(BOOL bByUser);
00248 fsTUM GetTUM();
00249 void SetTUM (fsTUM tum);
00250
00251 UINT GetAmountConnections ();
00252
00253 fsTrafficUsageMode* GetTUMs ();
00254
00255 void SetAutosaveInterval (UINT uInterval);
00256
00257 void StartGroup (vmsDownloadsGroupSmartPtr pGroup);
00258 void StopGroup (vmsDownloadsGroupSmartPtr pGroup);
00259
00260 int DeleteDownloads (DLDS_LIST &vDlds, BOOL bByUser, BOOL bDontConfirmFileDeleting);
00261
00262 int GetDownloadIndex (vmsDownloadSmartPtr dld, int nFindStartPos = 0);
00263
00264 BOOL Save ();
00265 BOOL LoadDownloads();
00266
00267 size_t GetCount() {return m_vDownloads.size ();};
00268
00269 vmsDownloadSmartPtr GetDownload (size_t iIndex);
00270 void SetEventsFunc (fntDownloadsMgrEventFunc pfn, LPVOID lpParam);
00271
00272 vmsDownloadSmartPtr GetDownloadByDownloadMgr(fsDownloadMgr *pMgr);
00273
00274 UINT Add (vmsDownloadSmartPtr dld, BOOL bKeepIDAsIs = FALSE, bool bPlaceToTop = false);
00275
00276 fsDownloadsMgr();
00277 virtual ~fsDownloadsMgr();
00278
00279 protected:
00280 static DWORD WINAPI _threadStartSeeding (LPVOID lp);
00281 void EventEx (vmsDownloadSmartPtr dld, LPCSTR pszEvent, fsDownloadMgr_EventDescType enType, int nMaxCharsPerLine);
00282 BOOL OnDldDone_CheckDownloadIsHtmlPageWithVideo(vmsDownloadSmartPtr dld);
00283
00284 void ApplyTrafficLimitForListOfDownloads (DLDS_LIST vDlds, UINT nLimit);
00285
00286 void ApplyTrafficLimit_HasHpDld();
00287
00288 void ApplyTrafficLimit_NoHpDld();
00289
00290 void GetRunningDownloads (DLDS_LIST &v);
00291
00292 void ResetDldHpManageState();
00293
00294 struct _inc_GrantAllBandwidthInfo {
00295 enum CurState {
00296 CS_Start,
00297 CS_Measuring_Bandwidth,
00298 CS_Measuring_DldMaxSpeed,
00299 CS_Done,
00300 } enCurState;
00301 vmsDownloadSmartPtr dld;
00302 UINT uBandwidth;
00303 UINT uDldMaxSpeed;
00304 fsTicksMgr timeStateChange;
00305 } m_gabInfo;
00306
00307 void OnDownloadDescEventRcvd (vmsDownloadSmartPtr dld, fsDownloadMgr_EventDescType enType, LPCSTR pszEvent);
00308
00309 BOOL OnDownloadStoppedOrDone (vmsDownloadSmartPtr dld);
00310
00311 static DWORD _BtDownloadManagerEventHandler (vmsBtDownloadManager* pMgr, vmsBtDownloadManagerEvent ev, DWORD dwInfo, LPVOID lp);
00312
00313 static void _BtSessionEventsHandler (class vmsBtSession*, struct vmsBtSessionEvent*, LPVOID lp);
00314
00315 static DWORD WINAPI _threadDeleteDownloadMgrEx (LPVOID lp);
00316
00317 BOOL OnDldDone_CheckDownloadIsBittorrent (vmsDownloadSmartPtr dld);
00318
00319 void DeletedDownloads_UseTmpList (BOOL bUse);
00320
00321 void DownloadsList_Insert (size_t nIndexBefore, vmsDownloadSmartPtr dld);
00322 void DownloadsList_Del (size_t nIndex);
00323 void DownloadsList_Add (vmsDownloadSmartPtr dld);
00324
00325 BOOL OnDldDone_CheckDownloadIsMetaLink (vmsDownloadSmartPtr dld);
00326
00327 long m_cThreadsRunning;
00328
00329 void OnDldDoneCheckIfNeedDel (vmsDownloadSmartPtr dld);
00330
00331 static DWORD WINAPI _threadIntegrityCheckAndVirCheckAndLaunch (LPVOID lp);
00332
00333 vmsFileRecentList m_LastFilesDownloaded;
00334
00335 BOOL SaveStateInformation();
00336 BOOL LoadStateInformation();
00337
00338 CRITICAL_SECTION m_csSave;
00339
00340 static DWORD WINAPI _threadArchiveDetected (LPVOID lp);
00341
00342 static DWORD WINAPI _threadConfirmZIP (LPVOID lp);
00343
00344 DWORD OnArchiveDetected (vmsDownloadSmartPtr dld, fsArchive::fsArchiveRebuilder* ar);
00345 #ifndef FDM_DLDR__RAWCODEONLY
00346
00347 void Event (fsDLHistoryRecord* rec, fsDownloadsMgrEvent ev);
00348
00349 static void _HistoryMgrEvents (fsDownloadsHistoryMgrEvent ev, int info, LPVOID);
00350 #endif
00351
00352 static DWORD WINAPI _threadWaitRestoringDlds (LPVOID lp);
00353 BOOL m_bRestoringNow;
00354
00355 int RestoreDownloads2(DLDS_LIST* vDlds, BOOL* pbNeedStop, int* piProgress);
00356
00357 static DWORD WINAPI _threadWaitDelDeletingsDlds (LPVOID lp);
00358
00359 int DeleteDeletedDownloads2(DLDS_LIST *vDlds, BOOL bNoCancel, BOOL* pbNeedStop, int* piProgress);
00360
00361 BOOL DeleteDownloadFile (vmsDownloadSmartPtr dld, BOOL bNoCancel, fsDeleteDownloadReaction &enDDR, BOOL bDownloadWillBeDeletedAlso);
00362
00363 vmsDownloadSmartPtr PutDownloadToDeleted (vmsDownloadSmartPtr dld);
00364
00365 DWORD OnBeforeDownload (vmsDownloadSmartPtr dld);
00366
00367 BOOL m_bMirrDontSearchIfSizeUnk;
00368 UINT m_uMirrRecalcSpeedTime;
00369 UINT m_cMaxMirrs;
00370 BOOL m_bMirrCalcSpeed;
00371 UINT m_uMirrFileMinSize;
00372 BOOL m_bMirrAutoSearch;
00373
00374 static DWORD WINAPI _threadWaitDelDlds (LPVOID lp);
00375
00376 int DeleteDownloads2 (DLDS_LIST *vDlds, BOOL bByUser, BOOL bDontConfirmFileDeleting, BOOL* pbNeedStop = NULL, int* piProgress = NULL);
00377 BOOL m_bVirCheck;
00378 fsString m_strVirName, m_strVirArgs, m_strVirExts;
00379 BOOL m_bDetLog;
00380 BOOL m_bDeletingNow, m_bDeletingDeletedNow;
00381 fsTUMManage m_enTUMManage;
00382 #ifndef FDM_DLDR__RAWCODEONLY
00383
00384 static void _IECatchMgrEvents (fsIECatchMgrEvent ev, LPVOID lp);
00385 #endif
00386
00387 BOOL IsMaxConnsReached();
00388
00389 BOOL IsServerFilled (LPCSTR pszServer, DWORD dwReqProtocols);
00390
00391 void InitTUM();
00392 fsMutex m_mxDlList;
00393 CRITICAL_SECTION m_csQSection;
00394
00395 fsMutex m_mxBuildConns;
00396 BOOL m_bAllowStart;
00397 BOOL m_bDisablePD;
00398
00399 void CheckNoActiveDownloads();
00400
00401 fs::array <UINT, MAX_SUMMS> m_vSummSpeed;
00402 UINT m_nID;
00403 BOOL m_bSkip1Cicle;
00404
00405 void ManageTraffic();
00406
00407 void OnSectionStop (vmsDownloadSmartPtr dld);
00408 void Event (vmsDownloadSmartPtr dld, LPCSTR pszEvent, fsDownloadMgr_EventDescType enType = EDT_RESPONSE_S);
00409
00410 BOOL OnQueryNewSection (vmsDownloadSmartPtr dld, UINT nUsingMirror);
00411 BOOL m_bAutoDelCompleted;
00412 fsDeleteDownloadReaction m_enDDR;
00413 fsTUM m_enTUM;
00414 fsTUM m_enUserTUM;
00415 UINT m_uAutosaveInterval;
00416 BOOL m_bNeedExit;
00417 static DWORD WINAPI _threadDownloadsMgr (LPVOID lp);
00418
00419 static DWORD WINAPI _threadDeleteDownload(LPVOID lp);
00420 fsDownloadRegSaver m_saver;
00421 DWORD Event (vmsDownloadSmartPtr dld, fsDownloadsMgrEvent ev);
00422
00423 static void _DownloadMgrEventDesc (fsDownloadMgr *pMgr, fsDownloadMgr_EventDescType enType, LPCSTR pszEvent, LPVOID lp);
00424 static DWORD _DownloadMgrEvents (fsDownloadMgr *pMgr, fsDownloaderEvent enEvent, UINT uInfo, LPVOID lp);
00425 DLDS_LIST m_vDownloads;
00426 DLDS_LIST m_vDeletedDownloads;
00427
00428 std::list <vmsDownloadSmartPtr> m_vDeletedDownloads_tmp;
00429 BOOL m_bBypassDeleted;
00430 BOOL m_bBypassCopleted;
00431 UINT m_cMaxDeleted;
00432 fntDownloadsMgrEventFunc m_pfnEvents;
00433 LPVOID m_lpEventsParam;
00434 fsTrafficUsageMode m_aTUM [3];
00435 };
00436
00437 #endif