1
0

options_in.cpp 9.3 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 "main.hpp"
  12. #include <vector>
  13. #include "../nu/AutoWide.h"
  14. extern std::vector<In_Module*> in_modules;
  15. static bool pluginsLoaded;
  16. INT_PTR CALLBACK InputProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  17. {
  18. hi helpinfo[]={
  19. {IDC_INPUTS,IDS_P_IN_INPUTS},
  20. {IDC_CONF,IDS_P_IN_CONF},
  21. {IDC_ABOUT,IDS_P_IN_ABOUT},
  22. {IDC_UNINSTINPUT,IDS_P_IN_UNINST},
  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_INPUTS);
  31. if (IsWindow(listWindow))
  32. {
  33. size_t x;
  34. RECT r = {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_INPUTS, 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 < in_modules.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(in_modules[x])
  56. {
  57. wchar_t fn[MAX_PATH] = {0}, buf[512] = {0};
  58. GetModuleFileNameW(in_modules[x]->hDllInstance, fn, MAX_PATH);
  59. PathStripPathW(fn);
  60. int ver = ((in_modules[x]->version & ~IN_UNICODE) & ~IN_INIT_RET);
  61. LVITEMW lvi = {LVIF_TEXT | LVIF_PARAM, (int)x, 0};
  62. lstrcpynW(buf, (ver == IN_VER ? (wchar_t*)in_modules[x]->description : AutoWide(in_modules[x]->description)), 512);
  63. lvi.pszText = buf;
  64. lvi.lParam = x;
  65. lvi.iItem = ListView_InsertItemW(listWindow, &lvi);
  66. lvi.mask = LVIF_TEXT;
  67. lvi.iSubItem = 1;
  68. lvi.pszText = fn;
  69. ListView_SetItemW(listWindow, &lvi);
  70. }
  71. }
  72. wchar_t dirstr[MAX_PATH] = {0};
  73. PathCombineW(dirstr, PLUGINDIR, L"IN_*.DLL");
  74. HANDLE h = FindFirstFileW(dirstr, &d);
  75. if (h != INVALID_HANDLE_VALUE)
  76. {
  77. do
  78. {
  79. PathCombineW(dirstr, PLUGINDIR, d.cFileName);
  80. HMODULE b = LoadLibraryExW(dirstr, NULL, LOAD_LIBRARY_AS_DATAFILE);
  81. for (x = 0; b && (x != in_modules.size()); x ++)
  82. {
  83. if (in_modules[x]->hDllInstance == b)
  84. {
  85. break;
  86. }
  87. }
  88. if (x == in_modules.size() || !b)
  89. {
  90. LVITEMW lvi = {LVIF_TEXT | LVIF_PARAM, (int)x, 0};
  91. lvi.pszText = d.cFileName;
  92. lvi.lParam = -2;
  93. lvi.iItem = ListView_InsertItemW(listWindow, &lvi);
  94. lvi.mask = LVIF_TEXT;
  95. lvi.iSubItem = 1;
  96. lvi.pszText = getStringW(IDS_NOT_LOADED, NULL, 0);
  97. ListView_SetItemW(listWindow, &lvi);
  98. }
  99. FreeLibrary(b);
  100. }
  101. while (FindNextFileW(h, &d));
  102. FindClose(h);
  103. }
  104. GetClientRect(listWindow, &r);
  105. ListView_SetColumnWidth(listWindow, 1, LVSCW_AUTOSIZE);
  106. ListView_SetColumnWidth(listWindow, 0, (r.right - r.left) - ListView_GetColumnWidth(listWindow, 1));
  107. DirectMouseWheel_EnableConvertToMouseWheel(listWindow, TRUE);
  108. pluginsLoaded = true;
  109. }
  110. }
  111. else if (uMsg == WM_DESTROY)
  112. {
  113. HWND listWindow = GetDlgItem(hwndDlg, IDC_INPUTS);
  114. if (IsWindow(listWindow))
  115. DirectMouseWheel_EnableConvertToMouseWheel(listWindow, FALSE);
  116. }
  117. else if (uMsg == WM_NOTIFY)
  118. {
  119. LPNMHDR p = (LPNMHDR)lParam;
  120. if (p->idFrom == IDC_INPUTS)
  121. {
  122. if (p->code == LVN_ITEMCHANGED)
  123. {
  124. LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam;
  125. LVITEM lvi = {LVIF_PARAM, pnmv->iItem};
  126. if (ListView_GetItem(p->hwndFrom, &lvi) && (pnmv->uNewState & LVIS_SELECTED))
  127. {
  128. int loaded = (lvi.lParam != -2);
  129. EnableWindow(GetDlgItem(hwndDlg, IDC_CONF), loaded);
  130. EnableWindow(GetDlgItem(hwndDlg, IDC_ABOUT), loaded);
  131. EnableWindow(GetDlgItem(hwndDlg, IDC_UNINSTINPUT), 1);
  132. }
  133. else
  134. {
  135. EnableWindow(GetDlgItem(hwndDlg, IDC_CONF), 0);
  136. EnableWindow(GetDlgItem(hwndDlg, IDC_ABOUT), 0);
  137. EnableWindow(GetDlgItem(hwndDlg, IDC_UNINSTINPUT), 0);
  138. }
  139. }
  140. else if (p->code == NM_DBLCLK)
  141. {
  142. PostMessageW(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_CONF, 0), (LPARAM)GetDlgItem(hwndDlg, IDC_CONF));
  143. }
  144. }
  145. else if (p->code == HDN_ITEMCHANGINGW)
  146. {
  147. if (pluginsLoaded)
  148. {
  149. #ifdef WIN64
  150. SetWindowLongPtrW(hwndDlg, DWLP_MSGRESULT, TRUE);
  151. #else
  152. SetWindowLong(hwndDlg, DWL_MSGRESULT, TRUE);
  153. #endif
  154. return TRUE;
  155. }
  156. }
  157. }
  158. else if (uMsg == WM_COMMAND)
  159. {
  160. switch (LOWORD(wParam))
  161. {
  162. case IDC_ABOUT:
  163. {
  164. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_ABOUT)))
  165. {
  166. HWND listWindow = GetDlgItem(hwndDlg, IDC_INPUTS);
  167. LVITEM lvi = {LVIF_PARAM, ListView_GetSelectionMark(listWindow)};
  168. if (ListView_GetItem(listWindow, &lvi))
  169. {
  170. if (lvi.lParam >= 0 && lvi.lParam < (int)in_modules.size()) in_modules[lvi.lParam]->About(hwndDlg);
  171. }
  172. }
  173. }
  174. break;
  175. case IDC_CONF:
  176. {
  177. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CONF)))
  178. {
  179. HWND listWindow = GetDlgItem(hwndDlg, IDC_INPUTS);
  180. LVITEM lvi = {LVIF_PARAM, ListView_GetSelectionMark(listWindow)};
  181. if (ListView_GetItem(listWindow, &lvi))
  182. {
  183. if (lvi.lParam >= 0 && lvi.lParam < (int)in_modules.size()) in_modules[lvi.lParam]->Config(hwndDlg);
  184. }
  185. }
  186. }
  187. break;
  188. case IDC_UNINSTINPUT:
  189. {
  190. HWND listWindow = GetDlgItem(hwndDlg, IDC_INPUTS);
  191. int which_sel = ListView_GetSelectionMark(listWindow);
  192. LVITEM lvi = {LVIF_PARAM, which_sel};
  193. if (ListView_GetItem(listWindow, &lvi))
  194. {
  195. if (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)in_modules.size())
  198. {
  199. int ret = IN_PLUGIN_UNINSTALL_REBOOT;
  200. int (*pr)(HINSTANCE hDllInst, HWND hwndDlg, int param);
  201. *(void**)&pr = (void*)GetProcAddress(in_modules[lvi.lParam]->hDllInstance,"winampUninstallPlugin");
  202. if (pr)ret=pr(in_modules[lvi.lParam]->hDllInstance,hwndDlg,0);
  203. if (ret == IN_PLUGIN_UNINSTALL_REBOOT)
  204. {
  205. extern void _w_s(char *name, char *data);
  206. char buf[1024] = {0};
  207. GetModuleFileNameA(in_modules[lvi.lParam]->hDllInstance,buf,sizeof(buf));
  208. _w_s("remove_genplug",buf);
  209. _w_i("show_prefs",31);
  210. PostMessageW(hMainWindow,WM_USER,0,IPC_RESTARTWINAMP);
  211. }
  212. // do dynamic unload if the plugin is able to support it (5.5+)
  213. else if (ret == IN_PLUGIN_UNINSTALL_NOW)
  214. {
  215. wchar_t buf[MAX_PATH] = {0};
  216. GetModuleFileNameW(in_modules[lvi.lParam]->hDllInstance,buf,MAX_PATH);
  217. in_modules[lvi.lParam]->Quit();
  218. FreeModule(in_modules[lvi.lParam]->hDllInstance);
  219. in_modules[lvi.lParam]=0;
  220. IFileTypeRegistrar *registrar=0;
  221. if (GetRegistrar(&registrar, true) == 0 && registrar)
  222. {
  223. registrar->DeleteItem(buf);
  224. if (registrar->DeleteItem(buf) != S_OK)
  225. {
  226. _w_sW("remove_genplug", buf);
  227. _w_i("show_prefs", 31);
  228. PostMessageW(hMainWindow, WM_USER, 0, IPC_RESTARTWINAMP);
  229. }
  230. else
  231. ListView_DeleteItem(listWindow, which_sel);
  232. registrar->Release();
  233. }
  234. ListView_DeleteItem(listWindow, lvi.lParam);
  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", 31);
  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_INPUTS));
  271. }
  272. }
  273. }
  274. break;
  275. case IDC_PLUGINVERS:
  276. myOpenURLWithFallback(hwndDlg, L"http://www.google.com/search?q=Winamp+Input+Plugins",L"http://www.google.com/search?q=Winamp+Input+Plugins");
  277. break;
  278. }
  279. }
  280. link_handledraw(hwndDlg,uMsg,wParam,lParam);
  281. return FALSE;
  282. } //input