1
0

Downloaded.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 *_channel, const wchar_t *_item, __time64_t publishDate)
  11. {
  12. Init();
  13. this->publishDate = publishDate;
  14. SetChannel( _channel );
  15. SetItem( _item );
  16. SetPath( _path );
  17. SetURL( _url );
  18. }
  19. DownloadedFile::DownloadedFile( const DownloadedFile &copy )
  20. {
  21. Init();
  22. operator =( copy );
  23. }
  24. DownloadedFile::~DownloadedFile()
  25. {
  26. Reset();
  27. }
  28. void DownloadedFile::Init()
  29. {
  30. url = 0;
  31. path = 0;
  32. channel = 0;
  33. item = 0;
  34. bytesDownloaded = 0;
  35. totalSize = 0;
  36. publishDate = 0;
  37. }
  38. void DownloadedFile::Reset()
  39. {
  40. if ( url )
  41. {
  42. free( url );
  43. url = 0;
  44. }
  45. if ( path )
  46. {
  47. free( path );
  48. path = 0;
  49. }
  50. if ( channel )
  51. {
  52. free( channel );
  53. channel = 0;
  54. }
  55. if ( item )
  56. {
  57. free( item );
  58. item = 0;
  59. }
  60. }
  61. void DownloadedFile::SetPath( const wchar_t *_path )
  62. {
  63. if ( path )
  64. free( path );
  65. path = _wcsdup( _path );
  66. }
  67. void DownloadedFile::SetURL( const wchar_t *_url )
  68. {
  69. if ( url )
  70. free( url );
  71. url = _wcsdup( _url );
  72. }
  73. void DownloadedFile::SetItem( const wchar_t *_item )
  74. {
  75. free( item );
  76. item = _wcsdup( _item );
  77. }
  78. void DownloadedFile::SetChannel( const wchar_t *_channel )
  79. {
  80. free( channel );
  81. channel = _wcsdup( _channel );
  82. }
  83. const DownloadedFile &DownloadedFile::operator =( const DownloadedFile &copy )
  84. {
  85. Reset();
  86. Init();
  87. SetChannel( copy.channel );
  88. SetItem( copy.item );
  89. bytesDownloaded = copy.bytesDownloaded;
  90. totalSize = copy.totalSize;
  91. publishDate = copy.publishDate;
  92. downloadDate = copy.downloadDate;
  93. SetPath( copy.path );
  94. SetURL( copy.url );
  95. return *this;
  96. }