config.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. #include "main.h"
  2. #include "api__in_vorbis.h"
  3. #include "../nu/ns_wc.h"
  4. #include <commctrl.h>
  5. #include <shlobj.h>
  6. #include "../winamp/wa_ipc.h"
  7. #include "../nu/AutoChar.h"
  8. #include <strsafe.h>
  9. int mc6_dm_names_ids[]={IDS_LEAVE_AS_IS,IDS_REMAP_6_CHANNELS,IDS_DOWNMIX_TO_4_CHANNELS,IDS_DOWNMIX_TO_2_CHANNELS_DS,IDS_DOWNMIX_TO_2_CHANNELS_DS2,IDS_DOWNMIX_TO_MONO};
  10. int mc6_map_names_id[]={IDS_CORRECT_FL_FC_FR_BL_BR_LFE,IDS_BROKEN_FL_FR_FC_BL_BR_LFE};
  11. int32_t priority_tab[7]={THREAD_PRIORITY_IDLE,THREAD_PRIORITY_LOWEST,THREAD_PRIORITY_BELOW_NORMAL,THREAD_PRIORITY_NORMAL,THREAD_PRIORITY_ABOVE_NORMAL,THREAD_PRIORITY_HIGHEST,THREAD_PRIORITY_TIME_CRITICAL};
  12. char* defaultDumpDir()
  13. {
  14. static char dumpdir[MAX_PATH] = {0};
  15. if(FAILED(SHGetFolderPathA(NULL, CSIDL_MYMUSIC, NULL, SHGFP_TYPE_CURRENT, dumpdir)))
  16. {
  17. if(FAILED(SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, dumpdir)))
  18. {
  19. lstrcpynA(dumpdir, "C:\\", MAX_PATH);
  20. }
  21. }
  22. return dumpdir;
  23. }
  24. CfgString
  25. cfg_ssave_format("ssave_format","%filename%"),
  26. cfg_dumpdir("dumpdir",defaultDumpDir());
  27. CfgInt
  28. cfg_http_bsize("http_bsize",0x10000),
  29. cfg_fsave("fsave",0),
  30. cfg_abr("abr",0),
  31. cfg_proxy_mode("proxy_mode",2),
  32. cfg_prebuf1("prebuf1",50),
  33. cfg_prebuf2("prebuf2",75),
  34. cfg_httpseek2("httpseek2",0),
  35. cfg_fix0r("fix0r",1),
  36. cfg_mc6_dm("mc6_dm",0),
  37. cfg_mc6_map("_mc6_map",0),
  38. cfg_remember_infosize("remember_infosize",1),
  39. cfg_fullbuf("fullbuf",0),
  40. cfg_cur_tab("cur_tab",0);
  41. static int old_preamp;
  42. CfgFont cfg_font("font");
  43. static LOGFONT cfg_font_edit;
  44. BOOL CALLBACK browseEnumProc(HWND hwnd, LPARAM lParam)
  45. {
  46. char cl[32] = {0};
  47. GetClassNameA(hwnd, cl, ARRAYSIZE(cl));
  48. if (!lstrcmpiA(cl, WC_TREEVIEWA))
  49. {
  50. PostMessage(hwnd, TVM_ENSUREVISIBLE, 0, (LPARAM)TreeView_GetSelection(hwnd));
  51. return FALSE;
  52. }
  53. return TRUE;
  54. }
  55. static int CALLBACK browzaproc(HWND hwnd, UINT msg, LPARAM lp, LPARAM dat)
  56. {
  57. if (msg == BFFM_INITIALIZED)
  58. {
  59. SendMessageW(hwnd, BFFM_SETSELECTIONW, 1, (LPARAM)dat);
  60. // this is not nice but it fixes the selection not working correctly on all OSes
  61. EnumChildWindows(hwnd, browseEnumProc, 0);
  62. }
  63. return 0;
  64. }
  65. static void d_browza(HWND wnd,HWND bt,wchar_t* tx)
  66. {
  67. IMalloc* pMalloc=0;
  68. SHGetMalloc(&pMalloc);
  69. if (!pMalloc) return;
  70. wchar_t dir[MAX_PATH] = {0};
  71. GetWindowTextW(bt,dir,MAX_PATH);
  72. BROWSEINFOW bi=
  73. {
  74. wnd,
  75. 0,
  76. 0,
  77. tx,
  78. BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE,
  79. browzaproc,
  80. (LPARAM)dir,
  81. 0
  82. };
  83. ITEMIDLIST* li=SHBrowseForFolderW(&bi);
  84. if (li)
  85. {
  86. SHGetPathFromIDListW(li,dir);
  87. SetWindowTextW(bt,dir);
  88. pMalloc->Free(li);
  89. }
  90. pMalloc->Release();
  91. }
  92. static BOOL CALLBACK CfgProc1(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
  93. {
  94. switch(msg)
  95. {
  96. case WM_INITDIALOG:
  97. {
  98. wchar_t temp[128] = {0}, cfg_dialog_name[128] = {0};
  99. StringCchPrintfW(cfg_dialog_name,128,WASABI_API_LNGSTRINGW(IDS_TITLE_PREFERENCES),
  100. WASABI_API_LNGSTRINGW_BUF(IDS_NULLSOFT_VORBIS_DECODER_OLD, temp, 128));
  101. SetWindowTextW(wnd,cfg_dialog_name);
  102. SendDlgItemMessage(wnd,IDC_FULLBUF,BM_SETCHECK,cfg_fullbuf,0);
  103. UINT n;
  104. HWND w=GetDlgItem(wnd,IDC_MC6_DM);
  105. for(n=0;n<sizeof(mc6_dm_names_ids)/sizeof(mc6_dm_names_ids[0]);n++)
  106. {
  107. SendMessageW(w,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(mc6_dm_names_ids[n]));
  108. }
  109. SendMessage(w,CB_SETCURSEL,cfg_mc6_dm,0);
  110. w=GetDlgItem(wnd,IDC_MC6_MAP);
  111. for(n=0;n<sizeof(mc6_map_names_id)/sizeof(mc6_map_names_id[0]);n++)
  112. {
  113. SendMessageW(w,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(mc6_map_names_id[n]));
  114. }
  115. SendMessage(w,CB_SETCURSEL,cfg_mc6_map,0);
  116. SendDlgItemMessage(wnd,IDC_AVG_BR,BM_SETCHECK,cfg_abr,0);
  117. SetDlgItemInt(wnd,IDC_HTTP_BSIZE,cfg_http_bsize>>10,0);
  118. if (cfg_fsave) SendDlgItemMessage(wnd,IDC_FSAVE,BM_SETCHECK,1,0);
  119. if (cfg_fix0r) SendDlgItemMessage(wnd,IDC_FIX0R,BM_SETCHECK,1,0);
  120. cfg_dumpdir.s_SetDlgItemText(wnd,IDC_STREAM_SAVE);
  121. w=GetDlgItem(wnd,IDC_PROXY);
  122. SendMessageW(w,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_NEVER));
  123. SendMessageW(w,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_PORT_80_ONLY));
  124. SendMessageW(w,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_ALWAYS));
  125. SendMessage(w,CB_SETCURSEL,cfg_proxy_mode,0);
  126. w=GetDlgItem(wnd,IDC_SLIDER1);
  127. SendMessage(w,TBM_SETRANGE,0,MAKELONG(1,100));
  128. SendMessage(w,TBM_SETPOS,1,cfg_prebuf1);
  129. w=GetDlgItem(wnd,IDC_SLIDER2);
  130. SendMessage(w,TBM_SETRANGE,0,MAKELONG(1,100));
  131. SendMessage(w,TBM_SETPOS,1,cfg_prebuf2);
  132. cfg_ssave_format.s_SetDlgItemText(wnd,IDC_SSAVE_FMT);
  133. SendMessage(wnd,WM_COMMAND,MAKEWPARAM(IDC_FSAVE,BN_CLICKED),(LPARAM)GetDlgItem(wnd,IDC_FSAVE));
  134. }
  135. return 1;
  136. case WM_COMMAND:
  137. switch(LOWORD(wp))
  138. {
  139. case IDC_STREAM_SAVE:
  140. d_browza(wnd,(HWND)lp,WASABI_API_LNGSTRINGW(IDS_SELECT_OUTPUT_DIRECTORY));
  141. break;
  142. case IDC_SSAVE_FMT_DEF:
  143. SetDlgItemText(wnd,IDC_SSAVE_FMT,L"%filename%");
  144. break;
  145. case IDC_FSAVE:
  146. {
  147. int checked = IsDlgButtonChecked(wnd,IDC_FSAVE);
  148. EnableWindow(GetDlgItem(wnd,IDC_STREAM_SAVE),checked);
  149. EnableWindow(GetDlgItem(wnd,IDC_SSAVE_FMT),checked);
  150. EnableWindow(GetDlgItem(wnd,IDC_SSAVE_FMT_DEF),checked);
  151. }
  152. break;
  153. case IDOK:
  154. case IDCANCEL:
  155. {
  156. if (LOWORD(wp) == IDOK)
  157. {
  158. cfg_fullbuf=(int)SendDlgItemMessage(wnd,IDC_FULLBUF,BM_GETCHECK,0,0);
  159. cfg_mc6_dm=(int)SendDlgItemMessage(wnd,IDC_MC6_DM,CB_GETCURSEL,0,0);
  160. cfg_mc6_map=(int)SendDlgItemMessage(wnd,IDC_MC6_MAP,CB_GETCURSEL,0,0);
  161. cfg_abr=(int)SendDlgItemMessage(wnd,IDC_AVG_BR,BM_GETCHECK,0,0);
  162. cfg_dumpdir.s_GetDlgItemText(wnd,IDC_STREAM_SAVE);
  163. cfg_http_bsize=GetDlgItemInt(wnd,IDC_HTTP_BSIZE,0,0)<<10;
  164. cfg_fsave=(int)SendDlgItemMessage(wnd,IDC_FSAVE,BM_GETCHECK,0,0);
  165. cfg_fix0r=(int)SendDlgItemMessage(wnd,IDC_FIX0R,BM_GETCHECK,0,0);
  166. cfg_proxy_mode=(int)SendDlgItemMessage(wnd,IDC_PROXY,CB_GETCURSEL,0,0);
  167. cfg_prebuf1=(int)SendDlgItemMessage(wnd,IDC_SLIDER1,TBM_GETPOS,0,0);
  168. cfg_prebuf2=(int)SendDlgItemMessage(wnd,IDC_SLIDER2,TBM_GETPOS,0,0);
  169. cfg_ssave_format.s_GetDlgItemText(wnd,IDC_SSAVE_FMT);
  170. }
  171. do_cfg(1);
  172. EndDialog(wnd,(LOWORD(wp) == IDOK));
  173. }
  174. break;
  175. }
  176. break;
  177. }
  178. const int controls[] =
  179. {
  180. IDC_SLIDER1,
  181. IDC_SLIDER2,
  182. };
  183. if (FALSE != WASABI_API_APP->DirectMouseWheel_ProcessDialogMessage(wnd, msg, wp, lp, controls, ARRAYSIZE(controls)))
  184. {
  185. return TRUE;
  186. }
  187. return 0;
  188. }
  189. extern HANDLE hThread;//hack
  190. void Config(HWND p)
  191. {
  192. if (WASABI_API_DIALOGBOXPARAMW(IDD_CONFIG,p,CfgProc1,0))
  193. {
  194. if (hThread) PostMessage(mod.hMainWindow,WM_USER,0,243);
  195. }
  196. }
  197. int CfgVar::read_int(const char *inifile, const char *section,const char * name,int def)
  198. {
  199. return GetPrivateProfileIntA(section, name, def, inifile);
  200. }
  201. void CfgVar::write_int(const char *inifile, const char *section, const char * name,int val)
  202. {
  203. char temp[32] = {0};
  204. StringCchPrintfA(temp, 32, "%d", val);
  205. WritePrivateProfileStringA(section, name, temp, inifile);
  206. }
  207. void CfgVar::write_struct(const char *inifile, const char *section, const char * name, void * ptr,UINT size)
  208. {
  209. WritePrivateProfileStructA("in_vorbis", name, ptr, size, INI_FILE);
  210. }
  211. bool CfgVar::read_struct(const char *inifile, const char *section, const char * name,void * ptr,UINT size)
  212. {
  213. return !!GetPrivateProfileStructA("in_vorbis", name, ptr, size, INI_FILE);
  214. }
  215. void do_cfg(int s)
  216. {
  217. #define CFG_VERSION 0x10204
  218. if (!s)
  219. {
  220. if (CfgVar::read_int(INI_FILE, "in_vorbis", "version",0)==CFG_VERSION)
  221. CfgVar::ReadConfig();
  222. }
  223. else
  224. {
  225. CfgVar::WriteConfig();
  226. CfgVar::write_int(INI_FILE, "in_vorbis", "version",CFG_VERSION);
  227. }
  228. }
  229. CfgVar * CfgVar::list=0;
  230. void CfgVar::ReadConfig()
  231. {
  232. CfgVar * p=list;
  233. while(p)
  234. {
  235. p->Read(p->name);
  236. p=p->next;
  237. }
  238. }
  239. void CfgVar::WriteConfig()
  240. {
  241. CfgVar * p=list;
  242. while(p)
  243. {
  244. p->Write(p->name);
  245. p=p->next;
  246. }
  247. }
  248. bool StringW::reg_read(const char * name)
  249. {
  250. char utf8_data[2048] = {0};
  251. wchar_t utf16_data[2048] = {0};
  252. GetPrivateProfileStringA("in_vorbis", name, "@default@", utf8_data, 2048, INI_FILE);
  253. if (!strcmp("@default@", utf8_data))
  254. return false;
  255. MultiByteToWideCharSZ(CP_UTF8, 0, utf8_data, -1, utf16_data, 2048);
  256. SetString(utf16_data);
  257. return true;
  258. }
  259. void StringW::reg_write(const char * name)
  260. {
  261. WritePrivateProfileStringA("in_vorbis", name, AutoChar((const WCHAR *)*this, CP_UTF8), INI_FILE);
  262. }
  263. void CfgString::Read(const char * name)
  264. {
  265. reg_read(name);
  266. }
  267. void CfgString::Write(const char * name)
  268. {
  269. StringW temp;
  270. if (temp.reg_read(name))
  271. {
  272. if (wcscmp(temp,*this)) reg_write(name);
  273. }
  274. else
  275. {
  276. if (wcscmp(def,*this)) reg_write(name);
  277. }
  278. }
  279. void CfgInt::Write(const char * name)
  280. {
  281. if (read_int(INI_FILE, "in_vorbis", name,def)!=value) write_int(INI_FILE, "in_vorbis",name,value);
  282. }
  283. void CfgInt::Read(const char * name)
  284. {
  285. value=read_int(INI_FILE, "in_vorbis", name,def);
  286. }