home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / Chip_2001-06_cd1.bin / zkuste / vbasic / Data / Utility / MSISDK15.msi / WiDiffDb.vbs < prev    next >
Text File  |  2000-10-05  |  5KB  |  123 lines

  1. ' Windows Installer utility to report the differences between two databases
  2. ' For use with Windows Scripting Host, CScript.exe only, lists to stdout
  3. ' Copyright (c) 1999-2000, Microsoft Corporation
  4. ' Simply generates a transform between the databases and then view the transform
  5. '
  6. Option Explicit
  7.  
  8. Const icdLong       = 0
  9. Const icdShort      = &h400
  10. Const icdObject     = &h800
  11. Const icdString     = &hC00
  12. Const icdNullable   = &h1000
  13. Const icdPrimaryKey = &h2000
  14. Const icdNoNulls    = &h0000
  15. Const icdPersistent = &h0100
  16. Const icdTemporary  = &h0000
  17.  
  18. Const msiOpenDatabaseModeReadOnly     = 0
  19. Const msiOpenDatabaseModeTransact     = 1
  20. Const msiOpenDatabaseModeCreate       = 3
  21. Const iteViewTransform       = 256
  22.  
  23. If Wscript.Arguments.Count < 2 Then
  24.     Wscript.Echo "Windows Installer database difference utility" &_
  25.         vbNewLine & " Generates a temporary transform file, then display it" &_
  26.         vbNewLine & " 1st argument is the path to the original installer database" &_
  27.         vbNewLine & " 2nd argument is the path to the updated installer database" &_
  28.         vbNewLine &_
  29.         vbNewLine & "Copyright (C) Microsoft Corporation, 1999-2000.  All rights reserved."
  30.     Wscript.Quit 1
  31. End If
  32.  
  33. ' Cannot run with GUI script host, as listing is performed to standard out
  34. If UCase(Mid(Wscript.FullName, Len(Wscript.Path) + 2, 1)) = "W" Then
  35.     WScript.Echo "Cannot use WScript.exe - must use CScript.exe with this program"
  36.     Wscript.Quit 2
  37. End If
  38.  
  39. ' Connect to Windows Installer object
  40. On Error Resume Next
  41. Dim installer : Set installer = Nothing
  42. Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
  43.  
  44. ' Create path for temporary transform file
  45. Dim WshShell : Set WshShell = Wscript.CreateObject("Wscript.Shell") : CheckError
  46. Dim tempFilePath:tempFilePath = WshShell.ExpandEnvironmentStrings("%TEMP%") & "\diff.tmp"
  47.  
  48. ' Open databases, generate transform, then list transform
  49. Dim database1 : Set database1 = installer.OpenDatabase(Wscript.Arguments(0), msiOpenDatabaseModeReadOnly) : CheckError
  50. Dim database2 : Set database2 = installer.OpenDatabase(Wscript.Arguments(1), msiOpenDatabaseModeReadOnly) : CheckError
  51. Dim different : different = Database2.GenerateTransform(Database1, tempFilePath) : CheckError
  52. If different Then
  53.     database1.ApplyTransform tempFilePath, iteViewTransform + 0 : CheckError' should not need error suppression flags
  54.     ListTransform database1
  55. End If
  56.  
  57. ' Open summary information streams and compare them
  58. Dim sumInfo1 : Set sumInfo1 = database1.SummaryInformation(0) : CheckError
  59. Dim sumInfo2 : Set sumInfo2 = database2.SummaryInformation(0) : CheckError
  60. Dim iProp, value1, value2
  61. For iProp = 1 to 19              
  62.     value1 = sumInfo1.Property(iProp) : CheckError
  63.     value2 = sumInfo2.Property(iProp) : CheckError
  64.     If value1 <> value2 Then
  65.         Wscript.Echo "\005SummaryInformation   [" & iProp & "] {" & value1 & "}->{" & value2 & "}"
  66.         different = True
  67.     End If
  68. Next
  69. If Not different Then Wscript.Echo "Databases are identical"
  70. Wscript.Quit 0
  71.  
  72. Function DecodeColDef(colDef)
  73.     Dim def
  74.     Select Case colDef AND (icdShort OR icdObject)
  75.     Case icdLong
  76.         def = "LONG"
  77.     Case icdShort
  78.         def = "SHORT"
  79.     Case icdObject
  80.         def = "OBJECT"
  81.     Case icdString
  82.         def = "CHAR(" & (colDef AND 255) & ")"
  83.     End Select
  84.     If (colDef AND icdNullable)   =  0 Then def = def & " NOT NULL"
  85.     If (colDef AND icdPrimaryKey) <> 0 Then def = def & " PRIMARY KEY"
  86.     DecodeColDef = def
  87. End Function
  88.  
  89. Sub ListTransform(database)
  90.     Dim view, record, row, column, change
  91.     On Error Resume Next
  92.     Set view = database.OpenView("SELECT * FROM `_TransformView` ORDER BY `Table`, `Row`")
  93.     If Err <> 0 Then Wscript.Echo "Transform viewing supported only in builds 4906 and beyond of MSI.DLL" : Wscript.Quit 2
  94.     view.Execute : CheckError
  95.     Do
  96.         Set record = view.Fetch : CheckError
  97.         If record Is Nothing Then Exit Do
  98.         change = Empty
  99.         If record.IsNull(3) Then
  100.             row = "<DDL>"
  101.             If NOT record.IsNull(4) Then change = "[" & record.StringData(5) & "]: " & DecodeColDef(record.StringData(4))
  102.         Else
  103.             row = "[" & Join(Split(record.StringData(3), vbTab, -1), ",") & "]"
  104.             If record.StringData(2) <> "INSERT" AND record.StringData(2) <> "DELETE" Then change = "{" & record.StringData(5) & "}->{" & record.StringData(4) & "}"
  105.         End If
  106.         column = record.StringData(1) & " " & record.StringData(2)
  107.         if Len(column) < 24 Then column = column & Space(24 - Len(column))
  108.         WScript.Echo column, row, change
  109.     Loop
  110. End Sub
  111.  
  112. Sub CheckError
  113.     Dim message, errRec
  114.     If Err = 0 Then Exit Sub
  115.     message = Err.Source & " " & Hex(Err) & ": " & Err.Description
  116.     If Not installer Is Nothing Then
  117.         Set errRec = installer.LastErrorRecord
  118.         If Not errRec Is Nothing Then message = message & vbNewLine & errRec.FormatText
  119.     End If
  120.     Wscript.Echo message
  121.     Wscript.Quit 2
  122. End Sub
  123.