home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / desaware / demo32 / vs5demo / vervrfy.bas < prev    next >
Encoding:
BASIC Source File  |  1996-10-24  |  17.8 KB  |  451 lines

  1. Attribute VB_Name = "VerVrfy"
  2. Option Explicit
  3.  
  4. 'contains version info for reference files that a conflict was found for
  5. Type VerConflictType
  6.     ReferenceFile As String     'name of reference file that a conflict was detected on
  7.     ReferenceVersion As String  'reference file version
  8.     ReferenceDate As String     'reference file date
  9.     ReferenceSize As String     'reference file size
  10.     ReferenceFlags As Long      'reference file flags
  11.     'contains index to the ConflictListType array, there can
  12.     'be more than one ConflictListType for each VerConflictType
  13.     ConflictListIndex As Integer
  14.                                     
  15. End Type
  16.  
  17. ' This structure holds information on the conflicting files, it is like
  18. ' a linked list, the VerConflictType contains an index to the first conflict,
  19. ' the last conflict contains a -1 in the index.
  20. ' Only the first conflict file is an actual conflict, the remaining files
  21. ' just indicates where else on the computer can the reference file be found.
  22. Type ConflictListType
  23.     ConflictFile As String      'string containing path of file found with same name
  24.                                 'as the reference file, blank if file not found
  25.     ConflictVersion As String   'version of first conflict file
  26.     ConflictDate As String      'date of first conflict file
  27.     ConflictSize As String      'size of first conflict file
  28.     ConflictFlags As Long       'conflict flags of first conflict file
  29.     ConflictFXFlags As Long     'fixed file info flags of first conflict file
  30.     ConflictNext As Integer     'next file in the conflict list, -1 if this is last one
  31. End Type
  32.  
  33. Global VerConflictList() As VerConflictType
  34. Global ConflictList() As ConflictListType
  35.  
  36. Global ConflictFilesFound%      'files found during scan that are in conflict with embedded files
  37. Global FileToCheck$             'specifies the name of file to verify for
  38. Global EmbedInfoFound%          'indicates whether we found other files during scan (we use this to
  39.                                 'determine whether the file contains embedded information or not)
  40. Global ConflictFormCaption$     'Caption for the conflict report form, if string is empty, then will default to form's caption.
  41. 'Version Information constants
  42. Global Const VC_GETALL = -1
  43. Global Const VC_REFERENCEFILE = 1
  44.  
  45. 'Version Conflict constants
  46. Global Const CF_OLDERFILE = &H1
  47. Global Const CF_NEWERFILE = &H2
  48. Global Const CF_OLDERVERSION = &H4
  49. Global Const CF_NEWERVERSION = &H8
  50. Global Const CF_SPECIALVERSION = &H10
  51. Global Const CF_ALWAYSWARN = &H20
  52. Global Const CF_FILEINMEMORY = &H40
  53. Global Const CF_FILENOTFOUND = &H80
  54. Global Const CF_NOVERSIONINFO = &H100
  55. Global Const CF_FILESIZELARGER = &H200
  56. Global Const CF_FILESIZESMALLER = &H400
  57. Global Const CF_NOTINREGISTRY = &H800
  58.  
  59. 'The following are duplicates of the VS_FF_* constants from Verinfo.bas
  60. Global Const VS_FF_DEBUG = &H1&
  61. Global Const VS_FF_PRERELEASE = &H2&
  62. Global Const VS_FF_PATCHED = &H4&
  63. Global Const VS_FF_PRIVATEBUILD = &H8&
  64. Global Const VS_FF_INFOINFERRED = &H10&
  65. Global Const VS_FF_SPECIALBUILD = &H20&
  66.  
  67. 'Text formatting constants
  68. Global NL As String 'new line
  69. Global TB As String 'tab
  70.  
  71. 'Tab Stop messages
  72. #If Win32 Then
  73.     Global Const EM_SETTABSTOPS = &HB0 + 27
  74.     Global Const EM_SETREADONLY = &HB0 + 31
  75.     Global Const LB_SETTABSTOPS = &H180 + 19
  76. #Else
  77.     Global Const EM_SETTABSTOPS = &H400 + 27
  78.     Global Const EM_SETREADONLY = &H400 + 31
  79.     Global Const LB_SETTABSTOPS = &H400 + 19
  80. #End If
  81.  
  82. 'File Open & Save Common Dialog constants
  83. Global Const OFN_READONLY = &H1&
  84. Global Const OFN_OVERWRITEPROMPT = &H2&
  85. Global Const OFN_HIDEREADONLY = &H4&
  86. Global Const OFN_NOCHANGEDIR = &H8&
  87. Global Const OFN_SHOWHELP = &H10&
  88. Global Const OFN_NOVALIDATE = &H100&
  89. Global Const OFN_ALLOWMULTISELECT = &H200&
  90. Global Const OFN_EXTENSIONDIFFERENT = &H400&
  91. Global Const OFN_PATHMUSTEXIST = &H800&
  92. Global Const OFN_FILEMUSTEXIST = &H1000&
  93. Global Const OFN_CREATEPROMPT = &H2000&
  94. Global Const OFN_SHAREAWARE = &H4000&
  95. Global Const OFN_NOREADONLYRETURN = &H8000&
  96. Global Const OFN_NOTESTFILECREATE = &H10000
  97.  
  98. Global Const TECHNOLOGY = 2 '  Device classification
  99. Global Const HORZSIZE = 4   '  Horizontal size in millimeters
  100. Global Const VERTSIZE = 6   '  Vertical size in millimeters
  101. Global Const HORZRES = 8    '  Horizontal width in pixels
  102. Global Const VERTRES = 10   '  Vertical width in pixels
  103. Global Const BITSPIXEL = 12 '  Number of bits per pixel
  104. Global Const PLANES = 14    '  Number of planes
  105.  
  106. ' 32-Bit API Functions
  107. #If Win32 Then
  108.     Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
  109.     Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  110.     Declare Function SendMessageByNum Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  111.     Declare Function WinHelpBynum Lib "User32" Alias "WinHelpA" (ByVal hWnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long
  112. #Else
  113.     ' 16-Bit API Functions
  114.     Declare Function GetDeviceCaps Lib "GDI" (ByVal hDC As Integer, ByVal nIndex As Integer) As Integer
  115.     Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  116.     Declare Function SendMessageByNum Lib "User" Alias "SendMessage" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As Long
  117.     Declare Function WinHelpBynum Lib "User" Alias "WinHelp" (ByVal hWnd As Integer, ByVal lpHelpFile As String, ByVal wCommand As Integer, ByVal dwData As Long) As Integer
  118. #End If
  119. Sub FillConflictFileListBox(ByVal append2ctl%, lbox As Control)
  120. Dim cfidx%, listidx%
  121.  
  122.     If Not append2ctl% Then lbox.Clear
  123.     
  124.     ' ConflictFilesFound contains the number of conflicting files that were found.
  125.     If ConflictFilesFound% > 0 Then
  126.         cfidx% = UBound(VerConflictList)
  127.         ' Get list of conflicting file names and place them in the list box.
  128.         For listidx% = 1 To cfidx% Step 1
  129.             lbox.AddItem VerConflictList(listidx%).ReferenceFile
  130.         Next
  131.     Else
  132.         ' If no conflicts were found, check to see whether it was
  133.         ' because the target file did not contain any embedded info.
  134.         If EmbedInfoFound% Then
  135.             lbox.AddItem NOCONFLICT
  136.         Else
  137.             lbox.AddItem NOEMBEDDED
  138.         End If
  139.     End If
  140.     
  141. End Sub
  142.  
  143. '
  144. ' Determine the number of colors supported by the current device
  145. '
  146. Function GetColorCount&(f As Form)
  147.     Dim pl&, bp&
  148.     pl& = GetDeviceCaps(f.hDC, PLANES)
  149.     bp& = GetDeviceCaps(f.hDC, BITSPIXEL)
  150.     If (pl& * bp&) > 24 Then
  151.         GetColorCount& = 2 ^ 24
  152.     Else
  153.         GetColorCount& = 2 ^ (pl& * bp&)
  154.     End If
  155. End Function
  156.  
  157. Function GetConflictInfo(ByVal ctype%, ByVal Index%, ByVal delim$) As String
  158. Dim tstr$
  159. Dim vclist%, vcount%
  160.  
  161.     If ctype% = VC_REFERENCEFILE Then
  162.         If Index% = VC_GETALL Then
  163.             vclist% = UBound(VerConflictList)
  164.             For vcount% = 1 To vclist% Step 1
  165.                 tstr$ = tstr$ & VerConflictList(vcount%).ReferenceFile & delim$
  166.             Next
  167.         Else
  168.             tstr$ = tstr$ & VerConflictList(ctype%).ReferenceFile & delim$
  169.         End If
  170.     End If
  171.  
  172.     GetConflictInfo = tstr$
  173. End Function
  174.  
  175. Function GetDetailConflictInfo(ByVal vcidx%) As String
  176. Dim clistindex%
  177. Dim eflags&
  178. Dim tstr$
  179.     
  180.     If vcidx% > UBound(VerConflictList) Then Exit Function
  181.  
  182.     'get index to conflict array list
  183.     clistindex% = VerConflictList(vcidx%).ConflictListIndex
  184.  
  185.     tstr$ = CONFLICT_REFFILEDATE & TB & VerConflictList(vcidx%).ReferenceDate & NL
  186.     tstr$ = tstr$ & CONFLICT_REFFILESIZE & TB & VerConflictList(vcidx%).ReferenceSize & NL
  187.     tstr$ = tstr$ & CONFLICT_REFFILEVER & TB & VerConflictList(vcidx%).ReferenceVersion & NL & NL
  188.     
  189.     tstr$ = tstr$ & CONFLICT_FILEFOUND & TB
  190.     
  191.     'get conflict information, conflict information is currently found for
  192.     'only the first conflict file
  193.     tstr$ = tstr$ & ConflictList(clistindex%).ConflictFile & NL
  194.     eflags& = ConflictList(clistindex%).ConflictFlags
  195.  
  196.     ' Display the necessary version information based on conflict found.
  197.     ' We can filter out certain messages depending on the error found.
  198.     ' For example:
  199.  
  200.     'If (eflags& And &H3) Then
  201.         'date conflict, get date string
  202.     '    tstr$ = tstr$ & ConflictList(clistindex%).ConflictDate & TB
  203.     'End If
  204.  
  205.     ' For now, we'll always display date and size
  206.     tstr$ = tstr$ & CONFLICT_FILEDATE & TB & ConflictList(clistindex%).ConflictDate & NL
  207.     tstr$ = tstr$ & CONFLICT_FILESIZE & TB & ConflictList(clistindex%).ConflictSize & NL
  208.  
  209.     'If (eflags& And &HC) Then
  210.         'version conflict, get version string
  211.     '    tstr$ = tstr$ & ConflictList(clistindex%).ConflictVersion & TB
  212.     'End If
  213.  
  214.     ' For now, we'll always display version
  215.     tstr$ = tstr$ & CONFLICT_FILEVER & TB & ConflictList(clistindex%).ConflictVersion & NL
  216.  
  217.     tstr$ = tstr$ & NL & GetWarnings(eflags&, NL, ConflictList(clistindex%).ConflictFXFlags)
  218.     clistindex% = ConflictList(clistindex%).ConflictNext
  219.  
  220.     If clistindex% < 0 Then
  221.         GetDetailConflictInfo = tstr$
  222.         Exit Function
  223.     End If
  224.  
  225.     ' If more than one file was found on the system, list their date, version,
  226.     ' and conflict information.  This will allow you to see whether a good
  227.     ' version exist on the target system.
  228.     tstr$ = tstr$ & NL & CONFLICT_FILEINOTHERDIR & NL
  229.  
  230.     While clistindex% > 0
  231.         tstr$ = tstr$ & NL & ConflictList(clistindex%).ConflictFile & NL
  232.         ' For now, we'll always display date
  233.         tstr$ = tstr$ & CONFLICT_FILEDATE & TB & ConflictList(clistindex%).ConflictDate & NL
  234.         ' For now, we'll always display size
  235.         tstr$ = tstr$ & CONFLICT_FILESIZE & TB & ConflictList(clistindex%).ConflictSize & NL
  236.         ' For now, we'll always display version
  237.         tstr$ = tstr$ & CONFLICT_FILEVER & TB & ConflictList(clistindex%).ConflictVersion & NL
  238.  
  239.         clistindex% = ConflictList(clistindex%).ConflictNext
  240.     Wend
  241.  
  242.     GetDetailConflictInfo = tstr$
  243. End Function
  244.  
  245. ' This function returns strings describing the fixed file info flags.
  246. Function GetFileFlagDesc(ByVal Flags&) As String
  247.     Dim ret$, comma$
  248.     
  249.     comma$ = ", "
  250.     If Flags& And VS_FF_DEBUG Then
  251.         ret$ = ret$ & FF_DEBUG & comma$
  252.     End If
  253.     If Flags& And VS_FF_INFOINFERRED Then
  254.         ret$ = ret$ & FF_INFOINFERRED & comma$
  255.     End If
  256.     If Flags& And VS_FF_PATCHED Then
  257.         ret$ = ret$ & FF_PATCHED & comma$
  258.     End If
  259.     If Flags& And VS_FF_PRERELEASE Then
  260.         ret$ = ret$ & FF_PRERELEASE & comma$
  261.     End If
  262.     If Flags& And VS_FF_PRIVATEBUILD Then
  263.         ret$ = ret$ & FF_PRIVATEBUILD & comma$
  264.     End If
  265.     If Flags& And VS_FF_SPECIALBUILD Then
  266.         ret$ = ret$ & FF_SPECIALBUILD & comma$
  267.     End If
  268.     If ret$ <> "" Then
  269.         GetFileFlagDesc = Left$(ret$, Len(ret$) - 2)
  270.     End If
  271. End Function
  272.  
  273. '
  274. ' Returns a string listing the warning messages for the specified error flag.
  275. ' The error flag is the Flags parameter from the FileConflict event of the VersionStamper.
  276. '
  277. Function GetWarnings$(ByVal eflags As Long, ByVal delim As String, ByVal fxflags As Long)
  278.     Dim tstr$
  279.     Dim fbit&
  280.     Dim bitcount%
  281.  
  282.     If (eflags = 0) Then Exit Function
  283.  
  284.     For bitcount% = 0 To 12 Step 1
  285.         fbit& = 2 ^ bitcount%
  286.         If (fbit& And eflags) Then
  287.             Select Case bitcount%
  288.                 Case 0: 'Older file was found
  289.                     tstr$ = tstr$ & CONFLICT_OLDERFILE & delim
  290.                 Case 1: 'Newer file was found
  291.                     tstr$ = tstr$ & CONFLICT_NEWERFILE & delim
  292.                 Case 2: 'Older version was found
  293.                     tstr$ = tstr$ & CONFLICT_OLDERVERSION & delim
  294.                 Case 3: 'Newer file was found
  295.                     tstr$ = tstr$ & CONFLICT_NEWERVERSION & delim
  296.                 Case 4: 'Special version was found
  297.                     tstr$ = tstr$ & CONFLICT_SPECIALVERSION & GetFileFlagDesc(fxflags) & delim
  298.                 Case 5: 'Always warn was set
  299.                     tstr$ = tstr$ & CONFLICT_ALWAYSWARN & delim
  300.                 Case 6: 'File was found in memory
  301.                     tstr$ = tstr$ & CONFLICT_FILEINMEMORY & delim
  302.                 Case 7: 'No matching file was found
  303.                     tstr$ = tstr$ & CONFLICT_FILENOTFOUND & delim
  304.                 Case 8: 'No version information detected in this file
  305.                     tstr$ = tstr$ & CONFLICT_VERINFONOTFOUND & delim
  306.                 Case 9: 'No version information detected in this file
  307.                     tstr$ = tstr$ & CONFLICT_FILESIZELARGER & delim
  308.                 Case 10: 'No version information detected in this file
  309.                     tstr$ = tstr$ & CONFLICT_FILESIZESMALLER & delim
  310.                 Case 11: 'No version information detected in this file
  311.                     tstr$ = tstr$ & CONFLICT_NOTINREGISTRY & delim
  312.             End Select
  313.         End If
  314.     Next
  315.  
  316.     GetWarnings = tstr$
  317.     
  318. End Function
  319.  
  320. Sub LoadConflictStruct(vc As VerConflictType, ByVal filename$, ByVal FoundFile$, ByVal eflags&, vsctl As VersionStampDemo)
  321. '
  322. ' Loads the VerConflictType with all of the available information
  323. ' for an embedded file descriptor.  This function can only be called during
  324. ' the FileConflict event for vsctl, since it uses the control's properties
  325. ' to obtain the description information.
  326. '
  327. Dim newsize%, listcount%, curindex%, startindex%, endindex%, otherindex%
  328.     
  329.     ' Set filename
  330.     vc.ReferenceFile = filename$
  331.     vc.ReferenceVersion = vsctl.RefVersion
  332.     vc.ReferenceDate = vsctl.RefDateString
  333.     vc.ReferenceSize = vsctl.RefSize
  334.     vc.ReferenceFlags = vsctl.RefFlags
  335.     listcount% = UBound(ConflictList)
  336.     startindex% = listcount% + 1
  337.     vc.ConflictListIndex = startindex%
  338.     
  339.     'if vsctl.OtherCount = 0, file was not found
  340.     If vsctl.OtherCount > 0 Then
  341.         endindex% = startindex% + vsctl.OtherCount - 1
  342.     Else
  343.         endindex% = startindex%
  344.     End If
  345.  
  346.     'allocate for new items
  347.     ReDim Preserve ConflictList(endindex%)
  348.  
  349.     otherindex% = 0
  350.     For curindex% = startindex% To endindex% Step 1
  351.         If vsctl.OtherCount > 0 Then
  352.             ConflictList(curindex%).ConflictFile = vsctl.OtherFile(otherindex%)
  353.             ConflictList(curindex%).ConflictVersion = vsctl.OtherVersion(otherindex%)
  354.             ConflictList(curindex%).ConflictDate = vsctl.OtherDateString(otherindex%)
  355.             ConflictList(curindex%).ConflictSize = vsctl.OtherSize(otherindex%)
  356.             ConflictList(curindex%).ConflictFXFlags = vsctl.OtherFlags(otherindex%)
  357.         Else
  358.             If (FoundFile <> "") Then
  359.                 ConflictList(curindex%).ConflictFile = FoundFile
  360.                 ConflictList(curindex%).ConflictVersion = vsctl.FoundVersion
  361.                 ConflictList(curindex%).ConflictDate = vsctl.FoundDateString
  362.                 ConflictList(curindex%).ConflictSize = vsctl.FoundSize
  363.                 ConflictList(curindex%).ConflictFXFlags = vsctl.FoundFlags
  364.             End If
  365.         End If
  366.  
  367.         ConflictList(curindex%).ConflictFlags = eflags
  368.         ' If more than one other files were found, create a linked list for them
  369.         If (curindex% <> endindex%) Then
  370.             ConflictList(curindex%).ConflictNext = curindex% + 1
  371.         Else
  372.             ConflictList(curindex%).ConflictNext = -1
  373.         End If
  374.         otherindex% = otherindex% + 1
  375.     Next
  376.  
  377. End Sub
  378.  
  379. Sub LogEnumComplete(vsctl As VersionStampDemo)
  380. Static scanningfiles%
  381.     'reset mousepointer
  382.     Screen.MousePointer = 0
  383.     If vsctl.VerifyMode = 4 Then Exit Sub   'scanning for a single object file
  384.     
  385.     If Not scanningfiles% Then
  386.         'checking file conflicts
  387.         If ConflictFilesFound% > 0 Then Exit Sub
  388.  
  389.         ' If no file conflicts were found, make sure this EXE contains
  390.         ' embedded information, scan it to find out.
  391.         scanningfiles% = True
  392.         EmbedInfoFound% = False
  393.  
  394.         'double check to make sure we scanned a file with embedded information
  395.         If vsctl.VerifyMode = 2 Then
  396.             vsctl.VerifyMode = 3
  397.         Else
  398.             vsctl.ScanFile = FileToCheck$
  399.         End If
  400.     Else
  401.         ' This ends our scanning check.
  402.         scanningfiles% = False
  403.     End If
  404.  
  405. End Sub
  406.  
  407. Sub LogFileConflict(ReferenceFile As String, FoundFile As String, Flags As Long, StopVerify As Integer, vsctl As VersionStampDemo)
  408.     Dim newidx%
  409.     ' Keep count of number of conflicts found.
  410.     ConflictFilesFound% = ConflictFilesFound% + 1
  411.     ' At each one, we add an entry to the global VerScanList
  412.     ' list of information.
  413.     newidx% = UBound(VerConflictList) + 1
  414.     ReDim Preserve VerConflictList(newidx%)
  415.  
  416.     ' We save here the information that we will need.
  417.     ' Save information for EVERY file that caused a conflict.
  418.     LoadConflictStruct VerConflictList(newidx%), ReferenceFile, FoundFile, Flags, vsctl
  419.  
  420. End Sub
  421.  
  422. Sub StartVerify(vsctl As VersionStampDemo)
  423.     'clears global lists and other variables first
  424.     ReDim VerConflictList(0)
  425.     ReDim ConflictList(0)
  426.  
  427.     ConflictFilesFound% = 0
  428.  
  429.     'The file verify may take a while, so bring up hourglass.
  430.     Screen.MousePointer = 11
  431.     'Are we checking this Exe or some other file
  432.     If FileToCheck$ <> "" Then
  433.         ' This method of verifying leaves the VerifyMode property at 0
  434.         vsctl.VerifyFile = FileToCheck$
  435.     Else
  436.         vsctl.VerifyMode = 2
  437.     End If
  438.  
  439. End Sub
  440.  
  441. Sub StopFileScan(ReferenceFile As String, VerifyFlags As Long, StopScan As Integer)
  442.     'This is used to check and make sure the target executable file has
  443.     'embedded information.
  444.     EmbedInfoFound% = True
  445.     'Since all we need to do is make sure at least one file was found
  446.     '(which tells us this EXE has embedded information), we can halt the scan.
  447.     StopScan = True
  448.  
  449. End Sub
  450.  
  451.