123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- #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 );
- }
- }
- }
|