1
0

DownloadsParse.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #include "Main.h"
  2. #include "DownloadsParse.h"
  3. #include "Downloaded.h"
  4. #include "Defaults.h"
  5. #include "ParseUtil.h"
  6. #include <wchar.h>
  7. #include <locale.h>
  8. static __time64_t filetime( const wchar_t *file )
  9. {
  10. if ( !file || !*file )
  11. return 0;
  12. WIN32_FIND_DATA f = { 0 };
  13. HANDLE h = FindFirstFile( file, &f );
  14. if ( h == INVALID_HANDLE_VALUE )
  15. return 0;
  16. FindClose( h );
  17. SYSTEMTIME s = { 0 };
  18. FileTimeToSystemTime( &f.ftCreationTime, &s );
  19. tm t = { 0 };
  20. t.tm_year = s.wYear - 1900;
  21. t.tm_mon = s.wMonth - 1;
  22. t.tm_mday = s.wDay;
  23. t.tm_hour = s.wHour;
  24. t.tm_min = s.wMinute;
  25. t.tm_sec = s.wMinute;
  26. return _mktime64( &t );
  27. }
  28. static void ReadDownload( const XMLNode *item, bool addToLib = false )
  29. {
  30. DownloadedFile newDownloaded;
  31. const wchar_t *channel = GetContent( item, L"channel" );
  32. newDownloaded.SetChannel( channel );
  33. const wchar_t *item_str = GetContent( item, L"item" );
  34. newDownloaded.SetItem( item_str );
  35. const wchar_t *url = GetContent( item, L"url" );
  36. newDownloaded.SetURL( url );
  37. const wchar_t *path = GetContent( item, L"path" );
  38. newDownloaded.SetPath( path );
  39. const wchar_t *publishDate = GetContent( item, L"publishDate" );
  40. if ( publishDate && publishDate[ 0 ] )
  41. newDownloaded.publishDate = _wtoi( publishDate );
  42. else
  43. newDownloaded.publishDate = filetime( newDownloaded.path );
  44. if ( addToLib )
  45. addToLibrary( newDownloaded );
  46. downloadedFiles.downloadList.push_back( newDownloaded );
  47. }
  48. static void ReadPreferences( const XMLNode *item )
  49. {
  50. const XMLNode *curNode;
  51. curNode = item->Get(L"download");
  52. if ( curNode )
  53. {
  54. const wchar_t *prop = curNode->GetProperty( L"downloadpath" );
  55. if ( prop )
  56. lstrcpyn( defaultDownloadPath, prop, MAX_PATH );
  57. autoDownload = PropertyIsTrue( curNode, L"autodownload" );
  58. prop = curNode->GetProperty( L"autoDownloadEpisodes" );
  59. if ( prop )
  60. autoDownloadEpisodes = _wtoi( prop );
  61. needToMakePodcastsView = PropertyIsTrue( curNode, L"needToMakePodcastsView" );
  62. }
  63. curNode = item->Get(L"update");
  64. if ( curNode )
  65. {
  66. const wchar_t *prop = curNode->GetProperty( L"updatetime" );
  67. if ( prop )
  68. updateTime = _wtoi64( prop );
  69. autoUpdate = PropertyIsTrue( curNode, L"autoupdate" );
  70. updateOnLaunch = PropertyIsTrue( curNode, L"updateonlaunch" );
  71. }
  72. curNode = item->Get(L"subscriptions");
  73. if ( curNode )
  74. {
  75. _locale_t C_locale = WASABI_API_LNG->Get_C_NumericLocale();
  76. const wchar_t *prop = curNode->GetProperty( L"htmldivider" );
  77. if ( prop )
  78. htmlDividerPercent = (float)_wtof_l( prop, C_locale );
  79. prop = curNode->GetProperty( L"channeldivider" );
  80. if ( prop && prop[ 0 ] )
  81. channelDividerPercent = (float)_wtof_l( prop, C_locale );
  82. prop = curNode->GetProperty( L"itemtitlewidth" );
  83. if ( prop && prop[ 0 ] )
  84. itemTitleWidth = _wtoi( prop );
  85. prop = curNode->GetProperty( L"itemdatewidth" );
  86. if ( prop && prop[ 0 ] )
  87. itemDateWidth = _wtoi( prop );
  88. prop = curNode->GetProperty( L"itemmediawidth" );
  89. if ( prop && prop[ 0 ] )
  90. itemMediaWidth = _wtoi( prop );
  91. prop = curNode->GetProperty( L"itemsizewidth" );
  92. if ( prop && prop[ 0 ] )
  93. itemSizeWidth = _wtoi( prop );
  94. prop = curNode->GetProperty( L"currentitemsort" );
  95. if ( prop && prop[ 0 ] )
  96. currentItemSort = _wtoi( prop );
  97. itemSortAscending = !PropertyIsFalse( curNode, L"itemsortascending" );
  98. channelSortAscending = !PropertyIsFalse( curNode, L"channelsortascending" );
  99. prop = curNode->GetProperty( L"channelLastSelection" );
  100. if ( prop && prop[ 0 ] )
  101. channelLastSelection = _wtoi( prop );
  102. }
  103. curNode = item->Get(L"downloadsView");
  104. if ( curNode )
  105. {
  106. const wchar_t *prop = curNode->GetProperty( L"downloadsChannelWidth" );
  107. if ( prop && prop[ 0 ] )
  108. downloadsChannelWidth = _wtoi( prop );
  109. if ( downloadsChannelWidth <= 0 )
  110. downloadsChannelWidth = DOWNLOADSCHANNELWIDTHDEFAULT;
  111. prop = curNode->GetProperty( L"downloadsItemWidth" );
  112. if ( prop && prop[ 0 ] )
  113. downloadsItemWidth = _wtoi( prop );
  114. if ( downloadsItemWidth <= 0 )
  115. downloadsItemWidth = DOWNLOADSITEMWIDTHDEFAULT;
  116. prop = curNode->GetProperty( L"downloadsProgressWidth" );
  117. if ( prop && prop[ 0 ] )
  118. downloadsProgressWidth = _wtoi( prop );
  119. if ( downloadsProgressWidth <= 0 )
  120. downloadsProgressWidth = DOWNLOADSPROGRESSWIDTHDEFAULT;
  121. prop = curNode->GetProperty( L"downloadsPathWidth" );
  122. if ( prop && prop[ 0 ] )
  123. downloadsPathWidth = _wtoi( prop );
  124. if ( downloadsPathWidth <= 0 )
  125. downloadsPathWidth = DOWNLOADSPATHWIDTHDEFAULTS;
  126. prop = curNode->GetProperty( L"downloadsItemSort" );
  127. if ( prop && prop[ 0 ] )
  128. downloadsItemSort = _wtoi( prop );
  129. downloadsSortAscending = !PropertyIsFalse( curNode, L"downloadsSortAscending" );
  130. }
  131. curNode = item->Get(L"service");
  132. if ( curNode )
  133. {
  134. const wchar_t *prop = curNode->GetProperty( L"url" );
  135. if ( prop )
  136. lstrcpyn( serviceUrl, prop, MAX_PATH );
  137. }
  138. }
  139. void DownloadsParse::ReadNodes( const wchar_t *url )
  140. {
  141. XMLNode::NodeList::const_iterator itr;
  142. const XMLNode *curNode = xmlDOM.GetRoot();
  143. curNode = curNode->Get( L"winamp:preferences" );
  144. if ( curNode )
  145. {
  146. int version = 1;
  147. const wchar_t *prop = curNode->GetProperty( L"version" );
  148. if ( prop && prop[ 0 ] )
  149. version = _wtoi( prop );
  150. ReadPreferences( curNode );
  151. curNode = curNode->Get( L"downloads" );
  152. if ( curNode )
  153. {
  154. const XMLNode::NodeList *downloadsList = curNode->GetList( L"download" );
  155. if ( downloadsList )
  156. {
  157. for ( itr = downloadsList->begin(); itr != downloadsList->end(); itr++ )
  158. ReadDownload( *itr, version < 2 );
  159. }
  160. }
  161. }
  162. }