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.

334 lines
11 KiB

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Begin VB.Form frmMain
  4. Caption = "Windows ME HHT Fix"
  5. ClientHeight = 1140
  6. ClientLeft = 60
  7. ClientTop = 345
  8. ClientWidth = 5970
  9. LinkTopic = "Form1"
  10. ScaleHeight = 1140
  11. ScaleWidth = 5970
  12. StartUpPosition = 3 'Windows Default
  13. Begin MSComDlg.CommonDialog dlg
  14. Left = 3480
  15. Top = 600
  16. _ExtentX = 847
  17. _ExtentY = 847
  18. _Version = 393216
  19. End
  20. Begin VB.CommandButton cmdBrowse
  21. Caption = "&Browse..."
  22. Height = 375
  23. Left = 5040
  24. TabIndex = 3
  25. Top = 120
  26. Width = 855
  27. End
  28. Begin VB.CommandButton cmdClose
  29. Caption = "&Close"
  30. Height = 375
  31. Left = 5040
  32. TabIndex = 2
  33. Top = 600
  34. Width = 855
  35. End
  36. Begin VB.CommandButton cmdGo
  37. Caption = "&OK"
  38. Height = 375
  39. Left = 4080
  40. TabIndex = 1
  41. Top = 600
  42. Width = 855
  43. End
  44. Begin VB.TextBox txtCabFile
  45. Height = 375
  46. Left = 120
  47. TabIndex = 0
  48. Top = 120
  49. Width = 4815
  50. End
  51. Begin VB.Label lblProgress
  52. Height = 375
  53. Left = 240
  54. TabIndex = 4
  55. Top = 600
  56. Width = 3735
  57. End
  58. End
  59. Attribute VB_Name = "frmMain"
  60. Attribute VB_GlobalNameSpace = False
  61. Attribute VB_Creatable = False
  62. Attribute VB_PredeclaredId = True
  63. Attribute VB_Exposed = False
  64. Option Explicit
  65. ' Utility Stuff, all this could go to a COM Object and be distributed
  66. ' like this.
  67. Private m_WsShell As IWshShell ' Used to Shell and Wait for Sub-Processes
  68. Private m_fso As Scripting.FileSystemObject ' For filesystem operations
  69. Private Sub Form_Initialize()
  70. Set m_WsShell = CreateObject("Wscript.Shell")
  71. Set m_fso = New Scripting.FileSystemObject
  72. End Sub
  73. Private Sub Form_Load()
  74. If (Len(Trim$(Command$)) > 0) Then
  75. Me.txtCabFile = Command$
  76. Me.txtCabFile.Enabled = False
  77. Me.cmdBrowse.Enabled = False
  78. Me.cmdGo.Enabled = False
  79. Me.Show Modal:=False
  80. cmdGo_Click
  81. cmdClose_Click
  82. End If
  83. End Sub
  84. Function Cab2Folder(ByVal strCabFile As String)
  85. Cab2Folder = ""
  86. ' We grab a Temporary Filename and create a folder out of it
  87. Dim strFolder As String
  88. strFolder = Environ("TEMP") + "\" + m_fso.GetTempName
  89. m_fso.CreateFolder strFolder
  90. ' We uncab CAB contents into the Source CAB Contents dir.
  91. Dim strCmd As String
  92. strCmd = "cabarc X " + strCabFile + " " + strFolder + "\"
  93. m_WsShell.Run strCmd, True, True
  94. Cab2Folder = strFolder
  95. End Function
  96. Sub Folder2Cab( _
  97. ByVal strFolder As String, _
  98. ByVal strCabFile As String _
  99. )
  100. ' We recab using the Destination directory contents
  101. ' cabarc -r -p -s 6144 N ..\algo.cab *.*
  102. m_fso.DeleteFile strCabFile, force:=True
  103. Dim strCmd As String
  104. strCmd = "cabarc -r -p -s 6144 N " + strCabFile + " " + strFolder + "\*.*"
  105. m_WsShell.Run strCmd, True, True
  106. End Sub
  107. ' ============ END UTILITY STUFF ========================
  108. ' ============ BoilerPlate Form Code
  109. Private Sub cmdBrowse_Click()
  110. dlg.Filter = "All Files (*.*)|*.*|Cab Files (*.cab)|*.cab"
  111. dlg.FilterIndex = 2
  112. dlg.ShowOpen
  113. If (Len(dlg.FileName) > 0) Then
  114. Me.txtCabFile = dlg.FileName
  115. End If
  116. End Sub
  117. Private Sub cmdClose_Click()
  118. Unload Me
  119. End Sub
  120. Private Sub cmdGo_Click()
  121. Me.txtCabFile.Text = Trim$(Me.txtCabFile.Text)
  122. If (Len(Me.txtCabFile.Text) > 0) Then
  123. FixCab Me.txtCabFile.Text
  124. End If
  125. End Sub
  126. Sub FixCab(ByVal strCabFile As String)
  127. Dim strErrMsg As String: strErrMsg = ""
  128. If (Not m_fso.FileExists(strCabFile)) Then
  129. MsgBox "Cannot find " & strCabFile
  130. GoTo Common_Exit
  131. End If
  132. Dim strCabFolder As String
  133. lblProgress = "Uncabbing " & strCabFile: DoEvents
  134. strCabFolder = Cab2Folder(strCabFile)
  135. lblProgress = "Applying Fixes ": DoEvents
  136. If (FixPerSe(strCabFolder)) Then
  137. lblProgress = "Recabbing " & strCabFile
  138. Folder2Cab strCabFolder, strCabFile
  139. Else
  140. MsgBox "Error: Fix Failed", Title:=App.EXEName
  141. End If
  142. ' Now we delete the Temporary Folders
  143. lblProgress = "Deleting Temporary Files": DoEvents
  144. m_fso.DeleteFolder strCabFolder, force:=True
  145. Common_Exit:
  146. lblProgress = "Done" + IIf(Len(strErrMsg) > 0, " - " + strErrMsg, "")
  147. End Sub
  148. ' ============= End BoilerPlate Form Code ================
  149. Function FixPerSe(ByVal strCabFolder As String) As Boolean
  150. FixPerSe = False
  151. ' Now we parse Package_Description.xml to find the HHT Files
  152. ' For each HHT File
  153. ' IF Node Creation is being performed in this HHT - THEN
  154. ' Delete this HHT from the Destination Directory
  155. ' Create 2 HHT Files in out Package_Description.XML
  156. ' Split Source HHT into 2 destination HHTs
  157. ' - 1 HHT for Node creation
  158. ' - 1 HHT for Content
  159. ' Write the 2 newly created Destination HHTs
  160. ' ENDIF
  161. ' END FOR Each
  162. '
  163. ' Save Resulting Package_Description.xml
  164. Dim oElem As IXMLDOMElement ' Used for all element Creation
  165. Dim oDomPkg As DOMDocument: Set oDomPkg = New DOMDocument
  166. Dim strPkgFile As String: strPkgFile = strCabFolder + "\package_description.xml"
  167. oDomPkg.async = False
  168. oDomPkg.Load strPkgFile
  169. If (oDomPkg.parseError <> 0) Then GoTo Common_Exit
  170. ' Let's check whether this fix was applied
  171. Dim oFixNode As IXMLDOMNode
  172. Set oFixNode = oDomPkg.selectSingleNode("HELPCENTERPACKAGE/package_fixes/fix[@id='1']")
  173. If (Not oFixNode Is Nothing) Then GoTo Common_Exit
  174. ' now, if it is the first time we run we have to create the Package_fixes
  175. ' NODE.
  176. If (oDomPkg.selectSingleNode("HELPCENTERPACKAGE/package_fixes") Is Nothing) Then
  177. Set oElem = oDomPkg.createElement("package_fixes")
  178. oDomPkg.selectSingleNode("HELPCENTERPACKAGE").appendChild oElem
  179. End If
  180. ' We record the fact that this fix was already applied
  181. Set oElem = oDomPkg.createElement("fix")
  182. oDomPkg.selectSingleNode("HELPCENTERPACKAGE/package_fixes").appendChild oElem
  183. oElem.setAttribute "id", "1"
  184. oElem.setAttribute "description", _
  185. "Fix for Windows ME HCUPDATE where nodes cannot " + _
  186. "be created in the same HHT as Content"
  187. Dim oMetadataNode As IXMLDOMNode
  188. Set oMetadataNode = oDomPkg.selectSingleNode("HELPCENTERPACKAGE/METADATA")
  189. Dim oMetadataCopy As IXMLDOMNode
  190. Set oMetadataCopy = oMetadataNode.cloneNode(deep:=True)
  191. Dim oDomHhtNode As IXMLDOMNode
  192. For Each oDomHhtNode In oMetadataCopy.selectNodes("HHT")
  193. Dim strHhtFile As String
  194. strHhtFile = oDomHhtNode.Attributes.getNamedItem("FILE").Text
  195. ' Let's load the HHT
  196. Dim oDomHht As DOMDocument: Set oDomHht = New DOMDocument
  197. oDomHht.async = False
  198. oDomHht.Load strCabFolder + "\" + strHhtFile
  199. If (oDomHht.parseError <> 0) Then GoTo Common_Exit
  200. ' And check whether Node Creation entries exist.
  201. Dim oNodeCreationEntries As IXMLDOMNodeList
  202. Set oNodeCreationEntries = oDomHht.selectNodes("METADATA/TAXONOMY_ENTRIES/TAXONOMY_ENTRY[@ENTRY]")
  203. If (Not oNodeCreationEntries Is Nothing) Then
  204. ' it means there are node Creation Entries
  205. ' So, we delete the HHT entry in Package Description.xml
  206. oMetadataNode.removeChild oMetadataNode.selectSingleNode("HHT[@FILE='" + strHhtFile + "']") ' oDomHhtNode
  207. ' and we replace the above with 2 new Entries in Package_description.xml
  208. ' for the new HHTs we are going to create.
  209. Dim strExt As String: strExt = FileExtension(strHhtFile)
  210. Set oElem = oDomPkg.createElement("HHT")
  211. Dim strHhtF1 As String: strHhtF1 = FilenameNoExt(strHhtFile) + "_1." + strExt
  212. oElem.setAttribute "FILE", strHhtF1
  213. oMetadataNode.appendChild oElem
  214. Set oElem = oDomPkg.createElement("HHT")
  215. Dim strHhtF2 As String: strHhtF2 = FilenameNoExt(strHhtFile) + "_2." + strExt
  216. oElem.setAttribute "FILE", strHhtF2
  217. oMetadataNode.appendChild oElem
  218. ' Now, in the second HHT we delete all Node Creation Entries
  219. ' We use the currently loaded HHT in the oDomHht for this.
  220. Dim oDomTaxoEntry As IXMLDOMNode
  221. For Each oDomTaxoEntry In oNodeCreationEntries
  222. oDomTaxoEntry.parentNode.removeChild oDomTaxoEntry
  223. Next
  224. oDomHht.Save strCabFolder + "\" + strHhtF2
  225. ' and In the first HHT we delete ALL content addition entries.
  226. oDomHht.Load strCabFolder + "\" + strHhtFile
  227. If (oDomHht.parseError <> 0) Then GoTo Common_Exit
  228. Dim oTaxoEntries As IXMLDOMNodeList
  229. Set oTaxoEntries = oDomHht.selectNodes("METADATA/TAXONOMY_ENTRIES/TAXONOMY_ENTRY")
  230. Debug.Print "There are " & oTaxoEntries.length & " taxonomy entries"
  231. For Each oDomTaxoEntry In oTaxoEntries
  232. If (oDomTaxoEntry.Attributes.getNamedItem("ENTRY") Is Nothing) Then
  233. oDomTaxoEntry.parentNode.removeChild oDomTaxoEntry
  234. End If
  235. Next
  236. oDomHht.Save strCabFolder + "\" + strHhtF1
  237. ' we delete the old HHT from the directory
  238. '
  239. m_fso.DeleteFile strCabFolder + "\" + strHhtFile
  240. End If
  241. Next
  242. ' Now we save the resulting package_description.xml
  243. oDomPkg.Save strPkgFile
  244. FixPerSe = True
  245. Common_Exit:
  246. Exit Function
  247. End Function
  248. '============= File Utilities =============
  249. Public Function FilenameNoExt(ByVal sPath As String) As String
  250. FilenameNoExt = sPath
  251. If "" = sPath Then Exit Function
  252. Dim bDQ As Boolean
  253. bDQ = (Left$(sPath, 1) = Chr(34))
  254. Dim iDot As Long
  255. iDot = InStrRev(sPath, ".")
  256. If iDot > 0 Then
  257. FilenameNoExt = Left$(sPath, iDot - 1) & IIf(bDQ, Chr(34), "")
  258. End If
  259. End Function
  260. Public Function FileExtension(ByVal sPath As String) As String
  261. FileExtension = ""
  262. If "" = sPath Then Exit Function
  263. Dim bDQ As Boolean
  264. bDQ = (Right$(sPath, Len(sPath) - 1) = Chr(34))
  265. If bDQ Then sPath = Left$(sPath, Len(sPath) - 1)
  266. Dim iDot As Long
  267. iDot = InStrRev(sPath, ".")
  268. If iDot > 0 Then
  269. FileExtension = UCase$(Right$(sPath, Len(sPath) - iDot))
  270. End If
  271. End Function