WOLDownload.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /******************************************************************************
  19. *
  20. * FILE
  21. * $Archive: /Commando/Code/WWOnline/WOLDownload.h $
  22. *
  23. * DESCRIPTION
  24. * This class specifies patch files to be downloaded from the server.
  25. *
  26. * PROGRAMMER
  27. * $Author: Denzil_l $
  28. *
  29. * VERSION INFO
  30. * $Revision: 5 $
  31. * $Modtime: 1/11/02 5:17p $
  32. *
  33. ******************************************************************************/
  34. #ifndef __WOLDOWNLOAD_H__
  35. #define __WOLDOWNLOAD_H__
  36. #include <atlbase.h>
  37. #include "RefCounted.h"
  38. #include "RefPtr.h"
  39. #include "WaitCondition.h"
  40. namespace WOL
  41. {
  42. #include <WOLAPI\wolapi.h>
  43. }
  44. namespace WWOnline {
  45. class Session;
  46. class DownloadEvent;
  47. class Download :
  48. public RefCounted,
  49. public WOL::IDownloadEvent,
  50. public Notifier<DownloadEvent>
  51. {
  52. public:
  53. static RefPtr<Download> Create(const WOL::Update& patch);
  54. bool Start(void);
  55. void Stop(void);
  56. bool IsDone(void) const;
  57. void Process(void);
  58. unsigned long GetSKU(void) const
  59. {return mWOLUpdate.SKU;}
  60. unsigned long GetVersion(void) const
  61. {return mWOLUpdate.version;}
  62. bool IsRequired(void) const
  63. {return (mWOLUpdate.required != 0);}
  64. const char* GetServerName(void) const
  65. {return (const char*)mWOLUpdate.server;}
  66. const char* GetLoginName(void) const
  67. {return (const char*)mWOLUpdate.login;}
  68. const char* GetPassword(void) const
  69. {return (const char*)mWOLUpdate.password;}
  70. const char* GetDownloadPath(void) const
  71. {return (const char*)mWOLUpdate.patchpath;}
  72. const char* GetFilename(void) const
  73. {return (const char*)mWOLUpdate.patchfile;}
  74. const char* GetLocalPath(void) const
  75. {return (const char*)mWOLUpdate.localpath;}
  76. int GetStatusCode(void) const
  77. {return mStatusCode;}
  78. const wchar_t* GetStatusText(void) const;
  79. int GetErrorCode(void) const
  80. {return mErrorCode;}
  81. const wchar_t* GetErrorText(void) const;
  82. void GetProgress(int& bytesRead, int& totalSize, int& timeElapsed, int& timeRemaining) const;
  83. DECLARE_NOTIFIER(DownloadEvent)
  84. protected:
  85. typedef enum {DLError = 0, DLPending, DLDownloading, DLAborted, DLComplete} DLState;
  86. Download(const WOL::Update& patch);
  87. ~Download();
  88. bool CreateDownloadObject(void);
  89. void ReleaseDownloadObject(void);
  90. void SetError(int errorCode, const char* errorText);
  91. const char* GetOnErrorText(int onErrorCode) const;
  92. // Prevent copy and assignment.
  93. Download(const Download&);
  94. const Download& operator=(const Download&);
  95. WOL::Update mWOLUpdate;
  96. CComPtr<WOL::IDownload> mDownloadObject;
  97. unsigned long mDownloadCookie;
  98. DLState mState;
  99. // Status / Error
  100. int mStatusCode;
  101. int mErrorCode;
  102. const char* mErrorText;
  103. // Progress
  104. int mBytesRead;
  105. int mTotalSize;
  106. int mTimeElapsed;
  107. int mTimeRemaining;
  108. //---------------------------------------------------------------------------
  109. // IUnknown methods
  110. //---------------------------------------------------------------------------
  111. protected:
  112. virtual HRESULT STDMETHODCALLTYPE QueryInterface(const IID& iid, void** ppv);
  113. virtual ULONG STDMETHODCALLTYPE AddRef(void);
  114. virtual ULONG STDMETHODCALLTYPE Release(void);
  115. //---------------------------------------------------------------------------
  116. // IDownloadEvent Methods
  117. //---------------------------------------------------------------------------
  118. protected:
  119. STDMETHOD(OnEnd)(void);
  120. STDMETHOD(OnError)(int error);
  121. STDMETHOD(OnProgressUpdate)(int bytesRead, int totalSize, int timeElapsed, int timeRemaining);
  122. STDMETHOD(OnQueryResume)(void);
  123. STDMETHOD(OnStatusUpdate)(int status);
  124. };
  125. typedef std::vector< RefPtr<Download> > DownloadList;
  126. class DownloadEvent
  127. {
  128. public:
  129. enum Event
  130. {
  131. DOWNLOAD_ERROR = -1,
  132. DOWNLOAD_STATUS,
  133. DOWNLOAD_BEGIN,
  134. DOWNLOAD_PROGRESS,
  135. DOWNLOAD_END,
  136. DOWNLOAD_STOPPED,
  137. DOWNLOAD_RESUME
  138. };
  139. Event GetEvent(void) const
  140. {return mEvent;}
  141. const RefPtr<Download>& GetDownload(void) const
  142. {return mDownload;}
  143. DownloadEvent(Event event, const RefPtr<Download>& download) :
  144. mEvent(event),
  145. mDownload(download)
  146. {}
  147. ~DownloadEvent()
  148. {}
  149. protected:
  150. // Prevent copy and assignment.
  151. DownloadEvent(const DownloadEvent&);
  152. const DownloadEvent& operator=(const DownloadEvent&);
  153. Event mEvent;
  154. const RefPtr<Download> mDownload;
  155. };
  156. typedef void (*DownloadWaitCallback)(DownloadEvent& event, unsigned long userdata);
  157. class DownloadWait :
  158. public SingleWait,
  159. public Observer<DownloadEvent>
  160. {
  161. public:
  162. static RefPtr<DownloadWait> Create(const DownloadList& files);
  163. void WaitBeginning(void);
  164. WaitResult GetResult(void);
  165. void EndWait(WaitResult, const wchar_t*);
  166. void SetCallback(DownloadWaitCallback callback, unsigned long userdata);
  167. unsigned int GetDownloadCount(void) const
  168. {return mFiles.size();}
  169. const RefPtr<Download>& GetCurrentDownload(void) const
  170. {return mCurrentDownload;}
  171. protected:
  172. DownloadWait(const DownloadList& files);
  173. virtual ~DownloadWait();
  174. // Prevent copy and assignment
  175. DownloadWait(const DownloadWait&);
  176. const DownloadWait& operator=(const DownloadWait&);
  177. void DoCallback(DownloadEvent& event);
  178. void HandleNotification(DownloadEvent&);
  179. protected:
  180. const DownloadList& mFiles;
  181. int mFileIndex;
  182. RefPtr<Download> mCurrentDownload;
  183. DownloadWaitCallback mCallback;
  184. unsigned long mUserdata;
  185. };
  186. } // namespace WWOnline
  187. #endif // __WOLDOWNLOAD_H__