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.

216 lines
7.5 KiB

  1. VERSION 1.0 CLASS
  2. BEGIN
  3. MultiUse = -1 'True
  4. Persistable = 0 'NotPersistable
  5. DataBindingBehavior = 0 'vbNone
  6. DataSourceBehavior = 0 'vbNone
  7. MTSTransactionMode = 0 'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "HssExts"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. Private m_oDom As DOMDocument ' We create a DOM Document to Load all the Extensions here.
  16. Private m_oFs As Scripting.FileSystemObject ' Needed only by DeleteExtension
  17. Public Event RunStatus(ByVal strMsg As String, ByRef bCancel As Boolean)
  18. Private Sub Class_Initialize()
  19. Set m_oDom = New DOMDocument
  20. Set m_oFs = New Scripting.FileSystemObject
  21. End Sub
  22. Function GetExtensionsList( _
  23. ByVal strExtFolder As String, _
  24. Optional ByRef oSkuColl As Scripting.Dictionary = Nothing _
  25. ) As IXMLDOMNodeList
  26. Set GetExtensionsList = Nothing
  27. ' We first check that we are indeed having a Directory
  28. strExtFolder = Trim$(strExtFolder)
  29. If (Len(strExtFolder) = 0) Then GoTo Common_Exit
  30. Dim oFs As Scripting.FileSystemObject: Set oFs = New Scripting.FileSystemObject
  31. If (Not oFs.FolderExists(strExtFolder)) Then GoTo Common_Exit
  32. Set m_oDom = New DOMDocument
  33. Dim oElem As IXMLDOMElement
  34. Set oElem = m_oDom.createElement("hss-tools-extensions")
  35. m_oDom.appendChild oElem
  36. ' We recurse through First Level SubFolders to grab all the extensions
  37. RaiseEvent RunStatus("Recursing " + strExtFolder + " for Extensions", True)
  38. Dim oDomExt As DOMDocument: Set oDomExt = New DOMDocument
  39. Dim oHssExt As HssExt: Set oHssExt = New HssExt
  40. Dim strExtPath As String
  41. Dim oSubF As Scripting.Folder
  42. For Each oSubF In oFs.GetFolder(strExtFolder).SubFolders
  43. strExtPath = oSubF.Path + "\ExtensionDescription.xml"
  44. Set oDomExt = oHssExt.InitFromDisk(strExtPath)
  45. If (oDomExt Is Nothing) Then GoTo Continue_For
  46. DeepDomCopy oDomExt.documentElement, oElem
  47. RaiseEvent RunStatus( _
  48. "Processed Extension " + _
  49. oDomExt.selectSingleNode("hss-tools-extension/display-name").Text, _
  50. True)
  51. Continue_For:
  52. Next
  53. If (oElem.childNodes Is Nothing) Then GoTo Common_Exit
  54. If (oSkuColl Is Nothing) Then GoTo Common_Exit
  55. If (oSkuColl.Count = 0) Then GoTo Common_Exit
  56. ' Now we return a list which is filtered by the SKUs we are interested in.
  57. Dim strFilter As String
  58. strFilter = "/hss-tools-extensions/hss-tools-extension[ "
  59. Dim v As Variant, i As Integer
  60. i = 0
  61. For Each v In oSkuColl.Keys
  62. i = i + 1
  63. If (i > 1) Then strFilter = strFilter + " or "
  64. strFilter = strFilter + "applicable-skus/sku = """ + CStr(v) + """"
  65. Next
  66. strFilter = strFilter + " ]"
  67. Set GetExtensionsList = oElem.selectNodes(strFilter)
  68. m_oDom.save strExtFolder + "\ExtensionsList.xml"
  69. Common_Exit:
  70. Exit Function
  71. End Function
  72. Function ExecuteExtensions( _
  73. ByRef oDomExts As IXMLDOMNodeList, _
  74. ByVal strcabFile As String, _
  75. ByVal strAuxFolder As String _
  76. ) As Boolean
  77. ExecuteExtensions = False
  78. ' Validations
  79. If (oDomExts Is Nothing) Then GoTo Common_Exit
  80. If (oDomExts.length = 0) Then GoTo Common_Exit
  81. Dim oFs As Scripting.FileSystemObject: Set oFs = New Scripting.FileSystemObject
  82. strcabFile = Trim$(strcabFile)
  83. If (Len(strcabFile) = 0) Then GoTo Common_Exit
  84. If (Not oFs.FileExists(strcabFile)) Then GoTo Common_Exit
  85. strAuxFolder = Trim$(strAuxFolder)
  86. If (Len(strAuxFolder) = 0) Then GoTo Common_Exit
  87. If (Not oFs.FolderExists(strAuxFolder)) Then GoTo Common_Exit
  88. ' now the real work
  89. Dim oWsShell As IWshShell ' Used to Shell and Wait for Sub-Processes
  90. Set oWsShell = CreateObject("Wscript.Shell")
  91. Dim strCmd As String
  92. Dim oExt As IXMLDOMNode
  93. For Each oExt In oDomExts
  94. If (oExt.selectSingleNode("run-this-extension").Text = "no") Then
  95. GoTo Continue_For
  96. End If
  97. strCmd = oExt.selectSingleNode("extension-folder").Text + "\" + oExt.selectSingleNode("executable-name").Text
  98. strCmd = strCmd + " " + strcabFile
  99. If (oExt.selectSingleNode("modifies-cab").Text = "no") Then
  100. strCmd = strCmd + " " + strAuxFolder
  101. End If
  102. RaiseEvent RunStatus("Running Extension " + _
  103. oExt.selectSingleNode("display-name").Text, True)
  104. oWsShell.Run strCmd, True, True
  105. Debug.Print "Extension"; oExt.selectSingleNode("display-name").Text
  106. Continue_For:
  107. Next
  108. ExecuteExtensions = True
  109. Common_Exit:
  110. End Function
  111. Public Sub DeleteExtension(ByRef oExt As IXMLDOMNode)
  112. Dim oExtFolder As IXMLDOMNode
  113. Set oExtFolder = oExt.selectSingleNode("extension-folder")
  114. If (oExtFolder Is Nothing) Then GoTo Common_Exit
  115. m_oFs.DeleteFolder oExtFolder.Text, Force:=True
  116. Common_Exit:
  117. End Sub
  118. Public Function ExtensionExists(ByVal strFileName As String) As Boolean
  119. ExtensionExists = False
  120. strFileName = LCase$(Trim$(strFileName))
  121. If (Len(strFileName) = 0) Then
  122. Err.Raise vbObjectError + "9999", _
  123. "HssExts::ExtensionExists", _
  124. "I need a non empty argument"
  125. End If
  126. Dim oDomList As IXMLDOMNodeList
  127. Set oDomList = m_oDom.selectNodes("/hss-tools-extensions/hss-tools-extension//executable-name")
  128. If (oDomList Is Nothing) Then GoTo Common_Exit
  129. Dim oExe As IXMLDOMNode
  130. For Each oExe In oDomList
  131. If (InStr(LCase$(oExe.Text), strFileName) > 0) Then
  132. ExtensionExists = True
  133. GoTo Common_Exit
  134. End If
  135. Next
  136. Common_Exit:
  137. Exit Function
  138. End Function
  139. ' Stolen from XMLUtils.bas
  140. Private Function DeepDomCopy(oDomSrcNode As IXMLDOMNode, oDomDstNode As IXMLDOMNode) As IXMLDOMNode
  141. If (oDomSrcNode.ownerDocument Is oDomDstNode.ownerDocument) Then
  142. Dim oNewDomNode As IXMLDOMNode
  143. Set oNewDomNode = oDomSrcNode.cloneNode(True)
  144. oDomDstNode.appendChild (oNewDomNode)
  145. Else
  146. ' Different DOM Nodes, so we really have to copy and
  147. ' recreate the node from one DOM Tree to another.
  148. Dim elNode As IXMLDOMElement
  149. Select Case oDomSrcNode.nodeType
  150. Case NODE_TEXT
  151. Dim oTextNode As IXMLDOMText
  152. Set oTextNode = oDomDstNode.ownerDocument.createTextNode(oDomSrcNode.Text)
  153. Set oNewDomNode = oDomDstNode.appendChild(oTextNode)
  154. Case Else
  155. Set elNode = oDomDstNode.ownerDocument.createElement(oDomSrcNode.nodeName)
  156. Set oNewDomNode = oDomDstNode.appendChild(elNode)
  157. ' If (Len(oDomSrcNode.Text) > 0) Then
  158. ' oNewDomNode.Text = oDomSrcNode.Text
  159. ' End If
  160. Dim oSrcAttr As IXMLDOMAttribute, oDstAttr As IXMLDOMAttribute
  161. For Each oSrcAttr In oDomSrcNode.Attributes
  162. Set oDstAttr = oDomDstNode.ownerDocument.createAttribute(oSrcAttr.nodeName)
  163. elNode.setAttribute oDstAttr.nodeName, oSrcAttr.Text
  164. Next
  165. Dim oDomSrcNodeChild As IXMLDOMNode
  166. For Each oDomSrcNodeChild In oDomSrcNode.childNodes
  167. DeepDomCopy oDomSrcNodeChild, oNewDomNode
  168. Next
  169. End Select
  170. End If
  171. Set DeepDomCopy = oNewDomNode
  172. End Function