main.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "main.h"
  2. #include "./navigation.h"
  3. #include "./wasabi.h"
  4. #include "./resource.h"
  5. #include "./external.h"
  6. #include "./wasabiCallback.h"
  7. #include "../nu/MediaLibraryInterface.h"
  8. #include "../replicant/nu/AutoChar.h"
  9. #include "../winamp/wa_ipc.h"
  10. #include "handler.h"
  11. #include "../nu/Singleton.h"
  12. #include "../ml_online/config.h"
  13. #include <strsafe.h>
  14. static NowPlayingURIHandler uri_handler;
  15. static SingletonServiceFactory<svc_urihandler, NowPlayingURIHandler> uri_handler_factory;
  16. static DWORD externalCookie = 0;
  17. static SysCallback *wasabiCallback = NULL;
  18. C_Config *g_config = NULL;
  19. static INT Plugin_Init(void);
  20. static void Plugin_Quit(void);
  21. static INT_PTR Plugin_MessageProc(INT msg, INT_PTR param1, INT_PTR param2, INT_PTR param3);
  22. EXTERN_C winampMediaLibraryPlugin plugin =
  23. {
  24. MLHDR_VER,
  25. "nullsoft(ml_nowplaying.dll)",
  26. Plugin_Init,
  27. Plugin_Quit,
  28. Plugin_MessageProc,
  29. 0,
  30. 0,
  31. 0,
  32. };
  33. HINSTANCE Plugin_GetInstance(void)
  34. {
  35. return plugin.hDllInstance;
  36. }
  37. HWND Plugin_GetWinamp(void)
  38. {
  39. return plugin.hwndWinampParent;
  40. }
  41. HWND Plugin_GetLibrary(void)
  42. {
  43. return plugin.hwndLibraryParent;
  44. }
  45. void initConfigCache()
  46. {
  47. wchar_t iniFileName[2048] = {0};
  48. mediaLibrary.BuildPath(L"Plugins\\ml", iniFileName, 2048);
  49. CreateDirectory(iniFileName, NULL);
  50. mediaLibrary.BuildPath(L"Plugins\\ml\\ml_online.ini", iniFileName, 2048);
  51. AutoChar charFn(iniFileName);
  52. g_config = new C_Config(AutoChar(iniFileName));
  53. }
  54. static INT Plugin_Init(void)
  55. {
  56. if (!WasabiApi_Initialize(Plugin_GetInstance()))
  57. return 1;
  58. if (NULL == OMBROWSERMNGR)
  59. {
  60. WasabiApi_Release();
  61. return 2;
  62. }
  63. mediaLibrary.library = plugin.hwndLibraryParent;
  64. mediaLibrary.winamp = plugin.hwndWinampParent;
  65. mediaLibrary.instance = plugin.hDllInstance;
  66. initConfigCache();
  67. if (NULL != WASABI_API_LNG)
  68. {
  69. static wchar_t szDescription[256];
  70. StringCchPrintf(szDescription, ARRAYSIZE(szDescription), WASABI_API_LNGSTRINGW(IDS_PLUGIN_NAME),
  71. PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR);
  72. plugin.description = (char*)szDescription;
  73. }
  74. ExternalDispatch *externalDispatch;
  75. if (SUCCEEDED(ExternalDispatch::CreateInstance(&externalDispatch)))
  76. {
  77. DispatchInfo dispatchInfo;
  78. dispatchInfo.id = 0;
  79. dispatchInfo.name =(LPWSTR)externalDispatch->GetName();
  80. dispatchInfo.dispatch = externalDispatch;
  81. if (0 == SENDWAIPC(Plugin_GetWinamp(), IPC_ADD_DISPATCH_OBJECT, (WPARAM)&dispatchInfo))
  82. externalCookie = dispatchInfo.id;
  83. externalDispatch->Release();
  84. }
  85. if(NULL != WASABI_API_SYSCB && NULL == wasabiCallback &&
  86. SUCCEEDED(WasabiCallback::CreateInstance((WasabiCallback**)&wasabiCallback)))
  87. {
  88. WASABI_API_SYSCB->syscb_registerCallback(wasabiCallback, 0);
  89. for (;;)
  90. {
  91. SysCallback *callback = WASABI_API_SYSCB->syscb_enum(SysCallback::BROWSER, 0);
  92. if (NULL == callback || callback == wasabiCallback)
  93. {
  94. if (NULL != callback)
  95. callback->Release();
  96. break;
  97. }
  98. WASABI_API_SYSCB->syscb_deregisterCallback(callback);
  99. WASABI_API_SYSCB->syscb_registerCallback(callback, 0);
  100. callback->Release();
  101. }
  102. }
  103. uri_handler_factory.Register(plugin.service, &uri_handler);
  104. Navigation_Initialize();
  105. return 0;
  106. }
  107. static void Plugin_Quit(void)
  108. {
  109. if (NULL != wasabiCallback)
  110. {
  111. if (NULL != WASABI_API_SYSCB)
  112. WASABI_API_SYSCB->syscb_deregisterCallback(wasabiCallback);
  113. wasabiCallback->Release();
  114. wasabiCallback = NULL;
  115. }
  116. if (0 != externalCookie)
  117. {
  118. HWND hWinamp = Plugin_GetWinamp();
  119. SENDWAIPC(hWinamp, IPC_REMOVE_DISPATCH_OBJECT, (WPARAM)externalCookie);
  120. externalCookie = 0;
  121. }
  122. uri_handler_factory.Deregister(plugin.service);
  123. WasabiApi_Release();
  124. }
  125. static INT_PTR Plugin_MessageProc(INT msg, INT_PTR param1, INT_PTR param2, INT_PTR param3)
  126. {
  127. INT_PTR result = 0;
  128. if (FALSE != Navigation_ProcessMessage(msg, param1, param2, param3, &result))
  129. return result;
  130. return FALSE;
  131. }
  132. EXTERN_C __declspec(dllexport) winampMediaLibraryPlugin *winampGetMediaLibraryPlugin()
  133. {
  134. return &plugin;
  135. }