1
0

main.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #include "main.h"
  2. #include "../Winamp/wa_ipc.h"
  3. #include "api__ml_iso.h"
  4. #include <api/service/waservicefactory.h>
  5. /* wasabi services we'll be using */
  6. api_service *WASABI_API_SVC = 0;
  7. api_application *WASABI_API_APP = 0;
  8. api_playlistmanager *AGAVE_API_PLAYLISTMANAGER = 0;
  9. /* gen_ml calls this function when it loads your plugin. return non-zero to abort loading your plugin */
  10. int Init()
  11. {
  12. // this plugin requires an interface only present on 5.54 and up, so we'll just refuse to load on older versions
  13. if (SendMessage(plugin.hwndWinampParent, WM_WA_IPC, 0, IPC_GETVERSION) < 0x5054)
  14. return 1;
  15. // go ahead and grab the wasabi service manager. we'll need it later when we get an ISO Creator object
  16. WASABI_API_SVC = (api_service *)SendMessage(plugin.hwndWinampParent, WM_WA_IPC, 0, IPC_GET_API_SERVICE);
  17. // get the application API
  18. // we need this to get/set Winamp's current working directory
  19. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(applicationApiServiceGuid);
  20. if (factory)
  21. WASABI_API_APP = (api_application *)factory->getInterface();
  22. // get the playlist manager API
  23. // we'll need this for loading playlists
  24. factory = WASABI_API_SVC->service_getServiceByGuid(api_playlistmanagerGUID);
  25. if (factory)
  26. AGAVE_API_PLAYLISTMANAGER = (api_playlistmanager *)factory->getInterface();
  27. // this media library plugin doesn't add a node to the treeview, so we don't really do anything in here besides
  28. // grabbing the service manager
  29. // all of the action will come via Send-To which is handled in MessageProc
  30. return 0;
  31. }
  32. void Quit()
  33. {
  34. }
  35. INT_PTR MessageProc(int message_type, INT_PTR param1, INT_PTR param2, INT_PTR param3)
  36. {
  37. switch(message_type)
  38. {
  39. // this gets sent when Winamp wants to build the send-to menu. If we want to be in the send-to
  40. // we make some API calls during this function
  41. case ML_MSG_ONSENDTOBUILD:
  42. {
  43. INT_PTR source_type = param1; // param 1 is the source type
  44. INT_PTR context = param2; // param 2 is just some context value that we have to use when we call back into the API
  45. // we only accept certain types of sources, so we'll explicitly check
  46. // if we were to handle ALL types, checking against the known types
  47. // is good practice in case new Winamp versions add additional source types
  48. switch(source_type)
  49. {
  50. case ML_TYPE_ITEMRECORDLIST: // Item Record List. Used by the local media library
  51. case ML_TYPE_FILENAMES: // raw list of filenames
  52. case ML_TYPE_PLAYLIST: // a playlist. we'll use the playlist loading API to crack it open
  53. case ML_TYPE_PLAYLISTS: // a list of playlists. we'll use the playlist loading API to crack each one open
  54. case ML_TYPE_ITEMRECORDLISTW: // unicode version of an Item Record List
  55. case ML_TYPE_FILENAMESW: // raw list of unicode filenames
  56. {
  57. // add ourselves to the send-to menu!
  58. mlAddToSendToStructW s;
  59. s.context = context; // pass in the context value passed to this function.
  60. s.desc = L"Create new ISO image";
  61. s.user32 = (INT_PTR)MessageProc; // this value has to be some unique value that you can identify later
  62. // by convention, use the pointer to this function, since it's obviously unique
  63. SendMessage(plugin.hwndLibraryParent, WM_ML_IPC, (WPARAM)&s, ML_IPC_ADDTOSENDTOW);
  64. }
  65. // returning 0 tells the media library to continue building the send-to menu
  66. // it doesn't mean we added or didn't add items to the send-to menu
  67. return 0;
  68. case ML_TYPE_STREAMNAMES: // doesn't make sense to burn a stream to an ISO file so we won't even popup on the send-to menu when it's streams
  69. case ML_TYPE_CDTRACKS: // we'll avoid CD tracks. in theory we could use the ripping API but let's not complicate this example
  70. case ML_TYPE_QUERYSTRING: // media library query. not sure that this is even used anywhere. either way we're not going to handle it
  71. case ML_TYPE_STREAMNAMESW: // don't cross the streams
  72. case ML_TYPE_TREEITEM: // not even sure this is used
  73. // break out of here because it's not supported. returning 0 just tells the send-to menu to continue building,
  74. // it doesn't mean we added or didn't add items to the send-to menu
  75. return 0;
  76. }
  77. // shouldn't get here
  78. return 0;
  79. }
  80. // this gets sent when a send-to menu item got selected
  81. // it might be ours. it might not.
  82. case ML_MSG_ONSENDTOSELECT:
  83. {
  84. // let's see if it's ours. We check 'user32' against the function pointer for this function
  85. INT_PTR unique = param3;
  86. if (unique != (INT_PTR)MessageProc) // not ours? let's bail
  87. return 0; // remember to always return 0 or else other media library plugins won't get the notification
  88. INT_PTR type = param1; // what type of data got sent
  89. INT_PTR data = param2; // pointer to the data. depends on the type
  90. switch(type)
  91. {
  92. case ML_TYPE_ITEMRECORDLIST: // Item Record List. Used by the local media library
  93. ConvertItemRecordListToISO((const itemRecordList *)data);
  94. return 1; // return 1 to say we handled it
  95. case ML_TYPE_FILENAMES: // raw list of filenames
  96. ConvertFilenamesToISO((const char *)data);
  97. return 1; // return 1 to say we handled it
  98. case ML_TYPE_PLAYLIST: // a playlist. we'll use the playlist loading API to crack it open
  99. ConvertPlaylistToISO((const mlPlaylist *)data);
  100. return 1; // return 1 to say we handled it
  101. case ML_TYPE_PLAYLISTS: // a list of playlists. we'll use the playlist loading API to crack each one open
  102. ConvertPlaylistsToISO((const mlPlaylist **)data);
  103. return 1; // return 1 to say we handled it
  104. case ML_TYPE_ITEMRECORDLISTW: // unicode version of an Item Record List
  105. ConvertUnicodeItemRecordListToISO((const itemRecordListW *)data);
  106. return 1; // return 1 to say we handled it
  107. case ML_TYPE_FILENAMESW: // raw list of unicode filenames
  108. ConvertUnicodeFilenamesToISO((const wchar_t *)data);
  109. return 1; // return 1 to say we handled it
  110. default: // something we didn't support
  111. return 0;
  112. }
  113. }
  114. }
  115. return 0;
  116. }
  117. winampMediaLibraryPlugin plugin =
  118. {
  119. MLHDR_VER,
  120. "ISO Creator",
  121. Init,
  122. Quit,
  123. MessageProc,
  124. 0,
  125. 0,
  126. 0,
  127. };
  128. extern "C" __declspec(dllexport) winampMediaLibraryPlugin *winampGetMediaLibraryPlugin()
  129. {
  130. return &plugin;
  131. }