androidplaylist.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "./androiddevice.h"
  2. #include "./AndroidPlaylist.h"
  3. #include <shlwapi.h>
  4. #include <strsafe.h>
  5. // dtor
  6. // cleanup the memory allocated for the vector of songs
  7. AndroidPlaylist::~AndroidPlaylist()
  8. {
  9. }
  10. // this is the constructor that gets called
  11. AndroidPlaylist::AndroidPlaylist(AndroidDevice& d, LPCTSTR fileName, BOOL m)
  12. : device(d), master(m), dirty(false)
  13. {
  14. StringCbCopyW(filename, sizeof(filename), fileName);
  15. StringCbCopyW(playlistName, sizeof(playlistName), PathFindFileName(fileName));
  16. StringCbCopyW(playlistPath, sizeof(playlistName), fileName);
  17. PathRemoveFileSpec(playlistPath);
  18. }
  19. void AndroidPlaylist::OnFile( const wchar_t *filename, const wchar_t *title, int lengthInMS, ifc_plentryinfo *info )
  20. {
  21. if ( filename == NULL )
  22. return;
  23. AndroidSong *song = NULL;
  24. //Nullsoft::Utility::AutoLock songs_lock(songs_guard);
  25. song = device.findSongInMasterPlaylist( filename );
  26. songs.push_back( song );
  27. }
  28. size_t AndroidPlaylist::size()
  29. {
  30. //Nullsoft::Utility::AutoLock songs_lock(songs_guard);
  31. return songs.size();
  32. }
  33. AndroidSong *&AndroidPlaylist::at(size_t index)
  34. {
  35. //Nullsoft::Utility::AutoLock songs_lock(songs_guard);
  36. return songs.at(index);
  37. }
  38. void AndroidPlaylist::push_back(AndroidSong *callback)
  39. {
  40. //Nullsoft::Utility::AutoLock songs_lock(songs_guard);
  41. songs.push_back(callback);
  42. dirty=TRUE;
  43. }
  44. void AndroidPlaylist::RemoveSong(AndroidSong *song)
  45. {
  46. //Nullsoft::Utility::AutoLock songs_lock(songs_guard);
  47. size_t old_size = songs.size();
  48. //songs.eraseAll(song);
  49. auto it = songs.begin();
  50. while (it != songs.end())
  51. {
  52. if (*it != song)
  53. {
  54. it++;
  55. continue;
  56. }
  57. it = songs.erase(it);
  58. }
  59. if (old_size != songs.size())
  60. dirty=TRUE;
  61. }
  62. void AndroidPlaylist::swap(size_t index1, size_t index2)
  63. {
  64. //Nullsoft::Utility::AutoLock songs_lock(songs_guard);
  65. AndroidSong *temp = songs[index1];
  66. songs[index1] = songs[index2];
  67. songs[index2] = temp;
  68. dirty = true;
  69. }
  70. void AndroidPlaylist::eraseAt(size_t index)
  71. {
  72. // Nullsoft::Utility::AutoLock songs_lock(songs_guard);
  73. songs.erase(songs.begin() + index);
  74. dirty=true;
  75. }
  76. static int filenamecmp( const wchar_t *f1, const wchar_t *f2 )
  77. {
  78. for ( ;;)
  79. {
  80. wchar_t c1 = *f1++;
  81. wchar_t c2 = *f2++;
  82. if ( !c1 && !c2 )
  83. return 0;
  84. if ( !c1 )
  85. return -1;
  86. if ( !c2 )
  87. return 1;
  88. c1 = towupper( c1 );
  89. c2 = towupper( c2 );
  90. if ( c1 == '\\' )
  91. c1 = '/';
  92. if ( c2 == '\\' )
  93. c2 = '/';
  94. if ( c1 < c2 )
  95. return -1;
  96. else if ( c1 > c2 )
  97. return 1;
  98. }
  99. }
  100. AndroidSong *AndroidPlaylist::FindSong(const wchar_t *filename)
  101. {
  102. //Nullsoft::Utility::AutoLock songs_lock(songs_guard);
  103. for (SongList::iterator e = songs.begin(); e != songs.end(); e++)
  104. {
  105. if (filenamecmp(filename, (*e)->filename) == 0)
  106. {
  107. return (*e);
  108. }
  109. }
  110. return 0;
  111. }
  112. #define CBCLASS AndroidPlaylist
  113. START_DISPATCH;
  114. VCB(IFC_PLAYLISTLOADERCALLBACK_ONFILE, OnFile)
  115. END_DISPATCH;