Leaked source code of windows server 2003
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.

504 lines
15 KiB

  1. VERSION 5.00
  2. Begin VB.Form frmMain
  3. BorderStyle = 1 'Fixed Single
  4. Caption = "RKConversion"
  5. ClientHeight = 2055
  6. ClientLeft = 45
  7. ClientTop = 330
  8. ClientWidth = 4710
  9. LinkTopic = "Form1"
  10. MaxButton = 0 'False
  11. MinButton = 0 'False
  12. ScaleHeight = 2055
  13. ScaleWidth = 4710
  14. StartUpPosition = 3 'Windows Default
  15. Begin VB.TextBox txtCABOutDesk
  16. Height = 285
  17. Left = 1560
  18. TabIndex = 5
  19. Top = 840
  20. Width = 3015
  21. End
  22. Begin VB.TextBox txtCABOutSrv
  23. Height = 285
  24. Left = 1560
  25. TabIndex = 3
  26. Top = 480
  27. Width = 3015
  28. End
  29. Begin VB.TextBox txtCABIn
  30. Height = 285
  31. Left = 1560
  32. TabIndex = 1
  33. Top = 120
  34. Width = 3015
  35. End
  36. Begin VB.TextBox txtXML
  37. Height = 285
  38. Left = 1560
  39. TabIndex = 7
  40. Top = 1200
  41. Width = 3015
  42. End
  43. Begin VB.CommandButton cmdOK
  44. Caption = "OK"
  45. Height = 375
  46. Left = 3720
  47. TabIndex = 8
  48. Top = 1560
  49. Width = 855
  50. End
  51. Begin VB.Label lblCAB
  52. Caption = "CAB Out (&Desktop):"
  53. Height = 255
  54. Index = 2
  55. Left = 120
  56. TabIndex = 4
  57. Top = 840
  58. Width = 1455
  59. End
  60. Begin VB.Label lblCAB
  61. Caption = "CAB Out (&Server):"
  62. Height = 255
  63. Index = 1
  64. Left = 120
  65. TabIndex = 2
  66. Top = 480
  67. Width = 1335
  68. End
  69. Begin VB.Label lblCAB
  70. Caption = "CAB &In:"
  71. Height = 255
  72. Index = 0
  73. Left = 120
  74. TabIndex = 0
  75. Top = 120
  76. Width = 1335
  77. End
  78. Begin VB.Label lblXML
  79. Caption = "&XML:"
  80. Height = 255
  81. Left = 120
  82. TabIndex = 6
  83. Top = 1200
  84. Width = 495
  85. End
  86. End
  87. Attribute VB_Name = "frmMain"
  88. Attribute VB_GlobalNameSpace = False
  89. Attribute VB_Creatable = False
  90. Attribute VB_PredeclaredId = True
  91. Attribute VB_Exposed = False
  92. Option Explicit
  93. 'Example:
  94. '<RKCONVERSION>
  95. '
  96. ' <TAXONOMY_ENTRIES_DESKTOP>
  97. ' <TAXONOMY_ENTRY
  98. ' TITLE = ""
  99. ' TYPE="0"
  100. ' ENTRY = "Windows_Resource_Kit"
  101. ' ACTION = "ADD"
  102. ' CATEGORY = ""
  103. ' />
  104. ' <TAXONOMY_ENTRY
  105. ' TITLE = "Professional"
  106. ' TYPE="0"
  107. ' ENTRY = "Professional"
  108. ' ACTION = "ADD"
  109. ' CATEGORY = "Windows_Resource_Kit"
  110. ' />
  111. ' <TAXONOMY_ENTRY
  112. ' TITLE = "Server"
  113. ' TYPE="0"
  114. ' ENTRY = "Server"
  115. ' ACTION = "ADD"
  116. ' CATEGORY = "Windows_Resource_Kit"
  117. ' />
  118. ' <TAXONOMY_ENTRY
  119. ' TITLE = "Tools"
  120. ' TYPE="0"
  121. ' ENTRY = "Tools"
  122. ' ACTION = "ADD"
  123. ' CATEGORY = "Windows_Resource_Kit"
  124. ' />
  125. ' </TAXONOMY_ENTRIES_DESKTOP>
  126. '
  127. ' <TAXONOMY_ENTRIES_SERVER>
  128. ' <TAXONOMY_ENTRY
  129. ' TITLE = ""
  130. ' CATEGORY = ""
  131. ' URI = "MS-ITS:%HELP_LOCATION%\reskit.chm::/HSS_rktopic.htm"
  132. ' ACTION = "DEL"
  133. ' />
  134. ' </TAXONOMY_ENTRIES_SERVER>
  135. '
  136. ' <PREFIX_STRINGS>
  137. ' <PREFIX_STRING
  138. ' FIND = "Windows_Whistler_Resource_Kit/Professional"
  139. ' REPLACE = "Windows_Resource_Kit/Professional"
  140. ' />
  141. ' <PREFIX_STRING
  142. ' FIND = "Windows_Whistler_Resource_Kit/Server"
  143. ' REPLACE = "Windows_Resource_Kit/Server"
  144. ' />
  145. ' <PREFIX_STRING
  146. ' FIND = "Tools"
  147. ' REPLACE = "Windows_Resource_Kit/Tools"
  148. ' />
  149. ' </PREFIX_STRINGS>
  150. '
  151. ' <PRODUCT ID="Windows_XP_PRO" DISPLAYNAME="Windows XP Professional"/>
  152. '
  153. '</RKCONVERSION>
  154. 'In the server CAB, SKU VALUE is set to SERVER.
  155. 'In the desktop CAB, SKU VALUE is set to DESKTOP.
  156. '
  157. 'Any Category starting with
  158. ' Tools...
  159. 'is replaced by
  160. ' Windows_Resource_Kit/Tools...
  161. 'All other entries are deleted from the Desktop HHT.
  162. '
  163. 'The TAXONOMY_ENTRY's are prepended as is to the TAXONOMY_ENTRY's of the input.
  164. Private Const OPT_CAB_IN_C As String = "i"
  165. Private Const OPT_CAB_OUT_SRV_C As String = "s"
  166. Private Const OPT_CAB_OUT_DESK_C As String = "d"
  167. Private Const OPT_XML_C As String = "x"
  168. Private Const PKG_DESC_FILE_C As String = "package_description.xml"
  169. ' (E)lements, (A)ttributes, and (V)alues in the (C)ab
  170. Private Const EC_SKU_C As String = "HELPCENTERPACKAGE/SKU"
  171. Private Const EC_PRODUCT_C As String = "HELPCENTERPACKAGE/PRODUCT"
  172. Private Const EC_HHT_C As String = "HELPCENTERPACKAGE/METADATA/HHT"
  173. Private Const EC_TAXONOMY_ENTRIES_C As String = "METADATA/TAXONOMY_ENTRIES"
  174. Private Const AC_VALUE_C As String = "VALUE"
  175. Private Const AC_FILE_C As String = "FILE"
  176. Private Const AC_CATEGORY_C As String = "CATEGORY"
  177. Private Const AC_keep_C As String = "RKConversionKeep"
  178. Private Const AC_ID_C As String = "ID"
  179. Private Const AC_DISPLAYNAME_C As String = "DISPLAYNAME"
  180. Private Const VC_SERVER_C As String = "SERVER"
  181. Private Const VC_DESKTOP_C As String = "DESKTOP"
  182. Private Const VC_keep_value_C As String = "1"
  183. ' (E)lements, and (A)ttributes in the (X)ml file
  184. Private Const EX_TAXONOMY_ENTRIES_DESKTOP_C As String = "RKCONVERSION/TAXONOMY_ENTRIES_DESKTOP"
  185. Private Const EX_TAXONOMY_ENTRIES_SERVER_C As String = "RKCONVERSION/TAXONOMY_ENTRIES_SERVER"
  186. Private Const EX_PREFIX_STRINGS_C As String = "RKCONVERSION/PREFIX_STRINGS"
  187. Private Const EX_PRODUCT_C As String = "RKCONVERSION/PRODUCT"
  188. Private Const AX_FIND_C As String = "FIND"
  189. Private Const AX_REPLACE_C As String = "REPLACE"
  190. Private Const AX_ID_C As String = "ID"
  191. Private Const AX_DISPLAYNAME_C As String = "DISPLAYNAME"
  192. Private FSO As Scripting.FileSystemObject
  193. Private WS As IWshShell
  194. Private Type FindReplace
  195. strFind As String
  196. strReplace As String
  197. End Type
  198. Private Sub Form_Load()
  199. Dim strCommand As String
  200. Set FSO = New Scripting.FileSystemObject
  201. Set WS = CreateObject("Wscript.Shell")
  202. strCommand = Trim$(Command$)
  203. txtCABIn = GetOption(strCommand, OPT_CAB_IN_C, True)
  204. txtCABOutSrv = GetOption(strCommand, OPT_CAB_OUT_SRV_C, True)
  205. txtCABOutDesk = GetOption(strCommand, OPT_CAB_OUT_DESK_C, True)
  206. txtXML = GetOption(strCommand, OPT_XML_C, True)
  207. If (Len(strCommand) <> 0) Then
  208. Me.Show Modal:=False
  209. cmdOK_Click
  210. End If
  211. End Sub
  212. Private Sub cmdOK_Click()
  213. Dim strFolderSrv As String
  214. Dim strFolderDesk As String
  215. If (txtCABIn = "" Or txtCABOutSrv = "" Or txtCABOutDesk = "" Or txtXML = "") Then
  216. MsgBox "Please specify all 4 arguments"
  217. Exit Sub
  218. End If
  219. Me.Enabled = False
  220. strFolderSrv = p_Cab2Folder(txtCABIn)
  221. strFolderDesk = p_Cab2Folder(txtCABIn)
  222. FixPerSe txtXML, strFolderSrv, strFolderDesk
  223. p_Folder2Cab strFolderSrv, txtCABOutSrv
  224. p_Folder2Cab strFolderDesk, txtCABOutDesk
  225. FSO.DeleteFolder strFolderSrv, Force:=True
  226. FSO.DeleteFolder strFolderDesk, Force:=True
  227. Unload Me
  228. End Sub
  229. Private Sub FixPerSe( _
  230. ByVal i_strXML As String, _
  231. ByVal i_strFolderSrv As String, _
  232. ByVal i_strFolderDesk As String _
  233. )
  234. Dim strHHT As String
  235. Dim strHHTDesktop As String
  236. Dim strHHTServer As String
  237. Dim DOMDoc As MSXML2.DOMDocument
  238. Dim DOMNode As MSXML2.IXMLDOMNode
  239. Dim arrFR() As FindReplace
  240. p_SetSKUAndGetHHT i_strFolderSrv, VC_SERVER_C, strHHT
  241. p_SetSKUAndGetHHT i_strFolderDesk, VC_DESKTOP_C, strHHT
  242. Set DOMDoc = New MSXML2.DOMDocument
  243. DOMDoc.Load i_strXML
  244. strHHTServer = i_strFolderSrv & "\" & strHHT
  245. strHHTDesktop = i_strFolderDesk & "\" & strHHT
  246. Set DOMNode = DOMDoc.selectSingleNode(EX_PREFIX_STRINGS_C)
  247. p_GetFindReplace DOMNode, arrFR
  248. p_Replace arrFR, strHHTDesktop
  249. Set DOMNode = DOMDoc.selectSingleNode(EX_TAXONOMY_ENTRIES_SERVER_C)
  250. p_PrependTaxonomyEntries DOMNode, strHHTServer
  251. Set DOMNode = DOMDoc.selectSingleNode(EX_TAXONOMY_ENTRIES_DESKTOP_C)
  252. p_PrependTaxonomyEntries DOMNode, strHHTDesktop
  253. p_SetProductIdAndDisplayName DOMDoc, i_strFolderDesk
  254. End Sub
  255. Private Sub p_PrependTaxonomyEntries( _
  256. ByVal i_DOMNode As MSXML2.IXMLDOMNode, _
  257. ByVal u_strHHT As String _
  258. )
  259. Dim DOMDoc As MSXML2.DOMDocument
  260. Dim DOMNodeList As MSXML2.IXMLDOMNodeList
  261. Dim DOMNodeTaxoEntries As MSXML2.IXMLDOMNode
  262. Dim DOMNode As MSXML2.IXMLDOMNode
  263. Dim DOMAttr As MSXML2.IXMLDOMAttribute
  264. Dim DOMElement As MSXML2.IXMLDOMElement
  265. Dim intIndex As Long
  266. Dim strQuery As String
  267. If (i_DOMNode Is Nothing) Then
  268. Exit Sub
  269. End If
  270. Set DOMDoc = New MSXML2.DOMDocument
  271. DOMDoc.Load u_strHHT
  272. Set DOMNodeTaxoEntries = DOMDoc.selectSingleNode(EC_TAXONOMY_ENTRIES_C)
  273. intIndex = i_DOMNode.childNodes.length - 1
  274. Do While intIndex >= 0
  275. Set DOMNode = i_DOMNode.childNodes.Item(intIndex)
  276. DOMNodeTaxoEntries.insertBefore DOMNode, DOMNodeTaxoEntries.childNodes.Item(0)
  277. intIndex = intIndex - 1
  278. Loop
  279. DOMDoc.save u_strHHT
  280. End Sub
  281. Private Sub p_Replace( _
  282. ByRef i_arrFR() As FindReplace, _
  283. ByVal u_strHHT As String _
  284. )
  285. Dim DOMDoc As MSXML2.DOMDocument
  286. Dim DOMNodeList As MSXML2.IXMLDOMNodeList
  287. Dim DOMNodeTaxoEntries As MSXML2.IXMLDOMNode
  288. Dim DOMNode As MSXML2.IXMLDOMNode
  289. Dim DOMAttr As MSXML2.IXMLDOMAttribute
  290. Dim DOMElement As MSXML2.IXMLDOMElement
  291. Dim intIndex As Long
  292. Dim strFind As String
  293. Dim strReplace As String
  294. Dim strQuery As String
  295. Set DOMDoc = New MSXML2.DOMDocument
  296. DOMDoc.Load u_strHHT
  297. DOMDoc.setProperty "SelectionLanguage", "XPath"
  298. For intIndex = LBound(i_arrFR) To UBound(i_arrFR)
  299. strFind = i_arrFR(intIndex).strFind
  300. strReplace = i_arrFR(intIndex).strReplace
  301. strQuery = "descendant::TAXONOMY_ENTRY[attribute::" & AC_CATEGORY_C & "[starts-with(" & _
  302. "translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')," & _
  303. """" & strFind & """ )]]"
  304. Set DOMNodeList = DOMDoc.selectNodes(strQuery)
  305. For Each DOMNode In DOMNodeList
  306. Set DOMAttr = DOMNode.Attributes.getNamedItem(AC_CATEGORY_C)
  307. DOMAttr.Value = Replace$(DOMAttr.Value, strFind, strReplace, , 1, vbTextCompare)
  308. Set DOMElement = DOMNode
  309. DOMElement.setAttribute AC_keep_C, VC_keep_value_C
  310. Next
  311. Next
  312. Set DOMNodeTaxoEntries = DOMDoc.selectSingleNode(EC_TAXONOMY_ENTRIES_C)
  313. For Each DOMNode In DOMNodeTaxoEntries.childNodes
  314. If (DOMNode.Attributes.getNamedItem(AC_keep_C) Is Nothing) Then
  315. DOMNodeTaxoEntries.removeChild DOMNode
  316. Else
  317. Set DOMElement = DOMNode
  318. DOMElement.removeAttribute AC_keep_C
  319. End If
  320. Next
  321. DOMDoc.save u_strHHT
  322. End Sub
  323. Private Sub p_GetFindReplace( _
  324. ByVal i_DOMNode As MSXML2.IXMLDOMNode, _
  325. ByRef o_arrFR() As FindReplace _
  326. )
  327. Dim DOMNode As MSXML2.IXMLDOMNode
  328. Dim DOMAttr As MSXML2.IXMLDOMAttribute
  329. Dim intIndex As Long
  330. For Each DOMNode In i_DOMNode.childNodes
  331. ReDim Preserve o_arrFR(intIndex)
  332. Set DOMAttr = DOMNode.Attributes.getNamedItem(AX_FIND_C)
  333. o_arrFR(intIndex).strFind = LCase$(DOMAttr.Value)
  334. Set DOMAttr = DOMNode.Attributes.getNamedItem(AX_REPLACE_C)
  335. o_arrFR(intIndex).strReplace = DOMAttr.Value
  336. intIndex = intIndex + 1
  337. Next
  338. End Sub
  339. Private Sub p_SetSKUAndGetHHT( _
  340. ByVal i_strFolder As String, _
  341. ByVal i_strValue As String, _
  342. ByRef o_strHHT As String _
  343. )
  344. Dim strFile As String
  345. Dim DOMDoc As MSXML2.DOMDocument
  346. Dim DOMNode As MSXML2.IXMLDOMNode
  347. Dim DOMAttr As MSXML2.IXMLDOMAttribute
  348. strFile = i_strFolder & "\" & PKG_DESC_FILE_C
  349. Set DOMDoc = New MSXML2.DOMDocument
  350. DOMDoc.Load strFile
  351. Set DOMNode = DOMDoc.selectSingleNode(EC_SKU_C)
  352. Set DOMAttr = DOMNode.Attributes.getNamedItem(AC_VALUE_C)
  353. DOMAttr.Value = i_strValue
  354. Set DOMNode = DOMDoc.selectSingleNode(EC_HHT_C)
  355. Set DOMAttr = DOMNode.Attributes.getNamedItem(AC_FILE_C)
  356. o_strHHT = DOMAttr.Value
  357. DOMDoc.save strFile
  358. End Sub
  359. Private Sub p_SetProductIdAndDisplayName( _
  360. ByVal i_DOMDoc As MSXML2.DOMDocument, _
  361. ByVal i_strFolder As String _
  362. )
  363. Dim DOMNode As MSXML2.IXMLDOMNode
  364. Dim DOMAttr As MSXML2.IXMLDOMAttribute
  365. Dim DOMDoc As MSXML2.DOMDocument
  366. Dim Element As MSXML2.IXMLDOMElement
  367. Dim strProductId As String
  368. Dim strDisplayName As String
  369. Dim strFile As String
  370. Set DOMNode = i_DOMDoc.selectSingleNode(EX_PRODUCT_C)
  371. If (DOMNode Is Nothing) Then
  372. Exit Sub
  373. End If
  374. Set DOMAttr = DOMNode.Attributes.getNamedItem(AX_ID_C)
  375. If (Not DOMAttr Is Nothing) Then
  376. strProductId = DOMAttr.Value
  377. End If
  378. Set DOMAttr = DOMNode.Attributes.getNamedItem(AX_DISPLAYNAME_C)
  379. If (Not DOMAttr Is Nothing) Then
  380. strDisplayName = DOMAttr.Value
  381. End If
  382. strFile = i_strFolder & "\" & PKG_DESC_FILE_C
  383. Set DOMDoc = New MSXML2.DOMDocument
  384. DOMDoc.Load strFile
  385. Set Element = DOMDoc.selectSingleNode(EC_PRODUCT_C)
  386. Element.setAttribute AC_ID_C, strProductId
  387. Set Element = DOMDoc.selectSingleNode(EC_SKU_C)
  388. Element.setAttribute AC_DISPLAYNAME_C, strDisplayName
  389. DOMDoc.save strFile
  390. End Sub
  391. Private Function p_Cab2Folder( _
  392. ByVal i_strCabFile As String _
  393. ) As String
  394. Dim strFolder As String
  395. Dim strCmd As String
  396. p_Cab2Folder = ""
  397. ' We grab a Temporary Filename and create a folder out of it
  398. strFolder = FSO.GetSpecialFolder(TemporaryFolder) + "\" + FSO.GetTempName
  399. FSO.CreateFolder strFolder
  400. ' We uncab CAB contents into the Source CAB Contents dir.
  401. strCmd = "cabarc X " + i_strCabFile + " " + strFolder + "\"
  402. WS.Run strCmd, True, True
  403. p_Cab2Folder = strFolder
  404. End Function
  405. Private Sub p_Folder2Cab( _
  406. ByVal i_strFolder As String, _
  407. ByVal i_strCabFile As String _
  408. )
  409. Dim strCmd As String
  410. If (FSO.FileExists(i_strCabFile)) Then
  411. FSO.DeleteFile i_strCabFile, True
  412. End If
  413. strCmd = "cabarc -r -s 6144 n """ & i_strCabFile & """ " & i_strFolder & "\*"
  414. WS.Run strCmd, True, True
  415. End Sub