Downloaded.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 *_channel, const wchar_t *_item, __time64_t publishDate );
  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 SetItem( const wchar_t *_item );
  19. void SetChannel( const wchar_t *_channel );
  20. size_t bytesDownloaded = 0;
  21. size_t totalSize = 0;
  22. __time64_t publishDate;
  23. __time64_t downloadDate = 0;
  24. wchar_t *path = 0;
  25. wchar_t *url = 0;
  26. wchar_t *channel = 0;
  27. wchar_t *item = 0;
  28. private:
  29. void Init();
  30. void Reset();
  31. };
  32. class DownloadList
  33. {
  34. public:
  35. typedef std::vector<DownloadedFile> DownloadedFileList;
  36. typedef DownloadedFileList::iterator iterator;
  37. typedef DownloadedFileList::const_iterator const_iterator;
  38. operator Nullsoft::Utility::LockGuard &() { return downloadedLock; }
  39. void Remove( size_t index ) { downloadList.erase( downloadList.begin() + index ); }
  40. bool RemoveAndDelete( int index )
  41. {
  42. SendMessage( mediaLibrary.library, WM_ML_IPC, (WPARAM)downloadList[ index ].path, ML_IPC_DB_REMOVEITEMW );
  43. if ( !DeleteFile( downloadList[ index ].path ) && GetLastError() != ERROR_FILE_NOT_FOUND )
  44. return false;
  45. downloadList.erase( downloadList.begin() + index );
  46. return true;
  47. }
  48. DownloadedFileList downloadList;
  49. Nullsoft::Utility::LockGuard downloadedLock;
  50. iterator begin() { return downloadList.begin(); }
  51. iterator end() { return downloadList.end(); }
  52. };
  53. extern DownloadList downloadedFiles;
  54. extern int downloadsItemSort;
  55. extern bool downloadsSortAscending;
  56. void CleanupDownloads();
  57. __time64_t filetime(const wchar_t *file);
  58. #endif