Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.7 KiB

  1. #include <wininet.h>
  2. #include <urlmon.h>
  3. #include "timetrak.h"
  4. #include "util2.h"
  5. // Our download sink. Works with out IMyDownloadCallback class. Consider making generic
  6. // so you can pass any class that implements the OnData and OnProgress and OnStop
  7. extern CRITICAL_SECTION g_cs;
  8. #define DOWNLOADFLAGS_USEWRITECACHE 0x00000001
  9. class CInstallEngine;
  10. struct IMyDownloadCallback
  11. {
  12. // OnProgess is called to allow you to present progess indication UI
  13. virtual HRESULT OnProgress(ULONG progress, LPCSTR pszStatus) = 0;
  14. };
  15. class CDownloader
  16. : public IBindStatusCallback,
  17. public IAuthenticate,
  18. public CTimeTracker
  19. {
  20. public:
  21. CDownloader();
  22. ~CDownloader();
  23. HRESULT SetupDownload(LPCSTR pszUrl, IMyDownloadCallback *, DWORD dwFlags, LPCSTR szFilename);
  24. HRESULT DoDownload(LPSTR szPath, DWORD dwBufSize);
  25. HRESULT Abort();
  26. HRESULT Suspend();
  27. HRESULT Resume();
  28. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObjOut);
  29. STDMETHOD_(ULONG, AddRef)();
  30. STDMETHOD_(ULONG, Release)();
  31. STDMETHOD(OnStartBinding)(
  32. /* [in] */ DWORD grfBSCOption,
  33. /* [in] */ IBinding *pib);
  34. STDMETHOD(GetPriority)(
  35. /* [out] */ LONG *pnPriority);
  36. STDMETHOD(OnLowResource)(
  37. /* [in] */ DWORD reserved);
  38. STDMETHOD(OnProgress)(
  39. /* [in] */ ULONG ulProgress,
  40. /* [in] */ ULONG ulProgressMax,
  41. /* [in] */ ULONG ulStatusCode,
  42. /* [in] */ LPCWSTR szStatusText);
  43. STDMETHOD(OnStopBinding)(
  44. /* [in] */ HRESULT hresult,
  45. /* [in] */ LPCWSTR szError);
  46. STDMETHOD(GetBindInfo)(
  47. /* [out] */ DWORD *grfBINDINFOF,
  48. /* [unique][out][in] */ BINDINFO *pbindinfo);
  49. STDMETHOD(OnDataAvailable)(
  50. /* [in] */ DWORD grfBSCF,
  51. /* [in] */ DWORD dwSize,
  52. /* [in] */ FORMATETC *pformatetc,
  53. /* [in] */ STGMEDIUM *pstgmed);
  54. STDMETHOD(OnObjectAvailable)(
  55. /* [in] */ REFIID riid,
  56. /* [iid_is][in] */ IUnknown *punk);
  57. // IAuthenticate methods
  58. STDMETHOD(Authenticate)(HWND *phwnd,
  59. LPWSTR *pszUserName, LPWSTR *pszPassword);
  60. private:
  61. char _szURL[INTERNET_MAX_URL_LENGTH];
  62. char _szDest[MAX_PATH];
  63. IBinding *_pBnd;
  64. IMyDownloadCallback *_pCb;
  65. IMoniker *_pMkr;
  66. UINT _uFlags;
  67. DWORD _cRef;
  68. IStream *_pStm;
  69. BOOL _fTimeout;
  70. BOOL _fTimeoutValid;
  71. UINT _uBytesSoFar;
  72. HANDLE _hFile;
  73. HANDLE _hDL;
  74. HRESULT _hDLResult;
  75. UINT _uTickCount;
  76. IBindCtx *_pBndContext;
  77. };
  78. HRESULT GetAMoniker( LPOLESTR url, IMoniker ** ppmkr );
  79. class CInstaller : public CTimeTracker
  80. {
  81. public:
  82. CInstaller(CInstallEngine *);
  83. ~CInstaller();
  84. HRESULT DoInstall(LPCSTR pszDir, LPSTR pszCmd, LPSTR pszArgs, LPCSTR pszProg, LPCSTR pszCancel,
  85. UINT uType, LPDWORD pdwStatus, IMyDownloadCallback *);
  86. HRESULT Abort();
  87. HRESULT Suspend();
  88. HRESULT Resume();
  89. STDMETHOD_(ULONG, AddRef)();
  90. STDMETHOD_(ULONG, Release)();
  91. private:
  92. DWORD _cRef;
  93. UINT _uTotalProgress;
  94. CInstallEngine *_pInsEng;
  95. HKEY _hkProg;
  96. HANDLE _hMutex;
  97. HANDLE _hStatus;
  98. void _WaitAndPumpProgress(HANDLE hProc, IMyDownloadCallback *pcb);
  99. };
  100. class CPatchDownloader : public CTimeTracker
  101. {
  102. public:
  103. CPatchDownloader(BOOL fEnable);
  104. ~CPatchDownloader();
  105. HRESULT SetupDownload(DWORD dwFullTotalSize, UINT uPatchCount, IMyDownloadCallback *pcb, LPCSTR pszDLDir);
  106. HRESULT DoDownload(LPCSTR szFile);
  107. BOOL IsEnabled() { return _fEnable; }
  108. DWORD GetFullDownloadSize() { return _dwFullTotalSize; }
  109. UINT GetDownloadCount() { return _uNumDownloads; }
  110. LPSTR GetPath() { return _szPath; }
  111. IMyDownloadCallback *GetCallback() { return _pCb; }
  112. static BOOL Callback(PATCH_DOWNLOAD_REASON Reason, PVOID lpvInfo, PVOID pvContext);
  113. private:
  114. IMyDownloadCallback *_pCb;
  115. BOOL _fEnable;
  116. DWORD _dwFullTotalSize;
  117. UINT _uNumDownloads;
  118. char _szPath[MAX_PATH];
  119. };