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.

151 lines
4.5 KiB

  1. Attribute VB_Name = "CabsAndHHTs"
  2. Option Explicit
  3. Public Const PKG_DESC_FILE_C As String = "package_description.xml"
  4. Private Const PKG_DESC_HHT_C As String = "HELPCENTERPACKAGE/METADATA/HHT"
  5. Private Const PKG_DESC_HHT_ATTRIBUTE_FILE_C As String = "FILE"
  6. Public Const E_FAIL As Long = &H80004005
  7. Public Function Cab2Folder( _
  8. ByVal i_strCabFile As String, _
  9. Optional ByVal i_strFolder As String = "" _
  10. ) As String
  11. Dim FSO As Scripting.FileSystemObject
  12. Dim WS As IWshShell
  13. Dim strFolder As String
  14. Dim strCmd As String
  15. Cab2Folder = ""
  16. Set FSO = New Scripting.FileSystemObject
  17. Set WS = CreateObject("Wscript.Shell")
  18. If (Not FSO.FileExists(i_strCabFile)) Then
  19. Err.Raise E_FAIL, , "File " & i_strCabFile & " doesn't exist."
  20. End If
  21. If (i_strFolder = "") Then
  22. ' We grab a Temporary Filename and create a folder out of it
  23. strFolder = FSO.GetSpecialFolder(TemporaryFolder) + "\" + FSO.GetTempName
  24. FSO.CreateFolder strFolder
  25. Else
  26. If (Not FSO.FolderExists(i_strFolder)) Then
  27. Err.Raise E_FAIL, , "Folder " & i_strFolder & " doesn't exist."
  28. End If
  29. strFolder = i_strFolder
  30. End If
  31. ' We uncab CAB contents into the Source CAB Contents dir.
  32. strCmd = "cabarc -o X """ & i_strCabFile & """ " & strFolder & "\"
  33. WS.Run strCmd, True, True
  34. Cab2Folder = strFolder
  35. End Function
  36. Public Sub Folder2Cab( _
  37. ByVal i_strFolder As String, _
  38. ByVal i_strCabFile As String _
  39. )
  40. Dim FSO As Scripting.FileSystemObject
  41. Dim WS As IWshShell
  42. Dim strCmd As String
  43. Set FSO = New Scripting.FileSystemObject
  44. Set WS = CreateObject("Wscript.Shell")
  45. If (Not FSO.FolderExists(i_strFolder)) Then
  46. Err.Raise E_FAIL, , "Folder " & i_strFolder & " doesn't exist."
  47. End If
  48. If (FSO.FileExists(i_strCabFile)) Then
  49. FSO.DeleteFile i_strCabFile, True
  50. End If
  51. strCmd = "cabarc -r -s 6144 n """ & i_strCabFile & """ " & i_strFolder & "\*"
  52. WS.Run strCmd, True, True
  53. End Sub
  54. Public Sub DeleteCabFolder( _
  55. ByVal i_strFolder As String _
  56. )
  57. On Error Resume Next
  58. Dim FSO As New Scripting.FileSystemObject
  59. FSO.DeleteFolder i_strFolder
  60. End Sub
  61. Public Function GetFileAsDomDocument( _
  62. ByVal i_strFile As String _
  63. ) As MSXML2.DOMDocument
  64. Dim FSO As Scripting.FileSystemObject
  65. Dim DOMDoc As MSXML2.DOMDocument
  66. Set DOMDoc = New MSXML2.DOMDocument
  67. Set FSO = New Scripting.FileSystemObject
  68. If (Not FSO.FileExists(i_strFile)) Then
  69. Err.Raise E_FAIL, , "File " & i_strFile & " doesn't exist."
  70. End If
  71. DOMDoc.async = False
  72. DOMDoc.Load i_strFile
  73. If (DOMDoc.parseError <> 0) Then
  74. Err.Raise E_FAIL, , "Unable to parse " & i_strFile & ": " & DOMDoc.parseError
  75. End If
  76. Set GetFileAsDomDocument = DOMDoc
  77. End Function
  78. Public Function GetPackageDescription( _
  79. ByVal i_strFolder As String _
  80. ) As MSXML2.DOMDocument
  81. Set GetPackageDescription = GetFileAsDomDocument(i_strFolder & "\" & PKG_DESC_FILE_C)
  82. End Function
  83. Public Function GetNumberOfHHTsListedInPackageDescription( _
  84. ByVal i_DOMDocPackageDescription As MSXML2.DOMDocument _
  85. ) As Long
  86. Dim DOMNodeListHHT As MSXML2.IXMLDOMNodeList
  87. If (i_DOMDocPackageDescription Is Nothing) Then
  88. Err.Raise E_FAIL, , "Argument i_DOMDocPackageDescription is Nothing."
  89. End If
  90. Set DOMNodeListHHT = i_DOMDocPackageDescription.selectNodes(PKG_DESC_HHT_C)
  91. GetNumberOfHHTsListedInPackageDescription = DOMNodeListHHT.length
  92. End Function
  93. Public Function GetNthHHTListedInPackageDescription( _
  94. ByVal i_DOMDocPackageDescription As MSXML2.DOMDocument, _
  95. ByVal i_intIndex As Long _
  96. ) As String
  97. Dim DOMNodeListHHT As MSXML2.IXMLDOMNodeList
  98. Dim DOMNode As MSXML2.IXMLDOMNode
  99. If (i_DOMDocPackageDescription Is Nothing) Then
  100. Err.Raise E_FAIL, , "Argument i_DOMDocPackageDescription is Nothing."
  101. End If
  102. Set DOMNodeListHHT = i_DOMDocPackageDescription.selectNodes(PKG_DESC_HHT_C)
  103. If ((i_intIndex < 1) Or (i_intIndex > DOMNodeListHHT.length)) Then
  104. Err.Raise E_FAIL, , "Index " & i_intIndex & " out of range."
  105. End If
  106. Set DOMNode = DOMNodeListHHT(i_intIndex - 1)
  107. GetNthHHTListedInPackageDescription = DOMNode.Attributes.getNamedItem(PKG_DESC_HHT_ATTRIBUTE_FILE_C).Text
  108. End Function