Wasabi.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "Winamp/in2.h"
  2. #include "Winamp/wa_ipc.h"
  3. #include "Wasabi.h"
  4. AlbumArtFactory albumArtFactory;
  5. class WavPack_AlbumArtProvider : public svc_albumArtProvider
  6. {
  7. public:
  8. bool IsMine(const wchar_t *filename);
  9. int ProviderType();
  10. // implementation note: use WASABI_API_MEMMGR to alloc bits and mimetype, so that the recipient can free through that
  11. int GetAlbumArtData(const wchar_t *filename, const wchar_t *type, void **bits, size_t *len, wchar_t **mimeType);
  12. int SetAlbumArtData(const wchar_t *filename, const wchar_t *type, void *bits, size_t len, const wchar_t *mimeType);
  13. int DeleteAlbumArt(const wchar_t *filename, const wchar_t *type);
  14. protected:
  15. RECVS_DISPATCH;
  16. };
  17. static const wchar_t *GetLastCharactercW(const wchar_t *string)
  18. {
  19. if (!string || !*string)
  20. return string;
  21. return CharPrevW(string, string+lstrlenW(string));
  22. }
  23. static const wchar_t *scanstr_backW(const wchar_t *str, const wchar_t *toscan, const wchar_t *defval)
  24. {
  25. const wchar_t *s = GetLastCharactercW(str);
  26. if (!str[0]) return defval;
  27. if (!toscan || !toscan[0]) return defval;
  28. while (1)
  29. {
  30. const wchar_t *t = toscan;
  31. while (*t)
  32. {
  33. if (*t == *s) return s;
  34. t = CharNextW(t);
  35. }
  36. t = CharPrevW(str, s);
  37. if (t == s)
  38. return defval;
  39. s = t;
  40. }
  41. }
  42. static const wchar_t *extensionW(const wchar_t *fn)
  43. {
  44. const wchar_t *end = scanstr_backW(fn, L"./\\", 0);
  45. if (!end)
  46. return (fn+lstrlenW(fn));
  47. if (*end == L'.')
  48. return end+1;
  49. return (fn+lstrlenW(fn));
  50. }
  51. int WavPack_HandlesExtension(const wchar_t *extension);
  52. bool WavPack_AlbumArtProvider::IsMine(const wchar_t *filename)
  53. {
  54. const wchar_t *extension = extensionW(filename);
  55. if (extension && *extension)
  56. {
  57. return WavPack_HandlesExtension(extension) != 0;
  58. }
  59. return false;
  60. }
  61. int WavPack_AlbumArtProvider::ProviderType()
  62. {
  63. return ALBUMARTPROVIDER_TYPE_EMBEDDED;
  64. }
  65. int WavPack_GetAlbumArt(const wchar_t *filename, const wchar_t *type, void **bits, size_t *len, wchar_t **mime_type);
  66. int WavPack_AlbumArtProvider::GetAlbumArtData(const wchar_t *filename, const wchar_t *type, void **bits, size_t *len, wchar_t **mime_type)
  67. {
  68. return WavPack_GetAlbumArt(filename, type, bits, len, mime_type);
  69. }
  70. int WavPack_SetAlbumArt(const wchar_t *filename, const wchar_t *type, void *bits, size_t len, const wchar_t *mime_type);
  71. int WavPack_AlbumArtProvider::SetAlbumArtData(const wchar_t *filename, const wchar_t *type, void *bits, size_t len, const wchar_t *mime_type)
  72. {
  73. return WavPack_SetAlbumArt(filename, type, bits, len, mime_type);
  74. }
  75. int WavPack_DeleteAlbumArt(const wchar_t *filename, const wchar_t *type);
  76. int WavPack_AlbumArtProvider::DeleteAlbumArt(const wchar_t *filename, const wchar_t *type)
  77. {
  78. return WavPack_DeleteAlbumArt(filename, type);
  79. }
  80. #define CBCLASS WavPack_AlbumArtProvider
  81. START_DISPATCH;
  82. CB(SVC_ALBUMARTPROVIDER_PROVIDERTYPE, ProviderType);
  83. CB(SVC_ALBUMARTPROVIDER_GETALBUMARTDATA, GetAlbumArtData);
  84. CB(SVC_ALBUMARTPROVIDER_ISMINE, IsMine);
  85. CB(SVC_ALBUMARTPROVIDER_SETALBUMARTDATA, SetAlbumArtData);
  86. CB(SVC_ALBUMARTPROVIDER_DELETEALBUMART, DeleteAlbumArt);
  87. END_DISPATCH;
  88. #undef CBCLASS
  89. static WavPack_AlbumArtProvider albumArtProvider;
  90. // {A558560E-4334-446a-9219-E1F34F518ADE}
  91. static const GUID wavpack_albumartproviderGUID =
  92. { 0xa558560e, 0x4334, 0x446a, { 0x92, 0x19, 0xe1, 0xf3, 0x4f, 0x51, 0x8a, 0xde } };
  93. FOURCC AlbumArtFactory::GetServiceType()
  94. {
  95. return svc_albumArtProvider::SERVICETYPE;
  96. }
  97. const char *AlbumArtFactory::GetServiceName()
  98. {
  99. return "WavPack Album Art Provider";
  100. }
  101. GUID AlbumArtFactory::GetGUID()
  102. {
  103. return wavpack_albumartproviderGUID;
  104. }
  105. void *AlbumArtFactory::GetInterface(int global_lock)
  106. {
  107. return &albumArtProvider;
  108. }
  109. int AlbumArtFactory::SupportNonLockingInterface()
  110. {
  111. return 1;
  112. }
  113. int AlbumArtFactory::ReleaseInterface(void *ifc)
  114. {
  115. return 1;
  116. }
  117. const char *AlbumArtFactory::GetTestString()
  118. {
  119. return 0;
  120. }
  121. int AlbumArtFactory::ServiceNotify(int msg, int param1, int param2)
  122. {
  123. return 1;
  124. }
  125. #define CBCLASS AlbumArtFactory
  126. START_DISPATCH;
  127. CB(WASERVICEFACTORY_GETSERVICETYPE, GetServiceType)
  128. CB(WASERVICEFACTORY_GETSERVICENAME, GetServiceName)
  129. CB(WASERVICEFACTORY_GETGUID, GetGUID)
  130. CB(WASERVICEFACTORY_GETINTERFACE, GetInterface)
  131. CB(WASERVICEFACTORY_SUPPORTNONLOCKINGGETINTERFACE, SupportNonLockingInterface)
  132. CB(WASERVICEFACTORY_RELEASEINTERFACE, ReleaseInterface)
  133. CB(WASERVICEFACTORY_GETTESTSTRING, GetTestString)
  134. CB(WASERVICEFACTORY_SERVICENOTIFY, ServiceNotify)
  135. END_DISPATCH;
  136. #undef CBCLASS