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.

491 lines
15 KiB

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
  4. Begin VB.Form frmMain
  5. BorderStyle = 1 'Fixed Single
  6. Caption = "Inverse CAB Creation Utility"
  7. ClientHeight = 3855
  8. ClientLeft = 2685
  9. ClientTop = 2190
  10. ClientWidth = 6000
  11. LinkTopic = "Form1"
  12. MaxButton = 0 'False
  13. MinButton = 0 'False
  14. ScaleHeight = 3855
  15. ScaleWidth = 6000
  16. Begin MSComctlLib.ProgressBar prgBar
  17. Height = 240
  18. Left = -675
  19. TabIndex = 10
  20. Top = 3375
  21. Width = 6870
  22. _ExtentX = 12118
  23. _ExtentY = 423
  24. _Version = 393216
  25. Appearance = 1
  26. End
  27. Begin VB.TextBox txtLog
  28. Height = 2100
  29. Left = 0
  30. MultiLine = -1 'True
  31. ScrollBars = 2 'Vertical
  32. TabIndex = 9
  33. Top = 1275
  34. Width = 5985
  35. End
  36. Begin MSComctlLib.StatusBar stbProgress
  37. Align = 2 'Align Bottom
  38. Height = 240
  39. Left = 0
  40. TabIndex = 8
  41. Top = 3615
  42. Width = 6000
  43. _ExtentX = 10583
  44. _ExtentY = 423
  45. Style = 1
  46. _Version = 393216
  47. BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
  48. NumPanels = 1
  49. BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
  50. EndProperty
  51. EndProperty
  52. End
  53. Begin VB.CommandButton cmdSave
  54. Caption = "..."
  55. Height = 255
  56. Left = 5520
  57. TabIndex = 5
  58. Top = 480
  59. Width = 420
  60. End
  61. Begin VB.TextBox txtSaveCab
  62. Height = 285
  63. Left = 1200
  64. TabIndex = 4
  65. Top = 480
  66. Width = 4260
  67. End
  68. Begin MSComDlg.CommonDialog dlg
  69. Left = 3540
  70. Top = 690
  71. _ExtentX = 847
  72. _ExtentY = 847
  73. _Version = 393216
  74. End
  75. Begin VB.CommandButton cmdBrowse
  76. Caption = "..."
  77. Height = 255
  78. Left = 5520
  79. TabIndex = 2
  80. Top = 120
  81. Width = 420
  82. End
  83. Begin VB.CommandButton cmdClose
  84. Caption = "&Close"
  85. Height = 375
  86. Left = 5100
  87. TabIndex = 7
  88. Top = 810
  89. Width = 855
  90. End
  91. Begin VB.CommandButton cmdGo
  92. Caption = "&OK"
  93. Height = 375
  94. Left = 4140
  95. TabIndex = 6
  96. Top = 810
  97. Width = 855
  98. End
  99. Begin VB.TextBox txtCabFile
  100. Height = 285
  101. Left = 1200
  102. TabIndex = 1
  103. Top = 120
  104. Width = 4260
  105. End
  106. Begin VB.Label Label2
  107. Caption = "Output CAB:"
  108. Height = 255
  109. Left = 120
  110. TabIndex = 3
  111. Top = 480
  112. Width = 975
  113. End
  114. Begin VB.Label Label1
  115. Caption = "Input CAB:"
  116. Height = 255
  117. Left = 120
  118. TabIndex = 0
  119. Top = 120
  120. Width = 975
  121. End
  122. End
  123. Attribute VB_Name = "frmMain"
  124. Attribute VB_GlobalNameSpace = False
  125. Attribute VB_Creatable = False
  126. Attribute VB_PredeclaredId = True
  127. Attribute VB_Exposed = False
  128. Option Explicit
  129. ' Utility Stuff, all this could go to a COM Object and be distributed
  130. ' like this.
  131. Private m_WsShell As IWshShell ' Used to Shell and Wait for Sub-Processes
  132. Private m_fso As Scripting.FileSystemObject ' For filesystem operations
  133. Private Sub Form_Initialize()
  134. Set m_WsShell = CreateObject("Wscript.Shell")
  135. Set m_fso = New Scripting.FileSystemObject
  136. End Sub
  137. Private Sub Form_Load()
  138. WriteLog App.EXEName & " Inverse CAB Creation Utility", False
  139. WriteLog String$(40, "="), False
  140. cmdGo.Default = True
  141. cmdClose.Cancel = True
  142. If (Len(Trim$(Command$)) > 0) Then
  143. Me.txtCabFile = Command$
  144. Me.txtCabFile.Enabled = False
  145. Me.cmdBrowse.Enabled = False
  146. Me.cmdGo.Enabled = False
  147. Me.Show Modal:=False
  148. cmdGo_Click
  149. cmdClose_Click
  150. End If
  151. End Sub
  152. Function Cab2Folder(ByVal strCabFile As String)
  153. Cab2Folder = ""
  154. ' We grab a Temporary Filename and create a folder out of it
  155. Dim strFolder As String
  156. strFolder = m_fso.GetSpecialFolder(TemporaryFolder) + "\" + m_fso.GetTempName
  157. m_fso.CreateFolder strFolder
  158. ' We uncab CAB contents into the Source CAB Contents dir.
  159. Dim strCmd As String
  160. strCmd = "cabarc X " + strCabFile + " " + strFolder + "\"
  161. m_WsShell.Run strCmd, True, True
  162. Cab2Folder = strFolder
  163. End Function
  164. Sub Folder2Cab( _
  165. ByVal strFolder As String, _
  166. ByVal strCabFile As String _
  167. )
  168. ' We recab using the Destination directory contents
  169. ' cabarc -s 6144 N ..\algo.cab *.*
  170. If (m_fso.FileExists(strCabFile)) Then
  171. m_fso.DeleteFile strCabFile, force:=True
  172. End If
  173. Dim strCmd As String
  174. strCmd = "cabarc -s 6144 N " + strCabFile + " " + strFolder + "\*.*"
  175. m_WsShell.Run strCmd, True, True
  176. End Sub
  177. Sub WriteLog(strMsg As String, Optional ByVal bWriteToStatusBar As Boolean = True)
  178. With Me
  179. .txtLog = .txtLog & vbCrLf & strMsg
  180. If (bWriteToStatusBar) Then
  181. .stbProgress.SimpleText = strMsg
  182. End If
  183. End With
  184. DoEvents
  185. End Sub
  186. ' ============ END UTILITY STUFF ========================
  187. ' ============ BoilerPlate Form Code
  188. Private Sub cmdBrowse_Click()
  189. dlg.Filter = "All Files (*.*)|*.*|Cab Files (*.cab)|*.cab"
  190. dlg.FilterIndex = 2
  191. dlg.ShowOpen
  192. If (Len(dlg.FileName) > 0) Then
  193. Me.txtCabFile = dlg.FileName
  194. End If
  195. End Sub
  196. Private Sub cmdSave_Click()
  197. dlg.Filter = "All Files (*.*)|*.*|Cab Files (*.cab)|*.cab"
  198. dlg.FilterIndex = 2
  199. dlg.ShowSave
  200. If (Len(dlg.FileName) > 0) Then
  201. Me.txtSaveCab = dlg.FileName
  202. End If
  203. End Sub
  204. Private Sub cmdClose_Click()
  205. Unload Me
  206. End Sub
  207. Private Sub cmdGo_Click()
  208. Me.txtCabFile.Text = Trim$(Me.txtCabFile.Text)
  209. Me.txtSaveCab.Text = Trim$(Me.txtSaveCab.Text)
  210. If (Len(Me.txtCabFile.Text) > 0) Then
  211. FixCab Me.txtCabFile.Text, Me.txtSaveCab.Text
  212. End If
  213. End Sub
  214. Sub FixCab(ByVal strCabFile As String, ByVal strSaveCab As String)
  215. Dim strErrMsg As String: strErrMsg = ""
  216. If (Not m_fso.FileExists(strCabFile)) Then
  217. MsgBox "Cannot find " & strCabFile
  218. GoTo Common_Exit
  219. End If
  220. Dim strCabFolder As String
  221. prgBar.Visible = True
  222. WriteLog "Uncabbing " & strCabFile
  223. strCabFolder = Cab2Folder(strCabFile)
  224. WriteLog "Applying Fixes "
  225. If (FixPerSe(strCabFolder)) Then
  226. WriteLog "Recabbing " & strCabFile
  227. Folder2Cab strCabFolder, strSaveCab
  228. Else
  229. MsgBox "Error: Fix Failed", Title:=App.EXEName
  230. End If
  231. ' Now we delete the Temporary Folders
  232. WriteLog "Deleting Temporary Files"
  233. m_fso.DeleteFolder strCabFolder, force:=True
  234. Common_Exit:
  235. WriteLog "Done" + IIf(Len(strErrMsg) > 0, " - " + strErrMsg, "")
  236. prgBar.Visible = False
  237. End Sub
  238. ' ========================================================
  239. ' ============= End BoilerPlate Form Code ================
  240. ' ========================================================
  241. Function FixPerSe(ByVal strCabFolder As String) As Boolean
  242. FixPerSe = False
  243. ' Now we parse Package_Description.xml to find the HHT Files
  244. Dim oElem As IXMLDOMElement ' Used for all element Creation
  245. Dim oDomPkg As DOMDocument: Set oDomPkg = New DOMDocument
  246. Dim strPkgFile As String: strPkgFile = strCabFolder + "\package_description.xml"
  247. oDomPkg.async = False
  248. oDomPkg.Load strPkgFile
  249. If (oDomPkg.parseError <> 0) Then
  250. p_DisplayParseError oDomPkg.parseError
  251. GoTo Common_Exit
  252. End If
  253. ' Let's check whether this fix was applied
  254. Dim oFixNode As IXMLDOMNode
  255. Set oFixNode = oDomPkg.selectSingleNode("HELPCENTERPACKAGE/package_fixes/fix[@id='2']")
  256. If (Not oFixNode Is Nothing) Then GoTo Common_Exit
  257. ' now, if it is the first time we run we have to create the Package_fixes
  258. ' NODE.
  259. If (oDomPkg.selectSingleNode("HELPCENTERPACKAGE/package_fixes") Is Nothing) Then
  260. Set oElem = oDomPkg.createElement("package_fixes")
  261. oDomPkg.selectSingleNode("HELPCENTERPACKAGE").appendChild oElem
  262. End If
  263. ' We record the fact that this fix was already applied
  264. Set oElem = oDomPkg.createElement("fix")
  265. oDomPkg.selectSingleNode("HELPCENTERPACKAGE/package_fixes").appendChild oElem
  266. oElem.setAttribute "id", "2"
  267. oElem.setAttribute "description", "Inverse CAB"
  268. Dim lTaxoInEntries As Long: lTaxoInEntries = 0
  269. Dim oMetadataNode As IXMLDOMNode
  270. Set oMetadataNode = oDomPkg.selectSingleNode("HELPCENTERPACKAGE/METADATA")
  271. Dim oDOMNode As IXMLDOMNode
  272. Dim oDomHhtNode As IXMLDOMNode
  273. For Each oDomHhtNode In oMetadataNode.selectNodes("HHT")
  274. Dim strHhtFile As String
  275. strHhtFile = oDomHhtNode.Attributes.getNamedItem("FILE").Text
  276. ' Let's load the HHT
  277. Dim oDomHht As DOMDocument: Set oDomHht = New DOMDocument
  278. oDomHht.async = False
  279. oDomHht.Load strCabFolder + "\" + strHhtFile
  280. If (oDomHht.parseError <> 0) Then
  281. p_DisplayParseError oDomHht.parseError
  282. GoTo Common_Exit
  283. End If
  284. lTaxoInEntries = lTaxoInEntries + oDomHht.selectNodes("//*[ @ACTION ]").length
  285. WriteLog m_fso.GetBaseName(strHhtFile) & _
  286. " has " & lTaxoInEntries & " entries with ACTION Attribute", False
  287. prgBar.Max = lTaxoInEntries
  288. prgBar.Value = 1
  289. Set oDOMNode = oDomHht.selectSingleNode("METADATA/TAXONOMY_ENTRIES")
  290. p_ReverseTaxonomy oDOMNode
  291. Set oDOMNode = oDomHht.selectSingleNode("METADATA/STOPSIGN_ENTRIES")
  292. p_ReverseOther oDOMNode
  293. Set oDOMNode = oDomHht.selectSingleNode("METADATA/STOPWORD_ENTRIES")
  294. p_ReverseOther oDOMNode
  295. Set oDOMNode = oDomHht.selectSingleNode("METADATA/OPERATOR_ENTRIES")
  296. p_ReverseOther oDOMNode
  297. Set oDOMNode = oDomHht.selectSingleNode("METADATA/HELPIMAGE")
  298. p_ReverseOther oDOMNode
  299. Set oDOMNode = oDomHht.selectSingleNode("METADATA/INDEX")
  300. p_ReverseOther oDOMNode
  301. oDomHht.Save strCabFolder + "\" + strHhtFile
  302. Next
  303. Dim lPkgInEntries As Long: lPkgInEntries = 0
  304. lPkgInEntries = lPkgInEntries + oDomPkg.selectNodes("//*[ @ACTION ]").length
  305. WriteLog m_fso.GetBaseName(strPkgFile) & _
  306. " has " & lPkgInEntries & " entries with ACTION Attribute", False
  307. If (lPkgInEntries > 0) Then
  308. prgBar.Max = lPkgInEntries
  309. prgBar.Value = 1
  310. Set oDOMNode = oDomPkg.selectSingleNode("HELPCENTERPACKAGE/SEARCHENGINES")
  311. p_ReverseOther oDOMNode
  312. Set oDOMNode = oDomPkg.selectSingleNode("HELPCENTERPACKAGE/CONFIG")
  313. p_ReverseOther oDOMNode
  314. Set oDOMNode = oDomPkg.selectSingleNode("HELPCENTERPACKAGE/INSTALL_CONTENT")
  315. p_ReverseOther oDOMNode
  316. Set oDOMNode = oDomPkg.selectSingleNode("HELPCENTERPACKAGE/TRUSTED_CONTENT")
  317. p_ReverseOther oDOMNode
  318. End If
  319. oDomPkg.Save strCabFolder + "\" + "\package_description.xml"
  320. FixPerSe = True
  321. Common_Exit:
  322. Exit Function
  323. End Function
  324. Private Sub p_ReverseTaxonomy( _
  325. ByRef u_DOMNode As IXMLDOMNode _
  326. )
  327. If (u_DOMNode Is Nothing) Then GoTo Common_Exit
  328. Dim u_DOMNodeCopy As IXMLDOMNode
  329. Set u_DOMNodeCopy = u_DOMNode.cloneNode(deep:=True)
  330. WriteLog "Reversing " & u_DOMNode.nodeName & _
  331. " with " & u_DOMNode.childNodes.length & " entries"
  332. Dim oTaxoEntry As IXMLDOMNode
  333. For Each oTaxoEntry In u_DOMNode.childNodes
  334. u_DOMNode.removeChild oTaxoEntry
  335. Next
  336. Dim lEnd As Long: lEnd = u_DOMNodeCopy.childNodes.length - 1
  337. Do While lEnd >= 0
  338. Set oTaxoEntry = u_DOMNodeCopy.childNodes.Item(lEnd)
  339. p_FlipAddDel oTaxoEntry
  340. u_DOMNodeCopy.removeChild oTaxoEntry
  341. u_DOMNode.appendChild oTaxoEntry
  342. Set oTaxoEntry = Nothing
  343. lEnd = lEnd - 1
  344. Loop
  345. Set u_DOMNodeCopy = Nothing
  346. Common_Exit:
  347. End Sub
  348. Private Sub p_ReverseOther( _
  349. ByRef u_DOMNode As IXMLDOMNode _
  350. )
  351. If (u_DOMNode Is Nothing) Then GoTo Common_Exit
  352. Dim oTaxoEntry As IXMLDOMNode
  353. WriteLog "Reversing " & u_DOMNode.nodeName & _
  354. " with " & u_DOMNode.childNodes.length & " entries"
  355. For Each oTaxoEntry In u_DOMNode.childNodes
  356. p_FlipAddDel oTaxoEntry
  357. Next
  358. Common_Exit:
  359. End Sub
  360. Private Sub p_FlipAddDel( _
  361. ByRef oNodeEntry As IXMLDOMNode _
  362. )
  363. Dim oAttribAction As IXMLDOMAttribute
  364. Set oAttribAction = oNodeEntry.Attributes.getNamedItem("ACTION")
  365. If (oAttribAction Is Nothing) Then
  366. Dim oElemEntryWithNoAction As IXMLDOMElement
  367. Set oElemEntryWithNoAction = oNodeEntry
  368. ' If there is no ACTION, then HelpSvc.exe assumes that
  369. ' ACTION=ADD, so we need to generate an ACTION = DEL
  370. oElemEntryWithNoAction.setAttribute "ACTION", "DEL"
  371. Else
  372. With oAttribAction
  373. Select Case .Value
  374. Case "ADD", ""
  375. .Value = "DEL"
  376. Case Else
  377. .Value = "ADD"
  378. End Select
  379. End With
  380. prgBar.Value = prgBar.Value + 1
  381. End If
  382. End Sub
  383. Public Sub p_DisplayParseError( _
  384. ByRef i_ParseError As IXMLDOMParseError _
  385. )
  386. Dim strError As String
  387. strError = "Error: " & i_ParseError.reason & _
  388. "Line: " & i_ParseError.Line & vbCrLf & _
  389. "Linepos: " & i_ParseError.linepos & vbCrLf & _
  390. "srcText: " & i_ParseError.srcText
  391. MsgBox strError, vbOKOnly, "Error while parsing"
  392. End Sub