config.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include <windows.h>
  2. #include "api.h"
  3. #include "resource.h"
  4. #include "../Winamp/wa_ipc.h"
  5. #include "../Winamp/in2.h"
  6. extern In_Module mod; // the output module (filled in near the bottom of this file)
  7. static char app_name[] = "Nullsoft NSV Decoder2";
  8. //char config_http_proxynonport80=1;
  9. int config_padtag=1024;
  10. int config_bufms=10000;
  11. int config_prebufms=2000;
  12. int config_underunbuf=3000;
  13. int config_bufms_f=1000;
  14. int config_prebufms_f=1000;
  15. int config_underunbuf_f=1000;
  16. int config_vidoffs=0;
  17. int config_precseek=3;
  18. int config_subtitles=1;
  19. void config_write();
  20. char INI_FILE[512] = {0};
  21. static int _r_i(char *name, int def)
  22. {
  23. if (!_strnicmp(name,"config_",7)) name += 7;
  24. return GetPrivateProfileIntA(app_name,name,def,INI_FILE);
  25. }
  26. #define RI(x) (( x ) = _r_i(#x,( x )))
  27. static void _w_i(char *name, int d)
  28. {
  29. char str[120] = {0};
  30. wsprintfA(str,"%d",d);
  31. if (!_strnicmp(name,"config_",7)) name += 7;
  32. WritePrivateProfileStringA(app_name,name,str,INI_FILE);
  33. }
  34. #define WI(x) _w_i(#x,( x ))
  35. static void _r_s(char *name,char *data, int mlen)
  36. {
  37. char buf[2048] = {0};
  38. strncpy(buf, data, 2048);
  39. if (!_strnicmp(name,"config_",7)) name += 7;
  40. GetPrivateProfileStringA(app_name,name,buf,data,mlen,INI_FILE);
  41. }
  42. #define RS(x) (_r_s(#x,x,sizeof(x)))
  43. static void _w_s(char *name, char *data)
  44. {
  45. if (!_strnicmp(name,"config_",7)) name += 7;
  46. WritePrivateProfileStringA(app_name,name,data,INI_FILE);
  47. }
  48. #define WS(x) (_w_s(#x,x))
  49. static void config_init()
  50. {
  51. char *p;
  52. if (mod.hMainWindow &&
  53. (p = (char *)SendMessageA(mod.hMainWindow, WM_WA_IPC, 0, IPC_GETINIFILE))
  54. && p!= (char *)1)
  55. {
  56. strncpy(INI_FILE, p, MAX_PATH);
  57. }
  58. else
  59. {
  60. GetModuleFileNameA(NULL,INI_FILE,sizeof(INI_FILE));
  61. p=INI_FILE+strlen(INI_FILE);
  62. while (p >= INI_FILE && *p != '.') p--;
  63. strcpy(++p,"ini");
  64. }
  65. }
  66. static INT_PTR CALLBACK configProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  67. {
  68. switch (uMsg)
  69. {
  70. case WM_INITDIALOG:
  71. // show config
  72. SetDlgItemInt(hwndDlg,IDC_BUF1,config_bufms,FALSE);
  73. SetDlgItemInt(hwndDlg,IDC_BUF2,config_prebufms,FALSE);
  74. SetDlgItemInt(hwndDlg,IDC_BUF3,config_underunbuf,FALSE);
  75. SetDlgItemInt(hwndDlg,IDC_BUF4,config_bufms_f,FALSE);
  76. SetDlgItemInt(hwndDlg,IDC_BUF5,config_prebufms_f,FALSE);
  77. SetDlgItemInt(hwndDlg,IDC_BUF6,config_underunbuf_f,FALSE);
  78. SetDlgItemInt(hwndDlg,IDC_OFFS,config_vidoffs,TRUE);
  79. SetDlgItemInt(hwndDlg,IDC_TAGPAD,config_padtag,FALSE);
  80. if (config_precseek&1)CheckDlgButton(hwndDlg,IDC_CHECK1,BST_CHECKED);
  81. if (config_precseek&2)CheckDlgButton(hwndDlg,IDC_CHECK2,BST_CHECKED);
  82. if (config_subtitles)CheckDlgButton(hwndDlg,IDC_CHECK3,BST_CHECKED);
  83. // if (!config_http_proxynonport80) CheckDlgButton(hwndDlg,IDC_CHECK5,BST_CHECKED);
  84. return 0;
  85. case WM_COMMAND:
  86. switch (LOWORD(wParam))
  87. {
  88. case IDC_CHECK1:
  89. case IDC_CHECK2:
  90. config_precseek=(IsDlgButtonChecked(hwndDlg,IDC_CHECK1)?1:0)|
  91. (IsDlgButtonChecked(hwndDlg,IDC_CHECK2)?2:0);
  92. break;
  93. case IDC_CHECK3:
  94. config_subtitles=(IsDlgButtonChecked(hwndDlg,IDC_CHECK3)?1:0);
  95. break;
  96. case IDC_OFFS:
  97. if (HIWORD(wParam) == EN_CHANGE)
  98. {
  99. BOOL t;
  100. config_vidoffs=GetDlgItemInt(hwndDlg,IDC_OFFS,&t,TRUE);
  101. }
  102. break;
  103. case IDCANCEL: EndDialog(hwndDlg,0); break;
  104. case IDOK:
  105. // save config
  106. // config_http_proxynonport80=!IsDlgButtonChecked(hwndDlg,IDC_CHECK5);
  107. {
  108. BOOL t;
  109. config_bufms=GetDlgItemInt(hwndDlg,IDC_BUF1,&t,FALSE);
  110. if (config_bufms < 100) config_bufms=100;
  111. if (config_bufms > 100000) config_bufms=100000;
  112. config_prebufms=GetDlgItemInt(hwndDlg,IDC_BUF2,&t,FALSE);
  113. if (config_prebufms < 100) config_prebufms=100;
  114. if (config_prebufms > config_bufms) config_prebufms=config_bufms;
  115. config_underunbuf=GetDlgItemInt(hwndDlg,IDC_BUF3,&t,FALSE);
  116. if (config_underunbuf < 100) config_underunbuf=100;
  117. if (config_underunbuf > config_bufms) config_underunbuf=config_bufms;
  118. config_bufms_f=GetDlgItemInt(hwndDlg,IDC_BUF4,&t,FALSE);
  119. if (config_bufms_f < 100) config_bufms_f=100;
  120. if (config_bufms_f > 100000) config_bufms_f=100000;
  121. config_prebufms_f=GetDlgItemInt(hwndDlg,IDC_BUF5,&t,FALSE);
  122. if (config_prebufms_f < 100) config_prebufms_f=100;
  123. if (config_prebufms_f > config_bufms_f) config_prebufms_f=config_bufms_f;
  124. config_underunbuf_f=GetDlgItemInt(hwndDlg,IDC_BUF6,&t,FALSE);
  125. if (config_underunbuf_f < 100) config_underunbuf_f=100;
  126. if (config_underunbuf_f > config_bufms_f) config_underunbuf_f=config_bufms_f;
  127. config_vidoffs=GetDlgItemInt(hwndDlg,IDC_OFFS,&t,TRUE);
  128. config_padtag=GetDlgItemInt(hwndDlg,IDC_TAGPAD,&t,FALSE);
  129. }
  130. config_write();
  131. EndDialog(hwndDlg,1);
  132. break;
  133. }
  134. break;
  135. }
  136. return 0;
  137. }
  138. void config(HWND hwndParent)
  139. {
  140. WASABI_API_DIALOGBOXW(IDD_DIALOG1,hwndParent,configProc);
  141. }
  142. void config_read()
  143. {
  144. config_init();
  145. RI(config_bufms);
  146. RI(config_prebufms);
  147. RI(config_underunbuf);
  148. RI(config_bufms_f);
  149. RI(config_prebufms_f);
  150. RI(config_underunbuf_f);
  151. RI(config_vidoffs);
  152. RI(config_padtag);
  153. // RI(allow_uvox);
  154. // RI(config_http_proxynonport80);
  155. RI(config_precseek);
  156. RI(config_subtitles);
  157. }
  158. void config_write()
  159. {
  160. WI(config_bufms);
  161. WI(config_prebufms);
  162. WI(config_underunbuf);
  163. WI(config_bufms_f);
  164. WI(config_prebufms_f);
  165. WI(config_underunbuf_f);
  166. WI(config_vidoffs);
  167. WI(config_padtag);
  168. WI(config_precseek);
  169. WI(config_subtitles);
  170. // WI(allow_uvox);
  171. // WI(config_http_proxynonport80);
  172. }