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.

473 lines
12 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1997
  3. All rights reserved.
  4. Module Name:
  5. driverif.hxx
  6. Abstract:
  7. Driver Info Class
  8. Author:
  9. Steve Kiraly (SteveKi) 23-Jan-1997
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "psetup.hxx"
  15. #include "drvsetup.hxx"
  16. #include "driverif.hxx"
  17. #include "compinfo.hxx"
  18. /********************************************************************
  19. Server Driver Information.
  20. ********************************************************************/
  21. TDriverInfo::
  22. TDriverInfo(
  23. IN EType eType,
  24. IN UINT uLevel,
  25. IN PVOID pInfo
  26. ) : _uLevel( uLevel ),
  27. _eType( eType ),
  28. _dwVersion ( 0 ),
  29. _pszDependentFiles( NULL )
  30. {
  31. DBGMSG( DBG_NONE, ( "TDriverInfo::ctor\n" ) );
  32. TStatusB bStatus;
  33. //
  34. // Copy the driver info level 2 information.
  35. //
  36. if( _uLevel >= 2 )
  37. {
  38. //
  39. // Convert pointer to a usable pointer.
  40. //
  41. PDRIVER_INFO_2 pInfo2 = reinterpret_cast<PDRIVER_INFO_2>( pInfo );
  42. _dwVersion = pInfo2->cVersion;
  43. bStatus DBGCHK = _strName.bUpdate( pInfo2->pName );
  44. bStatus DBGCHK = _strEnv.bUpdate( pInfo2->pEnvironment );
  45. bStatus DBGCHK = _strDriverPath.bUpdate( pInfo2->pDriverPath );
  46. bStatus DBGCHK = _strDataFile.bUpdate( pInfo2->pDataFile );
  47. bStatus DBGCHK = _strConfigFile.bUpdate( pInfo2->pConfigFile );
  48. //
  49. // Build the environment and verison string.
  50. //
  51. bStatus DBGCHK = bEnvironmentToString( _strEnv, _strEnvironment );
  52. bStatus DBGCHK = bVersionToString( _dwVersion, _strVersion );
  53. }
  54. if( _uLevel == 3 )
  55. {
  56. //
  57. // Convert pointer to a usable pointer.
  58. //
  59. PDRIVER_INFO_3 pInfo3 = reinterpret_cast<PDRIVER_INFO_3>( pInfo );
  60. //
  61. // Copy the info level 3 specific code.
  62. //
  63. bStatus DBGCHK = _strHelpFile.bUpdate( pInfo3->pHelpFile );
  64. bStatus DBGCHK = _strMonitorName.bUpdate( pInfo3->pMonitorName );
  65. bStatus DBGCHK = _strDefaultDataType.bUpdate( pInfo3->pDefaultDataType );
  66. //
  67. // Copy the dependent files.
  68. //
  69. bStatus DBGCHK = bCopyMultizString( &_pszDependentFiles, pInfo3->pDependentFiles );
  70. }
  71. }
  72. TDriverInfo::
  73. TDriverInfo(
  74. const TDriverInfo &rhs
  75. ) : _uLevel( 0 ),
  76. _eType( kError ),
  77. _dwVersion ( 0 ),
  78. _pszDependentFiles( NULL )
  79. {
  80. (VOID)bClone( rhs );
  81. }
  82. const TDriverInfo &
  83. TDriverInfo::
  84. operator=(
  85. const TDriverInfo &rhs
  86. )
  87. {
  88. (VOID)bClone( rhs );
  89. return *this;
  90. }
  91. TDriverInfo::
  92. ~TDriverInfo(
  93. VOID
  94. )
  95. {
  96. DBGMSG( DBG_NONE, ( "TDriverInfo::dtor\n" ) );
  97. //
  98. // If we are linked then remove ourself.
  99. //
  100. if( DriverInfo_bLinked() )
  101. {
  102. DriverInfo_vDelinkSelf();
  103. }
  104. delete [] _pszDependentFiles;
  105. }
  106. BOOL
  107. TDriverInfo::
  108. bValid(
  109. VOID
  110. ) const
  111. {
  112. BOOL bStatus;
  113. //
  114. // Check if the object is valid.
  115. //
  116. if( ( _uLevel == 2 || _uLevel == 3 )&&
  117. VALID_OBJ( _strVersion ) &&
  118. VALID_OBJ( _strName ) &&
  119. VALID_OBJ( _strEnvironment ) &&
  120. VALID_OBJ( _strDriverPath ) &&
  121. VALID_OBJ( _strDataFile ) &&
  122. VALID_OBJ( _strConfigFile ) &&
  123. VALID_OBJ( _strHelpFile ) &&
  124. VALID_OBJ( _strMonitorName ) &&
  125. VALID_OBJ( _strDefaultDataType )&&
  126. VALID_OBJ( _strInfName ) &&
  127. VALID_OBJ( _strEnv ) )
  128. {
  129. bStatus = TRUE;
  130. }
  131. else
  132. {
  133. bStatus = FALSE;
  134. }
  135. return bStatus;
  136. }
  137. VOID
  138. TDriverInfo::
  139. vPrint(
  140. VOID
  141. ) const
  142. {
  143. #if DBG
  144. DBGMSG( DBG_NONE, ( "DriverInfo %x\n", this ) );
  145. if( !bValid() )
  146. {
  147. DBGMSG( DBG_NONE, ( "DriverInfo object is invalid %x\n", this ) );
  148. }
  149. else
  150. {
  151. DBGMSG( DBG_TRACE, ( "uLevel %d\n", _uLevel ) );
  152. DBGMSG( DBG_TRACE, ( "eType %d\n", _eType ) );
  153. DBGMSG( DBG_TRACE, ( "dwVerison %d\n", _dwVersion ) );
  154. DBGMSG( DBG_TRACE, ( "_strEnv " TSTR "\n", (LPCTSTR)_strEnv ) );
  155. DBGMSG( DBG_TRACE, ( "strVersion " TSTR "\n", (LPCTSTR)_strVersion ) );
  156. DBGMSG( DBG_TRACE, ( "strName " TSTR "\n", (LPCTSTR)_strName ) );
  157. DBGMSG( DBG_TRACE, ( "strEnvironment " TSTR "\n", (LPCTSTR)_strEnvironment ) );
  158. DBGMSG( DBG_TRACE, ( "strDriverPath " TSTR "\n", (LPCTSTR)_strDriverPath ) );
  159. DBGMSG( DBG_TRACE, ( "strDataFile " TSTR "\n", (LPCTSTR)_strDataFile ) );
  160. DBGMSG( DBG_TRACE, ( "strConfigFile " TSTR "\n", (LPCTSTR)_strConfigFile ) );
  161. DBGMSG( DBG_TRACE, ( "strHelpFile " TSTR "\n", (LPCTSTR)_strHelpFile ) );
  162. DBGMSG( DBG_TRACE, ( "strMonitorName " TSTR "\n", (LPCTSTR)_strMonitorName ) );
  163. DBGMSG( DBG_TRACE, ( "strDefaultDataType " TSTR "\n", (LPCTSTR)_strDefaultDataType ) );
  164. DBGMSG( DBG_TRACE, ( "strInfName " TSTR "\n", (LPCTSTR)_strInfName ) );
  165. for( LPCTSTR psz = _pszDependentFiles; psz && *psz; psz += _tcslen( psz ) + 1 )
  166. {
  167. DBGMSG( DBG_TRACE, ( "_pszDependentFiles " TSTR "\n", psz ) );
  168. }
  169. }
  170. #endif
  171. }
  172. VOID
  173. TDriverInfo::
  174. vSetInfoState(
  175. EType eType
  176. )
  177. {
  178. _eType = eType;
  179. }
  180. TDriverInfo::EType
  181. TDriverInfo::
  182. vGetInfoState(
  183. VOID
  184. ) const
  185. {
  186. return _eType;
  187. }
  188. LPCTSTR
  189. TDriverInfo::
  190. strDependentFiles(
  191. VOID
  192. )
  193. {
  194. return _pszDependentFiles ? _pszDependentFiles : gszNULL;
  195. }
  196. INT
  197. TDriverInfo::
  198. operator==(
  199. const TDriverInfo &rhs
  200. ) const
  201. {
  202. DBGMSG( DBG_NONE, ( "TDriverInfo::operator ==\n" ) );
  203. return _strName == rhs._strName &&
  204. _strEnv == rhs._strEnv &&
  205. _dwVersion == rhs._dwVersion;
  206. }
  207. INT
  208. TDriverInfo::
  209. operator>(
  210. const TDriverInfo &rhs
  211. ) const
  212. {
  213. DBGMSG( DBG_TRACE, ( "TDriverInfo::operator >\n" ) );
  214. BOOL bRetval = 0;
  215. if( _eType > rhs._eType )
  216. {
  217. bRetval = 1;
  218. }
  219. else if( _eType == rhs._eType )
  220. {
  221. if( _dwVersion > rhs._dwVersion )
  222. {
  223. bRetval = 1;
  224. }
  225. else if( _dwVersion == rhs._dwVersion )
  226. {
  227. //
  228. // The environment string check is case sensitive.
  229. //
  230. INT iResult = _tcscmp( _strEnv, rhs._strEnv );
  231. if( iResult > 0 )
  232. {
  233. bRetval = 1;
  234. }
  235. else if( iResult == 0 )
  236. {
  237. iResult = _tcsicmp( _strName, rhs._strName );
  238. if( iResult > 0 )
  239. {
  240. bRetval = 1;
  241. }
  242. }
  243. }
  244. }
  245. return bRetval;
  246. }
  247. /********************************************************************
  248. Drivers Info - private member functions.
  249. ********************************************************************/
  250. BOOL
  251. TDriverInfo::
  252. bClone(
  253. const TDriverInfo &rhs
  254. )
  255. {
  256. DBGMSG( DBG_NONE, ( "TDriverInfo::bClone\n" ) );
  257. TStatusB bStatus;
  258. if( this == &rhs )
  259. {
  260. DBGMSG( DBG_WARN, ( "Clone of self\n" ) );
  261. bStatus DBGNOCHK = TRUE;
  262. }
  263. else
  264. {
  265. //
  266. // Initialize the simple types.
  267. //
  268. _uLevel = rhs._uLevel;
  269. _eType = rhs._eType;
  270. _dwVersion = rhs._dwVersion;
  271. //
  272. // If we are linked then remove ourself.
  273. //
  274. if( DriverInfo_bLinked() )
  275. {
  276. DriverInfo_vDelinkSelf();
  277. }
  278. //
  279. // Release any existing dependent file pointer.
  280. //
  281. if( _pszDependentFiles )
  282. {
  283. delete _pszDependentFiles;
  284. _pszDependentFiles = NULL;
  285. }
  286. //
  287. // Make a copy of the dependent file multiz string. A null dependent file
  288. // pointer only indicates there is not any dependent file information.
  289. //
  290. bStatus DBGCHK = bCopyMultizString( &_pszDependentFiles, rhs._pszDependentFiles );
  291. //
  292. // Copy the other information strings.
  293. //
  294. bStatus DBGCHK = _strName.bUpdate( rhs._strName );
  295. bStatus DBGCHK = _strVersion.bUpdate( rhs._strVersion );
  296. bStatus DBGCHK = _strEnvironment.bUpdate( rhs._strEnvironment );
  297. bStatus DBGCHK = _strDriverPath.bUpdate( rhs._strDriverPath );
  298. bStatus DBGCHK = _strDataFile.bUpdate( rhs._strDataFile );
  299. bStatus DBGCHK = _strConfigFile.bUpdate( rhs._strConfigFile );
  300. bStatus DBGCHK = _strHelpFile.bUpdate( rhs._strHelpFile );
  301. bStatus DBGCHK = _strMonitorName.bUpdate( rhs._strMonitorName );
  302. bStatus DBGCHK = _strDefaultDataType.bUpdate( rhs._strDefaultDataType );
  303. bStatus DBGCHK = _strEnv.bUpdate( rhs._strEnv );
  304. }
  305. return bValid();
  306. }
  307. BOOL
  308. TDriverInfo::
  309. bVersionToString(
  310. IN DWORD dwVersion,
  311. IN OUT TString &strVersion
  312. ) const
  313. {
  314. BOOL bStatus = FALSE;
  315. UINT uVersionResourceId;
  316. switch( dwVersion )
  317. {
  318. case kDriverVersion0:
  319. if( !_tcscmp( _strEnv, ENVIRONMENT_WINDOWS ) )
  320. uVersionResourceId = IDS_VERSION_WINDOWS_ME;
  321. else
  322. uVersionResourceId = IDS_VERSION_NT_31;
  323. break;
  324. case kDriverVersion1:
  325. if( !_tcscmp( _strEnv, ENVIRONMENT_POWERPC ) )
  326. uVersionResourceId = IDS_VERSION_351;
  327. else
  328. uVersionResourceId = IDS_VERSION_35X;
  329. break;
  330. case kDriverVersion2:
  331. if( !_tcscmp( _strEnv, ENVIRONMENT_POWERPC ) || !_tcscmp( _strEnv, ENVIRONMENT_MIPS ) || !_tcscmp( _strEnv, ENVIRONMENT_ALPHA ) )
  332. uVersionResourceId = IDS_VERSION_40;
  333. else
  334. uVersionResourceId = IDS_VERSION_40_50;
  335. break;
  336. case kDriverVersion3:
  337. if( !_tcscmp( _strEnv, ENVIRONMENT_IA64 ) )
  338. uVersionResourceId = IDS_VERSION_51;
  339. else
  340. uVersionResourceId = IDS_VERSION_50_51;
  341. break;
  342. default:
  343. uVersionResourceId = IDS_ARCH_UNKNOWN;
  344. break;
  345. }
  346. bStatus = strVersion.bLoadString( ghInst, uVersionResourceId );
  347. return bStatus;
  348. }
  349. BOOL
  350. TDriverInfo::
  351. bEnvironmentToString(
  352. IN LPCTSTR pszEnv,
  353. IN OUT TString &strVersion
  354. ) const
  355. {
  356. TStatusB bStatus;
  357. if( !_tcscmp( ENVIRONMENT_INTEL, pszEnv ) )
  358. bStatus DBGCHK = strVersion.bLoadString( ghInst, IDS_ARCH_INTEL );
  359. else if( !_tcscmp( ENVIRONMENT_MIPS, pszEnv ) )
  360. bStatus DBGCHK = strVersion.bLoadString( ghInst, IDS_ARCH_MIPS );
  361. else if( !_tcscmp( ENVIRONMENT_ALPHA, pszEnv ) )
  362. bStatus DBGCHK = strVersion.bLoadString( ghInst, IDS_ARCH_ALPHA );
  363. else if( !_tcscmp( ENVIRONMENT_POWERPC, pszEnv ) )
  364. bStatus DBGCHK = strVersion.bLoadString( ghInst, IDS_ARCH_POWERPC );
  365. else if( !_tcscmp( ENVIRONMENT_WINDOWS, pszEnv ) )
  366. bStatus DBGCHK = strVersion.bLoadString( ghInst, IDS_ARCH_INTEL );
  367. else if( !_tcscmp( ENVIRONMENT_IA64, pszEnv ) )
  368. bStatus DBGCHK = strVersion.bLoadString( ghInst, IDS_ARCH_IA64 );
  369. else
  370. bStatus DBGCHK = strVersion.bLoadString( ghInst, IDS_ARCH_UNKNOWN );
  371. return bStatus;
  372. }
  373. /********************************************************************
  374. DriverTransfer class.
  375. ********************************************************************/
  376. TDriverTransfer::
  377. TDriverTransfer(
  378. VOID
  379. ) : _cDriverInfo( 0 )
  380. {
  381. DBGMSG( DBG_NONE, ( "TDriverTransfer::ctor\n" ) );
  382. DriverInfoList_vReset();
  383. }
  384. TDriverTransfer::
  385. ~TDriverTransfer(
  386. VOID
  387. )
  388. {
  389. DBGMSG( DBG_NONE, ( "TDriverTransfer::dtor\n" ) );
  390. //
  391. // Release everything from the driver info list.
  392. //
  393. TIter Iter;
  394. TDriverInfo *pDriverInfo;
  395. DriverInfoList_vIterInit( Iter );
  396. for( Iter.vNext(); Iter.bValid(); )
  397. {
  398. pDriverInfo = DriverInfoList_pConvert( Iter );
  399. Iter.vNext();
  400. delete pDriverInfo;
  401. }
  402. }