1
0

prefs.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. #include "main.h"
  2. #include "../nu/AutoWide.h"
  3. #include "./resource.h"
  4. #include "./settings.h"
  5. #include "../Winamp/wa_ipc.h"
  6. #include <strsafe.h>
  7. static convertConfigStruct m_ccs;
  8. static int m_has_seled;
  9. static void myEnumProc(intptr_t user_data, const char *desc, int fourcc)
  10. {
  11. HWND hwndDlg = (HWND) user_data;
  12. if (fourcc == OLD_AAC_CODEC)
  13. return ;
  14. int a = (INT)SendDlgItemMessage(hwndDlg, IDC_ENCFORMAT, CB_ADDSTRING, 0, (LPARAM)(const wchar_t *)AutoWide(desc));
  15. SendDlgItemMessage(hwndDlg, IDC_ENCFORMAT, CB_SETITEMDATA, (WPARAM)a, fourcc);
  16. if ( m_ccs.format == fourcc )
  17. {
  18. m_has_seled = 1;
  19. SendDlgItemMessage( hwndDlg, IDC_ENCFORMAT, CB_SETCURSEL, (WPARAM)a, 0 );
  20. }
  21. }
  22. static void doConfigResizeChild(HWND parent, HWND child)
  23. {
  24. if (child)
  25. {
  26. RECT r;
  27. GetWindowRect(GetDlgItem(parent, IDC_ENC_CONFIG), &r);
  28. ScreenToClient(parent, (LPPOINT)&r);
  29. SetWindowPos(child, 0, r.left, r.top, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
  30. ShowWindow(child, SW_SHOWNA);
  31. }
  32. }
  33. static HWND subWnd;
  34. static void DisplayFormatExample(HWND hdlg, INT nItemId, BOOL bFile)
  35. {
  36. BOOL bUpper;
  37. TCHAR szBuffer[MAX_PATH*2] = {0};
  38. TCHAR szFormat[MAX_PATH] = {0};
  39. Settings_ReadString(C_EXTRACT, (bFile) ? EF_TITLEFMT : EF_PLAYLISTFMT, szFormat, ARRAYSIZE(szFormat));
  40. WASABI_API_LNGSTRINGW_BUF(((bFile) ? IDS_EXAMPLE_RIPPED_FILE_FILENAME : IDS_EXAMPLE_PLAYLIST_FILENAME),
  41. szBuffer, ARRAYSIZE(szBuffer));
  42. FormatFileName(szBuffer, ARRAYSIZE(szBuffer), szFormat,
  43. (bFile) ? 10 : 0xdeadbeef,
  44. TEXT("U2"), TEXT("The Joshua Tree"),
  45. (bFile) ? TEXT("Exit") : NULL,
  46. TEXT("Rock"),
  47. TEXT("1987"),
  48. TEXT("U2"),
  49. NULL,
  50. TEXT(""));
  51. wchar_t szExtension[32] = {0};
  52. if (bFile)
  53. {
  54. int c;
  55. Settings_GetInt(C_EXTRACT, EF_FOURCC, &c);
  56. if (c == OLD_AAC_CODEC) Settings_GetDefault(C_EXTRACT, EF_FOURCC, &c);
  57. GetExtensionString(szExtension, ARRAYSIZE(szExtension), c);
  58. Settings_GetBool(C_EXTRACT, EF_UPPEREXTENSION, &bUpper);
  59. if (bUpper) CharUpper(szExtension);
  60. else CharLower(szExtension);
  61. }
  62. else StringCchCopy(szExtension, ARRAYSIZE(szExtension), TEXT("m3u"));
  63. StringCchCat(szBuffer, ARRAYSIZE(szBuffer), TEXT("."));
  64. StringCchCat(szBuffer, ARRAYSIZE(szBuffer), szExtension);
  65. SetDlgItemText(hdlg, nItemId, szBuffer);
  66. }
  67. static INT_PTR CALLBACK CDPrefs1Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  68. {
  69. static HWND hActiveHelp = NULL;
  70. switch (uMsg)
  71. {
  72. case WM_INITDIALOG:
  73. SendDlgItemMessage(hwndDlg, IDC_DESTPATH, EM_SETLIMITTEXT, MAX_PATH, 0);
  74. Settings_SetCheckBox(C_EXTRACT, EF_UPPEREXTENSION, hwndDlg, IDC_UPPERCASEEXT);
  75. Settings_SetDirectoryCtrl(C_EXTRACT, EF_PATH, hwndDlg, IDC_DESTPATH);
  76. Settings_SetDlgItemText(C_EXTRACT, EF_TITLEFMT, hwndDlg, IDC_FILENAMEFMT);
  77. Settings_SetCheckBox(C_EXTRACT, EF_ADDMETADATA, hwndDlg, IDC_TAGFILES);
  78. Settings_SetCheckBox(C_EXTRACT, EF_CALCULATERG, hwndDlg, IDC_AUTO_RG);
  79. Settings_SetCheckBox(C_EXTRACT, EF_USETOTALTRACKS, hwndDlg, IDC_TOTAL_TRACKS);
  80. Settings_SetCheckBox(C_EXTRACT, EF_ADDTOMLDB, hwndDlg, IDC_CHECK_ML);
  81. Settings_SetDlgItemInt(C_EXTRACT, EF_TRACKOFFSET, hwndDlg, IDC_EDIT2);
  82. Settings_SetDlgItemText(C_EXTRACT, EF_COMMENTTEXT, hwndDlg, IDC_EDIT1);
  83. break;
  84. case WM_COMMAND:
  85. switch (LOWORD(wParam))
  86. {
  87. case IDC_DESTPATH:
  88. if (HIWORD(wParam) == EN_CHANGE) Settings_FromDirectoryCtrl(C_EXTRACT, EF_PATH, hwndDlg,IDC_DESTPATH);
  89. break;
  90. case IDC_UPPERCASEEXT:
  91. Settings_FromCheckBox(C_EXTRACT, EF_UPPEREXTENSION, hwndDlg, IDC_UPPERCASEEXT);
  92. DisplayFormatExample(hwndDlg, IDC_FMTOUT, TRUE);
  93. break;
  94. case IDC_FILENAMEFMT:
  95. if (HIWORD(wParam) == EN_CHANGE)
  96. {
  97. Settings_FromDlgItemText(C_EXTRACT, EF_TITLEFMT, hwndDlg, IDC_FILENAMEFMT);
  98. DisplayFormatExample(hwndDlg, IDC_FMTOUT, TRUE);
  99. }
  100. break;
  101. case IDC_BUTTON1:
  102. Settings_BrowseForFolder(C_EXTRACT, EF_PATH, hwndDlg, IDC_DESTPATH);
  103. break;
  104. case IDC_BUTTON2:
  105. if (hActiveHelp) SetWindowPos(hActiveHelp, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  106. else hActiveHelp = MLDisc_ShowHelp(hwndDlg, MAKEINTRESOURCE(IDS_RIPPED_FILENAME_FORMAT_HELP),
  107. MAKEINTRESOURCE(IDS_RIPPED_FILENAME_FORMAT_CAPTION), MAKEINTRESOURCE(IDS_RIPPED_FILENAME_FORMAT), HF_ALLOWRESIZE);
  108. break;
  109. case IDC_EDIT2: if (EN_CHANGE == HIWORD(wParam)) Settings_FromDlgItemText(C_EXTRACT, EF_TRACKOFFSET, hwndDlg, IDC_EDIT2);break;
  110. case IDC_EDIT1: if (EN_CHANGE == HIWORD(wParam)) Settings_FromDlgItemText(C_EXTRACT, EF_COMMENTTEXT, hwndDlg, IDC_EDIT1); break;
  111. case IDC_AUTO_RG: if (BN_CLICKED == HIWORD(wParam)) Settings_FromCheckBox(C_EXTRACT, EF_CALCULATERG, hwndDlg, IDC_AUTO_RG); break;
  112. case IDC_TOTAL_TRACKS: if (BN_CLICKED == HIWORD(wParam)) Settings_FromCheckBox(C_EXTRACT, EF_USETOTALTRACKS, hwndDlg, IDC_TOTAL_TRACKS); break;
  113. case IDC_TAGFILES: if (BN_CLICKED == HIWORD(wParam)) Settings_FromCheckBox(C_EXTRACT, EF_ADDMETADATA, hwndDlg, IDC_TAGFILES); break;
  114. case IDC_CHECK_ML: if (BN_CLICKED == HIWORD(wParam)) Settings_FromCheckBox(C_EXTRACT, EF_ADDTOMLDB, hwndDlg, IDC_CHECK_ML); break;
  115. }
  116. break;
  117. case WM_DESTROY:
  118. if (hActiveHelp) DestroyWindow(hActiveHelp);
  119. break;
  120. case WM_PARENTNOTIFY:
  121. if (hActiveHelp && LOWORD(wParam) == WM_DESTROY && hActiveHelp == (HWND)lParam)
  122. hActiveHelp = NULL;
  123. break;
  124. }
  125. return 0;
  126. }
  127. int getRegVer();
  128. static INT_PTR CALLBACK CDPrefs2Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  129. {
  130. switch (uMsg)
  131. {
  132. case WM_INITDIALOG:
  133. {
  134. m_ccs.hwndParent = hwndDlg;
  135. Settings_GetInt(C_EXTRACT, EF_FOURCC, &m_ccs.format);
  136. if (m_ccs.format == OLD_AAC_CODEC) Settings_GetDefault(C_EXTRACT, EF_FOURCC, &m_ccs.format);
  137. converterEnumFmtStruct enumf = { myEnumProc, (INT)(INT_PTR)hwndDlg };
  138. m_has_seled = 0;
  139. SendMessage(plugin.hwndWinampParent, WM_WA_IPC, (WPARAM)&enumf, IPC_CONVERT_CONFIG_ENUMFMTS);
  140. if (!m_has_seled)
  141. {
  142. SendDlgItemMessage(hwndDlg, IDC_ENCFORMAT, CB_SETCURSEL, 0, 0);
  143. m_ccs.format = mmioFOURCC('W', 'A', 'V', ' ');
  144. }
  145. HWND h = (HWND)SendMessage(plugin.hwndWinampParent, WM_WA_IPC, (WPARAM) & m_ccs, IPC_CONVERT_CONFIG);
  146. doConfigResizeChild(hwndDlg, h);
  147. }
  148. break;
  149. case WM_COMMAND:
  150. switch (LOWORD(wParam))
  151. {
  152. case IDC_ENCFORMAT:
  153. if (HIWORD(wParam) != CBN_SELCHANGE) return 0;
  154. {
  155. int sel = (INT)(INT_PTR)SendDlgItemMessage(hwndDlg, IDC_ENCFORMAT, CB_GETCURSEL, 0, 0);
  156. if (sel != CB_ERR)
  157. {
  158. SendMessage(plugin.hwndWinampParent, WM_WA_IPC, (WPARAM)&m_ccs, IPC_CONVERT_CONFIG_END);
  159. int last = m_ccs.format;
  160. if (RegisteredEncoder(last) || last == OLD_AAC_CODEC) Settings_GetDefault(C_EXTRACT, EF_FOURCC, &last);
  161. m_ccs.format = (int)SendDlgItemMessage(hwndDlg, IDC_ENCFORMAT, CB_GETITEMDATA, sel, 0);
  162. Settings_SetInt(C_EXTRACT, EF_FOURCC, m_ccs.format);
  163. HWND h = (HWND)SendMessage(plugin.hwndWinampParent, WM_WA_IPC, (WPARAM) & m_ccs, IPC_CONVERT_CONFIG);
  164. doConfigResizeChild(hwndDlg, h);
  165. }
  166. }
  167. break;
  168. }
  169. break;
  170. case WM_DESTROY:
  171. SendMessage(plugin.hwndWinampParent, WM_WA_IPC, (WPARAM)&m_ccs, IPC_CONVERT_CONFIG_END);
  172. break;
  173. }
  174. return 0;
  175. }
  176. static INT_PTR CALLBACK CDPrefs4Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  177. {
  178. static HWND hActiveHelp = NULL;
  179. switch (uMsg)
  180. {
  181. case WM_INITDIALOG:
  182. Settings_SetDlgItemText(C_EXTRACT, EF_PLAYLISTFMT, hwndDlg, IDC_FILENAMEFMT);
  183. Settings_SetCheckBox(C_EXTRACT, EF_CREATEM3U, hwndDlg, IDC_CHECK1);
  184. Settings_SetCheckBox(C_EXTRACT, EF_USEM3UEXT, hwndDlg, IDC_CHECK3);
  185. Settings_SetCheckBox(C_EXTRACT, EF_CREATEPLS, hwndDlg, IDC_CHECK2);
  186. Settings_SetCheckBox(C_EXTRACT, EF_CREATEMLPL, hwndDlg, IDC_CHECK4);
  187. EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK3), IsDlgButtonChecked(hwndDlg, IDC_CHECK1));
  188. break;
  189. case WM_COMMAND:
  190. switch (LOWORD(wParam))
  191. {
  192. case IDC_FILENAMEFMT:
  193. if (LOWORD(wParam) != IDC_FILENAMEFMT || HIWORD(wParam) == EN_CHANGE)
  194. {
  195. Settings_FromDlgItemText(C_EXTRACT, EF_PLAYLISTFMT, hwndDlg, IDC_FILENAMEFMT);
  196. DisplayFormatExample(hwndDlg, IDC_FMTOUT, FALSE);
  197. }
  198. return 0;
  199. case IDC_BUTTON2:
  200. if (hActiveHelp) SetWindowPos(hActiveHelp, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  201. else hActiveHelp = MLDisc_ShowHelp(hwndDlg, MAKEINTRESOURCE(IDS_RIPPPED_PLAYLIST_FORMAT_HELP),
  202. MAKEINTRESOURCE(IDS_RIPPED_PLAYLIST_FORMAT_CAPTION), MAKEINTRESOURCE(IDS_RIPPED_PLAYLIST_FORMAT), HF_ALLOWRESIZE);
  203. break;
  204. case IDC_CHECK1:
  205. if (BN_CLICKED == HIWORD(wParam)) Settings_FromCheckBox(C_EXTRACT, EF_CREATEM3U, hwndDlg, IDC_CHECK1);
  206. EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK3), IsDlgButtonChecked(hwndDlg, IDC_CHECK1));
  207. break;
  208. case IDC_CHECK3: if (BN_CLICKED == HIWORD(wParam)) Settings_FromCheckBox(C_EXTRACT, EF_USEM3UEXT, hwndDlg, IDC_CHECK3); break;
  209. case IDC_CHECK2: if (BN_CLICKED == HIWORD(wParam)) Settings_FromCheckBox(C_EXTRACT, EF_CREATEPLS, hwndDlg, IDC_CHECK2); break;
  210. case IDC_CHECK4: if (BN_CLICKED == HIWORD(wParam)) Settings_FromCheckBox(C_EXTRACT, EF_CREATEMLPL, hwndDlg, IDC_CHECK4); break;
  211. }
  212. break;
  213. case WM_DESTROY:
  214. if (hActiveHelp) DestroyWindow(hActiveHelp);
  215. break;
  216. case WM_PARENTNOTIFY:
  217. if (hActiveHelp && LOWORD(wParam) == WM_DESTROY && hActiveHelp == (HWND)lParam)
  218. hActiveHelp = NULL;
  219. break;
  220. }
  221. return 0;
  222. }
  223. static int has_extract;
  224. static void _dosetsel(HWND hwndDlg)
  225. {
  226. HWND tabwnd = GetDlgItem(hwndDlg, IDC_TAB1);
  227. int sel = TabCtrl_GetCurSel(tabwnd);
  228. if (sel >= 0 && (sel != g_config->ReadInt(L"lastcdprefp", 0) || !subWnd))
  229. {
  230. g_config->WriteInt(L"lastcdprefp", sel);
  231. if (subWnd) DestroyWindow(subWnd);
  232. subWnd = 0;
  233. UINT t = 0;
  234. DLGPROC p = NULL;
  235. if (!has_extract && sel) sel++;
  236. switch (sel)
  237. {
  238. case 2: t = IDD_PREFS_CDRIP1; p = CDPrefs1Proc; break;
  239. case 0: t = IDD_PREFS_CDRIP2; p = CDPrefs2Proc; break;
  240. case 3: t = IDD_PREFS_CDRIP4; p = CDPrefs4Proc; break;
  241. case 1:
  242. {
  243. t = 0;
  244. char buf2[512] = {0};
  245. char buf3[512] = {0};
  246. StringCchPrintfA(buf3, 512, "cdda_cf_%d", (INT)(INT_PTR)hwndDlg);
  247. getFileInfo("cda://", buf3, buf2, sizeof(buf2));
  248. subWnd = (HWND)(INT_PTR)atoi(buf2);
  249. }
  250. break;
  251. default: subWnd = 0; t = 0; break;
  252. }
  253. if (t) subWnd = WASABI_API_CREATEDIALOGW(t, hwndDlg, p);
  254. if (subWnd)
  255. {
  256. RECT r;
  257. GetClientRect(tabwnd, &r);
  258. TabCtrl_AdjustRect(tabwnd, FALSE, &r);
  259. SetWindowPos(subWnd, HWND_TOP, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOACTIVATE);
  260. ShowWindow(subWnd, SW_SHOWNA);
  261. }
  262. if(!SendMessage(plugin.hwndWinampParent,WM_WA_IPC,IPC_ISWINTHEMEPRESENT,IPC_USE_UXTHEME_FUNC))
  263. {
  264. SendMessage(plugin.hwndWinampParent,WM_WA_IPC,(WPARAM)tabwnd,IPC_USE_UXTHEME_FUNC);
  265. SendMessage(plugin.hwndWinampParent,WM_WA_IPC,(WPARAM)subWnd,IPC_USE_UXTHEME_FUNC);
  266. }
  267. }
  268. }
  269. BOOL CALLBACK CDRipPrefsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  270. {
  271. switch (uMsg)
  272. {
  273. case WM_INITDIALOG:
  274. {
  275. TCITEM item;
  276. HWND tabwnd = GetDlgItem(hwndDlg, IDC_TAB1);
  277. item.mask = TCIF_TEXT;
  278. item.pszText = WASABI_API_LNGSTRINGW(IDS_ENCODER);
  279. TabCtrl_InsertItem(tabwnd, 0, &item);
  280. wchar_t buf2[512] = {0};
  281. getFileInfoW(L"cda://", L"cdda_config_text", buf2, 512);
  282. if (buf2[0])
  283. {
  284. item.pszText = buf2;
  285. TabCtrl_InsertItem(tabwnd, 3, &item);
  286. has_extract = 1;
  287. }
  288. else has_extract = 0;
  289. item.pszText = WASABI_API_LNGSTRINGW(IDS_OUTPUT_FILE_SETTINGS);
  290. TabCtrl_InsertItem(tabwnd, 1 + has_extract, &item);
  291. item.pszText = WASABI_API_LNGSTRINGW(IDS_PLAYLIST_GENERATION);
  292. TabCtrl_InsertItem(tabwnd, 2 + has_extract, &item);
  293. TabCtrl_SetCurSel(tabwnd, g_config->ReadInt(L"lastcdprefp", 0));
  294. _dosetsel(hwndDlg);
  295. }
  296. return 0;
  297. case WM_NOTIFY:
  298. {
  299. LPNMHDR p = (LPNMHDR) lParam;
  300. if (p->idFrom == IDC_TAB1 && p->code == TCN_SELCHANGE) _dosetsel(hwndDlg);
  301. }
  302. return 0;
  303. case WM_DESTROY:
  304. subWnd = NULL;
  305. return 0;
  306. }
  307. return 0;
  308. }