Downloaded.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef NULLSOFT_DOWNLOADEDH
  2. #define NULLSOFT_DOWNLOADEDH
  3. #include "../nu/AutoLock.h"
  4. #include "../nu/AutoCharFn.h"
  5. #include "..\..\General\gen_ml/ml.h"
  6. #include <vector>
  7. #include "../nu/MediaLibraryInterface.h"
  8. class DownloadedFile
  9. {
  10. public:
  11. DownloadedFile();
  12. DownloadedFile( const wchar_t *_url, const wchar_t *_path, const wchar_t *_source, const wchar_t *_title, int downloadStatus, __time64_t downloadDate );
  13. DownloadedFile( const DownloadedFile &copy );
  14. ~DownloadedFile();
  15. const DownloadedFile &operator =( const DownloadedFile &copy );
  16. void SetPath( const wchar_t *_path );
  17. void SetURL( const wchar_t *_url );
  18. void SetTitle( const wchar_t *_title );
  19. void SetSource( const wchar_t *_source );
  20. enum
  21. {
  22. DOWNLOAD_FAILURE = 0,
  23. DOWNLOAD_SUCCESS = 1,
  24. DOWNLOAD_CANCELED = 2,
  25. };
  26. size_t bytesDownloaded = 0;
  27. size_t totalSize = 0;
  28. int downloadStatus = 0;
  29. __time64_t downloadDate = 0;
  30. wchar_t *path = 0;
  31. wchar_t *url = 0;
  32. wchar_t *source = 0;
  33. wchar_t *title = 0;
  34. private:
  35. void Init();
  36. void Reset();
  37. };
  38. class DownloadList
  39. {
  40. public:
  41. typedef std::vector<DownloadedFile> DownloadedFileList;
  42. typedef DownloadedFileList::iterator iterator;
  43. typedef DownloadedFileList::const_iterator const_iterator;
  44. operator Nullsoft::Utility::LockGuard &() { return downloadedLock; }
  45. void Remove( size_t index ) { downloadList.erase( downloadList.begin() + index ); }
  46. bool RemoveAndDelete( int index )
  47. {
  48. SendMessage( mediaLibrary.library, WM_ML_IPC, (WPARAM)downloadList[ index ].path, ML_IPC_DB_REMOVEITEMW );
  49. if ( !DeleteFile( downloadList[ index ].path ) && GetLastError() != ERROR_FILE_NOT_FOUND )
  50. return false;
  51. downloadList.erase( downloadList.begin() + index );
  52. return true;
  53. }
  54. DownloadedFileList downloadList;
  55. Nullsoft::Utility::LockGuard downloadedLock;
  56. iterator begin() { return downloadList.begin(); }
  57. iterator end() { return downloadList.end(); }
  58. };
  59. extern DownloadList downloadedFiles;
  60. extern int downloadsItemSort;
  61. extern bool downloadsSortAscending;
  62. void CleanupDownloads();
  63. wchar_t *GetDownloadStatus( int downloadStatus );
  64. #endif