1
0

config.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. #include "main.h"
  2. #include <shlobj.h>
  3. #include <commctrl.h>
  4. #include <windows.h>
  5. #include "../winamp/wa_ipc.h"
  6. #include "config.h"
  7. #include "api__in_mp3.h"
  8. #include "resource.h"
  9. char g_http_tmp[MAX_PATH] = {0};
  10. int config_write_mode = WRITE_UTF16;
  11. int config_read_mode = READ_LOCAL;
  12. int config_parse_apev2 = 1;
  13. int config_parse_lyrics3 = 1;
  14. int config_parse_id3v1 = 1;
  15. int config_parse_id3v2 = 1;
  16. int config_write_apev2 = 1;
  17. int config_write_id3v1 = 1;
  18. int config_write_id3v2 = 1;
  19. int config_create_id3v1 = 1;
  20. int config_create_id3v2 = 1;
  21. int config_create_apev2 = 0;
  22. int config_apev2_header = RETAIN_HEADER;
  23. int config_lp = 0;
  24. BOOL CALLBACK browseEnumProc(HWND hwnd, LPARAM lParam)
  25. {
  26. wchar_t cl[32] = {0};
  27. GetClassNameW(hwnd, cl, ARRAYSIZE(cl));
  28. if (!lstrcmpiW(cl, WC_TREEVIEW))
  29. {
  30. PostMessage(hwnd, TVM_ENSUREVISIBLE, 0, (LPARAM)TreeView_GetSelection(hwnd));
  31. return FALSE;
  32. }
  33. return TRUE;
  34. }
  35. static int CALLBACK BrowseCallbackProc( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  36. {
  37. switch (uMsg)
  38. {
  39. case BFFM_INITIALIZED:
  40. {
  41. SetWindowText(hwnd, WASABI_API_LNGSTRINGW(IDS_SELECT_DIRECTORY_TO_SAVE_TO));
  42. if (g_http_tmp[0]) SendMessage(hwnd, BFFM_SETSELECTIONA, 1, (LPARAM)g_http_tmp);
  43. // this is not nice but it fixes the selection not working correctly on all OSes
  44. EnumChildWindows(hwnd, browseEnumProc, 0);
  45. }
  46. }
  47. return 0;
  48. }
  49. static char app_name[] = "Nullsoft MPEG Decoder";
  50. char *get_inifile() { return INI_FILE; }
  51. int _r_i(char *name, int def)
  52. {
  53. if (!_strnicmp(name, "config_", 7)) name += 7;
  54. return GetPrivateProfileIntA(app_name, name, def, INI_FILE);
  55. }
  56. #define RI(x) (( x ) = _r_i(#x,( x )))
  57. void _w_i(char *name, int d)
  58. {
  59. char str[120] = {0};
  60. wsprintfA(str, "%d", d);
  61. if (!_strnicmp(name, "config_", 7)) name += 7;
  62. WritePrivateProfileStringA(app_name, name, str, INI_FILE);
  63. }
  64. #define WI(x) _w_i(#x,( x ))
  65. void _r_s(char *name, char *data, int mlen)
  66. {
  67. char buf[2048] = {0};
  68. lstrcpynA(buf, data, 2048);
  69. if (!_strnicmp(name, "config_", 7)) name += 7;
  70. GetPrivateProfileStringA(app_name, name, buf, data, mlen, INI_FILE);
  71. }
  72. #define RS(x) (_r_s(#x,x,sizeof(x)))
  73. void _w_s(char *name, char *data)
  74. {
  75. if (!_strnicmp(name, "config_", 7)) name += 7;
  76. WritePrivateProfileStringA(app_name, name, data, INI_FILE);
  77. }
  78. #define WS(x) (_w_s(#x,x))
  79. static void config_init()
  80. {
  81. char *p;
  82. if (mod.hMainWindow &&
  83. (p = (char *)SendMessage(mod.hMainWindow, WM_WA_IPC, 0, IPC_GETINIFILE))
  84. && p != (char *)1)
  85. {
  86. strncpy(INI_FILE, p, MAX_PATH);
  87. }
  88. else
  89. {
  90. GetModuleFileNameA(NULL, INI_FILE, sizeof(INI_FILE));
  91. p = INI_FILE + strlen(INI_FILE);
  92. while (p >= INI_FILE && *p != '.') p--;
  93. strcpy(++p, "ini");
  94. }
  95. }
  96. #ifdef AAC_SUPPORT
  97. #define DEF_EXT_LIST "MP3;MP2;MP1;AAC;VLB"
  98. #else
  99. #define DEF_EXT_LIST "MP3;MP2;MP1"
  100. #endif
  101. #define __STR2WSTR(str) L##str
  102. #define WIDEN(str) __STR2WSTR(str)
  103. #define DEF_EXT_LISTW WIDEN(DEF_EXT_LIST)
  104. #ifdef AAC_SUPPORT
  105. char config_extlist_aac[129] = DEF_EXT_LIST;
  106. #else
  107. char config_extlist[129] = DEF_EXT_LIST;
  108. #endif
  109. char config_rating_email[255] = {0};
  110. void config_read()
  111. {
  112. config_init();
  113. RI(allow_scartwork);
  114. RI(allow_sctitles);
  115. RI(sctitle_format);
  116. RI(config_http_buffersize);
  117. RI(config_http_prebuffer);
  118. RI(config_http_prebuffer_underrun);
  119. RI(config_downmix);
  120. RI(config_downsample);
  121. RI(config_max_bufsize_k);
  122. RI(config_eqmode);
  123. RI(config_gapless);
  124. if(FAILED(SHGetFolderPathA(NULL, CSIDL_MYMUSIC, NULL, SHGFP_TYPE_CURRENT, config_http_save_dir)))
  125. {
  126. if(FAILED(SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, config_http_save_dir)))
  127. {
  128. lstrcpynA(config_http_save_dir, "C:\\", MAX_PATH);
  129. }
  130. }
  131. RS(config_http_save_dir);
  132. RI(config_miscopts);
  133. RI(config_fastvis);
  134. #ifdef AAC_SUPPORT
  135. RS(config_extlist_aac);
  136. #else
  137. RS(config_extlist);
  138. #endif
  139. RI(config_write_mode);
  140. RI(config_read_mode);
  141. RI(config_parse_apev2);
  142. RI(config_parse_lyrics3);
  143. RI(config_parse_id3v1);
  144. RI(config_parse_id3v2);
  145. RI(config_write_apev2);
  146. RI(config_write_id3v1);
  147. RI(config_write_id3v2);
  148. RI(config_create_apev2);
  149. RI(config_create_id3v1);
  150. RI(config_create_id3v2);
  151. RI(config_apev2_header);
  152. RI(config_lp);
  153. RS(config_rating_email);
  154. }
  155. void config_write()
  156. {
  157. WI(allow_scartwork);
  158. WI(config_fastvis);
  159. WI(config_miscopts);
  160. WI(allow_sctitles);
  161. WI(sctitle_format);
  162. WI(config_http_buffersize);
  163. WI(config_http_buffersize);
  164. WI(config_http_prebuffer);
  165. WI(config_http_prebuffer_underrun);
  166. WI(config_downmix);
  167. WI(config_downsample);
  168. WI(config_max_bufsize_k);
  169. WI(config_eqmode);
  170. WS(config_http_save_dir);
  171. #ifdef AAC_SUPPORT
  172. WS(config_extlist_aac);
  173. #else
  174. WS(config_extlist);
  175. #endif
  176. WI(config_write_mode);
  177. WI(config_read_mode);
  178. WI(config_parse_apev2);
  179. WI(config_parse_lyrics3);
  180. WI(config_parse_id3v1);
  181. WI(config_parse_id3v2);
  182. WI(config_write_apev2);
  183. WI(config_write_id3v1);
  184. WI(config_write_id3v2);
  185. WI(config_create_apev2);
  186. WI(config_create_id3v1);
  187. WI(config_create_id3v2);
  188. WI(config_apev2_header);
  189. WI(config_lp);
  190. WS(config_rating_email);
  191. }
  192. static INT_PTR CALLBACK prefsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  193. static INT_PTR CALLBACK id3Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  194. static INT_PTR CALLBACK advancedTaggingProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  195. static INT_PTR CALLBACK httpProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  196. static INT_PTR CALLBACK outputProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  197. #define ISSEP(x) ((x) == ' ' || (x) == ';' || (x) == ',' || (x) == ':' || (x) == '.')
  198. char *getfileextensions()
  199. {
  200. static char list[512];
  201. char *op = list;
  202. // char *g_fileassos="MP3;MP2;MP1\0MPEG Audio Files (*.MP3;*.MP2;*.MP1)\0";
  203. char *p = config_extlist;
  204. int s = 0;
  205. while (p && *p)
  206. {
  207. while (ISSEP(*p)) p++;
  208. if (!p || !*p) break;
  209. if (s) *op++ = ';';
  210. s = 1;
  211. while (p && *p && !ISSEP(*p)) *op++ = *p++;
  212. }
  213. *op++ = 0;
  214. strcpy(op, WASABI_API_LNGSTRING(IDS_MPEG_AUDIO_FILES));
  215. while (op && *op) op++;
  216. p = config_extlist;
  217. s = 0;
  218. while (p && *p)
  219. {
  220. while (ISSEP(*p)) p++;
  221. if (!p || !*p) break;
  222. if (s) *op++ = ';';
  223. s = 1;
  224. *op++ = '*';
  225. *op++ = '.';
  226. while (p && *p && !ISSEP(*p)) *op++ = *p++;
  227. }
  228. *op++ = ')';
  229. *op++ = 0;
  230. *op++ = 0;
  231. return list;
  232. }
  233. void config(HWND hwndParent)
  234. {
  235. wchar_t title[128] = {0};
  236. int x;
  237. PROPSHEETHEADER pshead;
  238. PROPSHEETPAGE pspage[5];
  239. ZeroMemory(&pshead, sizeof(PROPSHEETHEADER));
  240. pshead.dwSize = sizeof(PROPSHEETHEADER);
  241. pshead.hwndParent = hwndParent;
  242. pshead.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP;
  243. pshead.hInstance = WASABI_API_LNG_HINST;
  244. pshead.pszCaption = WASABI_API_LNGSTRINGW_BUF(IDS_MPEG_AUDIO_DECODER_SETTINGS,title,128);//"MPEG Audio Decoder Settings";
  245. pshead.nPages = sizeof(pspage) / sizeof(pspage[0]);
  246. pshead.nStartPage = config_lp;
  247. pshead.ppsp = pspage;
  248. ZeroMemory(pspage, sizeof(pspage));
  249. for ( x = 0; x < sizeof(pspage) / sizeof(pspage[0]); x ++)
  250. pspage[x].dwSize = sizeof(PROPSHEETPAGE);
  251. for ( x = 0; x < sizeof(pspage) / sizeof(pspage[0]); x ++)
  252. pspage[x].hInstance = WASABI_API_LNG_HINST;
  253. pspage[0].pszTemplate = MAKEINTRESOURCE(IDD_PREFS);
  254. pspage[1].pszTemplate = MAKEINTRESOURCE(IDD_TAGOPTS);
  255. pspage[2].pszTemplate = MAKEINTRESOURCE(IDD_ADVANCED_TAGGING);
  256. pspage[3].pszTemplate = MAKEINTRESOURCE(IDD_OUTPUT);
  257. pspage[4].pszTemplate = MAKEINTRESOURCE(IDD_HTTP);
  258. pspage[0].pfnDlgProc = prefsProc;
  259. pspage[1].pfnDlgProc = id3Proc;
  260. pspage[2].pfnDlgProc = advancedTaggingProc;
  261. pspage[3].pfnDlgProc = outputProc;
  262. pspage[4].pfnDlgProc = httpProc;
  263. PropertySheet((PROPSHEETHEADER*)&pshead);
  264. config_write();
  265. extern char *g_fileassos;
  266. mod.FileExtensions = getfileextensions();
  267. }
  268. static INT_PTR CALLBACK id3Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  269. {
  270. switch (uMsg)
  271. {
  272. case WM_INITDIALOG:
  273. if (config_parse_id3v1) CheckDlgButton(hwndDlg, IDC_READ_ID3V1, BST_CHECKED);
  274. if (config_parse_id3v2) CheckDlgButton(hwndDlg, IDC_READ_ID3V2, BST_CHECKED);
  275. if (config_write_id3v1) CheckDlgButton(hwndDlg, IDC_WRITE_ID3V1, BST_CHECKED);
  276. if (config_write_id3v2) CheckDlgButton(hwndDlg, IDC_WRITE_ID3V2, BST_CHECKED);
  277. if (config_create_id3v1) CheckDlgButton(hwndDlg, IDC_CREATE_ID3V1, BST_CHECKED);
  278. if (config_create_id3v2) CheckDlgButton(hwndDlg, IDC_CREATE_ID3V2, BST_CHECKED);
  279. SendDlgItemMessage(hwndDlg,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_LATIN_1));
  280. SendDlgItemMessage(hwndDlg,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_SYSTEM_LANGUAGE));
  281. SendDlgItemMessage(hwndDlg,IDC_COMBO1,CB_SETCURSEL,(config_read_mode == READ_LOCAL),0);
  282. SendDlgItemMessage(hwndDlg,IDC_COMBO2,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_UNICODE_UTF_16));
  283. SendDlgItemMessage(hwndDlg,IDC_COMBO2,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_LATIN_1));
  284. SendDlgItemMessage(hwndDlg,IDC_COMBO2,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_SYSTEM_LANGUAGE));
  285. SendDlgItemMessage(hwndDlg,IDC_COMBO2,CB_SETCURSEL,config_write_mode,0);
  286. SetDlgItemTextA(hwndDlg,IDC_RATING_EMAIL,(config_rating_email[0] ? config_rating_email : "[email protected]\0"));
  287. return FALSE;
  288. case WM_NOTIFY:
  289. {
  290. LPNMHDR pnmh = (LPNMHDR) lParam;
  291. if (pnmh->code == PSN_SETACTIVE)
  292. {
  293. config_lp = 1;
  294. }
  295. if (pnmh->code == PSN_APPLY)
  296. {
  297. config_parse_id3v1 = IsDlgButtonChecked(hwndDlg, IDC_READ_ID3V1);
  298. config_parse_id3v2 = IsDlgButtonChecked(hwndDlg, IDC_READ_ID3V2);
  299. config_write_id3v1 = IsDlgButtonChecked(hwndDlg, IDC_WRITE_ID3V1);
  300. config_write_id3v2 = IsDlgButtonChecked(hwndDlg, IDC_WRITE_ID3V2);
  301. config_create_id3v1 = IsDlgButtonChecked(hwndDlg, IDC_CREATE_ID3V1);
  302. config_create_id3v2 = IsDlgButtonChecked(hwndDlg, IDC_CREATE_ID3V2);
  303. GetDlgItemTextA(hwndDlg,IDC_RATING_EMAIL,config_rating_email,sizeof(config_rating_email));
  304. if (!stricmp(config_rating_email, "[email protected]\0")) config_rating_email[0] = 0;
  305. return TRUE;
  306. }
  307. }
  308. return FALSE;
  309. case WM_COMMAND:
  310. switch (LOWORD(wParam))
  311. {
  312. case IDC_COMBO1:
  313. if(HIWORD(wParam) == CBN_SELCHANGE)
  314. {
  315. int cur = (int)SendMessage((HWND)lParam,CB_GETCURSEL,0,0);
  316. if(!cur) config_read_mode = READ_LATIN;
  317. else if(cur == 1) config_read_mode = READ_LOCAL;
  318. }
  319. break;
  320. case IDC_COMBO2:
  321. if(HIWORD(wParam) == CBN_SELCHANGE)
  322. {
  323. int cur = (int)SendMessage((HWND)lParam,CB_GETCURSEL,0,0);
  324. if(!cur) config_write_mode = WRITE_UTF16;
  325. else if(cur == 1) config_write_mode = WRITE_LATIN;
  326. else if(cur == 2) config_write_mode = WRITE_LOCAL;
  327. }
  328. break;
  329. case IDC_RATING_EMAIL_RESET:
  330. if(HIWORD(wParam) == BN_CLICKED)
  331. {
  332. config_rating_email[0] = 0;
  333. SetDlgItemTextA(hwndDlg,IDC_RATING_EMAIL,(config_rating_email[0] ? config_rating_email : "[email protected]\0"));
  334. }
  335. }
  336. return FALSE;
  337. }
  338. return FALSE;
  339. }
  340. static INT_PTR CALLBACK advancedTaggingProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  341. {
  342. switch (uMsg)
  343. {
  344. case WM_INITDIALOG:
  345. if (config_parse_apev2) CheckDlgButton(hwndDlg, IDC_READ_APEV2, BST_CHECKED);
  346. if (config_write_apev2) CheckDlgButton(hwndDlg, IDC_WRITE_APEV2, BST_CHECKED);
  347. if (config_create_apev2) CheckDlgButton(hwndDlg, IDC_CREATE_APEV2, BST_CHECKED);
  348. if (config_parse_lyrics3) CheckDlgButton(hwndDlg, IDC_READ_LYRICS3, BST_CHECKED);
  349. SendDlgItemMessage(hwndDlg,IDC_APEV2_HEADER_OPTIONS,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_APEV2_RETAIN_HEADER));
  350. SendDlgItemMessage(hwndDlg,IDC_APEV2_HEADER_OPTIONS,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_APEV2_ADD_HEADER));
  351. SendDlgItemMessage(hwndDlg,IDC_APEV2_HEADER_OPTIONS,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_APEV2_REMOVE_HEADER));
  352. SendDlgItemMessage(hwndDlg,IDC_APEV2_HEADER_OPTIONS,CB_SETCURSEL,config_apev2_header, 0);
  353. return FALSE;
  354. case WM_NOTIFY:
  355. {
  356. LPNMHDR pnmh = (LPNMHDR) lParam;
  357. if (pnmh->code == PSN_SETACTIVE)
  358. {
  359. config_lp = 2;
  360. }
  361. if (pnmh->code == PSN_APPLY)
  362. {
  363. config_parse_apev2 = IsDlgButtonChecked(hwndDlg, IDC_READ_APEV2);
  364. config_write_apev2 = IsDlgButtonChecked(hwndDlg, IDC_WRITE_APEV2);
  365. config_create_apev2 = IsDlgButtonChecked(hwndDlg, IDC_CREATE_APEV2);
  366. config_parse_lyrics3 = IsDlgButtonChecked(hwndDlg, IDC_READ_LYRICS3);
  367. return TRUE;
  368. }
  369. }
  370. return FALSE;
  371. case WM_COMMAND:
  372. switch (LOWORD(wParam))
  373. {
  374. case IDC_APEV2_HEADER_OPTIONS:
  375. if(HIWORD(wParam) == CBN_SELCHANGE)
  376. {
  377. int cur = (int)SendMessage((HWND)lParam,CB_GETCURSEL,0,0);
  378. if(!cur) config_apev2_header = RETAIN_HEADER;
  379. else if(cur == 1) config_apev2_header = ADD_HEADER;
  380. else if(cur == 2) config_apev2_header = REMOVE_HEADER;
  381. }
  382. break;
  383. }
  384. return FALSE;
  385. }
  386. return FALSE;
  387. }
  388. static INT_PTR CALLBACK prefsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  389. {
  390. switch (uMsg)
  391. {
  392. case WM_INITDIALOG:
  393. SetDlgItemTextA(hwndDlg, IDC_EDIT1, config_extlist);
  394. SendDlgItemMessage(hwndDlg, IDC_EDIT1, EM_LIMITTEXT, 128, 0);
  395. {
  396. wchar_t str[10] = L"";
  397. wsprintf(str, L"%d", config_max_bufsize_k);
  398. SetDlgItemText(hwndDlg, IDC_BUFMAX, str);
  399. SendMessage(GetDlgItem(hwndDlg, IDC_BUFMAX), EM_LIMITTEXT, 5, 0);
  400. }
  401. return FALSE;
  402. case WM_COMMAND:
  403. switch (LOWORD(wParam))
  404. {
  405. case IDC_BUTTON1:
  406. SetDlgItemText(hwndDlg, IDC_EDIT1, DEF_EXT_LISTW);
  407. break;
  408. }
  409. return FALSE;
  410. case WM_NOTIFY:
  411. {
  412. LPNMHDR pnmh = (LPNMHDR) lParam;
  413. if (pnmh->code == PSN_SETACTIVE)
  414. {
  415. config_lp = 0;
  416. }
  417. if (pnmh->code == PSN_APPLY)
  418. {
  419. config_max_bufsize_k = GetDlgItemInt(hwndDlg, IDC_BUFMAX, NULL, 0);
  420. GetDlgItemTextA(hwndDlg, IDC_EDIT1, config_extlist, 128);
  421. return TRUE;
  422. }
  423. }
  424. return FALSE;
  425. }
  426. return FALSE;
  427. }
  428. static INT_PTR CALLBACK outputProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  429. {
  430. switch (uMsg)
  431. {
  432. case WM_INITDIALOG:
  433. if (config_eqmode&1) CheckDlgButton(hwndDlg, IDC_RADIO2, 1);
  434. else CheckDlgButton(hwndDlg, IDC_RADIO1, 1);
  435. if (!(config_eqmode&4)) CheckDlgButton(hwndDlg, IDC_FASTL3EQ, 1);
  436. if (config_eqmode&8) CheckDlgButton(hwndDlg, IDC_FASTL12EQ, 1);
  437. if (config_miscopts&1) CheckDlgButton(hwndDlg, IDC_CHECK1, BST_CHECKED);
  438. if (config_miscopts&2) CheckDlgButton(hwndDlg, IDC_CHECK2, BST_CHECKED);
  439. if (config_downmix == 2) CheckDlgButton(hwndDlg, IDC_REVSTEREO, BST_CHECKED);
  440. if (config_downsample == 1)
  441. CheckDlgButton(hwndDlg, IDC_HALFRATE, BST_CHECKED);
  442. else if (config_downsample == 2)
  443. CheckDlgButton(hwndDlg, IDC_QRATE, BST_CHECKED);
  444. else
  445. CheckDlgButton(hwndDlg, IDC_FULLRATE, BST_CHECKED);
  446. return FALSE;
  447. case WM_NOTIFY:
  448. {
  449. LPNMHDR pnmh = (LPNMHDR) lParam;
  450. if (pnmh->code == PSN_SETACTIVE)
  451. {
  452. config_lp = 3;
  453. }
  454. if (pnmh->code == PSN_APPLY)
  455. {
  456. config_miscopts &= ~3;
  457. config_miscopts |= IsDlgButtonChecked(hwndDlg, IDC_CHECK1) ? 1 : 0;
  458. config_miscopts |= IsDlgButtonChecked(hwndDlg, IDC_CHECK2) ? 2 : 0;
  459. config_eqmode = IsDlgButtonChecked(hwndDlg, IDC_RADIO1) ? 0 : 1;
  460. config_eqmode |= IsDlgButtonChecked(hwndDlg, IDC_FASTL3EQ) ? 0 : 4;
  461. config_eqmode |= IsDlgButtonChecked(hwndDlg, IDC_FASTL12EQ) ? 8 : 0;
  462. config_downmix = IsDlgButtonChecked(hwndDlg, IDC_REVSTEREO) ? 2 : 0;
  463. config_downsample = IsDlgButtonChecked(hwndDlg, IDC_HALFRATE) ? 1 : 0;
  464. config_downsample = IsDlgButtonChecked(hwndDlg, IDC_QRATE) ? 2 : config_downsample;
  465. return TRUE;
  466. }
  467. }
  468. return FALSE;
  469. }
  470. return FALSE;
  471. }
  472. void SetHTTPSaveButtonText(HWND hwndDlg, char* path)
  473. {
  474. HWND control = GetDlgItem(hwndDlg, IDC_BUTTON2);
  475. HDC hdc = GetDC(control);
  476. RECT r = {0};
  477. char temp[MAX_PATH] = {0};
  478. lstrcpynA(temp, path, MAX_PATH);
  479. SelectObject(hdc, (HFONT)SendMessage(control, WM_GETFONT, 0, 0));
  480. GetClientRect(control, &r);
  481. r.left += 5;
  482. r.right -= 5;
  483. DrawTextA(hdc, temp, -1, &r, DT_PATH_ELLIPSIS|DT_WORD_ELLIPSIS|DT_MODIFYSTRING);
  484. SetWindowTextA(control, temp);
  485. ReleaseDC(control, hdc);
  486. }
  487. static INT_PTR CALLBACK httpProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  488. {
  489. switch (uMsg)
  490. {
  491. case WM_COMMAND:
  492. switch (LOWORD(wParam))
  493. {
  494. case IDC_CHECK2:
  495. EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON2), IsDlgButtonChecked(hwndDlg, IDC_CHECK2));
  496. break;
  497. case IDC_BUTTON2:
  498. {
  499. BROWSEINFO bi = {0};
  500. wchar_t name[MAX_PATH] = {0};
  501. bi.hwndOwner = hwndDlg;
  502. bi.pszDisplayName = name;
  503. bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
  504. bi.lpfn = BrowseCallbackProc;
  505. LPITEMIDLIST idlist = SHBrowseForFolder(&bi);
  506. if (idlist)
  507. {
  508. SHGetPathFromIDListA(idlist, g_http_tmp);
  509. IMalloc *m = 0;
  510. SHGetMalloc(&m);
  511. m->Free(idlist);
  512. SetHTTPSaveButtonText(hwndDlg, g_http_tmp);
  513. }
  514. }
  515. return 0;
  516. }
  517. return 0;
  518. case WM_INITDIALOG:
  519. SetDlgItemInt(hwndDlg, IDC_BUFFERS_NUMBUFS, config_http_buffersize, 0);
  520. SendMessage(GetDlgItem(hwndDlg, IDC_PREBUFSLIDER), TBM_SETRANGEMAX, 0, 50);
  521. SendMessage(GetDlgItem(hwndDlg, IDC_PREBUFSLIDER), TBM_SETRANGEMIN, 0, 0);
  522. SendMessage(GetDlgItem(hwndDlg, IDC_PREBUFSLIDER), TBM_SETPOS, 1, config_http_prebuffer / 2);
  523. SendMessage(GetDlgItem(hwndDlg, IDC_PREBUFSLIDER2), TBM_SETRANGEMAX, 0, 50);
  524. SendMessage(GetDlgItem(hwndDlg, IDC_PREBUFSLIDER2), TBM_SETRANGEMIN, 0, 0);
  525. SendMessage(GetDlgItem(hwndDlg, IDC_PREBUFSLIDER2), TBM_SETPOS, 1, config_http_prebuffer_underrun / 2);
  526. CheckDlgButton(hwndDlg, IDC_CHECK1, allow_sctitles);
  527. CheckDlgButton(hwndDlg, IDC_SC_ARTWORK, allow_scartwork);
  528. CheckDlgButton(hwndDlg, IDC_CHECK3, sctitle_format);
  529. if (config_miscopts&16)
  530. {
  531. CheckDlgButton(hwndDlg, IDC_CHECK2, BST_CHECKED);
  532. }
  533. EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON2), (config_miscopts&16));
  534. SetHTTPSaveButtonText(hwndDlg, config_http_save_dir);
  535. lstrcpynA(g_http_tmp, config_http_save_dir, MAX_PATH);
  536. return FALSE;
  537. case WM_NOTIFY:
  538. {
  539. LPNMHDR pnmh = (LPNMHDR) lParam;
  540. if (pnmh->code == PSN_SETACTIVE)
  541. {
  542. config_lp = 4;
  543. }
  544. if (pnmh->code == PSN_APPLY)
  545. {
  546. sctitle_format = !!IsDlgButtonChecked(hwndDlg, IDC_CHECK3);
  547. allow_sctitles = !!IsDlgButtonChecked(hwndDlg, IDC_CHECK1);
  548. allow_scartwork = !!IsDlgButtonChecked(hwndDlg, IDC_SC_ARTWORK);
  549. {
  550. int s;
  551. int t;
  552. t = GetDlgItemInt(hwndDlg, IDC_BUFFERS_NUMBUFS, &s, 0);
  553. if (s) config_http_buffersize = t;
  554. if (config_http_buffersize < 16) config_http_buffersize = 16;
  555. }
  556. config_http_prebuffer = (int)SendMessage(GetDlgItem(hwndDlg, IDC_PREBUFSLIDER), TBM_GETPOS, 0, 0) * 2;
  557. config_http_prebuffer_underrun = (int)SendMessage(GetDlgItem(hwndDlg, IDC_PREBUFSLIDER2), TBM_GETPOS, 0, 0) * 2;
  558. lstrcpynA(config_http_save_dir, g_http_tmp, MAX_PATH);
  559. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK2))
  560. {
  561. config_miscopts |= 16;
  562. }
  563. else
  564. {
  565. config_miscopts &= ~16;
  566. }
  567. return TRUE;
  568. }
  569. }
  570. return FALSE;
  571. }
  572. const int controls[] =
  573. {
  574. IDC_PREBUFSLIDER,
  575. IDC_PREBUFSLIDER2,
  576. };
  577. if (FALSE != WASABI_API_APP->DirectMouseWheel_ProcessDialogMessage(hwndDlg, uMsg, wParam, lParam, controls, ARRAYSIZE(controls)))
  578. {
  579. return TRUE;
  580. }
  581. return FALSE;
  582. }
  583. int DoAboutMessageBox(HWND parent, wchar_t* title, wchar_t* message)
  584. {
  585. MSGBOXPARAMSW msgbx = {sizeof(MSGBOXPARAMSW),0};
  586. msgbx.lpszText = message;
  587. msgbx.lpszCaption = title;
  588. msgbx.lpszIcon = MAKEINTRESOURCE(102);
  589. msgbx.hInstance = GetModuleHandle(0);
  590. msgbx.dwStyle = MB_USERICON;
  591. msgbx.hwndOwner = parent;
  592. return MessageBoxIndirectW(&msgbx);
  593. }
  594. void about(HWND hwndParent)
  595. {
  596. wchar_t message[1024] = {0}, text[1024] = {0};
  597. WASABI_API_LNGSTRINGW_BUF(IDS_NULLSOFT_MPEG_AUDIO_DECODER_OLD,text,1024);
  598. wsprintfW(message, WASABI_API_LNGSTRINGW(IDS_ABOUT_TEXT),
  599. mod.description, __DATE__);
  600. DoAboutMessageBox(hwndParent,text,message);
  601. }