main.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //#define PLUGIN_NAME "Nullsoft Bookmarks"
  2. #define PLUGIN_VERSION L"1.27"
  3. #include "Main.h"
  4. #include "../nu/AutoWide.h"
  5. #include <strsafe.h>
  6. #include "../../General/gen_ml/menu.h"
  7. #include "../../General/gen_ml/ml_ipc_0313.h"
  8. static int Init();
  9. static void Quit();
  10. extern "C" winampMediaLibraryPlugin plugin =
  11. {
  12. MLHDR_VER,
  13. "nullsoft(ml_bookmarks.dll)",
  14. Init,
  15. Quit,
  16. bm_pluginMessageProc,
  17. 0,
  18. 0,
  19. 0,
  20. };
  21. int bookmark_treeItem = 0;
  22. HMENU g_context_menus, g_context_menus2;
  23. HCURSOR hDragNDropCursor;
  24. C_Config *g_config;
  25. WNDPROC waProc=0;
  26. // wasabi based services for localisation support
  27. api_language *WASABI_API_LNG = 0;
  28. HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
  29. api_stats *AGAVE_API_STATS = 0;
  30. api_application *WASABI_API_APP = 0;
  31. static DWORD WINAPI wa_newWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  32. {
  33. if (msg == WM_WA_IPC && lParam == IPC_ADDBOOKMARK && wParam && wParam != 666)
  34. {
  35. bookmark_notifyAdd(AutoWide((char*)wParam));
  36. }
  37. else if (msg == WM_WA_IPC && lParam == IPC_ADDBOOKMARKW && wParam && wParam != 666)
  38. {
  39. bookmark_notifyAdd((wchar_t*)wParam);
  40. }
  41. else if ((msg == WM_COMMAND || msg == WM_SYSCOMMAND) && LOWORD(wParam) == WINAMP_EDIT_BOOKMARKS)
  42. {
  43. mediaLibrary.ShowMediaLibrary();
  44. mediaLibrary.SwitchToPluginView(bookmark_treeItem);
  45. return 0;
  46. }
  47. if (waProc)
  48. return (DWORD)CallWindowProcW(waProc, hwnd, msg, wParam, lParam);
  49. else
  50. return (DWORD)DefWindowProc(hwnd, msg, wParam, lParam);
  51. }
  52. int Init()
  53. {
  54. waProc = (WNDPROC)SetWindowLongPtrW( plugin.hwndWinampParent, GWLP_WNDPROC, (LONG_PTR)wa_newWndProc );
  55. mediaLibrary.library = plugin.hwndLibraryParent;
  56. mediaLibrary.winamp = plugin.hwndWinampParent;
  57. mediaLibrary.instance = plugin.hDllInstance;
  58. waServiceFactory *sf = plugin.service->service_getServiceByGuid( languageApiGUID );
  59. if ( sf )
  60. WASABI_API_LNG = reinterpret_cast<api_language *>( sf->getInterface() );
  61. sf = plugin.service->service_getServiceByGuid( AnonymousStatsGUID );
  62. if ( sf )
  63. AGAVE_API_STATS = reinterpret_cast<api_stats *>( sf->getInterface() );
  64. sf = plugin.service->service_getServiceByGuid( applicationApiServiceGuid );
  65. if ( sf )
  66. WASABI_API_APP = reinterpret_cast<api_application *>( sf->getInterface() );
  67. // need to have this initialised before we try to do anything with localisation features
  68. WASABI_API_START_LANG( plugin.hDllInstance, MlBookmarkLangGUID );
  69. static wchar_t szDescription[ 256 ];
  70. StringCchPrintfW( szDescription, ARRAYSIZE( szDescription ), WASABI_API_LNGSTRINGW( IDS_NULLSOFT_BOOKMARKS ), PLUGIN_VERSION );
  71. plugin.description = (char *)szDescription;
  72. wchar_t inifile[ MAX_PATH ] = { 0 };
  73. mediaLibrary.BuildPath( L"Plugins", inifile, MAX_PATH );
  74. CreateDirectoryW( inifile, NULL );
  75. mediaLibrary.BuildPath( L"Plugins\\gen_ml.ini", inifile, MAX_PATH );
  76. g_config = new C_Config( inifile );
  77. g_context_menus = WASABI_API_LOADMENU( IDR_MENU1 );
  78. g_context_menus2 = WASABI_API_LOADMENU( IDR_MENU1 );
  79. hDragNDropCursor = LoadCursor( GetModuleHandle( L"gen_ml.dll" ), MAKEINTRESOURCE( ML_IDC_DRAGDROP ) );
  80. NAVINSERTSTRUCT nis = { 0 };
  81. nis.item.cbSize = sizeof( NAVITEM );
  82. nis.item.pszText = WASABI_API_LNGSTRINGW( IDS_BOOKMARKS );
  83. nis.item.pszInvariant = L"Bookmarks";
  84. nis.item.mask = NIMF_TEXT | NIMF_TEXTINVARIANT | NIMF_IMAGE | NIMF_IMAGESEL;
  85. nis.item.iSelectedImage = nis.item.iImage = mediaLibrary.AddTreeImageBmp( IDB_TREEITEM_BOOKMARKS );
  86. // map to item id (will probably have to change but is a quick port to support invariant item naming)
  87. NAVITEM nvItem = { sizeof( NAVITEM ),0,NIMF_ITEMID, };
  88. nvItem.hItem = MLNavCtrl_InsertItem( plugin.hwndLibraryParent, &nis );
  89. MLNavItem_GetInfo( plugin.hwndLibraryParent, &nvItem );
  90. bookmark_treeItem = nvItem.id;
  91. return 0;
  92. }
  93. void Quit()
  94. {
  95. delete g_config;
  96. }
  97. extern "C" __declspec(dllexport) winampMediaLibraryPlugin *winampGetMediaLibraryPlugin()
  98. {
  99. return &plugin;
  100. }