Eq.cpp 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. #include <windowsx.h>
  2. #include "Main.h"
  3. #include "api.h"
  4. #include "../nu/AutoChar.h"
  5. #include "../nu/ns_wc.h"
  6. unsigned char eq_tab[10] = {31, 31, 31, 31, 31, 31, 31, 31, 31, 31};
  7. static int writeEQfile(wchar_t *file, char *name);
  8. static int readEQfile(wchar_t *file, char *name);
  9. static void deleteEQfile(wchar_t *file, char *name);
  10. static void addEQtolistbox(wchar_t *file, HWND listbox);
  11. static BOOL CALLBACK loadpresetProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  12. static BOOL CALLBACK delpresetProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  13. static BOOL CALLBACK savepresetProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  14. static BOOL CALLBACK loadmp3Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  15. static BOOL CALLBACK savemp3Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  16. static BOOL CALLBACK delmp3Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  17. static BOOL CALLBACK eqProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  18. static int EQ_OnRButtonUp(HWND hwnd, int x, int y, UINT flags);
  19. static int EQ_OnLButtonDblClk(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
  20. {
  21. if ((config_dsize && config_eqdsize ? 1 : 0)) { x /= 2; y /= 2; }
  22. if (y <= 14 && x < 252)
  23. {
  24. SendMessageW(hMainWindow, WM_COMMAND, WINAMP_OPTIONS_WINDOWSHADE_EQ, 0);
  25. }
  26. return 1;
  27. }
  28. static int EQ_OnLButtonUp(HWND hwnd, int x, int y, UINT flags);
  29. static int EQ_OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags);
  30. static int EQ_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags);
  31. static BOOL EQ_OnNCActivate(HWND hwnd, BOOL fActive, HWND hwndActDeact, BOOL fMinimized);
  32. static char last_preset[128] = "Default";
  33. static char sig[] = "Winamp EQ library file v1.1\x1A!--";
  34. void eq_autoload(const char *mp3fn)
  35. {
  36. if (!config_autoload_eq)
  37. return;
  38. if (readEQfile(EQDIR2, scanstr_back((char*)mp3fn, "\\", (char*)mp3fn - 1) + 1))
  39. readEQfile(EQDIR1, "Default");
  40. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  41. }
  42. void eq_dialog(HWND hwnd, int init_state)
  43. {
  44. if (!hEQWindow)
  45. return;
  46. int toggle = Ipc_WindowToggle(IPC_CB_WND_EQ, !config_eq_open);
  47. KillTimer(hEQWindow, 3);
  48. if (!toggle)
  49. return;
  50. if (!config_eq_open)
  51. {
  52. CheckMenuItem(main_menu, WINAMP_OPTIONS_EQ, MF_CHECKED);
  53. if (eq_startuphack)
  54. {
  55. if(!GetParent(hEQWindow))
  56. SetTimer(hEQWindow, 3, 10, NULL);
  57. config_eq_open = 1;
  58. }
  59. else
  60. {
  61. if(!init_state && !config_minimized)
  62. ShowWindow(hEQWindow, SW_SHOWNA);
  63. config_eq_open = 1;
  64. if (config_eq_ws)
  65. draw_eq_tbar(GetForegroundWindow() == hEQWindow ? 1 : (config_hilite ? 0 : 1));
  66. set_aot(1);
  67. }
  68. }
  69. else
  70. {
  71. if (GetForegroundWindow() == hEQWindow || IsChild(hEQWindow, GetForegroundWindow()))
  72. {
  73. SendMessageW(hMainWindow, WM_COMMAND, WINAMP_NEXT_WINDOW, 0);
  74. }
  75. CheckMenuItem(main_menu, WINAMP_OPTIONS_EQ, MF_UNCHECKED);
  76. ShowWindow(hEQWindow, SW_HIDE);
  77. config_eq_open = 0;
  78. }
  79. draw_eqplbut(config_eq_open, 0, config_pe_open, 0);
  80. return ;
  81. }
  82. static void
  83. EqWindow_OnMouseWheel(HWND hwnd, INT virtualKeys, INT distance, LONG pointer_s)
  84. {
  85. SendMessageW(hMainWindow, WM_MOUSEWHEEL, MAKEWPARAM(virtualKeys, distance), (LPARAM)pointer_s);
  86. }
  87. LRESULT CALLBACK EQ_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  88. {
  89. switch (uMsg)
  90. {
  91. case WM_NOTIFY:
  92. {
  93. LPTOOLTIPTEXT tt = (LPTOOLTIPTEXT)lParam;
  94. if(tt->hdr.hwndFrom = hEQTooltipWindow)
  95. {
  96. switch (tt->hdr.code)
  97. {
  98. case TTN_SHOW:
  99. SetWindowPos(tt->hdr.hwndFrom,HWND_TOPMOST,0,0,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE);
  100. break;
  101. }
  102. }
  103. }
  104. break;
  105. case WM_DESTROY:
  106. KillTimer(hwnd, 3);
  107. if (eq_init)
  108. draw_eq_kill();
  109. if (NULL != WASABI_API_APP) WASABI_API_APP->app_unregisterGlobalWindow(hwnd);
  110. break;
  111. case WM_TIMER:
  112. if (wParam == 3)
  113. {
  114. KillTimer(hwnd, 3);
  115. if (!IsMinimized(hMainWindow))
  116. {
  117. ShowWindow(hwnd, SW_SHOWNA);
  118. }
  119. // works around a quirk with Bento docked to the right-hand edge
  120. // where the pledit is left docked on reverting to classic skin (dro)
  121. if(!GetParent(hwnd)) set_aot(1);
  122. }
  123. break;
  124. case WM_DISPLAYCHANGE:
  125. InvalidateRect(hwnd, NULL, TRUE);
  126. break;
  127. case WM_SHOWWINDOW:
  128. if (wParam == TRUE && lParam == SW_PARENTOPENING && !config_eq_open)
  129. {
  130. return 0;
  131. }
  132. break;
  133. HANDLE_MSG(hwnd, WM_QUERYNEWPALETTE, Main_OnQueryNewPalette);
  134. HANDLE_MSG(hwnd, WM_PALETTECHANGED, Main_OnPaletteChanged);
  135. HANDLE_MSG(hwnd, WM_LBUTTONUP, EQ_OnLButtonUp);
  136. HANDLE_MSG(hwnd, WM_RBUTTONUP, EQ_OnRButtonUp);
  137. HANDLE_MSG(hwnd, WM_LBUTTONDBLCLK, EQ_OnLButtonDblClk);
  138. HANDLE_MSG(hwnd, WM_LBUTTONDOWN, EQ_OnLButtonDown);
  139. HANDLE_MSG(hwnd, WM_MOUSEMOVE, EQ_OnMouseMove);
  140. HANDLE_MSG(hwnd, WM_NCACTIVATE, EQ_OnNCActivate);
  141. case WM_SYSCOMMAND:
  142. if ((wParam & 0xfff0) == SC_SCREENSAVE || (wParam & 0xfff0) == SC_MONITORPOWER)
  143. return SendMessageW(hMainWindow, uMsg, wParam, lParam);
  144. break;
  145. case WM_CLOSE:
  146. WASABI_API_APP->main_shutdown();
  147. return 0;
  148. case WM_PRINTCLIENT:
  149. draw_printclient_eq((HDC)wParam, lParam);
  150. return 0;
  151. case WM_PAINT:
  152. draw_paint_eq(hwnd);
  153. return 0;
  154. case WM_SETCURSOR:
  155. if (config_usecursors && !disable_skin_cursors)
  156. {
  157. if ((HWND)wParam == hEQWindow && HIWORD(lParam) == WM_MOUSEMOVE) eq_ui_handlecursor();
  158. return TRUE;
  159. }
  160. else SetCursor(LoadCursor(NULL, IDC_ARROW));
  161. break;
  162. case WM_CREATE:
  163. hEQWindow = hwnd;
  164. SetWindowLongPtrW(hEQWindow, GWLP_USERDATA, (config_keeponscreen&2) ? 0x49474541 : 0);
  165. {
  166. int w = WINDOW_WIDTH << ((config_dsize && config_eqdsize) ? 1 : 0);
  167. int h = ((config_eq_ws ? 14 : WINDOW_HEIGHT)) << ((config_dsize && config_eqdsize) ? 1 : 0);
  168. SetWindowLong(hwnd, GWL_STYLE, GetWindowLongW(hwnd, GWL_STYLE)&~(WS_CAPTION));
  169. SetWindowPos(hEQWindow, 0, config_eq_wx, config_eq_wy, w, h, SWP_NOACTIVATE | SWP_NOZORDER | SWP_HIDEWINDOW);
  170. HACCEL hAccel = LoadAcceleratorsW(language_pack_instance, MAKEINTRESOURCEW(IDR_ACCELERATOR_EQ));
  171. if (!hAccel && language_pack_instance != hMainInstance) hAccel = LoadAcceleratorsW(hMainInstance, MAKEINTRESOURCEW(IDR_ACCELERATOR_EQ));
  172. if (hAccel) WASABI_API_APP->app_addAccelerators(hwnd, &hAccel, 1, TRANSLATE_MODE_NORMAL);
  173. }
  174. if (NULL != WASABI_API_APP) WASABI_API_APP->app_registerGlobalWindow(hwnd);
  175. return 0;
  176. case WM_USER:
  177. {
  178. int x;
  179. draw_eq_slid(0, config_preamp, 0);
  180. for (x = 1; x <= 10; x ++)
  181. draw_eq_slid(x, eq_tab[x - 1], 0);
  182. draw_eq_graphthingy();
  183. }
  184. return 0;
  185. case WM_COMMAND:
  186. switch (LOWORD(wParam))
  187. {
  188. case EQ_PANLEFT:
  189. if (config_pan - 4 < -128) config_pan = -128;
  190. else
  191. {
  192. if (config_pan - 4 > 0 && config_pan - 4 < 20) config_pan = 0;
  193. else config_pan -= 4;
  194. }
  195. in_setpan(config_pan);
  196. draw_panbar(config_pan, 0);
  197. update_panning_text(-2);
  198. return 0;
  199. case EQ_PANRIGHT:
  200. if (config_pan + 4 > 127) config_pan = 127;
  201. else
  202. {
  203. if (config_pan + 4 < 0 && config_pan + 4 > -20) config_pan = 0;
  204. else config_pan += 4;
  205. }
  206. in_setpan(config_pan);
  207. draw_panbar(config_pan, 0);
  208. update_panning_text(-2);
  209. return 0;
  210. case WINAMP_OPTIONS_WINDOWSHADE:
  211. SendMessageW(hMainWindow, WM_COMMAND, WINAMP_OPTIONS_WINDOWSHADE_EQ, 0);
  212. return 0;
  213. case IDM_EQ_LOADDEFAULT:
  214. readEQfile(EQDIR1, "Default");
  215. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  216. return 0;
  217. case IDM_EQ_SAVEDEFAULT:
  218. {
  219. writeEQfile(EQDIR1, "Default");
  220. }
  221. return 0;
  222. case ID_SAVE_EQF:
  223. case ID_LOAD_EQF:
  224. {
  225. wchar_t filename[1024] = {0};
  226. size_t size, ns;
  227. wchar_t *filter, *sf;
  228. UINT operation;
  229. OPENFILENAMEW l = {sizeof(OPENFILENAMEW), 0};
  230. size = 1024;
  231. filter = (wchar_t*)calloc(size, sizeof(wchar_t));
  232. sf = filter;
  233. ns = 1;
  234. getStringW(IDS_P_FILE_EQ, filter, size);
  235. StringCbLengthW(filter, size, &ns);
  236. size -= (++ns);
  237. filter += ns;
  238. StringCchCopyW(filter, size, L"*.eqf");
  239. StringCbLengthW(filter, size, &ns);
  240. size -= (++ns);
  241. filter += ns;
  242. getStringW(IDS_P_FILE_ALL, filter, size);
  243. StringCbLengthW(filter, size, &ns);
  244. size -= (++ns);
  245. filter += ns;
  246. StringCchCopyW(filter, size, L"*.*");
  247. StringCbLengthW(filter, size, &ns);
  248. //size -= (ns + 2);
  249. l.hwndOwner = hwnd;
  250. l.lpstrFilter = sf;
  251. l.lpstrFile = filename;
  252. l.nMaxFile = sizeof(filename) - 1;
  253. operation = (LOWORD(wParam) == ID_SAVE_EQF) ? IDS_P_EQ_FILE_WRITE : IDS_P_EQ_FILE_READ;
  254. l.lpstrTitle = getStringW(operation, NULL, 0);
  255. l.lpstrDefExt = L"eqf";
  256. l.Flags = OFN_HIDEREADONLY | OFN_EXPLORER;
  257. UninitDragDrops();
  258. if ((LOWORD(wParam) == ID_SAVE_EQF && GetSaveFileNameW(&l)) ||
  259. (LOWORD(wParam) != ID_SAVE_EQF && GetOpenFileNameW(&l)))
  260. {
  261. if (LOWORD(wParam) == ID_SAVE_EQF) writeEQfile(filename, "Entry1");
  262. else
  263. {
  264. readEQfile(filename, "Entry1");
  265. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  266. }
  267. }
  268. InitDragDrops();
  269. free(sf);
  270. }
  271. return 0;
  272. case IDM_EQ_SAVEPRE:
  273. LPDialogBoxW(IDD_SAVEPRESET, DIALOG_PARENT(hwnd), (WNDPROC)savepresetProc);
  274. return 0;
  275. case IDM_EQ_SAVEMP3:
  276. LPDialogBoxW(IDD_SAVEPRESET, DIALOG_PARENT(hwnd), (WNDPROC)savemp3Proc);
  277. return 0;
  278. case IDM_EQ_LOADPRE:
  279. LPDialogBoxW(IDD_LOADPRESET, DIALOG_PARENT(hwnd), (WNDPROC)loadpresetProc);
  280. return 0;
  281. case IDM_EQ_DELPRE:
  282. LPDialogBoxW(IDD_LOADPRESET, DIALOG_PARENT(hwnd), (WNDPROC)delpresetProc);
  283. return 0;
  284. case IDM_EQ_DELMP3:
  285. LPDialogBoxW(IDD_LOADPRESET, DIALOG_PARENT(hwnd), (WNDPROC)delmp3Proc);
  286. return 0;
  287. case IDM_EQ_LOADMP3:
  288. LPDialogBoxW(IDD_LOADPRESET, DIALOG_PARENT(hwnd), (WNDPROC)loadmp3Proc);
  289. return 0;
  290. case EQ_PRESETS:
  291. {
  292. extern HMENU top_menu;
  293. POINT p = {218, 19};
  294. if ((config_dsize && config_eqdsize))
  295. {
  296. p.x *= 2;
  297. p.y *= 2;
  298. }
  299. ClientToScreen(hEQWindow, &p);
  300. DoTrackPopup(GetSubMenu(top_menu, 1), TPM_LEFTALIGN, p.x, p.y, hEQWindow);
  301. }
  302. return 0;
  303. case EQ_AUTO:
  304. config_autoload_eq = !config_autoload_eq;
  305. draw_eq_onauto(config_use_eq, config_autoload_eq, 0, 0);
  306. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  307. return 0;
  308. case EQ_ENABLE:
  309. config_use_eq = !config_use_eq;
  310. eq_set(config_use_eq, (char*)eq_tab, config_preamp);
  311. draw_eq_onauto(config_use_eq, config_autoload_eq, 0, 0);
  312. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  313. return 0;
  314. case WINAMP_NEXT_WINDOW:
  315. return SendMessageW(hMainWindow, uMsg, wParam, lParam);
  316. case ID_PE_CLOSE:
  317. SendMessageW(hMainWindow, WM_COMMAND, WINAMP_OPTIONS_EQ, 0);
  318. return 0;
  319. default:
  320. {
  321. int id = LOWORD(wParam);
  322. if (id == EQ_INCPRE || id == EQ_DECPRE ||
  323. (id >= EQ_DEC1 && id <= EQ_DEC10) ||
  324. (id >= EQ_INC1 && id <= EQ_INC10))
  325. {
  326. int x;
  327. int addsub = ((id >= EQ_DEC1 && id <= EQ_DEC10) || id == EQ_DECPRE) ? -2 : 2;
  328. if (id == EQ_INCPRE || id == EQ_DECPRE)
  329. {
  330. config_preamp -= addsub;
  331. if (config_preamp < 0) config_preamp = 0;
  332. if (config_preamp > 63) config_preamp = 63;
  333. }
  334. else
  335. {
  336. int o = (id - (addsub > 0 ? EQ_INC1 : EQ_DEC1));
  337. int p = eq_tab[o];
  338. p -= addsub;
  339. if (p < 0) p = 0;
  340. if (p > 63) p = 63;
  341. eq_tab[o] = p;
  342. }
  343. draw_eq_slid(0, config_preamp, 0);
  344. for (x = 1; x <= 10; x ++)
  345. draw_eq_slid(x, eq_tab[x - 1], 0);
  346. draw_eq_graphthingy();
  347. eq_set(config_use_eq, (char*)eq_tab, config_preamp);
  348. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  349. }
  350. else
  351. {
  352. SendMessageW(hMainWindow, uMsg, wParam, lParam);
  353. if (GetForegroundWindow() == hMainWindow) SetForegroundWindow(hEQWindow);
  354. }
  355. }
  356. }
  357. return 0;
  358. case WM_MOUSEWHEEL:
  359. EqWindow_OnMouseWheel(hwnd, LOWORD(wParam), (SHORT)HIWORD(wParam), (LONG)lParam);
  360. return 0;
  361. }
  362. if (FALSE != IsDirectMouseWheelMessage(uMsg))
  363. {
  364. SendMessageW(hwnd, WM_MOUSEWHEEL, wParam, lParam);
  365. return TRUE;
  366. }
  367. return DefWindowProcW(hwnd, uMsg, wParam, lParam);
  368. }
  369. static BOOL CALLBACK loadpresetProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  370. {
  371. static unsigned char eqtbk[10];
  372. static int eqpa;
  373. static char lpp[512];
  374. switch (uMsg)
  375. {
  376. case WM_INITDIALOG:
  377. {
  378. addEQtolistbox(EQDIR1, GetDlgItem(hwndDlg, IDC_LOADEQLIST));
  379. int x = SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_FINDSTRINGEXACT, (WPARAM)0, (LPARAM)last_preset);
  380. if (x != LB_ERR)
  381. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)x, 0);
  382. else
  383. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)-1, 0);
  384. StringCchCopyA(lpp, 512, last_preset);
  385. // show window and restore last position as applicable
  386. POINT pt = {load_rect.left, load_rect.top};
  387. if (!windowOffScreen(hwndDlg, pt))
  388. SetWindowPos(hwndDlg, HWND_TOP, load_rect.left, load_rect.top, 0, 0, SWP_NOSIZE | SWP_NOSENDCHANGING);
  389. eqpa = config_preamp;
  390. memcpy(eqtbk, eq_tab, sizeof(eqtbk));
  391. }
  392. return TRUE;
  393. case WM_COMMAND:
  394. switch (LOWORD(wParam))
  395. {
  396. case IDOK:
  397. SendMessageA(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETTEXT,
  398. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETCURSEL, 0, 0),
  399. (LPARAM) last_preset);
  400. readEQfile(EQDIR1, last_preset);
  401. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  402. GetWindowRect(hwndDlg, &load_rect);
  403. EndDialog(hwndDlg, 0);
  404. return FALSE;
  405. case IDCANCEL:
  406. config_preamp = eqpa;
  407. memcpy(eq_tab, eqtbk, sizeof(eqtbk));
  408. StringCchCopyA(last_preset, 128, lpp);
  409. SendMessageW(hEQWindow, WM_USER, 0, 0);
  410. eq_set(config_use_eq, (char*)eq_tab, config_preamp);
  411. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  412. GetWindowRect(hwndDlg, &load_rect);
  413. EndDialog(hwndDlg, 1);
  414. return FALSE;
  415. case IDC_LOADEQLIST:
  416. if (HIWORD(wParam) == LBN_DBLCLK)
  417. SendMessageW(hwndDlg, WM_COMMAND, IDOK, 0);
  418. if (HIWORD(wParam) == LBN_SELCHANGE)
  419. {
  420. SendMessageA(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETTEXT,
  421. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETCURSEL, 0, 0),
  422. (LPARAM) last_preset);
  423. readEQfile(EQDIR1, last_preset);
  424. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  425. }
  426. return FALSE;
  427. }
  428. return FALSE;
  429. }
  430. return 0;
  431. }
  432. static BOOL CALLBACK loadmp3Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  433. {
  434. static unsigned char eqtbk[10];
  435. static int eqpa;
  436. char buf[1024] = {0};
  437. switch (uMsg)
  438. {
  439. case WM_INITDIALOG:
  440. addEQtolistbox(EQDIR2, GetDlgItem(hwndDlg, IDC_LOADEQLIST));
  441. SetWindowTextA(hwndDlg, getString(IDS_LOADAUTOLOAD, NULL, 0));
  442. {
  443. int x;
  444. const wchar_t *filespec = PathFindFileNameW(FileName);
  445. WideCharToMultiByteSZ(CP_ACP, 0, filespec, -1, buf, 1024, 0, 0);
  446. SetWindowTextA(GetDlgItem(hwndDlg, IDC_SAVEPRESET_EDIT), buf);
  447. x = SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_FINDSTRINGEXACT, (WPARAM)0, (LPARAM)buf);
  448. if (x != LB_ERR)
  449. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)x, 0);
  450. else
  451. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)-1, 0);
  452. // show window and restore last position as applicable
  453. POINT pt = {load_rect.left, load_rect.top};
  454. if (!windowOffScreen(hwndDlg, pt))
  455. SetWindowPos(hwndDlg, HWND_TOP, load_rect.left, load_rect.top, 0, 0, SWP_NOSIZE | SWP_NOSENDCHANGING);
  456. }
  457. eqpa = config_preamp;
  458. memcpy(eqtbk, eq_tab, sizeof(eqtbk));
  459. return TRUE;
  460. case WM_COMMAND:
  461. switch (LOWORD(wParam))
  462. {
  463. case IDOK:
  464. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETTEXT,
  465. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETCURSEL, 0, 0),
  466. (LPARAM) buf);
  467. readEQfile(EQDIR2, buf);
  468. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  469. GetWindowRect(hwndDlg, &load_rect);
  470. EndDialog(hwndDlg, 0);
  471. return FALSE;
  472. case IDCANCEL:
  473. config_preamp = eqpa;
  474. memcpy(eq_tab, eqtbk, sizeof(eqtbk));
  475. SendMessageW(hEQWindow, WM_USER, 0, 0);
  476. eq_set(config_use_eq, (char*)eq_tab, config_preamp);
  477. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  478. GetWindowRect(hwndDlg, &load_rect);
  479. EndDialog(hwndDlg, 1);
  480. return FALSE;
  481. case IDC_LOADEQLIST:
  482. if (HIWORD(wParam) == LBN_DBLCLK)
  483. SendMessageW(hwndDlg, WM_COMMAND, IDOK, 0);
  484. if (HIWORD(wParam) == LBN_SELCHANGE)
  485. {
  486. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETTEXT,
  487. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETCURSEL, 0, 0),
  488. (LPARAM) buf);
  489. readEQfile(EQDIR2, buf);
  490. PostMessageW(hMainWindow, WM_WA_IPC, IPC_CB_MISC_EQ, IPC_CB_MISC);
  491. EnableWindow(GetDlgItem(hwndDlg, IDOK), 1);
  492. }
  493. return FALSE;
  494. }
  495. return FALSE;
  496. }
  497. return 0;
  498. }
  499. static BOOL CALLBACK savepresetProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  500. {
  501. char buf[1024] = {0};
  502. switch (uMsg)
  503. {
  504. case WM_INITDIALOG:
  505. addEQtolistbox(EQDIR1, GetDlgItem(hwndDlg, IDC_LOADEQLIST));
  506. {
  507. int x;
  508. StringCchCopyA(buf, 1024, last_preset);
  509. SetWindowTextA( GetDlgItem( hwndDlg, IDC_SAVEPRESET_EDIT ), buf );
  510. x = SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_FINDSTRINGEXACT, (WPARAM)0, (LPARAM)buf);
  511. if (x != LB_ERR)
  512. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)x, 0);
  513. else
  514. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)-1, 0);
  515. // show window and restore last position as applicable
  516. POINT pt = {load_rect.left, load_rect.top};
  517. if (!windowOffScreen(hwndDlg, pt))
  518. SetWindowPos(hwndDlg, HWND_TOP, load_rect.left, load_rect.top, 0, 0, SWP_NOSIZE | SWP_NOSENDCHANGING);
  519. }
  520. SendMessageW(GetDlgItem(hwndDlg, IDC_SAVEPRESET_EDIT), EM_LIMITTEXT, _MAX_FNAME, 0);
  521. return TRUE;
  522. case WM_COMMAND:
  523. switch (LOWORD(wParam))
  524. {
  525. case IDOK:
  526. GetWindowTextA(GetDlgItem(hwndDlg, IDC_SAVEPRESET_EDIT), last_preset, sizeof(last_preset) - 1);
  527. writeEQfile(EQDIR1, last_preset);
  528. GetWindowRect(hwndDlg, &load_rect);
  529. EndDialog(hwndDlg, 0);
  530. return FALSE;
  531. case IDCANCEL:
  532. GetWindowRect(hwndDlg, &load_rect);
  533. EndDialog(hwndDlg, 1);
  534. return FALSE;
  535. case IDC_LOADEQLIST:
  536. if (HIWORD(wParam) == LBN_DBLCLK)
  537. SendMessageW(hwndDlg, WM_COMMAND, IDOK, 0);
  538. if (HIWORD(wParam) == LBN_SELCHANGE)
  539. {
  540. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETTEXT,
  541. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETCURSEL, 0, 0),
  542. (LPARAM) buf);
  543. SetWindowTextA(GetDlgItem(hwndDlg, IDC_SAVEPRESET_EDIT), buf);
  544. }
  545. return FALSE;
  546. case IDC_SAVEPRESET_EDIT:
  547. if (HIWORD(wParam) == EN_CHANGE)
  548. {
  549. int x;
  550. GetWindowTextA(GetDlgItem(hwndDlg, IDC_SAVEPRESET_EDIT), buf, sizeof(buf) - 1);
  551. if (lstrlenA(buf)) EnableWindow(GetDlgItem(hwndDlg, IDOK), 1);
  552. else EnableWindow(GetDlgItem(hwndDlg, IDOK), 0);
  553. x = SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_FINDSTRINGEXACT, (WPARAM)0, (LPARAM)buf);
  554. if (x != LB_ERR)
  555. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)x, 0);
  556. else
  557. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)-1, 0);
  558. }
  559. }
  560. return FALSE;
  561. }
  562. return 0;
  563. }
  564. static BOOL CALLBACK savemp3Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  565. {
  566. char buf[1024] = {0};
  567. switch (uMsg)
  568. {
  569. case WM_INITDIALOG:
  570. addEQtolistbox(EQDIR2, GetDlgItem(hwndDlg, IDC_LOADEQLIST));
  571. {
  572. int x;
  573. const wchar_t *filespec = PathFindFileNameW(FileName);
  574. WideCharToMultiByteSZ(CP_ACP, 0, filespec, -1, buf, 1024, 0, 0);
  575. SetWindowTextA(GetDlgItem(hwndDlg, IDC_SAVEPRESET_EDIT), buf);
  576. x = SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_FINDSTRINGEXACT, (WPARAM)0, (LPARAM)buf);
  577. if (x != LB_ERR)
  578. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)x, 0);
  579. else
  580. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)-1, 0);
  581. SetWindowTextA(hwndDlg, getString(IDS_SAVEAUTOLOAD, NULL, 0));
  582. // show window and restore last position as applicable
  583. POINT pt = {load_rect.left, load_rect.top};
  584. if (!windowOffScreen(hwndDlg, pt))
  585. SetWindowPos(hwndDlg, HWND_TOP, load_rect.left, load_rect.top, 0, 0, SWP_NOSIZE | SWP_NOSENDCHANGING);
  586. }
  587. SendMessageW(GetDlgItem(hwndDlg, IDC_SAVEPRESET_EDIT), EM_LIMITTEXT, _MAX_FNAME, 0);
  588. return TRUE;
  589. case WM_COMMAND:
  590. switch (LOWORD(wParam))
  591. {
  592. case IDOK:
  593. GetWindowTextA(GetDlgItem(hwndDlg, IDC_SAVEPRESET_EDIT), buf, sizeof(buf) - 1);
  594. writeEQfile(EQDIR2, buf);
  595. GetWindowRect(hwndDlg, &load_rect);
  596. EndDialog(hwndDlg, 0);
  597. return FALSE;
  598. case IDCANCEL:
  599. GetWindowRect(hwndDlg, &load_rect);
  600. EndDialog(hwndDlg, 1);
  601. return FALSE;
  602. case IDC_LOADEQLIST:
  603. if (HIWORD(wParam) == LBN_DBLCLK)
  604. SendMessageW(hwndDlg, WM_COMMAND, IDOK, 0);
  605. if (HIWORD(wParam) == LBN_SELCHANGE)
  606. {
  607. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETTEXT,
  608. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETCURSEL, 0, 0),
  609. (LPARAM) buf);
  610. SetWindowTextA(GetDlgItem(hwndDlg, IDC_SAVEPRESET_EDIT), buf);
  611. }
  612. return FALSE;
  613. case IDC_SAVEPRESET_EDIT:
  614. if (HIWORD(wParam) == EN_CHANGE)
  615. {
  616. int x;
  617. GetWindowTextA(GetDlgItem(hwndDlg, IDC_SAVEPRESET_EDIT), buf, sizeof(buf) - 1);
  618. x = SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_FINDSTRINGEXACT, (WPARAM)0, (LPARAM)buf);
  619. if (x != LB_ERR)
  620. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)x, 0);
  621. else
  622. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)-1, 0);
  623. }
  624. }
  625. return FALSE;
  626. }
  627. return 0;
  628. }
  629. static BOOL CALLBACK delpresetProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  630. {
  631. switch (uMsg)
  632. {
  633. case WM_INITDIALOG:
  634. {
  635. addEQtolistbox(EQDIR1, GetDlgItem(hwndDlg, IDC_LOADEQLIST));
  636. if (SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETCOUNT, 0, 0) == 0)
  637. EnableWindow(GetDlgItem(hwndDlg, IDOK), 0);
  638. SetWindowTextA(hwndDlg, getString(IDS_DELETEPRE1, NULL, 0));
  639. SetWindowTextA(GetDlgItem(hwndDlg, IDOK), getString(IDS_DELETEAUTOLOAD2, NULL, 0));
  640. int x = SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_FINDSTRINGEXACT, (WPARAM)0, (LPARAM)last_preset);
  641. if (x != LB_ERR)
  642. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)x, 0);
  643. else
  644. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)-1, 0);
  645. // show window and restore last position as applicable
  646. POINT pt = {load_rect.left, load_rect.top};
  647. if (!windowOffScreen(hwndDlg, pt))
  648. SetWindowPos(hwndDlg, HWND_TOP, load_rect.left, load_rect.top, 0, 0, SWP_NOSIZE | SWP_NOSENDCHANGING);
  649. }
  650. return TRUE;
  651. case WM_COMMAND:
  652. switch (LOWORD(wParam))
  653. {
  654. case IDOK:
  655. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETTEXT,
  656. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETCURSEL, 0, 0),
  657. (LPARAM) last_preset);
  658. deleteEQfile(EQDIR1, last_preset);
  659. GetWindowRect(hwndDlg, &load_rect);
  660. EndDialog(hwndDlg, 0);
  661. return FALSE;
  662. case IDCANCEL:
  663. GetWindowRect(hwndDlg, &load_rect);
  664. EndDialog(hwndDlg, 1);
  665. return FALSE;
  666. case IDC_LOADEQLIST:
  667. if (HIWORD(wParam) == LBN_DBLCLK)
  668. SendMessageW(hwndDlg, WM_COMMAND, IDOK, 0);
  669. return FALSE;
  670. }
  671. return FALSE;
  672. }
  673. return 0;
  674. }
  675. static BOOL CALLBACK delmp3Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  676. {
  677. char buf[1024] = {0};
  678. switch (uMsg)
  679. {
  680. case WM_INITDIALOG:
  681. {
  682. addEQtolistbox(EQDIR2, GetDlgItem(hwndDlg, IDC_LOADEQLIST));
  683. if (SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETCOUNT, 0, 0) == 0)
  684. EnableWindow(GetDlgItem(hwndDlg, IDOK), 0);
  685. SetWindowTextA(hwndDlg, getString(IDS_DELETEAUTOLOAD1, NULL, 0));
  686. SetWindowTextA(GetDlgItem(hwndDlg, IDOK), getString(IDS_DELETEAUTOLOAD2, NULL, 0));
  687. const wchar_t *filespec = PathFindFileNameW(FileName);
  688. WideCharToMultiByteSZ(CP_ACP, 0, filespec, -1, buf, 1024, 0, 0);
  689. int x = SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_FINDSTRINGEXACT, (WPARAM)0, (LPARAM)buf);
  690. if (x != LB_ERR)
  691. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)x, 0);
  692. else
  693. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_SETCURSEL, (WPARAM)-1, 0);
  694. // show window and restore last position as applicable
  695. POINT pt = {load_rect.left, load_rect.top};
  696. if (!windowOffScreen(hwndDlg, pt))
  697. SetWindowPos(hwndDlg, HWND_TOP, load_rect.left, load_rect.top, 0, 0, SWP_NOSIZE | SWP_NOSENDCHANGING);
  698. return TRUE;
  699. }
  700. case WM_COMMAND:
  701. switch (LOWORD(wParam))
  702. {
  703. case IDOK:
  704. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETTEXT,
  705. SendMessageW(GetDlgItem(hwndDlg, IDC_LOADEQLIST), LB_GETCURSEL, 0, 0),
  706. (LPARAM) buf);
  707. deleteEQfile(EQDIR2, buf);
  708. GetWindowRect(hwndDlg, &load_rect);
  709. EndDialog(hwndDlg, 0);
  710. return FALSE;
  711. case IDCANCEL:
  712. GetWindowRect(hwndDlg, &load_rect);
  713. EndDialog(hwndDlg, 1);
  714. return FALSE;
  715. case IDC_LOADEQLIST:
  716. if (HIWORD(wParam) == LBN_DBLCLK)
  717. SendMessageW(hwndDlg, WM_COMMAND, IDOK, 0);
  718. return FALSE;
  719. }
  720. return FALSE;
  721. }
  722. return 0;
  723. }
  724. static int EQ_OnRButtonUp(HWND hwnd, int x, int y, UINT flags)
  725. {
  726. POINT p;
  727. extern HMENU top_menu;
  728. GetCursorPos(&p);
  729. if ((config_dsize && config_eqdsize))
  730. {
  731. x /= 2;
  732. y /= 2;
  733. }
  734. if ((flags & MK_LBUTTON)) return 1;
  735. if (x >= 14 && y >= 18 && x <= 14 + 25 && y <= 18 + 12)
  736. {
  737. HMENU hmenu = GetSubMenu(GetSubMenu(top_menu, 4), 0);
  738. CheckMenuItem(hmenu, EQ_ENABLE, config_use_eq ? MF_CHECKED : MF_UNCHECKED);
  739. DoTrackPopup(hmenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, p.x, p.y, hwnd);
  740. }
  741. else if (x >= 14 + 25 && y >= 18 && x <= 14 + 25 + 33 && y <= 18 + 12)
  742. {
  743. HMENU hmenu = GetSubMenu(GetSubMenu(top_menu, 4), 1);
  744. CheckMenuItem(hmenu, EQ_AUTO, config_autoload_eq ? MF_CHECKED : MF_UNCHECKED);
  745. DoTrackPopup(hmenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, p.x, p.y, hwnd);
  746. }
  747. else
  748. {
  749. DoTrackPopup(main_menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, p.x, p.y, hMainWindow);
  750. }
  751. return 1;
  752. }
  753. static int EQ_OnLButtonUp(HWND hwnd, int x, int y, UINT flags)
  754. {
  755. ReleaseCapture();
  756. if ((config_dsize && config_eqdsize))
  757. {
  758. equi_handlemouseevent(x / 2, y / 2, -1, flags);
  759. }
  760. else
  761. {
  762. equi_handlemouseevent(x, y, -1, flags);
  763. }
  764. return 1;
  765. }
  766. // Mousedown handler. Just passes to routines in ui.c, scaling if in doublesize mode
  767. static int EQ_OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
  768. {
  769. if ((config_dsize && config_eqdsize))
  770. {
  771. x /= 2;
  772. y /= 2;
  773. }
  774. SetCapture(hwnd);
  775. equi_handlemouseevent(x, y, 1, keyFlags);
  776. return 1;
  777. }
  778. // Mousemove handler. Just passes to routines in ui.c, scaling if in doublesize mode
  779. static int EQ_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags)
  780. {
  781. if ((config_dsize && config_eqdsize))
  782. {
  783. x /= 2;
  784. y /= 2;
  785. }
  786. equi_handlemouseevent(x, y, 0, keyFlags);
  787. return 1;
  788. }
  789. static BOOL EQ_OnNCActivate(HWND hwnd, BOOL fActive, HWND hwndActDeact, BOOL fMinimized)
  790. {
  791. if (fActive == FALSE)
  792. {
  793. draw_eq_tbar(config_hilite ? 0 : 1);
  794. }
  795. else
  796. {
  797. draw_eq_tbar(1);
  798. }
  799. return TRUE;
  800. }
  801. int writeEQfile_init(wchar_t *file, char *name, unsigned char *tab)
  802. {
  803. unsigned char preamp = 31;
  804. char s[2048] = {0};
  805. DWORD a = 0;
  806. HANDLE hFile = CreateFileW(file, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  807. if (hFile == INVALID_HANDLE_VALUE) return 1;
  808. ReadFile(hFile, s, lstrlenA(sig), &a, NULL);
  809. if (memcmp(s, sig, lstrlenA(sig)))
  810. {
  811. SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
  812. a = 0; WriteFile(hFile, sig, lstrlenA(sig), &a, NULL);
  813. SetEndOfFile(hFile);
  814. }
  815. while (1)
  816. {
  817. a = 0;
  818. ReadFile(hFile, s, _MAX_FNAME + 1 + 10 + 1, &a, NULL);
  819. if (a != _MAX_FNAME + 1 + 10 + 1)
  820. {
  821. SetFilePointer(hFile, 0, NULL, FILE_END);
  822. break;
  823. }
  824. if (!_stricmp(name, s))
  825. {
  826. CloseHandle(hFile);
  827. return 0; // don't write it
  828. }
  829. }
  830. StringCchCopyExA(s, _MAX_FNAME+1, name, 0, 0, STRSAFE_FILL_BEHIND_NULL);
  831. memcpy(s + _MAX_FNAME + 1, tab, 10);
  832. memcpy(s + _MAX_FNAME + 1 + 10, &preamp, 1);
  833. a = 0; WriteFile(hFile, s, _MAX_FNAME + 1 + 10 + 1, &a, NULL);
  834. CloseHandle(hFile);
  835. return 0;
  836. }
  837. static int writeEQfile(wchar_t *file, char *name)
  838. {
  839. char s[2048] = {0};
  840. DWORD a = 0;
  841. HANDLE hFile = CreateFileW(file, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  842. if (hFile == INVALID_HANDLE_VALUE) return 1;
  843. ReadFile(hFile, s, lstrlenA(sig), &a, NULL);
  844. if (memcmp(s, sig, lstrlenA(sig)))
  845. {
  846. SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
  847. a = 0; WriteFile(hFile, sig, lstrlenA(sig), &a, NULL);
  848. SetEndOfFile(hFile);
  849. }
  850. while (1)
  851. {
  852. a = 0;
  853. ReadFile(hFile, s, _MAX_FNAME + 1 + sizeof(eq_tab) + sizeof(config_preamp), &a, NULL);
  854. if (a != _MAX_FNAME + 1 + sizeof(eq_tab) + sizeof(config_preamp))
  855. {
  856. SetFilePointer(hFile, 0, NULL, FILE_END);
  857. break;
  858. }
  859. if (!_stricmp(name, s))
  860. {
  861. SetFilePointer(hFile, -(signed)a, NULL, FILE_CURRENT);
  862. break;
  863. }
  864. }
  865. StringCchCopyExA(s, _MAX_FNAME+1, name, 0, 0, STRSAFE_FILL_BEHIND_NULL);
  866. memcpy(s + _MAX_FNAME + 1, eq_tab, sizeof(eq_tab));
  867. memcpy(s + _MAX_FNAME + 1 + sizeof(eq_tab), &config_preamp, sizeof(config_preamp));
  868. a = 0; WriteFile(hFile, s, _MAX_FNAME + 1 + sizeof(eq_tab) + sizeof(config_preamp), &a, NULL);
  869. CloseHandle(hFile);
  870. return 0;
  871. }
  872. static int readEQfile(wchar_t *file, char *name)
  873. {
  874. char s[2048] = {0};
  875. DWORD a = 0;
  876. HANDLE hFile = CreateFileW(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  877. if (hFile == INVALID_HANDLE_VALUE) return 1;
  878. ReadFile(hFile, s, lstrlenA(sig), &a, NULL);
  879. if (memcmp(s, sig, lstrlenA(sig)))
  880. {
  881. CloseHandle(hFile);
  882. return 1;
  883. }
  884. while (1)
  885. {
  886. a = 0;
  887. ReadFile(hFile, s, _MAX_FNAME + 1 + sizeof(eq_tab) + sizeof(config_preamp), &a, NULL);
  888. if (a != _MAX_FNAME + 1 + sizeof(eq_tab) + sizeof(config_preamp))
  889. {
  890. CloseHandle(hFile);
  891. return 1;
  892. }
  893. if (!_stricmp(name, s))
  894. break;
  895. }
  896. CloseHandle(hFile);
  897. memcpy(eq_tab, s + _MAX_FNAME + 1, sizeof(eq_tab));
  898. memcpy(&config_preamp, s + _MAX_FNAME + 1 + sizeof(eq_tab), sizeof(config_preamp));
  899. eq_set(config_use_eq, (char*)eq_tab, config_preamp);
  900. if (hEQWindow) SendMessageW(hEQWindow, WM_USER, 0, 0);
  901. return 0;
  902. }
  903. static void deleteEQfile(wchar_t *file, char *name)
  904. {
  905. wchar_t tmpfile[2048] = {0};
  906. char s[2048] = {0};
  907. DWORD a = 0;
  908. HANDLE hFile = CreateFileW(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  909. if (hFile == INVALID_HANDLE_VALUE) return ;
  910. StringCchPrintfW(tmpfile, 2048, L"%s.TMP", file);
  911. HANDLE hFileOut = CreateFileW(tmpfile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  912. if (hFileOut == INVALID_HANDLE_VALUE)
  913. {
  914. CloseHandle(hFile);
  915. return ;
  916. }
  917. ReadFile(hFile, s, lstrlenA(sig), &a, NULL);
  918. a = 0; WriteFile(hFileOut, s, lstrlenA(sig), &a, NULL);
  919. while (1)
  920. {
  921. a = 0;
  922. ReadFile(hFile, s, _MAX_FNAME + 1 + sizeof(eq_tab) + sizeof(config_preamp), &a, NULL);
  923. if (a != _MAX_FNAME + 1 + sizeof(eq_tab) + sizeof(config_preamp))
  924. {
  925. break;
  926. }
  927. if (_stricmp(name, s))
  928. WriteFile(hFileOut, s, a, &a, NULL);
  929. }
  930. CloseHandle(hFile);
  931. CloseHandle(hFileOut);
  932. DeleteFileW(file);
  933. StringCchPrintfW(tmpfile, 2048, L"%s.TMP", file);
  934. MoveFileW(tmpfile, file);
  935. return ;
  936. }
  937. static void addEQtolistbox(wchar_t *file, HWND listbox)
  938. {
  939. char s[2048] = {0};
  940. DWORD l = 0;
  941. HANDLE hFile = CreateFileW(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  942. if (hFile == INVALID_HANDLE_VALUE) return ;
  943. ReadFile(hFile, s, lstrlenA(sig), &l, NULL);
  944. if (memcmp(s, sig, lstrlenA(sig)))
  945. {
  946. CloseHandle(hFile);
  947. return ;
  948. }
  949. while (1)
  950. {
  951. DWORD a = 0;
  952. ReadFile(hFile, s, _MAX_FNAME + 1 + sizeof(eq_tab) + sizeof(config_preamp), &a, NULL);
  953. if (a != _MAX_FNAME + 1 + sizeof(eq_tab) + sizeof(config_preamp))
  954. break;
  955. SendMessageA(listbox, LB_ADDSTRING, 0, (LPARAM)s); // Must stay in ANSI mode
  956. }
  957. CloseHandle(hFile);
  958. }