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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
#include "Main.h"
#include "DownloadsParse.h"
#include "Downloaded.h"
#include "Defaults.h"
#include "ParseUtil.h"
#include <wchar.h>
#include <locale.h>
static __time64_t filetime( const wchar_t *file )
{
if ( !file || !*file )
return 0;
WIN32_FIND_DATAW f = { 0 };
HANDLE h = FindFirstFileW( file, &f );
if ( h == INVALID_HANDLE_VALUE )
{
/*wchar_t tmp[128] = {0};
wsprintf(tmp,L"%d",GetLastError());
MessageBox(0,file,tmp,0);*/
return 0;
}
FindClose( h );
SYSTEMTIME s = { 0 };
FileTimeToSystemTime( &f.ftCreationTime, &s );
tm t = { 0 };
t.tm_year = s.wYear - 1900;
t.tm_mon = s.wMonth - 1;
t.tm_mday = s.wDay;
t.tm_hour = s.wHour;
t.tm_min = s.wMinute;
t.tm_sec = s.wMinute;
__time64_t ret = _mktime64(&t);
/*wchar_t tmp[128] = {0};
wsprintf(tmp,L"%d",ret);
MessageBox(0,tmp,0,0);*/
return ret;
}
size_t GetFileSize(LPCWSTR path)
{
WIN32_FIND_DATAW data = {0};
if (path && *path)
{
HANDLE h = FindFirstFileW(path, &data);
if (h == INVALID_HANDLE_VALUE)
return -1;
FindClose(h);
}
return data.nFileSizeLow/* | (__int64)data.nFileSizeHigh << 32*/;
}
static void ReadDownload( const XMLNode *item )
{
DownloadedFile newDownloaded;
const wchar_t *source = GetContent( item, L"source" );
if ( !source ) source = GetContent( item, L"channel" );
newDownloaded.SetSource( source );
const wchar_t *title = GetContent( item, L"title" );
if ( !title ) title = GetContent( item, L"item" );;
newDownloaded.SetTitle( title );
const wchar_t *url = GetContent( item, L"url" );
newDownloaded.SetURL( url );
const wchar_t *path = GetContent( item, L"path" );
newDownloaded.SetPath( path );
// TODO ideally should be able to cope with __int64
// but the db is setup for int currently...
const wchar_t *size = GetContent( item, L"size" );
if ( size && size[ 0 ] )
{
size_t val = _wtoi( size );
if ( val > 0 ) newDownloaded.totalSize = val;
else if ( !val )
{
val = GetFileSize( path );
if ( val > 0 ) newDownloaded.totalSize = val;
else newDownloaded.totalSize = -1;
dirty++;
}
}
else
{
size_t val = GetFileSize( path );
if ( val > 0 ) newDownloaded.totalSize = val;
else newDownloaded.totalSize = -1;
dirty++;
}
const wchar_t *downloadDate = GetContent( item, L"downloadDate" );
if ( downloadDate && downloadDate[ 0 ] )
{
__time64_t val = (__time64_t)_wtoi( downloadDate );
if ( time > 0 ) newDownloaded.downloadDate = val;
}
else
{
__time64_t val = filetime( newDownloaded.path );
if ( time > 0 ) newDownloaded.downloadDate = val;
}
const wchar_t *status = GetContent( item, L"downloadStatus" );
if ( status && status[ 0 ] )
{
newDownloaded.downloadStatus = _wtoi( status );
}
else
{
newDownloaded.downloadStatus = DownloadedFile::DOWNLOAD_SUCCESS;
}
downloadedFiles.downloadList.push_back( newDownloaded );
}
void DownloadsParse::ReadNodes( const wchar_t *url )
{
XMLNode::NodeList::const_iterator itr;
const XMLNode *curNode = xmlDOM.GetRoot();
if ( curNode->Present( L"winamp:preferences" ) )
curNode = curNode->Get( L"winamp:preferences" );
curNode = curNode->Get( L"downloads" );
if ( curNode )
{
const wchar_t *prop = curNode->GetProperty( L"downloadsTitleWidth" );
if ( prop && prop[ 0 ] )
downloadsTitleWidth = _wtoi( prop );
if ( downloadsTitleWidth <= 0 )
downloadsTitleWidth = DOWNLOADSTITLEWIDTHDEFAULT;
prop = curNode->GetProperty( L"downloadsProgressWidth" );
if ( prop && prop[ 0 ] )
downloadsProgressWidth = _wtoi( prop );
if ( downloadsProgressWidth <= 0 )
downloadsProgressWidth = DOWNLOADSPROGRESSWIDTHDEFAULT;
prop = curNode->GetProperty( L"downloadsDateWidth" );
if ( prop && prop[ 0 ] )
downloadsDateWidth = _wtoi( prop );
if ( downloadsDateWidth <= 0 )
downloadsDateWidth = DOWNLOADSDATEWIDTHDEFAULTS;
prop = curNode->GetProperty( L"downloadsSourceWidth" );
if ( prop && prop[ 0 ] )
downloadsSourceWidth = _wtoi( prop );
if ( downloadsSourceWidth <= 0 )
downloadsSourceWidth = DOWNLOADSSOURCEWIDTHDEFAULT;
prop = curNode->GetProperty( L"downloadsPathWidth" );
if ( prop && prop[ 0 ] )
downloadsPathWidth = _wtoi( prop );
if ( downloadsPathWidth <= 0 )
downloadsPathWidth = DOWNLOADSPATHWIDTHDEFAULTS;
prop = curNode->GetProperty( L"downloadsItemSort" );
if ( prop && prop[ 0 ] )
downloadsItemSort = _wtoi( prop );
prop = curNode->GetProperty( L"downloadsSortAscending" );
if ( prop && prop[ 0 ] )
downloadsSortAscending = !PropertyIsFalse( curNode, L"downloadsSortAscending" );
const XMLNode::NodeList *downloadsList = curNode->GetList( L"download" );
if ( downloadsList )
{
for ( itr = downloadsList->begin(); itr != downloadsList->end(); itr++ )
ReadDownload( *itr );
}
}
}
|