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.

353 lines
11 KiB

  1. '////////////////////////////////////////////////////////////////////////////
  2. '
  3. ' Copyright (c) 1999-2000 Microsoft Corp. All Rights Reserved.
  4. '
  5. ' File name:
  6. '
  7. ' lib.vbs
  8. '
  9. ' Abstract:
  10. '
  11. ' Windows Embedded Prototype Script for Printers
  12. '
  13. ' Remarks:
  14. '
  15. ' This file encapsulates dependency mapping functionality. When a target
  16. ' designer user adds a printer driver component, this script examines the
  17. ' resource in the printer driver component and maps it to another component.
  18. ' For example, if a driver uses pscript5.dll, it must be a postscript
  19. ' printer, and it shall have the dependency for core postscript driver
  20. ' component.
  21. '
  22. ' In order to do this, we have the mapIt function. mapIt needs an array of
  23. ' booleans that indicate whether a component is mapped or not. It works this
  24. ' way, first the client should go through all the resources and populate the
  25. ' componentFlagArray and then it should add the dependencies according to
  26. ' this array. To do it this way we remove the duplicate dependencies and we
  27. ' decouple the logic of selecting mapped dependent components and the logic
  28. ' of adding dependencies.
  29. '
  30. ' Right now we have only three components, aka Core PostScript, Core Unidrv,
  31. ' and Core Plotter. Eventually we going to expand it so that every section
  32. ' in ntprint.inf, such as section [CNBJ], should be a separate component and
  33. ' should be mapped in this script.
  34. '
  35. ' Author:
  36. '
  37. ' Larry Zhu (lzhu) 11-29-2000
  38. '
  39. '////////////////////////////////////////////////////////////////////////////
  40. Option Explicit
  41. ' define a component type
  42. Class ComponentType
  43. Public nComponentID ' This is a zero based index and id
  44. Public strComponentVIGUID ' VI GUID of this component
  45. Public enumClass
  46. Public enumType
  47. Public enumMinRevision
  48. End Class
  49. ' define a tuple that maps a file to a component
  50. Class PrinterFilesMappingTuple
  51. Public strFileName
  52. Public nComponentID
  53. End Class
  54. '//////////////////////////////////////////////////////////////////////////////////
  55. '
  56. ' define the tables to store the mapping relations
  57. '
  58. '/////////////////////////////////////////////////////////////////////////////////
  59. ' define the table of components
  60. Public g_componentTuples()
  61. ReDim g_componentTuples(10) ' No need to increase this number
  62. Public g_nComponents: g_nComponents = 0 ' Num of components
  63. ' define the table of mappings
  64. Public g_printerFilesMappingTuples()
  65. ReDim g_printerFilesMappingTuples(20) ' No need to increase this number
  66. Public g_nTableEntries: g_nTableEntries = 0 ' Num of table entries
  67. ' whether the tables above are initialized
  68. Public g_bAreTablesInitialized: g_bAreTablesInitialized = False
  69. '////////////////////////////////////////////////////////////////////////////////////
  70. '
  71. ' Function name:
  72. '
  73. ' addTuple
  74. '
  75. ' Function description:
  76. '
  77. ' This subroutine adds one mapping tuple at a time and updates the mapping
  78. ' table in g_printerFilesMappingTuples
  79. '
  80. ' Arguments:
  81. '
  82. ' strFileName -- the file to be mapped
  83. ' nComponent -- the component ID
  84. '
  85. '//////////////////////////////////////////////////////////////////////////////////
  86. Sub addTuple(strFileName, nComponentID)
  87. '
  88. ' ReDim is expensive, to avoid excessive redim we double the array size when
  89. ' the table is not large enough
  90. '
  91. If (UBound(g_printerFilesMappingTuples) < g_nTableEntries) Then
  92. ReDim Preserve g_printerFilesMappingTuples(2*UBound(g_printerFilesMappingTuples))
  93. End If
  94. Set g_printerFilesMappingTuples(g_nTableEntries) = New PrinterFilesMappingTuple
  95. g_printerFilesMappingTuples(g_nTableEntries).strFileName = strFileName
  96. g_printerFilesMappingTuples(g_nTableEntries).nComponentID = nComponentID
  97. g_nTableEntries = g_nTableEntries + 1
  98. End Sub
  99. '////////////////////////////////////////////////////////////////////////////////////
  100. '
  101. ' Function name:
  102. '
  103. ' addComponent
  104. '
  105. ' Function description:
  106. '
  107. ' This sub adds one component at a time to the component table
  108. ' g_componentTuples and it increments the number of component
  109. ' g_nComponents.
  110. '
  111. ' Arguments:
  112. '
  113. ' enumClass -- the component class
  114. ' enumType -- the component type
  115. ' strComponentVIGUID -- the VI GUID for the component
  116. ' enumMinRevision -- the minimum revision for the component
  117. '
  118. ' Return value:
  119. '
  120. ' The component ID for the component just added
  121. '
  122. '//////////////////////////////////////////////////////////////////////////////////
  123. Function addComponent(enumClass, enumType, strComponentVIGUID, enumMinRevision)
  124. Dim oneComponent: Set oneComponent = New ComponentType
  125. oneComponent.nComponentID = g_nComponents
  126. oneComponent.enumClass = enumClass
  127. oneComponent.enumType = enumType
  128. oneComponent.strComponentVIGUID = strComponentVIGUID
  129. oneComponent.enumMinRevision = enumMinRevision
  130. '
  131. ' add one more element into component table
  132. '
  133. '
  134. ' ReDim is expensive, to avoid excessive redim we double the array size
  135. ' when the table is not large enough
  136. '
  137. If (UBound(g_componentTuples) < g_nComponents) Then
  138. ReDim Preserve g_componentTuples(2*UBound(g_componentTuples))
  139. End If
  140. Set g_componentTuples(g_nComponents) = oneComponent
  141. g_nComponents = g_nComponents + 1
  142. addComponent = oneComponent.nComponentID
  143. End Function
  144. '////////////////////////////////////////////////////////////////////////////////////
  145. '
  146. ' Function name:
  147. '
  148. ' InitializeTables
  149. '
  150. ' Function description:
  151. '
  152. ' This function initializes the tables of mapping tuples and the table of
  153. ' components which are stored in g_printerFilesMappingTuples and
  154. ' g_componentTuples respectively. It is safe to call this sub more than
  155. ' once.
  156. '
  157. ' Arguments:
  158. '
  159. ' None
  160. '
  161. '//////////////////////////////////////////////////////////////////////////////////
  162. Sub InitializeTables()
  163. ' make sure this routine is executed only once
  164. If g_bAreTablesInitialized Then Exit Sub
  165. g_bAreTablesInitialized = True
  166. Dim strComponentVIGUID, enumMinRevision
  167. '////////////////////////////////////////////////////////////////////////////
  168. '
  169. ' Printer Components
  170. '
  171. ' Remark: This part needs to be manually updated
  172. '
  173. '////////////////////////////////////////////////////////////////////////////
  174. ' Core PostScript Component
  175. Dim corePS_ID
  176. strComponentVIGUID = "{C32DA828-9D90-4311-8FC5-AEFC65FAE2D3}"
  177. enumMinRevision = 1
  178. corePS_ID = addComponent(cmiInclude, cmiExactlyOne, strComponentVIGUID, enumMinRevision)
  179. ' Core Unidrv Component
  180. Dim coreUnidrv_ID
  181. strComponentVIGUID = "{7EC3F69D-1DA9-4C8C-8F76-FA28E5531454}"
  182. enumMinRevision = 1
  183. coreUnidrv_ID = addComponent(cmiInclude, cmiExactlyOne, strComponentVIGUID, enumMinRevision)
  184. ' Core Plotter Component
  185. Dim corePlotter_ID
  186. strComponentVIGUID = "{7EC3F69D-1DA9-4C8C-8F76-FA28E5531454}"
  187. enumMinRevision = 1
  188. corePlotter_ID = addComponent(cmiInclude, cmiExactlyOne, strComponentVIGUID, enumMinRevision)
  189. '////////////////////////////////////////////////////////////////////////////
  190. '
  191. ' Add the mapping table
  192. '
  193. '////////////////////////////////////////////////////////////////////////////
  194. ' mapping for PostScript
  195. addTuple "pscript5.dll", corePS_ID
  196. addTuple "ps5ui.dll", corePS_ID
  197. ' mapping for UniDrv
  198. addTuple "unidrvui.dll", coreUnidrv_ID
  199. addTuple "unidrv.dll", coreUnidrv_ID
  200. ' mapping for plotter
  201. addTuple "plotter.dll", corePlotter_ID
  202. addTuple "plotui.dll", corePlotter_ID
  203. End Sub
  204. '////////////////////////////////////////////////////////////////////////////////////
  205. '
  206. ' Function name:
  207. '
  208. ' isValid
  209. '
  210. ' Function description:
  211. '
  212. ' This function checks whether the componentFlagArray has exactly one elment for each
  213. ' compenent.
  214. '
  215. ' Arguments:
  216. '
  217. ' componentFlagArray -- an array of flags that indicate which component
  218. ' is mapped
  219. '
  220. ' Return value
  221. '
  222. ' True if componentFlagArray has exactly one element for each component
  223. '
  224. '///////////////////////////////////////////////////////////////////////////////////
  225. Function isValid(componentFlagArray)
  226. If (Not UBound(componentFlagArray) = (g_nComponents - 1)) Or (Not g_bAreTablesInitialized) Then
  227. isValid = False
  228. Exit Function
  229. End If
  230. isValid = True
  231. End Function
  232. '////////////////////////////////////////////////////////////////////////////////////
  233. '
  234. ' Function name:
  235. '
  236. ' mapIt
  237. '
  238. ' Function description:
  239. '
  240. ' This function fills the componentFlagArry, which must be an array of
  241. ' booleans in componentFlagArry with number of elements equal to the number of components
  242. ' in componentTuples
  243. '
  244. ' Example usage:
  245. '
  246. ' Dim componentFlagArray()
  247. ' Dim componentFlagArray(g_nComponentIndex)
  248. '
  249. ' ' initialize this array to have all vlaues False if you prefer to
  250. '
  251. ' If Not isValid(componentFlagArray) Then
  252. ' < your function name > = False
  253. ' Exit Function
  254. ' End If
  255. '
  256. ' call mapIt(strFileName, componentFlagArray)
  257. '
  258. ' Arguments:
  259. '
  260. ' strFileName -- the name of dependent file
  261. ' componentFlagArray -- an array of flags that indicate which component
  262. ' is mapped
  263. '
  264. ' Return value
  265. '
  266. ' True if strFileName is mapped to a component, False otherwise
  267. '
  268. '///////////////////////////////////////////////////////////////////////////////////
  269. Function mapIt(strFileName, componentFlagArray())
  270. mapIt = False
  271. Dim i
  272. For i = 0 To (g_nTableEntries - 1)
  273. If 0 = StrComp(strFileName, g_printerFilesMappingTuples(i).strFileName, 1) Then
  274. componentFlagArray(g_printerFilesMappingTuples(i).nComponentID) = True
  275. mapIt = True
  276. Exit Function
  277. End If
  278. Next
  279. End Function
  280. '////////////////////////////////////////////////////////////////////////////////////
  281. '
  282. ' Function name:
  283. '
  284. ' initComponentFlagArray
  285. '
  286. ' Function description:
  287. '
  288. ' This function initializes componentFlagArray
  289. '
  290. ' Arguments:
  291. '
  292. ' componentFlagArray -- an array of flags that indicate which component
  293. ' is mapped
  294. '
  295. '///////////////////////////////////////////////////////////////////////////////////
  296. Sub initComponentFlagArray(componentFlagArray)
  297. Dim i
  298. For i = 0 To UBound(componentFlagArray)
  299. componentFlagArray(i) = False
  300. Next
  301. End Sub
  302. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''