1
0

options_gen.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "Main.h"
  9. #include "resource.h"
  10. #include "Options.h"
  11. #include "gen.h"
  12. #include <vector>
  13. #include "main.hpp"
  14. #include "../nu/AutoWide.h"
  15. extern std::vector<winampGeneralPurposePlugin*> gen_plugins;
  16. // gen tab procedure
  17. static bool pluginsLoaded;
  18. INT_PTR CALLBACK GenProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  19. {
  20. hi helpinfo[] = {
  21. {IDC_GENLIB, IDS_P_GEN_LIB},
  22. {IDC_GENCONF, IDS_P_GEN_CONF},
  23. };
  24. DO_HELP();
  25. if (uMsg == WM_INITDIALOG)
  26. {
  27. pluginsLoaded = false;
  28. WIN32_FIND_DATAW d = {0};
  29. link_startsubclass(hwndDlg, IDC_PLUGINVERS);
  30. HWND listWindow = GetDlgItem(hwndDlg, IDC_GENLIB);
  31. if (IsWindow(listWindow))
  32. {
  33. size_t x;
  34. RECT r = {0}, rc = {0};
  35. GetWindowRect(listWindow, &r);
  36. GetClientRect(listWindow, &r);
  37. MapWindowPoints(listWindow, hwndDlg, (LPPOINT)&r, 2);
  38. InflateRect(&r, 2, 2);
  39. DestroyWindow(listWindow);
  40. listWindow = CreateWindowExW(WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE, WC_LISTVIEWW, L"",
  41. WS_CHILD | WS_VISIBLE | WS_TABSTOP | LVS_REPORT | LVS_SINGLESEL |
  42. LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER,
  43. r.left, r.top, r.right - r.left, r.bottom - r.top,
  44. hwndDlg, (HMENU)IDC_GENLIB, NULL, NULL);
  45. SetWindowPos(listWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  46. ListView_SetExtendedListViewStyleEx(listWindow, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
  47. SendMessageW(listWindow, WM_SETFONT, SendMessageW(hwndDlg, WM_GETFONT, 0, 0), FALSE);
  48. LVCOLUMNW lvc = {0};
  49. ListView_InsertColumnW(listWindow, 0, &lvc);
  50. ListView_InsertColumnW(listWindow, 1, &lvc);
  51. for (x = 0; x != gen_plugins.size(); x ++)
  52. {
  53. // only try to add if the plugin is still there
  54. // (as 5.5+ allows for dynamic unloads if supported)
  55. if(gen_plugins[x])
  56. {
  57. wchar_t fn[MAX_PATH] = {0}, buf[512] = {0};
  58. GetModuleFileNameW(gen_plugins[x]->hDllInstance, fn, MAX_PATH);
  59. PathStripPathW(fn);
  60. LVITEMW lvi = {LVIF_TEXT | LVIF_PARAM, (int)x, 0};
  61. lstrcpyn(buf, (gen_plugins[x]->version == GPPHDR_VER_U ? (wchar_t*)gen_plugins[x]->description : AutoWide(gen_plugins[x]->description)), 512);
  62. lvi.pszText = buf;
  63. lvi.lParam = x;
  64. lvi.iItem = ListView_InsertItemW(listWindow, &lvi);
  65. lvi.mask = LVIF_TEXT;
  66. lvi.iSubItem = 1;
  67. lvi.pszText = fn;
  68. ListView_SetItemW(listWindow, &lvi);
  69. }
  70. }
  71. wchar_t dirstr[MAX_PATH] = {0};
  72. PathCombineW(dirstr, PLUGINDIR, L"GEN_*.DLL");
  73. HANDLE h = FindFirstFileW(dirstr, &d);
  74. if (h != INVALID_HANDLE_VALUE)
  75. {
  76. do
  77. {
  78. PathCombineW(dirstr, PLUGINDIR, d.cFileName);
  79. HMODULE b = LoadLibraryExW(dirstr, NULL, LOAD_LIBRARY_AS_DATAFILE);
  80. for (x = 0; b && (x != gen_plugins.size()); x ++)
  81. {
  82. if (gen_plugins[x]->hDllInstance == b)
  83. {
  84. break;
  85. }
  86. }
  87. if (x == gen_plugins.size() || !b)
  88. {
  89. LVITEMW lvi = {LVIF_TEXT | LVIF_PARAM, (int)x, 0};
  90. lvi.pszText = d.cFileName;
  91. lvi.lParam = -2;
  92. lvi.iItem = ListView_InsertItemW(listWindow, &lvi);
  93. lvi.mask = LVIF_TEXT;
  94. lvi.iSubItem = 1;
  95. lvi.pszText = getStringW(IDS_NOT_LOADED, NULL, 0);
  96. ListView_SetItemW(listWindow, &lvi);
  97. }
  98. FreeLibrary(b);
  99. }
  100. while (FindNextFileW(h, &d));
  101. FindClose(h);
  102. }
  103. GetClientRect(listWindow, &r);
  104. ListView_SetColumnWidth(listWindow, 1, LVSCW_AUTOSIZE);
  105. ListView_SetColumnWidth(listWindow, 0, (r.right - r.left) - ListView_GetColumnWidth(listWindow, 1));
  106. DirectMouseWheel_EnableConvertToMouseWheel(listWindow, TRUE);
  107. pluginsLoaded = true;
  108. }
  109. }
  110. else if (uMsg == WM_NOTIFY)
  111. {
  112. LPNMHDR p = (LPNMHDR)lParam;
  113. if (p->idFrom == IDC_GENLIB)
  114. {
  115. if (p->code == LVN_ITEMCHANGED)
  116. {
  117. LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam;
  118. LVITEM lvi = {LVIF_PARAM, pnmv->iItem};
  119. if (ListView_GetItem(p->hwndFrom, &lvi) && (pnmv->uNewState & LVIS_SELECTED))
  120. {
  121. EnableWindow(GetDlgItem(hwndDlg, IDC_GENCONF), (lvi.lParam != -2));
  122. EnableWindow(GetDlgItem(hwndDlg, IDC_UNINST), 1);
  123. }
  124. else
  125. {
  126. EnableWindow(GetDlgItem(hwndDlg, IDC_GENCONF), 0);
  127. EnableWindow(GetDlgItem(hwndDlg, IDC_UNINST), 0);
  128. }
  129. }
  130. else if (p->code == NM_DBLCLK)
  131. {
  132. PostMessageW(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_GENCONF, 0), (LPARAM)GetDlgItem(hwndDlg, IDC_GENCONF));
  133. }
  134. }
  135. else if (p->code == HDN_ITEMCHANGINGW)
  136. {
  137. if (pluginsLoaded)
  138. {
  139. #ifdef WIN64
  140. SetWindowLongPtrW(hwndDlg, DWLP_MSGRESULT, TRUE);
  141. #else
  142. SetWindowLong(hwndDlg, DWL_MSGRESULT, TRUE);
  143. #endif
  144. return TRUE;
  145. }
  146. }
  147. }
  148. else if (uMsg == WM_DESTROY)
  149. {
  150. HWND listWindow = GetDlgItem(hwndDlg, IDC_GENLIB);
  151. if (IsWindow(listWindow))
  152. DirectMouseWheel_EnableConvertToMouseWheel(listWindow, FALSE);
  153. }
  154. else if (uMsg == WM_COMMAND)
  155. {
  156. switch (LOWORD(wParam))
  157. {
  158. case IDC_GENCONF:
  159. {
  160. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_GENCONF)))
  161. {
  162. HWND listWindow = GetDlgItem(hwndDlg, IDC_GENLIB);
  163. LVITEM lvi = {LVIF_PARAM, ListView_GetSelectionMark(listWindow)};
  164. if (ListView_GetItem(listWindow, &lvi))
  165. {
  166. if (lvi.lParam >= 0 && lvi.lParam < (int)gen_plugins.size())
  167. {
  168. if (!(config_no_visseh&4))
  169. {
  170. try {
  171. gen_plugins[lvi.lParam]->config();
  172. }
  173. catch(...)
  174. {
  175. LPMessageBox(hwndDlg, IDS_PLUGINERROR, IDS_ERROR, MB_OK | MB_ICONEXCLAMATION);
  176. }
  177. }
  178. else
  179. {
  180. gen_plugins[lvi.lParam]->config();
  181. }
  182. }
  183. }
  184. }
  185. }
  186. return FALSE;
  187. case IDC_UNINST:
  188. {
  189. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_UNINST)))
  190. {
  191. HWND listWindow = GetDlgItem(hwndDlg, IDC_GENLIB);
  192. int which_sel = ListView_GetSelectionMark(listWindow);
  193. LVITEM lvi = {LVIF_PARAM, which_sel};
  194. if (ListView_GetItem(listWindow, &lvi) &&
  195. LPMessageBox(hwndDlg, IDS_P_PLUGIN_UNINSTALL,IDS_P_PLUGIN_UNINSTALL_CONFIRM, MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
  196. {
  197. if (lvi.lParam >= 0 && lvi.lParam < (int)gen_plugins.size())
  198. {
  199. int ret = GEN_PLUGIN_UNINSTALL_REBOOT;
  200. int (*pr)(HINSTANCE hDllInst, HWND hwndDlg, int param);
  201. if (lvi.lParam != -2)
  202. {
  203. *(void**)&pr = (void*)GetProcAddress(gen_plugins[lvi.lParam]->hDllInstance, "winampUninstallPlugin");
  204. if (pr) ret = pr(gen_plugins[lvi.lParam]->hDllInstance, hwndDlg, 0);
  205. }
  206. if (ret == GEN_PLUGIN_UNINSTALL_REBOOT)
  207. {
  208. extern void _w_s(char *name, char *data);
  209. wchar_t buf[MAX_PATH] = {0};
  210. GetModuleFileNameW(gen_plugins[lvi.lParam]->hDllInstance, buf, MAX_PATH);
  211. _w_sW("remove_genplug", buf);
  212. _w_i("show_prefs", 35);
  213. PostMessageW(hMainWindow, WM_USER, 0, IPC_RESTARTWINAMP);
  214. }
  215. // do dynamic unload if the plugin is able to support it (5.5+)
  216. else if (ret == GEN_PLUGIN_UNINSTALL_NOW)
  217. {
  218. wchar_t buf[MAX_PATH] = {0};
  219. GetModuleFileNameW(gen_plugins[lvi.lParam]->hDllInstance, buf, MAX_PATH);
  220. gen_plugins[lvi.lParam]->quit();
  221. FreeModule(gen_plugins[lvi.lParam]->hDllInstance);
  222. gen_plugins[lvi.lParam]=0;
  223. IFileTypeRegistrar *registrar=0;
  224. if (GetRegistrar(&registrar, true) == 0 && registrar)
  225. {
  226. if (registrar->DeleteItem(buf) != S_OK)
  227. {
  228. _w_sW("remove_genplug", buf);
  229. _w_i("show_prefs", 35);
  230. PostMessageW(hMainWindow, WM_USER, 0, IPC_RESTARTWINAMP);
  231. }
  232. registrar->Release();
  233. }
  234. ListView_DeleteItem(listWindow, which_sel);
  235. }
  236. }
  237. // will cope with not loaded plug-ins so we can still remove them, etc
  238. else if (lvi.lParam == -2)
  239. {
  240. wchar_t buf[1024] = {0}, base[1024] = {0};
  241. StringCchCopyW(base, 1024, PLUGINDIR);
  242. PathAddBackslashW(base);
  243. LVITEMW lvi = {LVIF_TEXT, which_sel};
  244. lvi.pszText = buf;
  245. lvi.cchTextMax = ARRAYSIZE(buf);
  246. ListView_GetItemW(listWindow, &lvi);
  247. wchar_t *p = wcschr(buf, L'.');
  248. if (p && *p == L'.')
  249. {
  250. p += 4;
  251. *p = 0;
  252. PathRemoveFileSpecW(base);
  253. PathAppendW(base, buf);
  254. }
  255. IFileTypeRegistrar *registrar=0;
  256. if (GetRegistrar(&registrar, true) == 0 && registrar)
  257. {
  258. if (registrar->DeleteItem(base) != S_OK)
  259. {
  260. _w_sW("remove_genplug", base);
  261. _w_i("show_prefs", 35);
  262. PostMessageW(hMainWindow, WM_USER, 0, IPC_RESTARTWINAMP);
  263. }
  264. else
  265. ListView_DeleteItem(listWindow, which_sel);
  266. registrar->Release();
  267. }
  268. }
  269. // resets the focus to the listbox so it'll keep ui response working
  270. SetFocus(GetDlgItem(hwndDlg, IDC_GENLIB));
  271. }
  272. }
  273. }
  274. return FALSE;
  275. case IDC_PLUGINVERS:
  276. myOpenURLWithFallback(hwndDlg, L"http://www.google.com/search?q=Winamp+General+Plugins", L"http://www.google.com/search?q=Winamp+General+Plugins");
  277. break;
  278. }
  279. }
  280. else
  281. link_handledraw(hwndDlg, uMsg, wParam, lParam);
  282. return FALSE;
  283. } //gen