DownloadViewCallback.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "Main.h"
  2. //#include "../Components/wac_downloads/wac_downloads_download_manager.h"
  3. using namespace Nullsoft::Utility;
  4. DownloadViewCallback::DownloadViewCallback()
  5. {}
  6. void DownloadViewCallback::OnInit( DownloadToken token )
  7. {
  8. // ---- Inform the download status service of our presence----
  9. downloadStatus.AddDownloadThread( token, WAC_API_DOWNLOADMANAGER->GetSource( token ), WAC_API_DOWNLOADMANAGER->GetTitle( token ), WAC_API_DOWNLOADMANAGER->GetLocation( token ) );
  10. }
  11. void DownloadViewCallback::OnConnect( DownloadToken token )
  12. {}
  13. void DownloadViewCallback::OnData( DownloadToken token, void *data, size_t datalen )
  14. {
  15. if ( token == NULL )
  16. return;
  17. api_httpreceiver *http = WAC_API_DOWNLOADMANAGER->GetReceiver( token );
  18. size_t totalSize = http->content_length();
  19. size_t downloaded = (size_t)WAC_API_DOWNLOADMANAGER->GetBytesDownloaded( token );
  20. // if killswitch is turned on, then cancel download
  21. downloadStatus.UpdateStatus( token, downloaded, totalSize );
  22. dirty++;
  23. }
  24. void DownloadViewCallback::OnCancel( DownloadToken token )
  25. {
  26. api_httpreceiver *http = WAC_API_DOWNLOADMANAGER->GetReceiver( token );
  27. DownloadedFile *data = new DownloadedFile( AutoWide( http->get_url() ), WAC_API_DOWNLOADMANAGER->GetLocation( token ), WAC_API_DOWNLOADMANAGER->GetSource( token ), WAC_API_DOWNLOADMANAGER->GetTitle( token ), DownloadedFile::DOWNLOAD_CANCELED, _time64( 0 ) );
  28. data->totalSize = http->content_length();
  29. data->bytesDownloaded = (size_t)WAC_API_DOWNLOADMANAGER->GetBytesDownloaded( token );
  30. {
  31. AutoLock lock( downloadedFiles );
  32. downloadedFiles.downloadList.push_back( *data );
  33. DownloadsUpdated( token, &downloadedFiles.downloadList[ downloadedFiles.downloadList.size() - 1 ] );
  34. }
  35. downloadStatus.DownloadThreadDone( token );
  36. delete data;
  37. dirty++;
  38. }
  39. void DownloadViewCallback::OnError( DownloadToken token, int error )
  40. {
  41. api_httpreceiver *http = WAC_API_DOWNLOADMANAGER->GetReceiver( token );
  42. DownloadedFile *data = new DownloadedFile( AutoWide( http->get_url() ), WAC_API_DOWNLOADMANAGER->GetLocation( token ), WAC_API_DOWNLOADMANAGER->GetSource( token ), WAC_API_DOWNLOADMANAGER->GetTitle( token ), DownloadedFile::DOWNLOAD_FAILURE, _time64( 0 ) );
  43. data->totalSize = http->content_length();
  44. data->bytesDownloaded = (size_t)WAC_API_DOWNLOADMANAGER->GetBytesDownloaded( token );
  45. {
  46. AutoLock lock( downloadedFiles );
  47. downloadedFiles.downloadList.push_back( *data );
  48. DownloadsUpdated( token, &downloadedFiles.downloadList[ downloadedFiles.downloadList.size() - 1 ] );
  49. }
  50. downloadStatus.DownloadThreadDone( token );
  51. delete data;
  52. dirty++;
  53. }
  54. void DownloadViewCallback::OnFinish( DownloadToken token )
  55. {
  56. api_httpreceiver *http = WAC_API_DOWNLOADMANAGER->GetReceiver( token );
  57. DownloadedFile *data = new DownloadedFile( AutoWide( http->get_url() ), WAC_API_DOWNLOADMANAGER->GetLocation( token ), WAC_API_DOWNLOADMANAGER->GetSource( token ), WAC_API_DOWNLOADMANAGER->GetTitle( token ), DownloadedFile::DOWNLOAD_SUCCESS, _time64( 0 ) );
  58. data->totalSize = http->content_length();
  59. data->bytesDownloaded = (size_t)WAC_API_DOWNLOADMANAGER->GetBytesDownloaded( token );
  60. {
  61. AutoLock lock( downloadedFiles );
  62. downloadedFiles.downloadList.push_back( *data );
  63. //AddDownloadData(*data);
  64. DownloadsUpdated( token, &downloadedFiles.downloadList[ downloadedFiles.downloadList.size() - 1 ] );
  65. }
  66. downloadStatus.DownloadThreadDone( token );
  67. delete data;
  68. dirty++;
  69. }
  70. size_t DownloadViewCallback::AddRef()
  71. {
  72. return this->_ref_count.fetch_add( 1 );
  73. }
  74. size_t DownloadViewCallback::Release()
  75. {
  76. std::size_t l_ref_countr = this->_ref_count.fetch_sub( 1 );
  77. if ( l_ref_countr == 0 )
  78. delete( this );
  79. return l_ref_countr;
  80. }
  81. DownloadViewCallback::~DownloadViewCallback()
  82. {}
  83. #define CBCLASS DownloadViewCallback
  84. START_DISPATCH;
  85. VCB( IFC_DOWNLOADMANAGERCALLBACK_ONFINISH, OnFinish )
  86. VCB( IFC_DOWNLOADMANAGERCALLBACK_ONCANCEL, OnCancel )
  87. VCB( IFC_DOWNLOADMANAGERCALLBACK_ONERROR, OnError )
  88. VCB( IFC_DOWNLOADMANAGERCALLBACK_ONDATA, OnData )
  89. VCB( IFC_DOWNLOADMANAGERCALLBACK_ONCONNECT, OnConnect )
  90. VCB( IFC_DOWNLOADMANAGERCALLBACK_ONINIT, OnInit )
  91. CB( ADDREF, AddRef )
  92. CB( RELEASE, Release )
  93. END_DISPATCH;
  94. #undef CBCLASS