home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / logging.bas < prev    next >
Encoding:
BASIC Source File  |  1995-07-26  |  11.2 KB  |  292 lines

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