MediaLibraryInterface.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. #include "MediaLibraryInterface.h"
  2. #include <commctrl.h>
  3. #include "../nu/ns_wc.h"
  4. #include "../winamp/wa_ipc.h"
  5. #include "../Agave/Language/api_language.h"
  6. #define _ML_HEADER_IMPMLEMENT
  7. #include "..\Plugins\General\gen_ml/ml_ipc_0313.h"
  8. #undef _ML_HEADER_IMPMLEMENT
  9. #include "..\Plugins\General\gen_ml/ml_imageloader.h"
  10. #include <shlwapi.h>
  11. #include <strsafe.h>
  12. MediaLibraryInterface mediaLibrary;
  13. void MediaLibraryInterface::AddTreeItem(MLTREEITEM &newItem)
  14. {
  15. SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_ADD);
  16. }
  17. void MediaLibraryInterface::AddTreeItem(MLTREEITEMW &newItem)
  18. {
  19. SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_ADDW);
  20. }
  21. int MediaLibraryInterface::AddTreeImage(int resourceId)
  22. {
  23. return AddTreeImage(resourceId, -1, (BMPFILTERPROC)FILTER_DEFAULT1);
  24. }
  25. int MediaLibraryInterface::AddTreeImage(int resourceId, int imageIndex, BMPFILTERPROC filter)
  26. {
  27. MLTREEIMAGE img = {instance, resourceId, imageIndex, filter, 0, 0};
  28. return (int)(INT_PTR)SendMessage(library, WM_ML_IPC, (WPARAM) &img, ML_IPC_TREEIMAGE_ADD);
  29. }
  30. int MediaLibraryInterface::AddTreeImageBmp(int resourceId)
  31. {
  32. HMLIMGLST hmlilNavigation = MLNavCtrl_GetImageList(library);
  33. MLIMAGESOURCE mlis = {sizeof(MLIMAGESOURCE),0};
  34. MLIMAGELISTITEM item = {0};
  35. item.cbSize = sizeof( MLIMAGELISTITEM );
  36. item.hmlil = hmlilNavigation;
  37. item.filterUID = MLIF_FILTER1_UID;
  38. item.pmlImgSource = &mlis;
  39. mlis.hInst = instance;
  40. mlis.bpp = 24;
  41. mlis.lpszName = MAKEINTRESOURCEW(resourceId);
  42. mlis.type = SRC_TYPE_BMP;
  43. mlis.flags = ISF_FORCE_BPP;
  44. return MLImageList_Add(library, &item);
  45. }
  46. void MediaLibraryInterface::SetTreeItem(MLTREEITEM &item)
  47. {
  48. MLTREEITEMINFO ii = {0};
  49. ii.item = item;
  50. ii.mask = MLTI_IMAGE | MLTI_CHILDREN | MLTI_TEXT | MLTI_ID;
  51. SendMessage(library, WM_ML_IPC, (WPARAM) &ii, ML_IPC_TREEITEM_SETINFO);
  52. }
  53. void MediaLibraryInterface::SetTreeItem(MLTREEITEMW &item)
  54. {
  55. MLTREEITEMINFOW ii = {0};
  56. ii.item = item;
  57. ii.mask = MLTI_IMAGE | MLTI_CHILDREN | MLTI_TEXT | MLTI_ID;
  58. SendMessage(library, WM_ML_IPC, (WPARAM) &ii, ML_IPC_TREEITEM_SETINFOW);
  59. }
  60. void MediaLibraryInterface::InsertTreeItem(MLTREEITEM &newItem)
  61. {
  62. SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_INSERT);
  63. }
  64. void MediaLibraryInterface::InsertTreeItem(MLTREEITEMW &newItem)
  65. {
  66. SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_INSERTW);
  67. }
  68. void MediaLibraryInterface::RemoveTreeItem(INT_PTR treeId)
  69. {
  70. SendMessage(library, WM_ML_IPC, (WPARAM)treeId, ML_IPC_DELTREEITEM);
  71. }
  72. void MediaLibraryInterface::SelectTreeItem(INT_PTR treeId)
  73. {
  74. SendMessage(library, WM_ML_IPC, (WPARAM)treeId, ML_IPC_SETCURTREEITEM);
  75. }
  76. INT_PTR MediaLibraryInterface::GetSelectedTreeItem(void)
  77. {
  78. return (INT_PTR)SendMessage(library, WM_ML_IPC, 0, ML_IPC_GETCURTREEITEM);
  79. }
  80. void MediaLibraryInterface::UpdateTreeItem(MLTREEITEMINFO &newItem)
  81. {
  82. SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_SETINFO);
  83. }
  84. void MediaLibraryInterface::UpdateTreeItem(MLTREEITEMINFOW &newItem)
  85. {
  86. SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_SETINFOW);
  87. }
  88. int MediaLibraryInterface::SkinList(HWND list)
  89. {
  90. return (int)(INT_PTR)SendMessage(library, WM_ML_IPC, (WPARAM)list, ML_IPC_SKIN_LISTVIEW);
  91. }
  92. void MediaLibraryInterface::UnskinList(int token)
  93. {
  94. SendMessage(library, WM_ML_IPC, (WPARAM)token, ML_IPC_UNSKIN_LISTVIEW);
  95. }
  96. void MediaLibraryInterface::ListViewShowSort(int token, BOOL show)
  97. {
  98. LV_SKIN_SHOWSORT lvs = {0};
  99. lvs.listView = token;
  100. lvs.showSort = show;
  101. SendMessage(library, WM_ML_IPC, (WPARAM)&lvs, ML_IPC_LISTVIEW_SHOWSORT);
  102. }
  103. void MediaLibraryInterface::ListViewSort(int token, int columnIndex, BOOL ascending)
  104. {
  105. LV_SKIN_SORT lvs = {0};
  106. lvs.listView = token;
  107. lvs.ascending = ascending;
  108. lvs.columnIndex = columnIndex;
  109. SendMessage(library, WM_ML_IPC, (WPARAM)&lvs, ML_IPC_LISTVIEW_SORT);
  110. }
  111. void MediaLibraryInterface::ListSkinUpdateView(int listSkin)
  112. {
  113. SendMessage(library, WM_ML_IPC, listSkin, ML_IPC_LISTVIEW_UPDATE);
  114. }
  115. void *MediaLibraryInterface::GetWADLGFunc(int num)
  116. {
  117. return (void *)SendMessage(library, WM_ML_IPC, (WPARAM)num, ML_IPC_SKIN_WADLG_GETFUNC);
  118. }
  119. void MediaLibraryInterface::PlayStream(wchar_t *url, bool force)
  120. {
  121. wchar_t temp[ 2048 ] = { 0 };
  122. wchar_t *end = 0;
  123. StringCchCopyExW( temp, 2047, url, &end, 0, 0 );
  124. if ( end )
  125. {
  126. end[ 1 ] = 0; // double null terminate
  127. mlSendToWinampStruct send;
  128. send.type = ML_TYPE_STREAMNAMESW;
  129. send.enqueue = force ? ( 0 | 2 ) : 0;
  130. send.data = (void *)temp;
  131. SendMessage( library, WM_ML_IPC, (WPARAM)&send, ML_IPC_SENDTOWINAMP );
  132. }
  133. }
  134. void MediaLibraryInterface::PlayStreams(std::vector<const wchar_t*> &urls, bool force)
  135. {
  136. size_t totalSize = 0;
  137. std::vector<const wchar_t*>::iterator itr;
  138. for (itr = urls.begin();itr != urls.end();itr++)
  139. {
  140. totalSize += lstrlenW(*itr) + 1;
  141. }
  142. totalSize++;
  143. wchar_t *sendTo = new wchar_t[totalSize];
  144. wchar_t *ptr = sendTo;
  145. for (itr = urls.begin();itr != urls.end();itr++)
  146. {
  147. //AutoChar narrow(*itr);
  148. StringCchCopyExW(ptr, totalSize, *itr, &ptr, &totalSize, 0);
  149. ptr++;
  150. if (totalSize)
  151. totalSize--;
  152. else
  153. break;
  154. }
  155. ptr[0] = 0;
  156. mlSendToWinampStruct send;
  157. send.type = ML_TYPE_STREAMNAMESW;
  158. send.enqueue = force?(0 | 2):0;
  159. send.data = sendTo;
  160. SendMessage(library, WM_ML_IPC, (WPARAM)&send, ML_IPC_SENDTOWINAMP);
  161. delete [] sendTo;
  162. }
  163. void MediaLibraryInterface::EnqueueStream(wchar_t *url, bool force)
  164. {
  165. wchar_t temp[2048] = {0};
  166. wchar_t *end=0;
  167. StringCchCopyExW(temp, 2047, url, &end, 0, 0);
  168. if (end)
  169. {
  170. end[1]=0; // double null terminate
  171. mlSendToWinampStruct send;
  172. send.type = ML_TYPE_STREAMNAMESW;
  173. send.enqueue = force?(1 | 2):1;
  174. send.data = (void *)temp;
  175. SendMessage(library, WM_ML_IPC, (WPARAM)&send, ML_IPC_SENDTOWINAMP);
  176. }
  177. }
  178. int MediaLibraryInterface::SkinComboBox(HWND comboBox)
  179. {
  180. return (int)(INT_PTR)SendMessage(library, WM_ML_IPC, (WPARAM)comboBox, ML_IPC_SKIN_COMBOBOX);
  181. }
  182. void MediaLibraryInterface::UnskinComboBox(int token)
  183. {
  184. SendMessage(library, WM_ML_IPC, (WPARAM)token, ML_IPC_UNSKIN_COMBOBOX);
  185. }
  186. const char *MediaLibraryInterface::GetIniDirectory()
  187. {
  188. if (!iniDirectory)
  189. {
  190. iniDirectory = (const char*)SendMessage(winamp, WM_WA_IPC, 0, IPC_GETINIDIRECTORY);
  191. if (((unsigned int)(ULONG_PTR)iniDirectory) < 65536)
  192. iniDirectory=0;
  193. }
  194. return iniDirectory;
  195. }
  196. const wchar_t *MediaLibraryInterface::GetIniDirectoryW()
  197. {
  198. if (!iniDirectoryW)
  199. {
  200. iniDirectoryW = (const wchar_t*)SendMessage(winamp, WM_WA_IPC, 0, IPC_GETINIDIRECTORYW);
  201. if (((unsigned int)(ULONG_PTR)iniDirectoryW) < 65536)
  202. iniDirectoryW=0;
  203. }
  204. return iniDirectoryW;
  205. }
  206. void MediaLibraryInterface::BuildPath(const wchar_t *pathEnd, wchar_t *path, size_t numChars)
  207. {
  208. PathCombineW(path, GetIniDirectoryW(), pathEnd);
  209. }
  210. void MediaLibraryInterface::AddToSendTo(char description[], INT_PTR context, INT_PTR unique)
  211. {
  212. mlAddToSendToStruct s;
  213. s.context = context;
  214. s.desc = description;
  215. s.user32 = unique;
  216. SendMessage(library, WM_ML_IPC, (WPARAM)&s, ML_IPC_ADDTOSENDTO);
  217. }
  218. void MediaLibraryInterface::AddToSendTo(wchar_t description[], INT_PTR context, INT_PTR unique)
  219. {
  220. mlAddToSendToStructW s;
  221. s.context = context;
  222. s.desc = description;
  223. s.user32 = unique;
  224. SendMessage(library, WM_ML_IPC, (WPARAM)&s, ML_IPC_ADDTOSENDTOW);
  225. }
  226. void MediaLibraryInterface::BranchSendTo(INT_PTR context)
  227. {
  228. mlAddToSendToStructW s = {0};
  229. s.context = context;
  230. SendMessage(library, WM_ML_IPC, (WPARAM)&s, ML_IPC_BRANCHSENDTO);
  231. }
  232. void MediaLibraryInterface::AddToBranchSendTo(const wchar_t description[], INT_PTR context, INT_PTR unique)
  233. {
  234. mlAddToSendToStructW s;
  235. s.context = context;
  236. s.desc = const_cast<wchar_t *>(description);
  237. s.user32 = unique;
  238. SendMessage(library, WM_ML_IPC, (WPARAM)&s, ML_IPC_ADDTOBRANCH);
  239. }
  240. void MediaLibraryInterface::EndBranchSendTo(const wchar_t description[], INT_PTR context)
  241. {
  242. mlAddToSendToStructW s = {0};
  243. s.context = context;
  244. s.desc = const_cast<wchar_t *>(description);
  245. SendMessage(library, WM_ML_IPC, (WPARAM)&s, ML_IPC_BRANCHSENDTO);
  246. }
  247. void MediaLibraryInterface::PlayFile(const wchar_t *url)
  248. {
  249. wchar_t temp[2048] = {0};
  250. wchar_t *end=0;
  251. StringCchCopyExW(temp, 2047, url, &end, 0, 0);
  252. if (end)
  253. {
  254. end[1]=0; // double null terminate
  255. mlSendToWinampStruct send;
  256. send.type = ML_TYPE_FILENAMESW;
  257. send.enqueue = 0 | 2;
  258. send.data = (void *)temp;
  259. SendMessage(library, WM_ML_IPC, (WPARAM)&send, ML_IPC_SENDTOWINAMP);
  260. }
  261. }
  262. void MediaLibraryInterface::EnqueueFile(const wchar_t *url)
  263. {
  264. wchar_t temp[2048] = {0};
  265. wchar_t *end=0;
  266. StringCchCopyExW(temp, 2047, url, &end, 0, 0);
  267. if (end)
  268. {
  269. end[1]=0; // double null terminate
  270. mlSendToWinampStruct send;
  271. send.type = ML_TYPE_FILENAMESW;
  272. send.enqueue = 1 | 2;
  273. send.data = (void *)temp;
  274. SendMessage(library, WM_ML_IPC, (WPARAM)&send, ML_IPC_SENDTOWINAMP);
  275. }
  276. }
  277. void MediaLibraryInterface::BuildPluginPath(const TCHAR *filename, TCHAR *path, size_t pathSize)
  278. {
  279. if (!pluginDirectory)
  280. pluginDirectory = (const char *)SendMessage(winamp, WM_WA_IPC, 0, IPC_GETPLUGINDIRECTORY);
  281. #ifdef UNICODE
  282. StringCchPrintf(path, pathSize, L"%S\\%s", pluginDirectory, filename);
  283. #else
  284. StringCchPrintf(path, pathSize, "%s\\%s", pluginDirectory, filename);
  285. #endif
  286. }
  287. void MediaLibraryInterface::AddToMediaLibrary(const char *filename)
  288. {
  289. LMDB_FILE_ADD_INFO fi = {const_cast<char *>(filename), -1, -1};
  290. SendMessage(library, WM_ML_IPC, (WPARAM)&fi, ML_IPC_DB_ADDORUPDATEFILE);
  291. PostMessage(library, WM_ML_IPC, 0, ML_IPC_DB_SYNCDB);
  292. }
  293. void MediaLibraryInterface::AddToMediaLibrary(const wchar_t *filename)
  294. {
  295. LMDB_FILE_ADD_INFOW fi = {const_cast<wchar_t *>(filename), -1, -1};
  296. SendMessage(library, WM_ML_IPC, (WPARAM)&fi, ML_IPC_DB_ADDORUPDATEFILEW);
  297. PostMessage(library, WM_ML_IPC, 0, ML_IPC_DB_SYNCDB);
  298. }
  299. IDispatch *MediaLibraryInterface::GetDispatchObject()
  300. {
  301. IDispatch *dispatch = (IDispatch *)SendMessage(winamp, WM_WA_IPC, 0, IPC_GET_DISPATCH_OBJECT);
  302. if (dispatch == (IDispatch *)1)
  303. return 0;
  304. else
  305. return dispatch;
  306. }
  307. int MediaLibraryInterface::GetUniqueDispatchId()
  308. {
  309. return (int)(INT_PTR)SendMessage(winamp, WM_WA_IPC, 0, IPC_GET_UNIQUE_DISPATCH_ID);
  310. }
  311. void MediaLibraryInterface::ListSkinDisableHorizontalScrollbar(int listSkin)
  312. {
  313. SendMessage(library, WM_ML_IPC, listSkin, ML_IPC_LISTVIEW_DISABLEHSCROLL);
  314. }
  315. DWORD MediaLibraryInterface::AddDispatch(wchar_t *name, IDispatch *object)
  316. {
  317. DispatchInfo dispatchInfo;
  318. dispatchInfo.name = name;
  319. dispatchInfo.dispatch = object;
  320. if (SendMessage(winamp, WM_WA_IPC, (WPARAM)&dispatchInfo, IPC_ADD_DISPATCH_OBJECT) == 0)
  321. return dispatchInfo.id;
  322. else
  323. return 0;
  324. }
  325. void MediaLibraryInterface::GetFileInfo(const char *filename, char *title, int titleCch, int *length)
  326. {
  327. basicFileInfoStruct infoStruct = {0};
  328. infoStruct.filename = filename;
  329. infoStruct.title = title;
  330. infoStruct.titlelen = titleCch;
  331. SendMessage(winamp, WM_WA_IPC, (WPARAM)&infoStruct, IPC_GET_BASIC_FILE_INFO);
  332. *length = infoStruct.length;
  333. }
  334. void MediaLibraryInterface::GetFileInfo(const wchar_t *filename, wchar_t *title, int titleCch, int *p_length)
  335. {
  336. if (filename)
  337. {
  338. basicFileInfoStructW infoStruct = {0};
  339. infoStruct.filename = filename;
  340. infoStruct.title = title;
  341. infoStruct.titlelen = titleCch;
  342. SendMessage(winamp, WM_WA_IPC, (WPARAM)&infoStruct, IPC_GET_BASIC_FILE_INFOW);
  343. if ( p_length != NULL )
  344. *p_length = infoStruct.length;
  345. }
  346. else
  347. {
  348. title[0] = 0;
  349. *p_length = -1;
  350. }
  351. }
  352. const char *MediaLibraryInterface::GetWinampIni()
  353. {
  354. if (winampIni && *winampIni)
  355. return winampIni;
  356. winampIni = (const char *)SendMessage(winamp, WM_WA_IPC, 0, IPC_GETINIFILE);
  357. return winampIni;
  358. }
  359. const wchar_t *MediaLibraryInterface::GetWinampIniW()
  360. {
  361. if (winampIniW && *winampIniW)
  362. return winampIniW;
  363. winampIniW = (const wchar_t *)SendMessage(winamp, WM_WA_IPC, 0, IPC_GETINIFILEW);
  364. return winampIniW;
  365. }
  366. INT_PTR MediaLibraryInterface::GetChildId(INT_PTR id)
  367. {
  368. return SendMessage(library, WM_ML_IPC, id, ML_IPC_TREEITEM_GETCHILD_ID);
  369. }
  370. INT_PTR MediaLibraryInterface::GetNextId(INT_PTR id)
  371. {
  372. return SendMessage(library, WM_ML_IPC, id, ML_IPC_TREEITEM_GETNEXT_ID);
  373. }
  374. void MediaLibraryInterface::RenameTreeId(INT_PTR treeId, const wchar_t *newName)
  375. {
  376. MLTREEITEMINFOW info = {0};
  377. info.mask = MLTI_TEXT;
  378. info.item.size = sizeof(info.item);
  379. info.item.id = treeId;
  380. info.item.title = const_cast<wchar_t *>(newName);
  381. SendMessage(library, WM_ML_IPC, (WPARAM) &info, ML_IPC_TREEITEM_SETINFOW);
  382. }