/[pcsx2_0.9.7]/trunk/plugins/CDVDpeops/Cfg.c
ViewVC logotype

Contents of /trunk/plugins/CDVDpeops/Cfg.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 10 months ago) by william
File MIME type: text/plain
File size: 16765 byte(s)
committing r3113 initial commit again...
1 /***************************************************************************
2 cfg.c - description
3 -------------------
4 begin : Sun Nov 16 2003
5 copyright : (C) 2003 by Pete Bernert
6 email : BlackDove@addcom.de
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. See also the license.txt file for *
15 * additional informations. *
16 * *
17 ***************************************************************************/
18
19 //*************************************************************************//
20 // History of changes:
21 //
22 // 2003/11/16 - Pete
23 // - generic cleanup for the Peops release
24 //
25 //*************************************************************************//
26
27 ////////////////////////////////////////////////////////////////////////
28
29 #include "stdafx.h"
30 #include "resource.h"
31 #define _IN_CFG
32 #include "externals.h"
33
34 ////////////////////////////////////////////////////////////////////////
35
36 /////////////////////////////////////////////////////////////////////////////
37 // read config from registry
38
39 void ReadConfig(void)
40 {
41 HKEY myKey;DWORD temp,type,size;
42
43 // init values
44
45 iCD_AD=-1;
46 iCD_TA=-1;
47 iCD_LU=-1;
48 iRType=0;
49 iUseSpeedLimit=0;
50 iSpeedLimit=2;
51 iNoWait=0;
52 iMaxRetry=5;
53 iShowReadErr=0;
54 iUsePPF=0;
55 iUseSubReading=0;
56 iUseDataCache=0;
57 iCheckTrayStatus=0;
58 memset(szPPF,0,260);
59 memset(szSUBF,0,260);
60
61 // read values
62
63 if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\PS2Eplugin\\CDVD\\CDVDPeops",0,KEY_ALL_ACCESS,&myKey)==ERROR_SUCCESS)
64 {
65 size = 4;
66 if(RegQueryValueEx(myKey,"Adapter",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
67 iCD_AD=(int)temp;
68 size = 4;
69 if(RegQueryValueEx(myKey,"Target",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
70 iCD_TA=(int)temp;
71 size = 4;
72 if(RegQueryValueEx(myKey,"LUN",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
73 iCD_LU=(int)temp;
74 size = 4;
75 if(RegQueryValueEx(myKey,"UseCaching",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
76 iUseCaching=(int)temp;
77 size = 4;
78 if(RegQueryValueEx(myKey,"UseDataCache",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
79 iUseDataCache=(int)temp;
80 size = 4;
81 if(RegQueryValueEx(myKey,"UseSpeedLimit",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
82 iUseSpeedLimit=(int)temp;
83 size = 4;
84 if(RegQueryValueEx(myKey,"SpeedLimit",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
85 iSpeedLimit=(int)temp;
86 size = 4;
87 if(RegQueryValueEx(myKey,"NoWait",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
88 iNoWait=(int)temp;
89 size = 4;
90 if(RegQueryValueEx(myKey,"CheckTrayStatus",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
91 iCheckTrayStatus=(int)temp;
92 size = 4;
93 if(RegQueryValueEx(myKey,"MaxRetry",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
94 iMaxRetry=(int)temp;
95 size = 4;
96 if(RegQueryValueEx(myKey,"ShowReadErr",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
97 iShowReadErr=(int)temp;
98 size = 4;
99 if(RegQueryValueEx(myKey,"UsePPF",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
100 iUsePPF=(int)temp;
101 size = 4;
102 if(RegQueryValueEx(myKey,"UseSubReading",0,&type,(LPBYTE)&temp,&size)==ERROR_SUCCESS)
103 iUseSubReading=(int)temp;
104 size=259;
105 RegQueryValueEx(myKey,"PPFFile",0,&type,(LPBYTE)szPPF,&size);
106 size=259;
107 RegQueryValueEx(myKey,"SCFile",0,&type,(LPBYTE)szSUBF,&size);
108
109 RegCloseKey(myKey);
110 }
111
112 // disabled for now
113 iUsePPF=0;
114 }
115
116 ////////////////////////////////////////////////////////////////////////
117 // write user config
118
119 void WriteConfig(void)
120 {
121 HKEY myKey;DWORD myDisp,temp;
122
123 RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\PS2Eplugin\\CDVD\\CDVDPeops",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&myKey,&myDisp);
124 temp=iInterfaceMode;
125 RegSetValueEx(myKey,"InterfaceMode",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
126 temp=iCD_AD;
127 RegSetValueEx(myKey,"Adapter",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
128 temp=iCD_TA;
129 RegSetValueEx(myKey,"Target",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
130 temp=iCD_LU;
131 RegSetValueEx(myKey,"LUN",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
132 temp=iUseCaching;
133 RegSetValueEx(myKey,"UseCaching",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
134 temp=iUseDataCache;
135 RegSetValueEx(myKey,"UseDataCache",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
136 temp=iUseSpeedLimit;
137 RegSetValueEx(myKey,"UseSpeedLimit",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
138 temp=iSpeedLimit;
139 RegSetValueEx(myKey,"SpeedLimit",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
140 temp=iNoWait;
141 RegSetValueEx(myKey,"NoWait",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
142 temp=iCheckTrayStatus ;
143 RegSetValueEx(myKey,"CheckTrayStatus",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
144 temp=iMaxRetry;
145 RegSetValueEx(myKey,"MaxRetry",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
146 temp=iShowReadErr;
147 RegSetValueEx(myKey,"ShowReadErr",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
148 temp=iUsePPF;
149 RegSetValueEx(myKey,"UsePPF",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
150 temp=iUseSubReading;
151 RegSetValueEx(myKey,"UseSubReading",0,REG_DWORD,(LPBYTE) &temp,sizeof(temp));
152
153 RegSetValueEx(myKey,"PPFFile",0,REG_BINARY,(LPBYTE)szPPF,259);
154 RegSetValueEx(myKey,"SCFile",0,REG_BINARY,(LPBYTE)szSUBF,259);
155
156 RegCloseKey(myKey);
157 }
158
159 ////////////////////////////////////////////////////////////////////////
160 // choose ppf/sbi/m3s file name
161
162 void OnChooseFile(HWND hW,int iFType)
163 {
164 OPENFILENAME ofn;char szB[260];BOOL b;
165
166 ofn.lStructSize=sizeof(OPENFILENAME);
167 ofn.hwndOwner=hW;
168 ofn.hInstance=NULL;
169 if(iFType==0) ofn.lpstrFilter="PPF Files\0*.PPF\0\0\0";
170 else if(iFType==1) ofn.lpstrFilter="SBI Files\0*.SBI\0M3S Files\0*.M3S\0\0\0";
171 else if(iFType==2) ofn.lpstrFilter="SUB Files\0*.SUB\0\0\0";
172 else if(iFType==3) ofn.lpstrFilter="SBI Files\0*.SBI\0\0\0";
173 else ofn.lpstrFilter="M3S Files\0*.M3S\0\0\0";
174
175 ofn.lpstrCustomFilter=NULL;
176 ofn.nMaxCustFilter=0;
177 ofn.nFilterIndex=0;
178 if(iFType==0) GetDlgItemText(hW,IDC_PPFFILE,szB,259);
179 else if(iFType==1) GetDlgItemText(hW,IDC_SUBFILE,szB,259);
180 else if(iFType==2) GetDlgItemText(hW,IDC_SUBFILEEDIT,szB,259);
181 else if(iFType==3) GetDlgItemText(hW,IDC_OUTFILEEDIT,szB,259);
182 else GetDlgItemText(hW,IDC_OUTFILEEDIT,szB,259);
183
184 ofn.lpstrFile=szB;
185 ofn.nMaxFile=259;
186 ofn.lpstrFileTitle=NULL;
187 ofn.nMaxFileTitle=0;
188 ofn.lpstrInitialDir=NULL;
189 ofn.lpstrTitle=NULL;
190 if(iFType<3)
191 ofn.Flags=OFN_FILEMUSTEXIST|OFN_NOCHANGEDIR|OFN_HIDEREADONLY;
192 else
193 ofn.Flags=OFN_CREATEPROMPT|OFN_NOCHANGEDIR|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
194 ofn.nFileOffset=0;
195 ofn.nFileExtension=0;
196 ofn.lpstrDefExt=0;
197 ofn.lCustData=0;
198 ofn.lpfnHook=NULL;
199 ofn.lpTemplateName=NULL;
200
201 if(iFType<3)
202 b=GetOpenFileName(&ofn);
203 else b=GetSaveFileName(&ofn);
204
205 if(b)
206 {
207 if(iFType==0) SetDlgItemText(hW,IDC_PPFFILE,szB);
208 else if(iFType==1) SetDlgItemText(hW,IDC_SUBFILE,szB);
209 else if(iFType==2) SetDlgItemText(hW,IDC_SUBFILEEDIT,szB);
210 else if(iFType==3) SetDlgItemText(hW,IDC_OUTFILEEDIT,szB);
211 else SetDlgItemText(hW,IDC_OUTFILEEDIT,szB);
212 }
213 }
214
215 ////////////////////////////////////////////////////////////////////////
216 // file drive combo
217
218 void EnumDrives(HWND hW)
219 {
220 HWND hWC;char szB[256];int i=0,k=0,iNum;
221 char * p, * pBuf, * pN;
222
223 hWC=GetDlgItem(hW,IDC_DRIVE);
224 ComboBox_ResetContent(hWC);
225 ComboBox_AddString(hWC,"NONE"); // add always existing 'none'
226
227 wsprintf(szB,"[%d:%d:%d",iCD_AD,iCD_TA,iCD_LU); // make current user info text
228
229 pN=pBuf=(char *)malloc(32768);
230 memset(pBuf,0,32768);
231 iNum=GetGenCDDrives(pBuf); // get the system cd drives list
232
233 for(i=0;i<iNum;i++) // loop drives
234 {
235 ComboBox_AddString(hWC,pN); // -> add drive name
236 p=strchr(pN,']');
237 if(p)
238 {
239 *p=0;
240 if(strcmp(szB,pN)==0) k=i+1; // -> is it the current user drive? sel it
241 *p=']';
242 }
243 pN+=strlen(pN)+1; // next drive in buffer
244 }
245
246 free(pBuf);
247
248 ComboBox_SetCurSel(hWC,k); // do the drive sel
249 }
250
251 ////////////////////////////////////////////////////////////////////////
252 // get curr selected drive
253
254 void GetCDRInfos(HWND hW,int * iA, int * iT,int * iL)
255 {
256 HWND hWC=GetDlgItem(hW,IDC_DRIVE);
257 char szB[256];int i;char * p;
258
259 i=ComboBox_GetCurSel(hWC);
260 if(i<=0) // none selected
261 {
262 *iA=-1;*iT=-1;*iL=-1;
263 MessageBox(hW,"Please select a cdrom drive!","Config error",MB_OK|MB_ICONINFORMATION);
264 return;
265 }
266
267 ComboBox_GetLBText(hWC,i,szB); // get cd text
268 p=szB+1;
269 *iA=atoi(p); // get AD,TA,LU
270 p=strchr(szB,':')+1;
271 *iT=atoi(p);
272 p=strchr(p,':')+1;
273 *iL=atoi(p);
274 }
275
276 ////////////////////////////////////////////////////////////////////////
277 // interface mode has changed
278
279 void OnIMode(HWND hW)
280 {
281 HWND hWC=GetDlgItem(hW,IDC_IMODE);
282 int iM = ComboBox_GetCurSel(hWC);
283
284 GetCDRInfos(hW,&iCD_AD,&iCD_TA,&iCD_LU); // get sel drive
285 CloseGenInterface(); // close current interface
286 iInterfaceMode=iM; // set new interface mode
287 OpenGenInterface(); // open new interface
288 ComboBox_SetCurSel(hWC,iInterfaceMode); // sel interface again (maybe it was not supported on open)
289 EnumDrives(hW); // enum drives again
290 }
291
292 ////////////////////////////////////////////////////////////////////////
293 // cache mode has changed
294
295 void OnCache(HWND hW)
296 {
297 HWND hWC=GetDlgItem(hW,IDC_CACHE);
298 if(ComboBox_GetCurSel(hWC)<=0)
299 ShowWindow(GetDlgItem(hW,IDC_DATACACHE),SW_HIDE);
300 else ShowWindow(GetDlgItem(hW,IDC_DATACACHE),SW_SHOW);
301 }
302
303 ////////////////////////////////////////////////////////////////////////
304 // show/hide files depending on subc mode
305
306 void ShowSubFileStuff(HWND hW)
307 {
308 HWND hWC=GetDlgItem(hW,IDC_SUBCHAN0);
309 int iShow,iSel=ComboBox_GetCurSel(hWC);
310
311 if(iSel==2) iShow=SW_SHOW;
312 else iShow=SW_HIDE;
313
314 ShowWindow(GetDlgItem(hW,IDC_SFSTATIC),iShow);
315 ShowWindow(GetDlgItem(hW,IDC_SUBFILE),iShow);
316 ShowWindow(GetDlgItem(hW,IDC_CHOOSESUBF),iShow);
317
318 if(iSel==1)
319 {
320 ComboBox_SetCurSel(GetDlgItem(hW,IDC_CACHE),0);
321 ShowWindow(GetDlgItem(hW,IDC_DATACACHE),SW_HIDE);
322 }
323 }
324
325 ////////////////////////////////////////////////////////////////////////
326 // init dialog
327
328 BOOL OnInitCDRDialog(HWND hW)
329 {
330 HWND hWC;int i=0;
331
332 ReadConfig(); // read config
333
334 hWC=GetDlgItem(hW,IDC_IMODE); // interface
335 ComboBox_AddString(hWC,"NONE");
336 ComboBox_AddString(hWC,"W9X/ME - ASPI scsi commands");
337 ComboBox_AddString(hWC,"W2K/XP - IOCTL scsi commands");
338
339 // not supported with my dvd drive - DISABLED!
340 // ComboBox_AddString(hWC,"W2K/XP - IOCTL raw reading");
341
342 ComboBox_SetCurSel(hWC,iInterfaceMode);
343
344 EnumDrives(hW); // enum drives
345
346 hWC=GetDlgItem(hW,IDC_CACHE); // caching
347 ComboBox_AddString(hWC,"None - reads one sector");
348 ComboBox_AddString(hWC,"Read ahead - fast, reads more sectors at once");
349 ComboBox_AddString(hWC,"Async read - faster, additional asynchronous reads");
350 ComboBox_AddString(hWC,"Thread read - fast with IOCTL, always async reads");
351 ComboBox_AddString(hWC,"Smooth read - for drives with ps2 cd/dvd reading troubles");
352 ComboBox_SetCurSel(hWC,iUseCaching);
353
354 if(iUseDataCache)
355 CheckDlgButton(hW,IDC_DATACACHE,TRUE);
356 if(!iUseCaching)
357 ShowWindow(GetDlgItem(hW,IDC_DATACACHE),SW_HIDE);
358
359 if(iUseSpeedLimit) // speed limit
360 CheckDlgButton(hW,IDC_SPEEDLIMIT,TRUE);
361
362 if(iNoWait) // wait for drive
363 CheckDlgButton(hW,IDC_NOWAIT,TRUE);
364
365 if(iCheckTrayStatus) // tray status
366 CheckDlgButton(hW,IDC_TRAYSTATE,TRUE);
367
368 SetDlgItemInt(hW,IDC_RETRY,iMaxRetry,FALSE); // retry on error
369 if(iMaxRetry) CheckDlgButton(hW,IDC_TRYAGAIN,TRUE);
370 if(iShowReadErr) CheckDlgButton(hW,IDC_SHOWREADERR,TRUE);
371
372 hWC=GetDlgItem(hW,IDC_SUBCHAN0); // subchannel mode
373 ComboBox_AddString(hWC,"Don't read subchannels");
374 ComboBox_AddString(hWC,"Read subchannels (slow, few drives support it, best chances with BE mode)");
375 ComboBox_AddString(hWC,"Use subchannel SBI/M3S info file (recommended)");
376 ComboBox_SetCurSel(hWC,iUseSubReading);
377
378 ShowSubFileStuff(hW); // show/hide subc controls
379
380 hWC=GetDlgItem(hW,IDC_SPEED); // speed limit
381 ComboBox_AddString(hWC,"2 X");
382 ComboBox_AddString(hWC,"4 X");
383 ComboBox_AddString(hWC,"8 X");
384 ComboBox_AddString(hWC,"16 X");
385
386 i=0;
387 if(iSpeedLimit==4) i=1;
388 if(iSpeedLimit==8) i=2;
389 if(iSpeedLimit==16) i=3;
390
391 ComboBox_SetCurSel(hWC,i);
392
393 if(iUsePPF) CheckDlgButton(hW,IDC_USEPPF,TRUE); // ppf
394 SetDlgItemText(hW,IDC_PPFFILE,szPPF);
395 SetDlgItemText(hW,IDC_SUBFILE,szSUBF);
396
397 return TRUE;
398 }
399
400 ////////////////////////////////////////////////////////////////////////
401
402 void OnCDROK(HWND hW)
403 {
404 int iA,iT,iL,iR;
405 HWND hWC=GetDlgItem(hW,IDC_RTYPE);
406
407 GetCDRInfos(hW,&iA,&iT,&iL);
408 if(iA==-1) return;
409
410 hWC=GetDlgItem(hW,IDC_CACHE);
411 iUseCaching=ComboBox_GetCurSel(hWC);
412 if(iUseCaching<0) iUseCaching=0;
413 if(iUseCaching>4) iUseCaching=4;
414
415 iCD_AD=iA;iCD_TA=iT;iCD_LU=iL;
416
417 if(IsDlgButtonChecked(hW,IDC_SPEEDLIMIT))
418 iUseSpeedLimit=1;
419 else iUseSpeedLimit=0;
420
421 iUseSubReading=0;
422 hWC=GetDlgItem(hW,IDC_SUBCHAN0);
423 iUseSubReading=ComboBox_GetCurSel(hWC);
424 if(iUseSubReading<0) iUseSubReading=0;
425 if(iUseSubReading>2) iUseSubReading=2;
426 if(iUseSubReading==1) iUseCaching=0;
427
428 if(IsDlgButtonChecked(hW,IDC_DATACACHE))
429 iUseDataCache=1;
430 else iUseDataCache=0;
431 if(iUseCaching==0) iUseDataCache=0;
432
433 if(IsDlgButtonChecked(hW,IDC_NOWAIT))
434 iNoWait=1;
435 else iNoWait=0;
436
437 if(IsDlgButtonChecked(hW,IDC_TRAYSTATE))
438 iCheckTrayStatus=1;
439 else iCheckTrayStatus=0;
440
441 iMaxRetry=GetDlgItemInt(hW,IDC_RETRY,NULL,FALSE);
442 if(iMaxRetry<1) iMaxRetry=1;
443 if(iMaxRetry>10) iMaxRetry=10;
444 if(!IsDlgButtonChecked(hW,IDC_TRYAGAIN)) iMaxRetry=0;
445
446 if(IsDlgButtonChecked(hW,IDC_SHOWREADERR))
447 iShowReadErr=1;
448 else iShowReadErr=0;
449
450 hWC=GetDlgItem(hW,IDC_SPEED);
451 iR=ComboBox_GetCurSel(hWC);
452
453 iSpeedLimit=2;
454 if(iR==1) iSpeedLimit=4;
455 if(iR==2) iSpeedLimit=8;
456 if(iR==3) iSpeedLimit=16;
457
458 if(IsDlgButtonChecked(hW,IDC_USEPPF))
459 iUsePPF=1;
460 else iUsePPF=0;
461
462 GetDlgItemText(hW,IDC_PPFFILE,szPPF,259);
463 GetDlgItemText(hW,IDC_SUBFILE,szSUBF,259);
464
465 WriteConfig(); // write registry
466
467 EndDialog(hW,TRUE);
468 }
469
470 ////////////////////////////////////////////////////////////////////////
471
472 void OnCDRCancel(HWND hW)
473 {
474 EndDialog(hW,FALSE);
475 }
476
477 ////////////////////////////////////////////////////////////////////////
478
479 BOOL CALLBACK CDRDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
480 {
481 switch(uMsg)
482 {
483 case WM_INITDIALOG:
484 return OnInitCDRDialog(hW);
485
486 case WM_COMMAND:
487 {
488 switch(LOWORD(wParam))
489 {
490 case IDC_SUBCHAN0: if(HIWORD(wParam)==CBN_SELCHANGE)
491 {ShowSubFileStuff(hW);return TRUE;}
492 case IDC_IMODE: if(HIWORD(wParam)==CBN_SELCHANGE)
493 {OnIMode(hW);return TRUE;}
494 break;
495 case IDC_CACHE: if(HIWORD(wParam)==CBN_SELCHANGE)
496 {OnCache(hW);return TRUE;}
497 break;
498 case IDCANCEL: OnCDRCancel(hW); return TRUE;
499 case IDOK: OnCDROK(hW); return TRUE;
500 case IDC_CHOOSEFILE: OnChooseFile(hW,0);return TRUE;
501 case IDC_CHOOSESUBF: OnChooseFile(hW,1);return TRUE;
502 }
503 }
504 }
505 return FALSE;
506 }
507
508 ////////////////////////////////////////////////////////////////////////
509
510 BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
511 {
512 switch(uMsg)
513 {
514 case WM_COMMAND:
515 {
516 switch(LOWORD(wParam))
517 {
518 case IDCANCEL: EndDialog(hW,FALSE);return TRUE;
519 case IDOK: EndDialog(hW,FALSE);return TRUE;
520 }
521 }
522 }
523 return FALSE;
524 }
525
526 ////////////////////////////////////////////////////////////////////////
527

  ViewVC Help
Powered by ViewVC 1.1.22