Handler.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #include "Handler.h"
  2. #include "resource.h"
  3. #include "M3ULoader.h"
  4. #include "PLSLoader.h"
  5. #include "B4SLoader.h"
  6. #include <shlwapi.h>
  7. void GetExtension(const wchar_t *filename, wchar_t *ext, size_t extCch)
  8. {
  9. const wchar_t *s = PathFindExtensionW(filename);
  10. if (!PathIsURLW(filename)
  11. || (!wcsstr(s, L"?") && !wcsstr(s, L"&") && !wcsstr(s, L"=") && *s))
  12. {
  13. lstrcpynW(ext, s, (int)extCch);
  14. return ;
  15. }
  16. // s is not a terribly good extension, let's try again
  17. {
  18. wchar_t *copy = _wcsdup(filename);
  19. s = L"";
  20. again:
  21. {
  22. wchar_t *p = StrRChrW(copy,NULL, L'?');
  23. if (p)
  24. {
  25. *p = 0;
  26. s = PathFindExtensionW(copy);
  27. if (!*s) goto again;
  28. }
  29. lstrcpynW(ext, s, (int)extCch);
  30. }
  31. free(copy);
  32. }
  33. }
  34. const wchar_t *M3UHandler::enumExtensions(size_t n)
  35. {
  36. switch(n)
  37. {
  38. case 0:
  39. return L"M3U";
  40. case 1:
  41. return L"M3U8";
  42. default:
  43. return 0;
  44. }
  45. }
  46. int M3UHandler::SupportedFilename(const wchar_t *filename)
  47. {
  48. wchar_t ext[16] = {0};
  49. GetExtension(filename, ext, 16);
  50. if (!lstrcmpiW(ext, L".M3U"))
  51. return SVC_PLAYLISTHANDLER_SUCCESS;
  52. if (!lstrcmpiW(ext, L".M3U8"))
  53. return SVC_PLAYLISTHANDLER_SUCCESS;
  54. return SVC_PLAYLISTHANDLER_FAILED;
  55. }
  56. ifc_playlistloader *M3UHandler::CreateLoader(const wchar_t *filename)
  57. {
  58. return new M3ULoader;
  59. }
  60. void M3UHandler::ReleaseLoader(ifc_playlistloader *loader)
  61. {
  62. M3ULoader *m3u;
  63. m3u = static_cast<M3ULoader *>(loader);
  64. delete m3u;
  65. }
  66. const wchar_t *M3UHandler::GetName()
  67. {
  68. static wchar_t m3upl[64];
  69. // no point re-loading this all of the time since it won't change once we've been loaded
  70. return (!m3upl[0]?WASABI_API_LNGSTRINGW_BUF(IDS_M3U_PLAYLIST,m3upl,64):m3upl);
  71. }
  72. /* ----------------------------------------------------- */
  73. const wchar_t *PLSHandler::enumExtensions(size_t n)
  74. {
  75. switch(n)
  76. {
  77. case 0:
  78. return L"PLS";
  79. default:
  80. return 0;
  81. }
  82. }
  83. int PLSHandler::SupportedFilename(const wchar_t *filename)
  84. {
  85. wchar_t ext[16] = {0};
  86. GetExtension(filename, ext, 16);
  87. if (!lstrcmpiW(ext, L".PLS"))
  88. return SVC_PLAYLISTHANDLER_SUCCESS;
  89. // TODO: open file and sniff it for file signature
  90. return SVC_PLAYLISTHANDLER_FAILED;
  91. }
  92. ifc_playlistloader *PLSHandler::CreateLoader(const wchar_t *filename)
  93. {
  94. return new PLSLoader;
  95. }
  96. void PLSHandler::ReleaseLoader(ifc_playlistloader *loader)
  97. {
  98. PLSLoader *pls;
  99. pls = static_cast<PLSLoader *>(loader);
  100. delete pls;
  101. }
  102. const wchar_t *PLSHandler::GetName()
  103. {
  104. static wchar_t plspl[64];
  105. // no point re-loading this all of the time since it won't change once we've been loaded
  106. return (!plspl[0]?WASABI_API_LNGSTRINGW_BUF(IDS_PLS_PLAYLIST,plspl,64):plspl);
  107. }
  108. /* --- B4S --- */
  109. const wchar_t *B4SHandler::enumExtensions(size_t n)
  110. {
  111. switch(n)
  112. {
  113. case 0:
  114. return L"B4S";
  115. //case 1:
  116. //return L"BPL";
  117. default:
  118. return 0;
  119. }
  120. }
  121. int B4SHandler::SupportedFilename(const wchar_t *filename)
  122. {
  123. wchar_t ext[16] = {0};
  124. GetExtension(filename, ext, 16);
  125. if (!lstrcmpiW(ext, L".B4S"))
  126. return SVC_PLAYLISTHANDLER_SUCCESS;
  127. if (!lstrcmpiW(ext, L".BPL"))
  128. return SVC_PLAYLISTHANDLER_SUCCESS;
  129. // TODO: open file and sniff it for file signature
  130. return SVC_PLAYLISTHANDLER_FAILED;
  131. }
  132. ifc_playlistloader *B4SHandler::CreateLoader(const wchar_t *filename)
  133. {
  134. return new B4SLoader;
  135. }
  136. void B4SHandler::ReleaseLoader(ifc_playlistloader *loader)
  137. {
  138. B4SLoader *pls;
  139. pls = static_cast<B4SLoader *>(loader);
  140. delete pls;
  141. }
  142. const wchar_t *B4SHandler::GetName()
  143. {
  144. static wchar_t wa3pl[64];
  145. // no point re-loading this all of the time since it won't change once we've been loaded
  146. return (!wa3pl[0]?WASABI_API_LNGSTRINGW_BUF(IDS_WINAMP3_PLAYLIST,wa3pl,64):wa3pl);
  147. }
  148. #ifdef CBCLASS
  149. #undef CBCLASS
  150. #endif
  151. #define CBCLASS M3UHandler
  152. START_DISPATCH;
  153. CB(SVC_PLAYLISTHANDLER_ENUMEXTENSIONS, enumExtensions)
  154. CB(SVC_PLAYLISTHANDLER_SUPPORTFILENAME, SupportedFilename)
  155. CB(SVC_PLAYLISTHANDLER_CREATELOADER, CreateLoader)
  156. VCB(SVC_PLAYLISTHANDLER_RELEASELOADER, ReleaseLoader)
  157. CB(SVC_PLAYLISTHANDLER_GETNAME, GetName)
  158. CB(SVC_PLAYLISTHANDLER_HASWRITER, HasWriter)
  159. END_DISPATCH;
  160. #undef CBCLASS
  161. #define CBCLASS PLSHandler
  162. START_DISPATCH;
  163. CB(SVC_PLAYLISTHANDLER_ENUMEXTENSIONS, enumExtensions)
  164. CB(SVC_PLAYLISTHANDLER_SUPPORTFILENAME, SupportedFilename)
  165. CB(SVC_PLAYLISTHANDLER_CREATELOADER, CreateLoader)
  166. VCB(SVC_PLAYLISTHANDLER_RELEASELOADER, ReleaseLoader)
  167. CB(SVC_PLAYLISTHANDLER_GETNAME, GetName)
  168. CB(SVC_PLAYLISTHANDLER_HASWRITER, HasWriter)
  169. END_DISPATCH;
  170. #undef CBCLASS
  171. #define CBCLASS B4SHandler
  172. START_DISPATCH;
  173. CB(SVC_PLAYLISTHANDLER_ENUMEXTENSIONS, enumExtensions)
  174. CB(SVC_PLAYLISTHANDLER_SUPPORTFILENAME, SupportedFilename)
  175. CB(SVC_PLAYLISTHANDLER_CREATELOADER, CreateLoader)
  176. VCB(SVC_PLAYLISTHANDLER_RELEASELOADER, ReleaseLoader)
  177. CB(SVC_PLAYLISTHANDLER_GETNAME, GetName)
  178. CB(SVC_PLAYLISTHANDLER_HASWRITER, HasWriter)
  179. END_DISPATCH;