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.

363 lines
9.7 KiB

  1. /*----------------------------------------------------------------------------
  2. | mmdriver.c - Install Multimedia Drivers
  3. |
  4. | Copyright (C) Microsoft, 1989, 1990. All Rights Reserved
  5. |
  6. | History:
  7. | 09/11/90 davidle created
  8. | Install Multimedia Drivers
  9. |
  10. | Tue Jan 29 1991 -by- MichaelE
  11. | Redesigned installing installable drivers so additional drivers
  12. | can be installed by adding them to setup.inf's [installable.drivers]
  13. |
  14. | Wed Mar 20 1991 -by- MichaelE
  15. | Changed mmAddInstallableDriver to accept multiple VxDs.
  16. | Changed and WriteNextPrivateProfileString to check if the profile
  17. | being concatenated is already there.
  18. |
  19. | Sun Apr 14 1991 -by- MichaelE
  20. | WriteNextPrivateProfileString -> Next386EnhDevice.
  21. |
  22. | Sun Apr 14 1991 -by- JohnYG
  23. | Taken from setup for drivers applet.
  24. |
  25. | Wed Jun 05 1991 -by- MichaelE
  26. | Added FileCopy of associated file list to windows system dir.
  27. |
  28. *----------------------------------------------------------------------------*/
  29. #include <windows.h>
  30. #include <mmsystem.h>
  31. #include <winsvc.h>
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include "drivers.h"
  35. #include "sulib.h"
  36. /*
  37. * Local functions
  38. */
  39. static BOOL mmAddInstallableDriver (PINF, LPSTR, LPSTR, PIDRIVER );
  40. static void GetDrivers (PINF, PSTR, PSTR);
  41. /**************************************************************************
  42. *
  43. * AccessServiceController()
  44. *
  45. * Check we will be able to access the service controller to install
  46. * a driver
  47. *
  48. * returns FALSE if we can't get access - otherwise TRUE
  49. *
  50. **************************************************************************/
  51. BOOL AccessServiceController(void)
  52. {
  53. SC_HANDLE SCManagerHandle;
  54. SCManagerHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
  55. if (SCManagerHandle == NULL) {
  56. return FALSE;
  57. }
  58. CloseServiceHandle(SCManagerHandle);
  59. return TRUE;
  60. }
  61. /**************************************************************************
  62. *
  63. * mmAddNewDriver() - only exported function in this file.
  64. *
  65. * This function installs (copies) a driver
  66. *
  67. * returns FALSE if no drivers could be installed.
  68. * TRUE if at least one driver installation was sucessful.
  69. * All added types in lpszNewTypes buffer.
  70. *
  71. **************************************************************************/
  72. BOOL mmAddNewDriver( LPSTR lpstrDriver, LPSTR lpstrNewTypes, PIDRIVER pIDriver )
  73. {
  74. PINF pinf;
  75. if ((pinf = FindInstallableDriversSection(NULL)) == NULL)
  76. return FALSE;
  77. return mmAddInstallableDriver(pinf, lpstrDriver, lpstrNewTypes, pIDriver);
  78. }
  79. /**************************************************************************
  80. * mmAddInstallableDriver() - Do the dirty work looking for VxD's copying them
  81. * looking for drivers, copying them, and returning the best type names.
  82. *
  83. *
  84. **************************************************************************/
  85. BOOL mmAddInstallableDriver( PINF pInfIDrivers,
  86. LPSTR pstrDriver,
  87. LPSTR lpstrNewTypes,
  88. PIDRIVER pIDriver)
  89. {
  90. PSTR pstr, pstrSection;
  91. static char szTemp[10];
  92. PINF pInfSection= pInfIDrivers;
  93. int i;
  94. char szBuffer[MAX_INF_LINE_LEN],
  95. szFilename[MAXSTR],
  96. szType[MAX_SECT_NAME_LEN];
  97. /*
  98. * format of a line in [installable.drivers] of setup.inf:
  99. * driver profile = [0]
  100. * filename, [1]
  101. * "type(s)", [2]
  102. * "description", [3]
  103. * "VxD and .sys filename(s)",[4]
  104. * "default config params" [5]
  105. * "Related drivers" [6]
  106. *
  107. * find the driver profile line in szMDrivers we are installing
  108. */
  109. while ( TRUE )
  110. {
  111. infParseField( pInfIDrivers, 0, szBuffer );
  112. if ( lstrcmpi( szBuffer, pstrDriver ) == 0 )
  113. break;
  114. else if ( ! (pInfIDrivers = infNextLine( pInfIDrivers )) )
  115. return FALSE;
  116. }
  117. /*
  118. * copy the driver file and add driver type(s) to the installable
  119. * driver section
  120. */
  121. if ( !infParseField( pInfIDrivers, 1, szFilename ))
  122. return FALSE;
  123. /*
  124. * Ignore the disk number
  125. */
  126. strcpy(szDrv, RemoveDiskId(szFilename));
  127. /*
  128. * Cache whether it's a kernel driver
  129. */
  130. pIDriver->KernelDriver = IsFileKernelDriver(szFilename);
  131. /*
  132. * Can't install kernel drivers if don't have privilege
  133. */
  134. if (pIDriver->KernelDriver && !AccessServiceController()) {
  135. char szMesg[MAXSTR];
  136. char szMesg2[MAXSTR];
  137. char szTitle[50];
  138. LoadString(myInstance, IDS_INSUFFICIENT_PRIVILEGE, szMesg, sizeof(szMesg));
  139. LoadString(myInstance, IDS_CONFIGURE_DRIVER, szTitle, sizeof(szTitle));
  140. wsprintf(szMesg2, szMesg, szDrv);
  141. MessageBox(hMesgBoxParent, szMesg2, szTitle, MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL);
  142. return FALSE;
  143. }
  144. /*
  145. * Do the file copying
  146. */
  147. if (FileCopy( szFilename,
  148. szSystem,
  149. (FPFNCOPY)wsCopySingleStatus,
  150. FC_FILE ) != NO_ERROR) {
  151. return FALSE;
  152. }
  153. /*
  154. * Add options
  155. */
  156. if (infParseField (pInfIDrivers,5,szBuffer+1))
  157. {
  158. szBuffer[0]=' ';
  159. lstrcat(szFilename,szBuffer);
  160. }
  161. /*
  162. * copy filename and options
  163. */
  164. strncpy(pIDriver->szFile, FileName(szFilename), sizeof(pIDriver->szFile));
  165. pIDriver->szFile[sizeof(pIDriver->szFile) - 1] = 0;
  166. /*
  167. * copy description
  168. */
  169. infParseField( pInfIDrivers, 3, pIDriver->szDesc );
  170. /*
  171. * determine the section from the description. A kernel driver
  172. * will appear as a driver of type 'KERNEL' in system.ini
  173. *
  174. * If the description contains [MCI] then it's MCI.
  175. */
  176. if (strstr(pIDriver->szDesc, TEXT("MCI")))
  177. pstrSection = szMCI;
  178. else
  179. pstrSection = szDrivers;
  180. /*
  181. * Copy name plus parameters to our driver data
  182. */
  183. strncpy(pIDriver->szSection, pstrSection, sizeof(pIDriver->szSection));
  184. pIDriver->szSection[sizeof(pIDriver->szSection) - 1] = 0;
  185. mbstowcs(pIDriver->wszSection, pIDriver->szSection, MAX_PATH);
  186. /*
  187. * We return all types in a parseable, contcatentated string
  188. */
  189. for ( i = 1, infParseField( pInfIDrivers, 2, szBuffer );
  190. infParseField( szBuffer, i, szType );
  191. i++ )
  192. {
  193. pstr = &(szType[lstrlen(szType)]);
  194. *pstr++ = ',';
  195. *pstr = 0;
  196. lstrcat(lpstrNewTypes, szType );
  197. }
  198. if (!*lpstrNewTypes)
  199. /*
  200. * We weren't able to return any types.
  201. */
  202. return FALSE;
  203. /*
  204. * copy an associated file list (if it exists) to windows system dir
  205. */
  206. if (FileCopy(pstrDriver,
  207. szSystem,
  208. (FPFNCOPY)wsCopySingleStatus,
  209. FC_SECTION) != ERROR_SUCCESS)
  210. return(FALSE);
  211. /*
  212. * if there are system driver files copy them to the system
  213. * drivers directory.
  214. *
  215. * NOTE that it is assumed here that any installation and
  216. * configuration for these drivers is performed by the main
  217. * (.drv) driver being installed.
  218. *
  219. */
  220. if (infParseField( pInfIDrivers, 4, szBuffer ) && szBuffer[0])
  221. {
  222. for ( i = 1; infParseField( szBuffer, i, szFilename ); i++ )
  223. {
  224. strcpy(szDrv, RemoveDiskId(szFilename));
  225. /*
  226. * FileCopy will adjust the 'system' directory to
  227. * system\drivers. It's done this way because FileCopy
  228. * must anyway look for old files in the same directory.
  229. */
  230. if (FileCopy(szFilename,
  231. szSystem,
  232. (FPFNCOPY)wsCopySingleStatus,
  233. FC_FILE )
  234. != ERROR_SUCCESS)
  235. {
  236. return FALSE;
  237. }
  238. }
  239. }
  240. #ifdef DOBOOT // Don't do boot section on NT
  241. infParseField(pInfIDrivers, 7, szTemp);
  242. if (!_strcmpi(szTemp, szBoot))
  243. bInstallBootLine = TRUE;
  244. #endif // DOBOOT
  245. /*
  246. * Read the related drivers list (drivers which must/can also be
  247. * be installed).
  248. */
  249. if (bRelated == FALSE)
  250. {
  251. infParseField(pInfIDrivers, 6, pIDriver->szRelated);
  252. if (strlen(pIDriver->szRelated))
  253. {
  254. GetDrivers(pInfSection, pIDriver->szRelated, pIDriver->szRemove);
  255. pIDriver->bRelated = TRUE;
  256. bRelated = TRUE;
  257. }
  258. }
  259. return TRUE;
  260. }
  261. /*
  262. * Used to get the list of the related driver filenames
  263. *
  264. * pInfIDrivers - Pointer to the [installable.drivers] section or equivalent
  265. * szAliasList - List of driver aliases (ie key values - eg msalib).
  266. * szDriverList - List of drivers file names found
  267. */
  268. void GetDrivers(PINF pInfIDrivers, PSTR szAliasList, PSTR szDriverList)
  269. {
  270. char szBuffer[50];
  271. char szAlias[50];
  272. char szFileName[50];
  273. PINF pInfILocal;
  274. BOOL bEnd;
  275. int i;
  276. for ( i = 1; infParseField(szAliasList, i, szAlias); i++ )
  277. {
  278. pInfILocal = pInfIDrivers;
  279. bEnd = FALSE;
  280. while (!bEnd)
  281. {
  282. infParseField( pInfILocal, 0, szBuffer);
  283. if (lstrcmpi( szBuffer, szAlias) == 0 )
  284. {
  285. if (infParseField(pInfILocal, 1, szFileName))
  286. {
  287. lstrcat(szDriverList, RemoveDiskId(szFileName));
  288. lstrcat(szDriverList, ",");
  289. }
  290. break;
  291. }
  292. else
  293. if ( ! (pInfILocal = infNextLine( pInfILocal )) )
  294. bEnd = TRUE;
  295. }
  296. }
  297. }