androidplaylistsaver.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "./androidplaylistsaver.h"
  2. #include "./androidplaylist.h"
  3. #include "./androiddevice.h"
  4. #include "./api.h"
  5. #include <strsafe.h>
  6. AndroidPlaylistSaver::AndroidPlaylistSaver(LPCTSTR iFilename, LPCTSTR iPlaylistName, AndroidPlaylist *iPlaylist)
  7. : filename((LPTSTR)iFilename), title((LPTSTR)iPlaylistName), playlist(iPlaylist)
  8. {
  9. }
  10. AndroidPlaylistSaver::~AndroidPlaylistSaver()
  11. {
  12. }
  13. HRESULT AndroidPlaylistSaver::Save()
  14. {
  15. INT result = WASABI_API_PLAYLISTMNGR->Save(filename, this);
  16. return (PLAYLISTMANAGER_SUCCESS == result) ? S_OK : E_FAIL;
  17. }
  18. size_t AndroidPlaylistSaver::GetNumItems()
  19. {
  20. return playlist->size();
  21. }
  22. size_t AndroidPlaylistSaver::GetItem(size_t item, wchar_t *filename, size_t filenameCch)
  23. {
  24. AndroidSong* song = (AndroidSong *) playlist->at(item);
  25. if (!song) return 0;
  26. HRESULT hr = StringCchCopyEx(filename, filenameCch, song->filename, NULL, NULL, STRSAFE_IGNORE_NULLS);
  27. if (FAILED(hr))
  28. *filename = L'\0';
  29. return SUCCEEDED(hr);
  30. }
  31. size_t AndroidPlaylistSaver::GetItemTitle(size_t item, wchar_t *title, size_t titleCch)
  32. {
  33. AndroidSong* song = (AndroidSong *) playlist->at(item);
  34. if (!song) return 0;
  35. HRESULT hr = StringCchCopyEx(title, titleCch, song->title, NULL, NULL, STRSAFE_IGNORE_NULLS);
  36. if (FAILED(hr))
  37. *title = L'\0';
  38. return SUCCEEDED(hr);
  39. }
  40. int AndroidPlaylistSaver::GetItemLengthMs(size_t item)
  41. {
  42. AndroidSong* song = (AndroidSong *) playlist->at(item);
  43. if (!song) return 0;
  44. return song->length ? song->length: -1;
  45. }
  46. size_t AndroidPlaylistSaver::GetItemExtendedInfo(size_t item, const wchar_t *metadata, wchar_t *info, size_t infoCch)
  47. {
  48. return 0;
  49. }
  50. #define CBCLASS AndroidPlaylistSaver
  51. START_DISPATCH;
  52. CB(IFC_PLAYLIST_GETNUMITEMS, GetNumItems)
  53. CB(IFC_PLAYLIST_GETITEM, GetItem)
  54. CB(IFC_PLAYLIST_GETITEMTITLE, GetItemTitle)
  55. CB(IFC_PLAYLIST_GETITEMLENGTHMILLISECONDS, GetItemLengthMs)
  56. CB(IFC_PLAYLIST_GETITEMEXTENDEDINFO, GetItemExtendedInfo)
  57. END_DISPATCH;