Downloaded.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #include "main.h"
  2. #include "Downloaded.h"
  3. DownloadList downloadedFiles;
  4. using namespace Nullsoft::Utility;
  5. Nullsoft::Utility::LockGuard downloadedLock;
  6. DownloadedFile::DownloadedFile()
  7. {
  8. Init();
  9. }
  10. DownloadedFile::DownloadedFile( const wchar_t *_url, const wchar_t *_path, const wchar_t *_source, const wchar_t *_title, int downloadStatus, __time64_t downloadDate )
  11. {
  12. Init();
  13. this->downloadStatus = downloadStatus;
  14. this->downloadDate = downloadDate;
  15. SetSource( _source );
  16. SetTitle( _title );
  17. SetPath( _path );
  18. SetURL( _url );
  19. }
  20. DownloadedFile::DownloadedFile( const DownloadedFile &copy )
  21. {
  22. Init();
  23. operator =( copy );
  24. }
  25. DownloadedFile::~DownloadedFile()
  26. {
  27. Reset();
  28. }
  29. void DownloadedFile::Init()
  30. {
  31. url = 0;
  32. path = 0;
  33. source = 0;
  34. title = 0;
  35. bytesDownloaded = 0;
  36. totalSize = 0;
  37. downloadDate = 0;
  38. }
  39. void DownloadedFile::Reset()
  40. {
  41. if ( url )
  42. {
  43. free( url );
  44. url = 0;
  45. }
  46. if ( path )
  47. {
  48. free( path );
  49. path = 0;
  50. }
  51. if ( source )
  52. {
  53. free( source );
  54. source = 0;
  55. }
  56. if ( title )
  57. {
  58. free( title );
  59. title = 0;
  60. }
  61. }
  62. void DownloadedFile::SetPath( const wchar_t *_path )
  63. {
  64. if ( path )
  65. free( path );
  66. path = _wcsdup( _path );
  67. }
  68. void DownloadedFile::SetURL( const wchar_t *_url )
  69. {
  70. if ( url )
  71. free( url );
  72. url = _wcsdup( _url );
  73. }
  74. void DownloadedFile::SetTitle( const wchar_t *_title )
  75. {
  76. if ( title )
  77. free( title );
  78. title = _wcsdup( _title );
  79. }
  80. void DownloadedFile::SetSource( const wchar_t *_source )
  81. {
  82. if ( source )
  83. free( source );
  84. source = _wcsdup( _source );
  85. }
  86. const DownloadedFile &DownloadedFile::operator =( const DownloadedFile &copy )
  87. {
  88. Reset();
  89. Init();
  90. SetSource( copy.source );
  91. SetTitle( copy.title );
  92. bytesDownloaded = copy.bytesDownloaded;
  93. totalSize = copy.totalSize;
  94. downloadStatus = copy.downloadStatus;
  95. downloadDate = copy.downloadDate;
  96. SetPath( copy.path );
  97. SetURL( copy.url );
  98. return *this;
  99. }
  100. wchar_t *GetDownloadStatus( int downloadStatus )
  101. {
  102. switch ( downloadStatus )
  103. {
  104. case DownloadedFile::DOWNLOAD_SUCCESS:
  105. return WASABI_API_LNGSTRINGW( IDS_DOWNLOAD_SUCCESS );
  106. case DownloadedFile::DOWNLOAD_FAILURE:
  107. return WASABI_API_LNGSTRINGW( IDS_DOWNLOAD_FAILURE );
  108. case DownloadedFile::DOWNLOAD_CANCELED:
  109. return WASABI_API_LNGSTRINGW( IDS_DOWNLOAD_CANCELED );
  110. default:
  111. return WASABI_API_LNGSTRINGW( IDS_DOWNLOAD_FAILURE );
  112. }
  113. }