home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / Misc / DXSetup / logging.bas < prev    next >
Encoding:
BASIC Source File  |  2001-10-08  |  10.8 KB  |  274 lines

  1. Attribute VB_Name = "basLogging"
  2. Option Explicit
  3.  
  4. '
  5. ' Module basLogging (32-bit functionality only)
  6. '
  7. 'The routines in this module are used for logging actions,
  8. 'warnings, notes and errors in an application removal
  9. 'logfile.  This logfile will be used by the application
  10. 'removal utility (ST6UNST.EXE) in the event that the user
  11. 'decides to remove the installed application (via a Program
  12. 'Manager icon under Windows NT or the Add/Remove Programs
  13. 'control panel applet under Windows 95).
  14. '
  15. 'The functions are based on transaction-like "actions".
  16. 'Whenever the setup program starts to process a new action
  17. '(an action is anything which the application removal
  18. 'utility must undo), the function NewAction() must be
  19. 'called with the appropriate parameters for that action
  20. '(search for NewAction in this project to see how the
  21. 'correct parameters for various actions are formed).
  22. 'When the action has been successfully completed, the
  23. 'function CommitAction() is called, or, if the
  24. 'action was not successfully completed, AbortAction()
  25. 'must be called.  If CommitAction() is called, then the
  26. 'action is logged at that point, and the application
  27. 'removal utility will undo that action (example, delete
  28. 'a file which was copied by setup).
  29. '
  30. 'Actions may be nested (for instance, a file copy
  31. 'action may have a nested direction creation action).
  32. 'Any errors, warnings or notes logged will note in
  33. 'the logfile the pending action (if any).  Even if
  34. 'an error is logged, the pending action must either
  35. 'be committed or canceled.  See comments for each
  36. 'function below for more specifics.
  37. '
  38.  
  39. 'Application removal is only supported for 32-bit projects
  40.  
  41. 'Set this constant to FALSE if you do not want warnings to appear
  42. 'in the logfile
  43. Public Const fLOG_WARNINGS = True
  44.  
  45. 'Global Action Key constants
  46. Public Const gstrKEY_PRIVATEFILE = "PrivateFile"
  47. Public Const gstrKEY_TEMPFILE = "TempFile"
  48. Public Const gstrKEY_SHAREDFILE = "SharedFile"
  49. Public Const gstrKEY_SYSTEMFILE = "SystemFile"
  50. Public Const gstrKEY_CREATEDIR = "CreateDir"
  51. Public Const gstrKEY_SHELLLINK = "ShellLink"
  52. Public Const gstrKEY_DLLSELFREGISTER = "DllSelfRegister"
  53. Public Const gstrKEY_EXESELFREGISTER = "ExeSelfRegister"
  54. Public Const gstrKEY_TLBREGISTER = "TLBRegister"
  55. Public Const gstrKEY_REMOTEREGISTER = "RemoteRegister"
  56. Public Const gstrKEY_REGKEY = "RegKey"
  57. Public Const gstrKEY_REGVALUE = "RegValue"
  58.  
  59. 'vb6stkit.dll logging errors
  60. Private Const LOGERR_SUCCESS = 0
  61. Private Const LOGERR_INVALIDARGS = 1
  62. Private Const LOGERR_OUTOFMEMORY = 2
  63. Private Const LOGERR_EXCEEDEDCAPACITY = 3
  64. Private Const LOGERR_WRITEERROR = 4
  65. Private Const LOGERR_NOCURRENTACTION = 5
  66. Private Const LOGERR_UNEXPECTED = 6
  67. Private Const LOGERR_FILENOTFOUND = 7
  68.  
  69. 'Logging error Severities
  70. Private Const LogErrOK = 1 ' OK to continue upon this error
  71. Private Const LogErrFatal = 2 ' Must terminate install upon this error
  72.  
  73. 'vb6stkit.DLL interfaces
  74. Private Declare Function DllAbortAction Lib "vb6stkit.dll" Alias "AbortAction" () As Long
  75. Private Declare Function DllAddActionNote Lib "vb6stkit.dll" Alias "AddActionNote" (ByVal lpszNote As String) As Long
  76. Private Declare Function DllCommitAction Lib "vb6stkit.dll" Alias "CommitAction" () As Long
  77. Private Declare Function fDllWithinAction Lib "vb6stkit.dll" Alias "fWithinAction" () As Long
  78. Private Declare Function DllLogError Lib "vb6stkit.dll" Alias "LogError" (ByVal lpszERROR As String, ByVal lpszDURINGACTION As String, ByVal lpszErrMsg As String) As Long
  79. Private Declare Function DllLogNote Lib "vb6stkit.dll" Alias "LogNote" (ByVal lpszNote As String) As Long
  80. Private Declare Function DllLogWarning Lib "vb6stkit.dll" Alias "LogWarning" (ByVal lpszWARNING As String, ByVal lpszDURINGACTION As String, ByVal lpszWarningMsg As String) As Long
  81. Private Declare Function DllNewAction Lib "vb6stkit.dll" Alias "NewAction" (ByVal lpszKey As String, ByVal lpszData As String) As Long
  82. Private Declare Function DllEnableLogging Lib "vb6stkit.dll" Alias "EnableLogging" (ByVal lpszFilename As String) As Long
  83. Private Declare Function DllDisableLogging Lib "vb6stkit.dll" Alias "DisableLogging" () As Long
  84.  
  85. '-----------------------------------------------------------
  86. ' SUB: AbortAction
  87. '
  88. ' Aborts the current action.
  89. '-----------------------------------------------------------
  90. '
  91. Public Sub AbortAction()
  92.     ShowLoggingError DllAbortAction(), LogErrFatal
  93. End Sub
  94.  
  95. '-----------------------------------------------------------
  96. ' SUB: AddActionNote
  97. '
  98. ' Adds an note which will be written to the log file
  99. ' immediately following the current action
  100. '-----------------------------------------------------------
  101. '
  102. Public Sub AddActionNote(ByVal strNote As String)
  103.     ShowLoggingError DllAddActionNote(strNote), LogErrOK
  104. End Sub
  105.  
  106. '-----------------------------------------------------------
  107. ' SUB: CommitAction
  108. '
  109. ' Marks the successful completion of the current action.
  110. ' The action will be output to the log file.
  111. '-----------------------------------------------------------
  112. '
  113. Public Sub CommitAction()
  114.     ShowLoggingError DllCommitAction(), LogErrFatal
  115. End Sub
  116.  
  117. '-----------------------------------------------------------
  118. ' SUB: DisableLogging
  119. '
  120. ' Disables application removal logging.  All logging
  121. ' functions can still be called, and must still be
  122. ' symentically correct, but no data will be written to disk.
  123. '-----------------------------------------------------------
  124. '
  125. Public Sub DisableLogging()
  126.     ShowLoggingError DllDisableLogging(), LogErrFatal
  127. End Sub
  128.  
  129. '-----------------------------------------------------------
  130. ' SUB: EnableLogging
  131. '
  132. ' Enables application setup/removal logging to the specified logfile
  133. '-----------------------------------------------------------
  134. '
  135. Public Sub EnableLogging(ByVal strLogFileName As String)
  136.     ShowLoggingError DllEnableLogging(strLogFileName), LogErrFatal
  137. End Sub
  138.  
  139. '-----------------------------------------------------------
  140. ' SUB: LogError
  141. '
  142. ' Logs an error to the logfile.  The action is NOT aborted.
  143. '-----------------------------------------------------------
  144. '
  145. Public Sub LogError(ByVal strErr As String)
  146.     ShowLoggingError DllLogError(ResolveResString(resLOG_ERROR), ResolveResString(resLOG_DURINGACTION), strErr), LogErrFatal
  147. End Sub
  148.  
  149. '-----------------------------------------------------------
  150. ' SUB: LogWarning
  151. '
  152. ' Logs a warning to the logfile.  The action is NOT aborted.
  153. ' Warnings are different from errors in that generally
  154. ' warnings are not brought to the end user's attention.
  155. ' Also, the bootstrapper does not ever log warnings.  It only
  156. ' logs errors.
  157. '
  158. ' The logging of warnings can be turned off by changing the
  159. ' value of fLOG_WARNINGS in the declarations section of this
  160. ' module.
  161. '-----------------------------------------------------------
  162. '
  163. Public Sub LogWarning(ByVal strWarning As String)
  164.     If fLOG_WARNINGS Then
  165.         ShowLoggingError DllLogWarning(ResolveResString(resLOG_WARNING), ResolveResString(resLOG_DURINGACTION), strWarning), LogErrFatal
  166.     End If
  167. End Sub
  168.  
  169. '-----------------------------------------------------------
  170. ' SUB: LogNote
  171. '
  172. ' Logs a note to the logfile.  It is not necessary to have
  173. ' a current action in order to execute this subroutine.
  174. '-----------------------------------------------------------
  175. '
  176. Public Sub LogNote(ByVal strNote As String)
  177.     ShowLoggingError DllLogNote(strNote), LogErrOK
  178. End Sub
  179.  
  180. '-----------------------------------------------------------
  181. ' SUB: NewAction
  182. '
  183. ' Marks the start of a new action for logging.  If this
  184. ' routine is called before any current action is committed
  185. ' or aborted, the previous action will be placed
  186. ' on a stack.  Once the new action has been committed or
  187. ' aborted, the previous action will become active again.
  188. ' The reporting of errors, warnings, notes and action
  189. ' results are not printed until the action aborts or
  190. ' commits.
  191. ' Several actions may be stacked in a first-in-first-out
  192. ' manner by calling this routine repeatedly.
  193. '-----------------------------------------------------------
  194. '
  195. Public Sub NewAction(ByVal strKey As String, ByVal strData As String)
  196.     ShowLoggingError DllNewAction(strKey, strData), LogErrFatal
  197. End Sub
  198.  
  199. Private Sub ShowLoggingError(ByVal lErr As Long, ByVal lErrSeverity As Long)
  200.     Dim strErrMsg As String
  201.     Static fRecursive As Boolean
  202.  
  203.     Dim iRet As Integer
  204.     Dim fAbort As Boolean
  205.  
  206.     If lErr = LOGERR_SUCCESS Then
  207.         Exit Sub
  208.     End If
  209.     
  210.     If fRecursive Then
  211.         'If we're getting called recursively, we're likely
  212.         'getting errors while trying to write out errors to
  213.         'the logfile.  Nothing to do but turn off logging
  214.         'and abort setup.
  215.         DisableLogging
  216.         MsgError ResolveResString(resUNEXPECTED), vbExclamation Or vbOKOnly, gstrTitle
  217.         ExitSetup frmSetup1, gintRET_FATAL
  218.     End If
  219.  
  220.     fRecursive = True
  221.  
  222.     Select Case lErr
  223.         Case LOGERR_OUTOFMEMORY, LOGERR_WRITEERROR, LOGERR_UNEXPECTED, LOGERR_FILENOTFOUND
  224.             strErrMsg = ResolveResString(resUNEXPECTED)
  225.         Case LOGERR_INVALIDARGS, LOGERR_EXCEEDEDCAPACITY, LOGERR_NOCURRENTACTION
  226.             'Note: These errors are most likely the result of improper customization
  227.             'of this project.  Make certain that any changes you have made to these
  228.             'files are valid and bug-free.
  229.             'LOGERR_INVALIDARGS -- some parameter to a logging function was invalid or improper
  230.             'LOGERR_EXCEEDEDCAPACITY -- the stacking depth of actions has probably been
  231.             '   exceeded.  This most likely means that CommitAction or AbortAction statements
  232.             '   are missing from your code.
  233.             'LOGERR_NOCURRENTACTION -- the logging function you tried to use requires that
  234.             '   there be a current action, but there was none.  Check for a missing NewAction
  235.             '   statement.
  236.             strErrMsg = ResolveResString(resUNEXPECTED)
  237.         Case Else
  238.             strErrMsg = ResolveResString(resUNEXPECTED)
  239.     End Select
  240.  
  241.     If lErrSeverity = LogErrOK Then
  242.         ' User can select whether or not to continue
  243.         iRet = MsgFunc(strErrMsg, vbOKCancel Or vbExclamation, gstrTitle)
  244.         If gfNoUserInput Then iRet = vbCancel ' can't continue if silent install.
  245.         Select Case iRet
  246.             Case vbOK
  247.             Case vbCancel
  248.                 fAbort = True
  249.             Case Else
  250.                 fAbort = True
  251.         End Select
  252.     Else
  253.         ' Fatal
  254.         MsgFunc strErrMsg, vbOKOnly Or vbExclamation, gstrTitle
  255.         fAbort = True
  256.     End If
  257.  
  258.     If fAbort Then
  259.         ExitSetup frmCopy, gintRET_ABORT
  260.     End If
  261.  
  262.     fRecursive = False
  263. End Sub
  264.  
  265. '-----------------------------------------------------------
  266. ' FUNCTION: fWithinAction
  267. '
  268. ' Returns TRUE iff there is a current Action
  269. '-----------------------------------------------------------
  270. '
  271. Public Function fWithinAction() As Boolean
  272.     fWithinAction = (fDllWithinAction() <> 0)
  273. End Function
  274.