options_filetypes.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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 "Options.h"
  10. #include "api.h"
  11. #include "../nu/AutoWide.h"
  12. #include "../nu/AutoChar.h"
  13. #include "resource.h"
  14. #define OPT_CD 0x1
  15. #define OPT_ENQ 0x2
  16. #define OPT_DIR 0x4
  17. #define OPT_EXT 0x8
  18. #define OPT_ICON 0x10
  19. static int optchanged,
  20. old_whichicon,
  21. old_whichicon2;
  22. static void hideShowAgentItems(HWND hwndDlg)
  23. {
  24. int enabled = IsDlgButtonChecked(hwndDlg, IDC_CHECK1);
  25. EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK2), enabled);
  26. }
  27. static BOOL iconsChanged(void)
  28. {
  29. if(optchanged & OPT_ICON)
  30. {
  31. if(old_whichicon != config_whichicon || old_whichicon2 != config_whichicon2)
  32. {
  33. return TRUE;
  34. }
  35. }
  36. return FALSE;
  37. }
  38. // this is used to block selections being shown in the file types listbox
  39. // when running on Windows 8 as selecting doesn't work due to OS changes,
  40. // so we block mouse clicks as well as the space key for toggling things.
  41. LRESULT win8_handleclick(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  42. {
  43. if(uMsg == WM_KEYDOWN && wParam == VK_SPACE)
  44. {
  45. return 0;
  46. }
  47. LRESULT ret = CallWindowProcW((WNDPROC)GetPropW(hwndDlg, L"win8_proc"), hwndDlg, uMsg, wParam, lParam);
  48. if(uMsg == WM_LBUTTONDOWN)
  49. {
  50. SendMessageW(hwndDlg,LB_SETSEL,0,-1);
  51. }
  52. return ret;
  53. }
  54. // file type tab procedure
  55. INT_PTR CALLBACK FtypeProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  56. {
  57. hi helpinfo[]={
  58. {IDC_FILETYPES_ICONSCROLL,IDS_P_FT_ICON},
  59. {IDC_FILETYPES_ICONSCROLL2,IDS_P_FT_ICON2},
  60. {IDC_ADDFILES,IDS_P_FT_ENQUEUE},
  61. {IDC_DIRCONTEXT,IDS_P_FT_DIRCONTEXT},
  62. {IDC_FTYPE_LIST,(!IsWin8()?IDS_P_FT_EXTENSIONS:IDS_P_FT_EXTENSIONS_WIN8)},
  63. {IDC_SELALL,IDS_P_FT_ALL},
  64. {IDC_SELNONE,IDS_P_FT_NO},
  65. {IDC_CD,IDS_P_FT_CD},
  66. {IDC_RSTART,IDS_P_FT_RSTART},
  67. {IDC_CHECK1,IDS_P_A_ENABLE},
  68. {IDC_CHECK2,IDS_P_A_TRAY},
  69. };
  70. DO_HELP();
  71. switch (uMsg)
  72. {
  73. case WM_INITDIALOG:
  74. {
  75. optchanged=0;
  76. old_whichicon=config_whichicon;
  77. old_whichicon2=config_whichicon2;
  78. link_startsubclass(hwndDlg, IDC_SET_DEF_PROGRAM);
  79. SetPropW(GetDlgItem(hwndDlg, IDC_SET_DEF_PROGRAM), L"slim", (HANDLE)1);
  80. if (FindWindowW(L"WinampAgentMain",NULL))
  81. CheckDlgButton(hwndDlg,IDC_CHECK1,BST_CHECKED);
  82. if (GetPrivateProfileIntW(L"WinampAgent",L"is_intray",1,INI_FILE))
  83. CheckDlgButton(hwndDlg,IDC_CHECK2,BST_CHECKED);
  84. SendMessageW(GetDlgItem(hwndDlg,IDC_FILETYPES_ICONSCROLL),TBM_SETRANGEMAX,0,12);
  85. SendMessageW(GetDlgItem(hwndDlg,IDC_FILETYPES_ICONSCROLL),TBM_SETRANGEMIN,0,0);
  86. SendMessageW(GetDlgItem(hwndDlg,IDC_FILETYPES_ICONSCROLL),TBM_SETPOS,1,config_whichicon);
  87. SendMessageW(GetDlgItem(hwndDlg,IDC_FILETYPES_ICONSCROLL2),TBM_SETRANGEMAX,0,12);
  88. SendMessageW(GetDlgItem(hwndDlg,IDC_FILETYPES_ICONSCROLL2),TBM_SETRANGEMIN,0,0);
  89. SendMessageW(GetDlgItem(hwndDlg,IDC_FILETYPES_ICONSCROLL2),TBM_SETPOS,1,config_whichicon2);
  90. CheckDlgButton(hwndDlg,IDC_ADDFILES,config_addtolist?BST_CHECKED:BST_UNCHECKED);
  91. CheckDlgButton(hwndDlg,IDC_DIRCONTEXT,config_isdircontext()?BST_CHECKED:BST_UNCHECKED);
  92. CheckDlgButton(hwndDlg,IDC_CD,config_iscdplayer()?BST_CHECKED:BST_UNCHECKED);
  93. CheckDlgButton(hwndDlg,IDC_RSTART,config_check_ft_startup?BST_CHECKED:BST_UNCHECKED);
  94. wchar_t *exl = in_getextlistW();
  95. wchar_t *a = exl;
  96. wchar_t buf[MAX_PATH] = {0};
  97. HWND hwnd = GetDlgItem(hwndDlg,IDC_FTYPE_LIST);
  98. if (IsWindow(hwnd))
  99. {
  100. while (a && *a)
  101. {
  102. int len = min(lstrlenW(a) + 1, MAX_PATH);
  103. lstrcpynW(buf, a, len);
  104. int i = SendMessageW(hwnd, LB_ADDSTRING, 0, (LPARAM)buf);
  105. if (!IsWin8() && config_isregistered(a))
  106. {
  107. SendMessageW(hwnd,LB_SETSEL,(WPARAM)TRUE,(LPARAM)i);
  108. }
  109. a+=len;
  110. }
  111. DirectMouseWheel_EnableConvertToMouseWheel(hwnd, TRUE);
  112. if (IsWin8())
  113. {
  114. SetPropW(hwnd, L"win8_proc",
  115. (HANDLE)SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)win8_handleclick));
  116. }
  117. }
  118. if (playlistManager && playlistManager != (api_playlistmanager *)1)
  119. {
  120. size_t playlistEnum = 0;
  121. int lastFind = -1;
  122. const wchar_t *playlistExt=0;
  123. while (NULL != (playlistExt=playlistManager->EnumExtension(playlistEnum++)))
  124. {
  125. int len = min(lstrlenW(playlistExt) + 1, MAX_PATH);
  126. lstrcpynW(buf, playlistExt, len);
  127. CharUpperBuffW(buf, len);
  128. if ((lastFind = SendMessageW(hwnd, LB_FINDSTRINGEXACT, lastFind, (LPARAM)buf)) == LB_ERR)
  129. {
  130. int i = SendMessageW(hwnd, LB_ADDSTRING, 0, (LPARAM)buf);
  131. if (!IsWin8() && config_isregistered((wchar_t*)playlistExt))
  132. {
  133. SendMessageW(hwnd, LB_SETSEL, (WPARAM)TRUE, (LPARAM)i);
  134. }
  135. }
  136. }
  137. }
  138. GlobalFree((HGLOBAL)exl);
  139. SendMessageW(hwnd,LB_SETTOPINDEX,0,0);
  140. wchar_t s[MAX_PATH] = {0};
  141. GetModuleFileNameW(hMainInstance,s,MAX_PATH);
  142. PathRemoveFileSpecW(s);
  143. PathAppendW(s, L"winampa.exe");
  144. HANDLE hf = CreateFileW(s,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
  145. if (hf != INVALID_HANDLE_VALUE)
  146. CloseHandle(hf);
  147. else
  148. {
  149. int ids[]={IDC_WATEXT2,IDC_WATEXT1,IDC_CHECK1,IDC_CHECK2};
  150. for (int x=0; x<sizeof(ids)/sizeof(ids[0]); x++)
  151. ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_HIDE);
  152. }
  153. hideShowAgentItems(hwndDlg);
  154. }
  155. return 0;
  156. case WM_DESTROY:
  157. {
  158. extern void _w_s(char *name, char *data);
  159. HWND hwnd=GetDlgItem(hwndDlg,IDC_FTYPE_LIST);
  160. int top = SendMessageW(hwnd,LB_GETCOUNT,0,0);
  161. DirectMouseWheel_EnableConvertToMouseWheel(hwnd, FALSE);
  162. // if control is held when closing the page then force a saving irrespective
  163. if ((GetAsyncKeyState(VK_CONTROL)&0x8000)) optchanged = OPT_CD|OPT_ENQ|OPT_DIR|OPT_EXT|OPT_ICON;
  164. // TODO: clear all capabilities/FileAssociations in registry so we can have a fresh list
  165. if (optchanged & OPT_EXT || iconsChanged())
  166. {
  167. if (!config_registermediaplayer(2))
  168. {
  169. LPMessageBox(hwndDlg, IDS_P_FILE_ASSOC_FAILURE, IDS_P_FILE_ASSOC, MB_OK | MB_ICONEXCLAMATION);
  170. return 0;
  171. }
  172. }
  173. config_addtolist = IsDlgButtonChecked(hwndDlg,IDC_ADDFILES)?1:0;
  174. if (optchanged & OPT_EXT || optchanged & OPT_ENQ || iconsChanged())
  175. {
  176. if (!config_setup_filetypes(1))
  177. {
  178. LPMessageBox(hwndDlg, IDS_P_FILE_ASSOC_FAILURE, IDS_P_FILE_ASSOC, MB_OK | MB_ICONEXCLAMATION);
  179. return 0;
  180. }
  181. }
  182. if (optchanged & OPT_DIR)
  183. {
  184. if (IsDlgButtonChecked(hwndDlg,IDC_DIRCONTEXT))
  185. {
  186. if (!config_isdircontext())
  187. {
  188. if (!config_adddircontext(1))
  189. {
  190. LPMessageBox(hwndDlg, IDS_P_FILE_ASSOC_FAILURE, IDS_P_FILE_ASSOC, MB_OK | MB_ICONEXCLAMATION);
  191. return 0;
  192. }
  193. }
  194. }
  195. else
  196. {
  197. if (config_isdircontext())
  198. {
  199. if (!config_removedircontext(1))
  200. {
  201. LPMessageBox(hwndDlg, IDS_P_FILE_ASSOC_FAILURE, IDS_P_FILE_ASSOC, MB_OK | MB_ICONEXCLAMATION);
  202. return 0;
  203. }
  204. }
  205. }
  206. }
  207. if (optchanged & OPT_CD)
  208. {
  209. if (!config_regcdplayer(IsDlgButtonChecked(hwndDlg,IDC_CD), 1))
  210. {
  211. LPMessageBox(hwndDlg, IDS_P_FILE_ASSOC_FAILURE, IDS_P_FILE_ASSOC, MB_OK | MB_ICONEXCLAMATION);
  212. return 0;
  213. }
  214. }
  215. if (optchanged & OPT_EXT || iconsChanged())
  216. {
  217. // on Windows 8 we specify all of the extensions which are supported
  218. // so they can be selected by the 'set default programs' interface as
  219. // the preferences dialog is not able to do it due to OS changes made
  220. wchar_t ext_list[16384] = {0};
  221. if (IsWin8())
  222. {
  223. for (int x = 0; x < top; x ++)
  224. {
  225. wchar_t buf[256] = {0};
  226. SendMessageW(hwnd, LB_GETTEXT, x, (LPARAM)buf);
  227. if (x) StringCchCatW(ext_list, ARRAYSIZE(ext_list), L":");
  228. StringCchCatW(ext_list, ARRAYSIZE(ext_list), buf);
  229. if (!config_register_capability(buf, 1))
  230. {
  231. LPMessageBox(hwndDlg, IDS_P_FILE_ASSOC_FAILURE, IDS_P_FILE_ASSOC, MB_OK | MB_ICONEXCLAMATION);
  232. break;
  233. }
  234. config_register(buf,1);
  235. }
  236. }
  237. else
  238. {
  239. for (int x = 0; x < top; x ++)
  240. {
  241. wchar_t buf[256] = {0};
  242. SendMessageW(hwnd, LB_GETTEXT, x, (LPARAM)buf);
  243. if (SendMessageW(hwnd,LB_GETSEL,x,0))
  244. {
  245. if (x) StringCchCatW(ext_list, ARRAYSIZE(ext_list), L":");
  246. StringCchCatW(ext_list, ARRAYSIZE(ext_list), buf);
  247. }
  248. if (!config_register_capability(buf, 1))
  249. {
  250. LPMessageBox(hwndDlg, IDS_P_FILE_ASSOC_FAILURE, IDS_P_FILE_ASSOC, MB_OK | MB_ICONEXCLAMATION);
  251. break;
  252. }
  253. config_register(buf, SendMessageW(hwnd,LB_GETSEL,x,0));
  254. }
  255. }
  256. _w_sW("config_extlist", ext_list);
  257. }
  258. hwnd = FindWindowW(L"WinampAgentMain",NULL);
  259. if (IsWindow(hwnd)) SendMessageW(hwnd,WM_USER+1,0,0);
  260. if (iconsChanged()) SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_IDLIST|SHCNF_FLUSHNOWAIT,NULL,NULL);
  261. }
  262. return 0;
  263. case WM_COMMAND:
  264. switch (LOWORD(wParam))
  265. {
  266. case IDC_SET_DEF_PROGRAM:
  267. {
  268. if(IsWin8())
  269. {
  270. IApplicationAssociationRegistrationUI* pAARUI;
  271. HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI,
  272. NULL,
  273. CLSCTX_INPROC,
  274. __uuidof(IApplicationAssociationRegistrationUI),
  275. (void**)&pAARUI);
  276. BOOL opened = FALSE;
  277. if (SUCCEEDED(hr))
  278. {
  279. hr = pAARUI->LaunchAdvancedAssociationUI(AutoWide(app_name));
  280. pAARUI->Release();
  281. if (SUCCEEDED(hr)){
  282. opened = TRUE;
  283. }
  284. }
  285. if(opened == FALSE)
  286. {
  287. LPMessageBox(hwndDlg, IDS_DEF_PROG_LOAD_ERROR, IDS_ERROR, MB_OK | MB_ICONWARNING);
  288. }
  289. }
  290. }
  291. break;
  292. case IDC_CHECK2:
  293. {
  294. HWND hwnd=FindWindowW(L"WinampAgentMain",NULL);
  295. if (IsDlgButtonChecked(hwndDlg,IDC_CHECK2))
  296. WritePrivateProfileStringW(L"WinampAgent",L"is_intray",L"1",INI_FILE);
  297. else
  298. WritePrivateProfileStringW(L"WinampAgent",L"is_intray",L"0",INI_FILE);
  299. if (hwnd) SendMessageW(hwnd,WM_USER+1,0,0);
  300. }
  301. break;
  302. case IDC_CHECK1:
  303. if (IsDlgButtonChecked(hwndDlg,IDC_CHECK1))
  304. {
  305. config_agent_add();
  306. }
  307. else
  308. {
  309. config_agent_remove();
  310. }
  311. hideShowAgentItems(hwndDlg);
  312. break;
  313. case IDC_SELALL:
  314. {
  315. int top = SendDlgItemMessage(hwndDlg,IDC_FTYPE_LIST,LB_GETCOUNT,0,0),x;
  316. for (x = 0; x < top; x ++)
  317. {
  318. SendDlgItemMessage(hwndDlg,IDC_FTYPE_LIST,LB_SETSEL,1,x);
  319. }
  320. optchanged |= OPT_EXT;
  321. }
  322. break;
  323. case IDC_SELALL2:
  324. case IDC_SELALL3:
  325. {
  326. HWND h=GetDlgItem(hwndDlg,IDC_FTYPE_LIST);
  327. int top = SendMessageW(h,LB_GETCOUNT,0,0), x;
  328. for (x = 0; x < top; x ++)
  329. {
  330. char buf[1024] = {0}, buf2[64] = {0};
  331. lstrcpynA(buf,"test.", sizeof(buf)/sizeof(*buf));
  332. SendMessageW(h,LB_GETTEXT,x,(LPARAM)(buf+5));
  333. in_get_extended_fileinfo(buf,"type",buf2,32); // I FUCKING LOVE YOU rOn
  334. SendMessageW(h,LB_SETSEL,(!!atoi(buf2)) ^ (!!(LOWORD(wParam) == IDC_SELALL2)),x);
  335. }
  336. optchanged |= OPT_EXT;
  337. }
  338. break;
  339. case IDC_SELNONE:
  340. {
  341. int top = SendDlgItemMessage(hwndDlg,IDC_FTYPE_LIST,LB_GETCOUNT,0,0),x;
  342. for (x = 0; x < top; x ++)
  343. {
  344. SendDlgItemMessage(hwndDlg,IDC_FTYPE_LIST,LB_SETSEL,0,x);
  345. }
  346. optchanged |= OPT_EXT;
  347. }
  348. break;
  349. case IDC_RSTART:
  350. config_check_ft_startup=(IsDlgButtonChecked(hwndDlg,IDC_RSTART)?1:0);
  351. break;
  352. // 5.58+ (22/01/2010 - dro)
  353. // do this to track if an option has been changed so that elevation, etc
  354. // will only be done when it is needed as prior behaviour is to just set
  355. // the options again when things haven't been altered which is annoying
  356. // when you have a UAC prompt appearing when it really isn't needed
  357. case IDC_CD:
  358. optchanged ^= OPT_CD;
  359. break;
  360. case IDC_ADDFILES:
  361. optchanged ^= OPT_ENQ;
  362. break;
  363. case IDC_DIRCONTEXT:
  364. optchanged ^= OPT_DIR;
  365. break;
  366. case IDC_FTYPE_LIST:
  367. if(HIWORD(wParam) == LBN_SELCHANGE) optchanged |= OPT_EXT;
  368. break;
  369. }
  370. return 0;
  371. case WM_PAINT:
  372. {
  373. PAINTSTRUCT ps;
  374. HICON hIcon;
  375. RECT r;
  376. BeginPaint(hwndDlg,&ps);
  377. GetWindowRect(GetDlgItem(hwndDlg,IDC_FILETYPES_ICON),&r);
  378. ScreenToClient(hwndDlg,(LPPOINT) &r);
  379. ScreenToClient(hwndDlg,(LPPOINT) &r + 1);
  380. hIcon = (HICON)LoadImage(hMainInstance,MAKEINTRESOURCE(geticonid(config_whichicon)),IMAGE_ICON,32,32,LR_SHARED);
  381. if (hIcon)
  382. {
  383. DrawIconEx(ps.hdc,r.left,r.top,hIcon,32,32,0,NULL,DI_NORMAL);
  384. }
  385. GetWindowRect(GetDlgItem(hwndDlg,IDC_FILETYPES_ICON2),&r);
  386. ScreenToClient(hwndDlg,(LPPOINT) &r);
  387. ScreenToClient(hwndDlg,(LPPOINT) &r + 1);
  388. hIcon = (HICON)LoadImage(hMainInstance,MAKEINTRESOURCE(geticonid(config_whichicon2)),IMAGE_ICON,32,32,LR_SHARED);
  389. if (hIcon)
  390. {
  391. DrawIconEx(ps.hdc,r.left,r.top,hIcon,32,32,0,NULL,DI_NORMAL);
  392. }
  393. EndPaint(hwndDlg,&ps);
  394. }
  395. return 0;
  396. case WM_VSCROLL:
  397. {
  398. HWND swnd = (HWND) lParam;
  399. if (swnd == GetDlgItem(hwndDlg,IDC_FILETYPES_ICONSCROLL))
  400. {
  401. RECT r;
  402. config_whichicon = (unsigned char) SendMessageW(swnd,TBM_GETPOS,0,0);
  403. GetWindowRect(GetDlgItem(hwndDlg,IDC_FILETYPES_ICON),&r);
  404. ScreenToClient(hwndDlg,(LPPOINT) &r);
  405. ScreenToClient(hwndDlg,(LPPOINT) &r + 1);
  406. InvalidateRect(hwndDlg,&r,TRUE);
  407. optchanged |= OPT_ICON;
  408. }
  409. if (swnd == GetDlgItem(hwndDlg,IDC_FILETYPES_ICONSCROLL2))
  410. {
  411. RECT r;
  412. config_whichicon2 = (unsigned char) SendMessageW(swnd,TBM_GETPOS,0,0);
  413. GetWindowRect(GetDlgItem(hwndDlg,IDC_FILETYPES_ICON2),&r);
  414. ScreenToClient(hwndDlg,(LPPOINT) &r);
  415. ScreenToClient(hwndDlg,(LPPOINT) &r + 1);
  416. InvalidateRect(hwndDlg,&r,TRUE);
  417. optchanged |= OPT_ICON;
  418. }
  419. }
  420. return 0;
  421. }
  422. const int controls[] =
  423. {
  424. IDC_FILETYPES_ICONSCROLL,
  425. IDC_FILETYPES_ICONSCROLL2,
  426. };
  427. if (FALSE != DirectMouseWheel_ProcessDialogMessage(hwndDlg, uMsg, wParam, lParam, controls, ARRAYSIZE(controls)))
  428. return TRUE;
  429. link_handledraw(hwndDlg,uMsg,wParam,lParam);
  430. return FALSE;
  431. } // filetypes