PlaylistHandler.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #include "main.h"
  2. #include "config.h"
  3. #include "PlaylistHandler.h"
  4. #include "WPLLoader.h"
  5. #include "ASXLoader.h"
  6. #include <shlwapi.h>
  7. #include "resource.h"
  8. void GetExtension(const wchar_t *filename, wchar_t *ext, size_t extCch)
  9. {
  10. const wchar_t *s = PathFindExtensionW(filename);
  11. if (!PathIsURLW(filename)
  12. || (!wcsstr(s, L"?") && !wcsstr(s, L"&") && !wcsstr(s, L"=") && *s))
  13. {
  14. lstrcpynW(ext, s, extCch);
  15. return ;
  16. }
  17. // s is not a terribly good extension, let's try again
  18. {
  19. wchar_t *copy = _wcsdup(filename);
  20. s = L"";
  21. again:
  22. {
  23. wchar_t *p = StrRChrW(copy,NULL, L'?');
  24. if (p)
  25. {
  26. *p = 0;
  27. s = PathFindExtensionW(copy);
  28. if (!*s) goto again;
  29. }
  30. lstrcpynW(ext, s, extCch);
  31. }
  32. free(copy);
  33. }
  34. }
  35. /* ---------------------------------- WPL --------------------------------------- */
  36. const wchar_t *WPLHandler::enumExtensions(size_t n)
  37. {
  38. switch(n)
  39. {
  40. case 0:
  41. return L"WPL";
  42. /*case 1:
  43. return L"ZPL";*/
  44. default:
  45. return 0;
  46. }
  47. }
  48. int WPLHandler::SupportedFilename(const wchar_t *filename)
  49. {
  50. wchar_t ext[16] = {0};
  51. GetExtension(filename, ext, 16);
  52. if (!lstrcmpiW(ext, L".WPL") || !lstrcmpiW(ext, L".ZPL"))
  53. return SVC_PLAYLISTHANDLER_SUCCESS;
  54. // TODO: open file and sniff it for file signature
  55. return SVC_PLAYLISTHANDLER_FAILED;
  56. }
  57. ifc_playlistloader *WPLHandler::CreateLoader(const wchar_t *filename)
  58. {
  59. return new WPLLoader;
  60. }
  61. void WPLHandler::ReleaseLoader(ifc_playlistloader *loader)
  62. {
  63. WPLLoader *pls;
  64. pls = static_cast<WPLLoader *>(loader);
  65. delete pls;
  66. }
  67. const wchar_t *WPLHandler::GetName()
  68. {
  69. static wchar_t wplpl[64];
  70. // no point re-loading this all of the time since it won't change once we've been loaded
  71. return (!wplpl[0]?WASABI_API_LNGSTRINGW_BUF(IDS_WINDOWS_MEDIA_PLAYLIST,wplpl,64):wplpl);
  72. }
  73. /* --- ASX --- */
  74. const wchar_t *ASXHandler::enumExtensions(size_t n)
  75. {
  76. switch(n)
  77. {
  78. case 0:
  79. return L"ASX";
  80. case 1:
  81. if (config_extra_asx_extensions)
  82. return L"WAX";
  83. else
  84. return 0;
  85. case 2:
  86. if (config_extra_asx_extensions)
  87. return L"WMX";
  88. else
  89. return 0;
  90. case 3:
  91. if (config_extra_asx_extensions)
  92. return L"WVX";
  93. else
  94. return 0;
  95. default:
  96. return 0;
  97. }
  98. }
  99. int ASXHandler::SupportedFilename(const wchar_t *filename)
  100. {
  101. wchar_t ext[16] = {0};
  102. GetExtension(filename, ext, 16);
  103. if (!lstrcmpiW(ext, L".ASX"))
  104. return SVC_PLAYLISTHANDLER_SUCCESS;
  105. if (!lstrcmpiW(ext, L".WAX"))
  106. return SVC_PLAYLISTHANDLER_SUCCESS;
  107. if (!lstrcmpiW(ext, L".WMX"))
  108. return SVC_PLAYLISTHANDLER_SUCCESS;
  109. if (!lstrcmpiW(ext, L".WVX"))
  110. return SVC_PLAYLISTHANDLER_SUCCESS;
  111. // TODO: open file and sniff it for file signature
  112. return SVC_PLAYLISTHANDLER_FAILED;
  113. }
  114. ifc_playlistloader *ASXHandler::CreateLoader(const wchar_t *filename)
  115. {
  116. return new ASXLoader;
  117. }
  118. void ASXHandler::ReleaseLoader(ifc_playlistloader *loader)
  119. {
  120. ASXLoader *pls;
  121. pls = static_cast<ASXLoader *>(loader);
  122. delete pls;
  123. }
  124. const wchar_t *ASXHandler::GetName()
  125. {
  126. static wchar_t asxpl[64];
  127. // no point re-loading this all of the time since it won't change once we've been loaded
  128. return (!asxpl[0]?WASABI_API_LNGSTRINGW_BUF(IDS_ASX_PLAYLIST,asxpl,64):asxpl);
  129. }
  130. #define CBCLASS WPLHandler
  131. START_DISPATCH;
  132. CB(SVC_PLAYLISTHANDLER_ENUMEXTENSIONS, enumExtensions)
  133. CB(SVC_PLAYLISTHANDLER_SUPPORTFILENAME, SupportedFilename)
  134. CB(SVC_PLAYLISTHANDLER_CREATELOADER, CreateLoader)
  135. VCB(SVC_PLAYLISTHANDLER_RELEASELOADER, ReleaseLoader)
  136. CB(SVC_PLAYLISTHANDLER_GETNAME, GetName)
  137. END_DISPATCH;
  138. #undef CBCLASS
  139. #define CBCLASS ASXHandler
  140. START_DISPATCH;
  141. CB(SVC_PLAYLISTHANDLER_ENUMEXTENSIONS, enumExtensions)
  142. CB(SVC_PLAYLISTHANDLER_SUPPORTFILENAME, SupportedFilename)
  143. CB(SVC_PLAYLISTHANDLER_CREATELOADER, CreateLoader)
  144. VCB(SVC_PLAYLISTHANDLER_RELEASELOADER, ReleaseLoader)
  145. CB(SVC_PLAYLISTHANDLER_GETNAME, GetName)
  146. END_DISPATCH;
  147. #undef CBCLASS