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.

323 lines
8.2 KiB

  1. VERSION 5.00
  2. Begin VB.Form frmMain
  3. BorderStyle = 1 'Fixed Single
  4. Caption = "CabStatistics"
  5. ClientHeight = 3855
  6. ClientLeft = 45
  7. ClientTop = 330
  8. ClientWidth = 4710
  9. LinkTopic = "Form1"
  10. MaxButton = 0 'False
  11. MinButton = 0 'False
  12. ScaleHeight = 3855
  13. ScaleWidth = 4710
  14. StartUpPosition = 3 'Windows Default
  15. Begin VB.TextBox txtOutput
  16. Height = 2775
  17. Left = 120
  18. Locked = -1 'True
  19. MultiLine = -1 'True
  20. ScrollBars = 2 'Vertical
  21. TabIndex = 4
  22. Top = 480
  23. Width = 4455
  24. End
  25. Begin VB.CommandButton cmdClose
  26. Caption = "Close"
  27. Height = 375
  28. Left = 3720
  29. TabIndex = 3
  30. Top = 3360
  31. Width = 855
  32. End
  33. Begin VB.TextBox txtCAB
  34. Height = 285
  35. Left = 600
  36. TabIndex = 1
  37. Top = 120
  38. Width = 3975
  39. End
  40. Begin VB.CommandButton cmdGo
  41. Caption = "Go"
  42. Height = 375
  43. Left = 2760
  44. TabIndex = 2
  45. Top = 3360
  46. Width = 855
  47. End
  48. Begin VB.Label lblCAB
  49. Caption = "CAB:"
  50. Height = 255
  51. Index = 0
  52. Left = 120
  53. TabIndex = 0
  54. Top = 120
  55. Width = 375
  56. End
  57. End
  58. Attribute VB_Name = "frmMain"
  59. Attribute VB_GlobalNameSpace = False
  60. Attribute VB_Creatable = False
  61. Attribute VB_PredeclaredId = True
  62. Attribute VB_Exposed = False
  63. Option Explicit
  64. Private Const PKG_DESC_FILE_C As String = "package_description.xml"
  65. Private Const PKG_DESC_HHT_C As String = "HELPCENTERPACKAGE/METADATA/HHT"
  66. Private Const HHT_KEYWORD_C As String = "METADATA/TAXONOMY_ENTRIES/TAXONOMY_ENTRY/KEYWORD"
  67. Private Const HHT_NODE_C As String = "METADATA/TAXONOMY_ENTRIES//TAXONOMY_ENTRY[string-length(@ENTRY) > 0]"
  68. Private Const HHT_TOPIC_C As String = "METADATA/TAXONOMY_ENTRIES//TAXONOMY_ENTRY[string-length(@ENTRY) = 0]"
  69. Private FSO As Scripting.FileSystemObject
  70. Private WS As IWshShell
  71. Private Sub Form_Load()
  72. Dim strCAB As String
  73. Set FSO = New Scripting.FileSystemObject
  74. Set WS = CreateObject("Wscript.Shell")
  75. cmdGo.Default = True
  76. cmdClose.Cancel = True
  77. strCAB = Trim$(Command$)
  78. txtCAB = strCAB
  79. If (Len(strCAB) <> 0) Then
  80. Me.Show False
  81. cmdGo_Click
  82. End If
  83. End Sub
  84. Private Sub cmdGo_Click()
  85. On Error GoTo LError
  86. Dim strCAB As String
  87. Dim strFolder As String
  88. strCAB = Trim$(txtCAB.Text)
  89. If (strCAB = "") Then
  90. MsgBox "Please specify the CAB", vbOKOnly
  91. Exit Sub
  92. End If
  93. Me.Enabled = False
  94. strFolder = p_Cab2Folder(strCAB)
  95. FixPerSe strCAB, strFolder
  96. FSO.DeleteFolder strFolder, True
  97. LEnd:
  98. Me.Enabled = True
  99. Exit Sub
  100. LError:
  101. GoTo LEnd
  102. End Sub
  103. Private Sub cmdClose_Click()
  104. Set FSO = Nothing
  105. Set WS = Nothing
  106. Unload Me
  107. End Sub
  108. Private Sub FixPerSe( _
  109. ByVal i_strCAB As String, _
  110. ByVal i_strFolder As String _
  111. )
  112. On Error GoTo LError
  113. Dim File As Scripting.File
  114. Dim DOMDocPkgDesc As MSXML2.DOMDocument
  115. Dim DOMNodeListHHT As MSXML2.IXMLDOMNodeList
  116. Dim DOMNodeHHTRef As MSXML2.IXMLDOMNode
  117. Dim DOMNodeHHT As MSXML2.DOMDocument
  118. Dim DOMNodeList As MSXML2.IXMLDOMNodeList
  119. Dim strHhtFile As String
  120. Dim intTotalKeywordMatches As Long
  121. Dim intTotalNodes As Long
  122. Dim intTotalTopics As Long
  123. Dim intKeywordMatches As Long
  124. Dim intNodes As Long
  125. Dim intTopics As Long
  126. Set File = FSO.GetFile(i_strCAB)
  127. p_Output "CAB file size: " & File.Size
  128. p_Output ""
  129. Set DOMDocPkgDesc = p_GetPackage(i_strFolder)
  130. If (DOMDocPkgDesc Is Nothing) Then
  131. GoTo LEnd
  132. End If
  133. Set DOMNodeListHHT = DOMDocPkgDesc.selectNodes(PKG_DESC_HHT_C)
  134. For Each DOMNodeHHTRef In DOMNodeListHHT
  135. Set DOMNodeHHT = p_GetHht(DOMNodeHHTRef, i_strFolder, strHhtFile)
  136. DOMNodeHHT.setProperty "SelectionLanguage", "XPath"
  137. p_Output "File: " & strHhtFile
  138. If (Not DOMNodeHHT Is Nothing) Then
  139. Set DOMNodeList = DOMNodeHHT.selectNodes(HHT_KEYWORD_C)
  140. intKeywordMatches = DOMNodeList.length
  141. p_Output " Keyword matches: " & intKeywordMatches
  142. intTotalKeywordMatches = intTotalKeywordMatches + intKeywordMatches
  143. Set DOMNodeList = DOMNodeHHT.selectNodes(HHT_NODE_C)
  144. intNodes = DOMNodeList.length
  145. p_Output " Nodes: " & intNodes
  146. intTotalNodes = intTotalNodes + intNodes
  147. Set DOMNodeList = DOMNodeHHT.selectNodes(HHT_TOPIC_C)
  148. intTopics = DOMNodeList.length
  149. p_Output " Topics: " & intTopics
  150. intTotalTopics = intTotalTopics + intTopics
  151. End If
  152. Next
  153. p_Output ""
  154. p_Output "Total Keyword matches: " & intTotalKeywordMatches
  155. p_Output "Total Nodes: " & intTotalNodes
  156. p_Output "Total Topics: " & intTotalTopics
  157. LEnd:
  158. Exit Sub
  159. LError:
  160. MsgBox _
  161. "Error 0x" & Hex(Err.Number) & vbCrLf & _
  162. Err.Description
  163. End Sub
  164. Private Sub p_Output( _
  165. ByVal i_str As String _
  166. )
  167. If (txtOutput <> "") Then
  168. txtOutput = txtOutput & vbCrLf & i_str
  169. Else
  170. txtOutput = i_str
  171. End If
  172. End Sub
  173. Private Function p_GetPackage( _
  174. ByVal i_strFolder As String _
  175. ) As MSXML2.DOMDocument
  176. Dim DOMDocPkg As MSXML2.DOMDocument
  177. Dim strPkgFile As String
  178. Set DOMDocPkg = New MSXML2.DOMDocument
  179. strPkgFile = i_strFolder & "\" & PKG_DESC_FILE_C
  180. DOMDocPkg.async = False
  181. DOMDocPkg.Load strPkgFile
  182. If (DOMDocPkg.parseError <> 0) Then
  183. p_DisplayParseError DOMDocPkg.parseError
  184. GoTo LEnd
  185. End If
  186. Set p_GetPackage = DOMDocPkg
  187. LEnd:
  188. End Function
  189. Private Function p_GetHht( _
  190. ByVal i_DOMNodeHHT As MSXML2.IXMLDOMNode, _
  191. ByVal i_strFolder As String, _
  192. ByRef o_strHhtFile As String _
  193. ) As MSXML2.IXMLDOMNode
  194. Dim DOMDocHHT As MSXML2.DOMDocument
  195. If (i_DOMNodeHHT Is Nothing) Then GoTo LEnd
  196. o_strHhtFile = i_DOMNodeHHT.Attributes.getNamedItem("FILE").Text
  197. Set DOMDocHHT = New MSXML2.DOMDocument
  198. DOMDocHHT.async = False
  199. DOMDocHHT.Load i_strFolder + "\" + o_strHhtFile
  200. If (DOMDocHHT.parseError <> 0) Then
  201. p_DisplayParseError DOMDocHHT.parseError
  202. GoTo LEnd
  203. End If
  204. Set p_GetHht = DOMDocHHT
  205. LEnd:
  206. End Function
  207. Private Function p_Cab2Folder( _
  208. ByVal i_strCabFile As String _
  209. ) As String
  210. Dim strFolder As String
  211. Dim strCmd As String
  212. p_Cab2Folder = ""
  213. ' We grab a Temporary Filename and create a folder out of it
  214. strFolder = FSO.GetSpecialFolder(TemporaryFolder) + "\" + FSO.GetTempName
  215. FSO.CreateFolder strFolder
  216. ' We uncab CAB contents into the Source CAB Contents dir.
  217. strCmd = "cabarc X " + i_strCabFile + " " + strFolder + "\"
  218. WS.Run strCmd, True, True
  219. p_Cab2Folder = strFolder
  220. End Function
  221. Private Sub p_Folder2Cab( _
  222. ByVal i_strFolder As String, _
  223. ByVal i_strCabFile As String _
  224. )
  225. Dim strCmd As String
  226. If (FSO.FileExists(i_strCabFile)) Then
  227. FSO.DeleteFile i_strCabFile, True
  228. End If
  229. strCmd = "cabarc -r -s 6144 n """ & i_strCabFile & """ " & i_strFolder & "\*"
  230. WS.Run strCmd, True, True
  231. End Sub
  232. Private Sub p_DisplayParseError( _
  233. ByRef i_ParseError As MSXML2.IXMLDOMParseError _
  234. )
  235. Dim strError As String
  236. With i_ParseError
  237. strError = "Error: " & .reason & _
  238. "Line: " & .Line & vbCrLf & _
  239. "Linepos: " & .linepos & vbCrLf & _
  240. "srcText: " & .srcText
  241. End With
  242. MsgBox strError, vbOKOnly, "Error while parsing"
  243. End Sub