DownloadManager.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. ** Command & Conquer Generals(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. // FILE: DownloadManager.h //////////////////////////////////////////////////////
  19. // Generals download class definitions
  20. // Author: Matthew D. Campbell, July 2002
  21. #pragma once
  22. #ifndef __DOWNLOADMANAGER_H__
  23. #define __DOWNLOADMANAGER_H__
  24. #include "WWDownload/downloadDefs.h"
  25. #include "WWDownload/download.h"
  26. #include <string>
  27. #include <list>
  28. class CDownload;
  29. class QueuedDownload
  30. {
  31. public:
  32. std::string server;
  33. std::string userName;
  34. std::string password;
  35. std::string file;
  36. std::string localFile;
  37. std::string regKey;
  38. bool tryResume;
  39. };
  40. /////////////////////////////////////////////////////////////////////////////
  41. // DownloadManager
  42. class DownloadManager : public IDownload
  43. {
  44. public:
  45. DownloadManager();
  46. virtual ~DownloadManager();
  47. public:
  48. void init( void );
  49. HRESULT update( void );
  50. void reset( void );
  51. virtual HRESULT OnError( int error );
  52. virtual HRESULT OnEnd();
  53. virtual HRESULT OnQueryResume();
  54. virtual HRESULT OnProgressUpdate( int bytesread, int totalsize, int timetaken, int timeleft );
  55. virtual HRESULT OnStatusUpdate( int status );
  56. virtual HRESULT downloadFile( std::string server, std::string username, std::string password, std::string file, std::string localfile, std::string regkey, bool tryResume );
  57. std::string getLastLocalFile( void );
  58. bool isDone( void ) { return m_sawEnd || m_wasError; }
  59. bool isOk( void ) { return m_sawEnd; }
  60. bool wasError( void ) { return m_wasError; }
  61. std::string getStatusString( void ) { return m_statusString; }
  62. std::string getErrorString( void ) { return m_errorString; }
  63. void queueFileForDownload( std::string server, std::string username, std::string password, std::string file, std::string localfile, std::string regkey, bool tryResume );
  64. bool isFileQueuedForDownload( void ) { return !m_queuedDownloads.empty(); }
  65. HRESULT downloadNextQueuedFile( void );
  66. private:
  67. bool m_winsockInit;
  68. CDownload *m_download;
  69. bool m_wasError;
  70. bool m_sawEnd;
  71. std::string m_errorString;
  72. std::string m_statusString;
  73. protected:
  74. std::list<QueuedDownload> m_queuedDownloads;
  75. };
  76. extern DownloadManager *TheDownloadManager;
  77. #endif // __DOWNLOADMANAGER_H__