Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
6.2 KiB

  1. /*******************************Module*Header*********************************\
  2. * Module Name: cdconfig.c
  3. *
  4. * Media Control Architecture Redbook CD Audio Driver
  5. *
  6. * History:
  7. * RobinSp - 6 Mar 1992 ported to Windows NT
  8. *
  9. * Copyright (c) 1990-1995 Microsoft Corporation
  10. *
  11. \****************************************************************************/
  12. #include <windows.h>
  13. #include <mmsystem.h>
  14. #include <mmddk.h>
  15. #include "mcicda.h"
  16. #include "cdconfig.h"
  17. #include "cda.h"
  18. #include "cdio.h"
  19. #define MAXINILENGTH 128
  20. TCHAR szIniFile[] = TEXT("system.ini");
  21. TCHAR szNull[] = TEXT("");
  22. int numdrives;
  23. STATICFN LPWSTR GetTail(LPWSTR pch)
  24. {
  25. while (*pch && *pch != ' ')
  26. pch++;
  27. while (*pch == ' ')
  28. pch++ ;
  29. return (pch);
  30. }
  31. STATICFN UINT GetCmdParam (LPDRVCONFIGINFO lpdci)
  32. {
  33. WCHAR sz[MAXINILENGTH];
  34. LPWSTR lpsz;
  35. if ((lpdci->dwDCISize == sizeof(DRVCONFIGINFO)) && GetPrivateProfileStringW(
  36. lpdci->lpszDCISectionName,
  37. lpdci->lpszDCIAliasName,
  38. szNull, sz, MAXINILENGTH, szIniFile))
  39. {
  40. WCHAR parameters[6];
  41. LPWSTR pszDefault;
  42. // We have got the name of the driver
  43. // Just in case the user has added the command parameter to the
  44. // end of the name we had better make sure there is only one token
  45. // on the line. If there is a command parameter this becomes the
  46. // default on the call to read WIN.INI
  47. lpsz = GetTail (sz);
  48. pszDefault = lpsz; // Either the number on the end, or NULL
  49. if (*lpsz) {
  50. // RATS!! There is a parameter on the end of the driver name
  51. while (*--lpsz == TEXT(' ')) {
  52. }
  53. *++lpsz = TEXT('\0'); // Terminate the string after the DLL name
  54. }
  55. if (GetProfileString(sz, lpdci->lpszDCIAliasName, lpsz, parameters, sizeof(parameters)/sizeof(WCHAR))) {
  56. if (parameters[0] == TEXT('\0') ||
  57. parameters[0] < TEXT('0') || parameters[0] > L'9')
  58. return 0;
  59. else
  60. return parameters[0] - L'0';
  61. } else
  62. return(0);
  63. } else
  64. return 0;
  65. }
  66. STATICFN void PutCmdParam(LPDRVCONFIGINFO lpdci, UINT nDrive)
  67. {
  68. WCHAR sz[MAXINILENGTH];
  69. LPWSTR lpch;
  70. if (lpdci->dwDCISize == sizeof(DRVCONFIGINFO))
  71. {
  72. if (GetPrivateProfileStringW(
  73. lpdci->lpszDCISectionName,
  74. lpdci->lpszDCIAliasName,
  75. szNull, sz, MAXINILENGTH-5, szIniFile))
  76. {
  77. // There might be a command parameter on the end of the DLL name.
  78. // Ensure we only have the first token
  79. sz[MAXINILENGTH-1] = 0;
  80. lpch = GetTail(sz);
  81. if (*lpch) {
  82. // RATS!! Not a simple name
  83. while (*--lpch == L' ') {
  84. }
  85. *++lpch = TEXT('\0'); // Terminate the string after the DLL name
  86. }
  87. // lpch addresses the 0 terminating the DLL name
  88. // we now add the command parameter into the same buffer, but
  89. // as a separate string. This will then be written to win.ini
  90. // [mcicda.dll]
  91. // aliasname = parameter
  92. *++lpch = (TCHAR)(nDrive + '0');
  93. *(lpch+1) = '\0';
  94. WriteProfileString(sz, lpdci->lpszDCIAliasName, lpch);
  95. }
  96. }
  97. }
  98. BOOL ConfigDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  99. {
  100. int i;
  101. HWND hListbox;
  102. static LPDRVCONFIGINFO lpdci;
  103. switch (msg) {
  104. case WM_INITDIALOG:
  105. {
  106. WCHAR wszFormat[32];
  107. hListbox = GetDlgItem (hDlg, C_DRIVE_LIST);
  108. LoadString( hInstance, IDS_DRIVE, wszFormat,
  109. sizeof(wszFormat) / sizeof(WCHAR) );
  110. lpdci = (LPDRVCONFIGINFO)lParam;
  111. for (i = 0; i < numdrives; ++i)
  112. {
  113. TCHAR item_name[32];
  114. wsprintf( item_name, wszFormat, CdInfo[i].cDrive );
  115. SendMessage (hListbox, LB_ADDSTRING, 0, (DWORD)(LPWSTR)item_name);
  116. }
  117. i = GetCmdParam(lpdci);
  118. SendMessage (hListbox, LB_SETCURSEL, (UINT)i, 0);
  119. break;
  120. }
  121. case WM_COMMAND:
  122. switch (LOWORD(wParam))
  123. {
  124. case IDOK:
  125. hListbox = GetDlgItem (hDlg, C_DRIVE_LIST);
  126. i = SendMessage (hListbox, LB_GETCURSEL, 0, 0L);
  127. if (i != LB_ERR)
  128. PutCmdParam(lpdci, i);
  129. EndDialog(hDlg, DRVCNF_OK);
  130. break;
  131. case IDCANCEL:
  132. EndDialog(hDlg, DRVCNF_CANCEL);
  133. break;
  134. default:
  135. break;
  136. }
  137. break;
  138. default:
  139. return FALSE;
  140. break;
  141. }
  142. return TRUE;
  143. }
  144. STATICFN void DisplayMessage(
  145. HWND hwndParent,
  146. UINT wMessageID)
  147. {
  148. WCHAR aszCaption[128];
  149. WCHAR aszMessage[128];
  150. LoadStringW( hInstance, wMessageID, aszMessage,
  151. sizeof(aszMessage) / sizeof(WCHAR) );
  152. LoadStringW( hInstance, IDS_CONFIGCAPTION, aszCaption,
  153. sizeof(aszCaption) / sizeof(WCHAR) );
  154. MessageBoxW( hwndParent, aszMessage, aszCaption,
  155. MB_ICONINFORMATION | MB_OK);
  156. }
  157. int PASCAL FAR CDAConfig (HWND hwndParent, LPDRVCONFIGINFO lpInfo)
  158. {
  159. int iResult;
  160. //
  161. // Initialize global count of number of CD drives present
  162. //
  163. numdrives = CDA_init_audio();
  164. //
  165. // If no drives are detected we still allow the install
  166. //
  167. // If there is more than one drive ask the user which one they want
  168. // to use with this driver.
  169. //
  170. // Note that the user may select cancel in the dialog.
  171. //
  172. switch (numdrives) {
  173. case -1:
  174. case 0:
  175. DisplayMessage(hwndParent, IDS_NODRIVES);
  176. iResult = DRVCNF_OK;
  177. break;
  178. case 1:
  179. DisplayMessage(hwndParent, IDS_ONEDRIVE);
  180. iResult = DRVCNF_OK;
  181. break;
  182. default:
  183. iResult = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CONFIG), hwndParent, (DLGPROC)ConfigDlgProc, (DWORD)lpInfo);
  184. break;
  185. }
  186. //
  187. // Close the devices we opened
  188. //
  189. CDA_terminate_audio ();
  190. //
  191. // Tell the control panel whether to cancel or continue
  192. //
  193. return iResult;
  194. }