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.

262 lines
6.9 KiB

  1. /* ADD.C
  2. **
  3. ** Copyright (C) Microsoft, 1990, All Rights Reserved.
  4. **
  5. ** Multimedia Control Panel Applet for removing
  6. ** device drivers. See the ispec doc DRIVERS.DOC for more information.
  7. **
  8. ** This file deals with the case where an OEM driver being installed.
  9. **
  10. ** History:
  11. **
  12. ** Thu Nov 1 1991 -by- Sanjaya
  13. ** Created. Originally part of drivers.c
  14. */
  15. #include <windows.h>
  16. #include <mmsystem.h>
  17. #include <memory.h>
  18. #include <string.h>
  19. #include <cpl.h>
  20. #include "drivers.h"
  21. #include <cphelp.h>
  22. #include "sulib.h"
  23. extern PINF pinfOldDefault;
  24. extern BOOL bBadOemSetup;
  25. TCHAR *szFilter[] = {TEXT("Inf Files(*.inf)"), TEXT("*.inf"), TEXT("Drv Files(*.drv)"), TEXT("*.drv"), TEXT("")};
  26. BOOL GetDir (HWND);
  27. void BrowseDlg (HWND, int);
  28. /* AddDriversDlg
  29. *
  30. * Returns 2 if dialog needs to be redrawn
  31. * Returns 1 if the oem file has been succesfully located
  32. * Returns 0 if Cancel has been pressed
  33. */
  34. INT_PTR AddDriversDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  35. {
  36. switch (message)
  37. {
  38. case WM_INITDIALOG:
  39. SetDlgItemText(hDlg, ID_TEXT, (LPTSTR)szUnlisted);
  40. SetDlgItemText(hDlg, ID_EDIT, (LPTSTR)szDirOfSrc);
  41. return(TRUE);
  42. case WM_COMMAND:
  43. switch(LOWORD(wParam))
  44. {
  45. case IDOK:
  46. if (GetDir(hDlg))
  47. {
  48. DialogBox(myInstance, MAKEINTRESOURCE(DLG_UPDATE),
  49. GetParent(hDlg), AddUnlistedDlg);
  50. break;
  51. } else {
  52. EndDialog(hDlg, 2);
  53. }
  54. break;
  55. case IDCANCEL:
  56. EndDialog(hDlg, 0);
  57. return(TRUE);
  58. case IDS_BROWSE:
  59. lstrcpy(szDrv, szOemInf);
  60. BrowseDlg(hDlg, 1);
  61. break;
  62. case IDH_DLG_INSERT_DISK:
  63. goto DoHelp;
  64. }
  65. break;
  66. default:
  67. if (message == wHelpMessage) {
  68. DoHelp:
  69. WinHelp(hDlg, szDriversHlp, HELP_CONTEXT, IDH_DLG_INSERT_DISK);
  70. return TRUE;
  71. } else
  72. return FALSE;
  73. }
  74. return (FALSE); /* Didn't process a message */
  75. }
  76. BOOL GetDir(HWND hDlg)
  77. {
  78. LPTSTR pstr;
  79. OFSTRUCT of;
  80. wsStartWait();
  81. /*
  82. * Test the edit box for a proper path
  83. * and look for the oemsetup.inf
  84. * file. If we don't find it , highlight the
  85. * text in the edit box and bring up a dialog box
  86. */
  87. GetDlgItemText( hDlg, ID_EDIT, szDirOfSrc, MAX_PATH);
  88. RemoveSpaces(szFullPath, szDirOfSrc);
  89. lstrcpy(szDirOfSrc, szFullPath);
  90. for (pstr = szFullPath;*pstr;pstr++);
  91. if (*(pstr-1) != TEXT('\\'))
  92. *pstr++ = TEXT('\\');
  93. *pstr = TEXT('\0');
  94. lstrcpy(szDiskPath, szFullPath);
  95. /*
  96. * Look for an oemsetup.inf
  97. * If you can't find it return false
  98. *
  99. */
  100. lstrcpy(pstr, szOemInf);
  101. if ((HFILE)HandleToUlong(CreateFile(szFullPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == -1)
  102. {
  103. SendDlgItemMessage(hDlg, ID_EDIT, EM_SETSEL, 0, -1L);
  104. wsEndWait();
  105. return (FALSE);
  106. }
  107. /*
  108. * Change the default inf to this new oemsetup.inf
  109. * Discard the value of the previous .inf, since it might
  110. * just be another set of oem drivers.
  111. */
  112. if (bBadOemSetup)
  113. infSetDefault(infOpen(szFullPath));
  114. else
  115. pinfOldDefault = infSetDefault(infOpen(szFullPath));
  116. EndDialog(hDlg, 1);
  117. wsEndWait();
  118. return(TRUE);
  119. }
  120. /*
  121. * Hooks into common dialog to show only directories
  122. */
  123. UINT_PTR CALLBACK AddFileHookProc(HWND hDlg, UINT iMessage,
  124. WPARAM wParam, LPARAM lParam)
  125. {
  126. TCHAR szTemp[200];
  127. HWND hTemp;
  128. switch (iMessage)
  129. {
  130. case WM_INITDIALOG:
  131. GetDlgItemText(((LPOPENFILENAME)lParam)->hwndOwner, ID_TEXT,
  132. szTemp, sizeof(szTemp)/sizeof(TCHAR));
  133. SetDlgItemText(hDlg, ctlLast+1, szTemp);
  134. goto PostMyMessage;
  135. case WM_COMMAND:
  136. switch (LOWORD(wParam))
  137. {
  138. case lst2:
  139. case cmb2:
  140. case IDOK:
  141. PostMyMessage:
  142. PostMessage(hDlg, WM_COMMAND, ctlLast+2, 0L);
  143. break;
  144. case IDH_DLG_BROWSE:
  145. goto DoHelp;
  146. case ctlLast+2:
  147. if (bFindOEM)
  148. {
  149. if (SendMessage(hTemp=GetDlgItem(hDlg, lst1), LB_GETCOUNT,
  150. 0, 0L))
  151. {
  152. SendMessage(hTemp, LB_SETCURSEL, 0, 0L);
  153. SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(lst1, LBN_SELCHANGE),
  154. (LONG_PTR)hTemp);
  155. break;
  156. }
  157. }
  158. SetDlgItemText(hDlg, edt1, szDrv);
  159. break;
  160. }
  161. break;
  162. default:
  163. if (iMessage == wHelpMessage)
  164. {
  165. DoHelp:
  166. WinHelp(hDlg, szDriversHlp, HELP_CONTEXT, IDH_DLG_BROWSE);
  167. return(TRUE);
  168. }
  169. }
  170. return FALSE; // commdlg, do your thing
  171. }
  172. /*
  173. * Function : BrowseDlg
  174. *
  175. * Call the GetOpenFileName dialog to open a file
  176. *
  177. * Parameters :
  178. *
  179. * hDlg : Parent Dialog box
  180. *
  181. * iIndex : Index into szFilter to determine which filter(s) to use
  182. */
  183. void BrowseDlg(HWND hDlg, int iIndex)
  184. {
  185. OPENFILENAME OpenFileName;
  186. TCHAR szPath[MAX_PATH];
  187. TCHAR szFile[MAX_PATH];
  188. *szPath = TEXT('\0');
  189. *szFile = TEXT('\0');
  190. OpenFileName.lStructSize = sizeof(OPENFILENAME);
  191. OpenFileName.hwndOwner = hDlg;
  192. OpenFileName.hInstance = myInstance;
  193. OpenFileName.lpstrFilter = szFilter[0];
  194. OpenFileName.lpstrCustomFilter = NULL;
  195. OpenFileName.nMaxCustFilter = 0;
  196. OpenFileName.nFilterIndex = iIndex;
  197. OpenFileName.lpstrFile = (LPTSTR)szPath;
  198. OpenFileName.nMaxFile = sizeof(szPath) / sizeof(TCHAR);
  199. OpenFileName.lpstrFileTitle = szFile;
  200. OpenFileName.nMaxFileTitle = sizeof(szFile) / sizeof(TCHAR);
  201. OpenFileName.lpstrInitialDir = NULL;
  202. OpenFileName.lpstrTitle = NULL;
  203. OpenFileName.Flags = OFN_HIDEREADONLY | OFN_ENABLEHOOK |
  204. /* OFN_FILEMUSTEXIST | */ OFN_ENABLETEMPLATE | OFN_NOCHANGEDIR |
  205. OFN_SHOWHELP;
  206. OpenFileName.lCustData = (LONG_PTR)hDlg;
  207. OpenFileName.lpfnHook = AddFileHookProc;
  208. OpenFileName.lpTemplateName = (LPTSTR)MAKEINTRESOURCE(DLG_BROWSE);
  209. OpenFileName.nFileOffset = 0;
  210. OpenFileName.nFileExtension = 0;
  211. OpenFileName.lpstrDefExt = NULL;
  212. if (GetOpenFileName(&OpenFileName))
  213. {
  214. UpdateWindow(hDlg); // force buttons to repaint
  215. szPath[OpenFileName.nFileOffset] = TEXT('\0');
  216. SetDlgItemText(hDlg, ID_EDIT, szPath);
  217. }
  218. }