aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Library/ml_wire/Downloaded.h
blob: 2ba1ace87a86773f270df1b68a48a5f963b7d090 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef NULLSOFT_DOWNLOADEDH
#define NULLSOFT_DOWNLOADEDH

#include "../nu/AutoLock.h"
#include "../nu/AutoCharFn.h"
#include "..\..\General\gen_ml/ml.h"
#include <vector>
#include "../nu/MediaLibraryInterface.h"

class DownloadedFile
{
public:
	DownloadedFile();
	DownloadedFile( const wchar_t *_url, const wchar_t *_path, const wchar_t *_channel, const wchar_t *_item, __time64_t publishDate );
	DownloadedFile( const DownloadedFile &copy );
	~DownloadedFile();

	const DownloadedFile &operator =( const DownloadedFile &copy );

	void SetPath( const wchar_t *_path );
	void SetURL( const wchar_t *_url );
	void SetItem( const wchar_t *_item );
	void SetChannel( const wchar_t *_channel );

	size_t      bytesDownloaded = 0;
	size_t      totalSize       = 0;

	__time64_t  publishDate;
	__time64_t  downloadDate    = 0;

	wchar_t    *path            = 0;
	wchar_t    *url             = 0;
	wchar_t    *channel         = 0;
	wchar_t    *item            = 0;


private:
	void Init();
	void Reset();
};

class DownloadList
{
public:
	typedef std::vector<DownloadedFile> DownloadedFileList;
	typedef DownloadedFileList::iterator iterator;
	typedef DownloadedFileList::const_iterator const_iterator;

	operator Nullsoft::Utility::LockGuard &()                         { return downloadedLock; }

	void Remove( size_t index )                                       { downloadList.erase( downloadList.begin() + index ); }

	bool RemoveAndDelete( int index )
	{
		SendMessage( mediaLibrary.library, WM_ML_IPC, (WPARAM)downloadList[ index ].path, ML_IPC_DB_REMOVEITEMW );

		if ( !DeleteFile( downloadList[ index ].path ) && GetLastError() != ERROR_FILE_NOT_FOUND )
			return false;

		downloadList.erase( downloadList.begin() + index );

		return true;
	}

	DownloadedFileList downloadList;
	Nullsoft::Utility::LockGuard downloadedLock;

	iterator begin()                                                  { return downloadList.begin(); }
	iterator end()                                                    { return downloadList.end(); }
};

extern DownloadList downloadedFiles;
extern int          downloadsItemSort;
extern bool         downloadsSortAscending;

void     CleanupDownloads();
__time64_t filetime(const wchar_t *file);

#endif