usbplaylistsaver.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "./usbplaylistsaver.h"
  2. #include "./usbplaylist.h"
  3. #include "./usbdevice.h"
  4. #include "./api.h"
  5. #include <strsafe.h>
  6. USBPlaylistSaver::USBPlaylistSaver(LPCTSTR iFilename, LPCTSTR iPlaylistName, USBPlaylist *iPlaylist)
  7. : title((LPTSTR)iPlaylistName), filename((LPTSTR)iFilename), playlist(iPlaylist)
  8. {
  9. }
  10. USBPlaylistSaver::~USBPlaylistSaver()
  11. {
  12. }
  13. HRESULT USBPlaylistSaver::Save()
  14. {
  15. INT result = WASABI_API_PLAYLISTMNGR->Save(filename, this);
  16. return (PLAYLISTMANAGER_SUCCESS == result) ? S_OK : E_FAIL;
  17. }
  18. size_t USBPlaylistSaver::GetNumItems()
  19. {
  20. return (size_t) playlist->songs.size();
  21. }
  22. size_t USBPlaylistSaver::GetItem(size_t item, wchar_t *filename, size_t filenameCch)
  23. {
  24. UsbSong* song = (UsbSong *) playlist->songs.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 USBPlaylistSaver::GetItemTitle(size_t item, wchar_t *title, size_t titleCch)
  32. {
  33. UsbSong* song = (UsbSong *) playlist->songs.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 USBPlaylistSaver::GetItemLengthMs(size_t item)
  41. {
  42. UsbSong* song = (UsbSong *) playlist->songs.at(item);
  43. if (!song) return 0;
  44. return song->length ? song->length: -1;
  45. }
  46. size_t USBPlaylistSaver::GetItemExtendedInfo(size_t item, const wchar_t *metadata, wchar_t *info, size_t infoCch)
  47. {
  48. return 0;
  49. }
  50. #define CBCLASS USBPlaylistSaver
  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;