OA_Main.bas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. Option Compare Database
  2. '****
  3. '*
  4. '* Main methods for OpenAccess add-in
  5. '*
  6. '****
  7. Public Const opInterrupted = 10
  8. Public Const opCancelled = 11
  9. Public Const opCompleted = 12
  10. '>> main function, called when addin is run
  11. Public Function main()
  12. DoCmd.OpenForm "OpenAccess"
  13. End Function
  14. Public Function make_sources(Optional ByVal optimizer As Boolean = True, _
  15. Optional ByVal zip As Boolean = True) As Integer
  16. 'exports the source-code of the app
  17. On Error GoTo err
  18. Dim step As String
  19. make_sources = opInterrupted
  20. step = "Initialization"
  21. If optimizer Then
  22. Call activate_optimizer
  23. End If
  24. 'Save is needed to correctly list objects to export
  25. CurrentProject.Application.RunCommand acCmdSave
  26. If Not prompt_for_export_confirmation Then
  27. GoTo cancelOp
  28. End If
  29. If zip Then
  30. ' zip the app file
  31. step = "Zip the app file"
  32. logger "make_sources", "INFO", step
  33. Call zip_app_file
  34. End If
  35. ' run the export
  36. step = "Run VCS Export"
  37. logger "make_sources", "INFO", step
  38. Call ExportAllSource
  39. ' new sources date
  40. step = "Updates sources date"
  41. logger "make_sources", "INFO", step
  42. Call update_sources_date
  43. make_sources = opCompleted
  44. Exit Function
  45. err:
  46. MsgBox "Unknown error - " & err.Description & " (#" & err.number & ")" & vbNewLine & "See the log file for more information", vbCritical, "CRITICAL ERROR"
  47. If err.number <> "60000" Then
  48. logger "make_sources", "ERROR", "Unknown error at: " & step & " - " & err.Description & "(#" & err.number & ")"
  49. End If
  50. Call update_oa_param("sources_date", CStr(old_sources_date))
  51. Exit Function
  52. cancelOp:
  53. make_sources = opCancelled
  54. Exit Function
  55. End Function
  56. Public Function update_from_sources(Optional ByVal backup As Boolean) As Integer
  57. 'updates the application from the sources
  58. Dim backup_ok As Boolean
  59. Dim step, msg As String
  60. update_from_sources = opInterrupted
  61. If backup Then
  62. step = "Creates a backup of the app file"
  63. logger "update_from_sources", "INFO", step
  64. backup_ok = make_backup()
  65. If Not backup_ok Then
  66. logger "update_from_sources", "ERROR", "Error: unable to backup the app file, do it manually, then click OK"
  67. MsgBox "Error: unable to backup the app file, do it manually, then click OK", vbExclamation, "Backup"
  68. End If
  69. End If
  70. step = "Prompt for confirmation"
  71. If Not prompt_for_import_confirmation Then
  72. GoTo cancelOp
  73. End If
  74. step = "Run VCS Import"
  75. logger "update_from_sources", "INFO", step
  76. Call ImportAllSource
  77. step = "Cleaning obsolete objects in app"
  78. msg = CleanApp(True)
  79. If Len(msg) > 0 Then
  80. msg = "Following objects do not exist in the sources, do you want to delete them?" & vbNewLine & _
  81. "" & msg
  82. If MsgBox(msg, vbYesNo, "Cleaning") = vbYes Then
  83. Call CleanApp
  84. End If
  85. End If
  86. ' new sources date to keep the optimizer working
  87. step = "Updates sources date"
  88. logger "update_from_sources", "INFO", step
  89. Call update_sources_date
  90. update_from_sources = opCompleted
  91. Exit Function
  92. err:
  93. MsgBox "Unknown error - " & err.Description & " (#" & err.number & ")" & vbNewLine & "See the log file for more information", vbCritical, "CRITICAL ERROR"
  94. If err.number <> "60000" Then
  95. logger "update_from_sources", "CRITICAL", "Unknown error at: " & step & " - " & err.Description & "(#" & err.number & ")"
  96. End If
  97. Exit Function
  98. cancelOp:
  99. update_from_sources = opCancelled
  100. Exit Function
  101. End Function
  102. Public Function zip_app_file() As Boolean
  103. On Error GoTo UnknownErr
  104. Dim command, shortname As String
  105. zip_app_file = False
  106. shortname = Split(CurrentProject.name, ".")(0)
  107. 'run the shell comand
  108. Call cmd("cd " & CurrentProject.Path & " & " & _
  109. "zip tmp_" & shortname & ".zip " & CurrentProject.name & _
  110. " & exit")
  111. 'remove the old zip file
  112. If dir(CurrentProject.Path & "\" & shortname & ".zip") <> "" Then
  113. Kill CurrentProject.Path & "\" & shortname & ".zip"
  114. End If
  115. 'rename the temporary zip
  116. Call cmd("cd " & CurrentProject.Path & " & " & _
  117. "ren tmp_" & shortname & ".zip" & " " & shortname & ".zip" & _
  118. " & exit")
  119. logger "zip_app_file", "INFO", CurrentProject.Path & "\" & CurrentProject.name & " zipped to " & CurrentProject.Path & "\" & shortname & ".zip"
  120. zip_app_file = True
  121. end_:
  122. Exit Function
  123. UnknownErr:
  124. logger "zip_app_file", "ERROR", "Unable to zip " & CurrentProject.Path & "\" & CurrentProject.name & " - " & err.Description
  125. MsgBox "Unknown error: unable to ZIP the app file, do it manually"
  126. GoTo end_
  127. End Function
  128. Public Function make_backup() As Boolean
  129. On Error GoTo err
  130. make_backup = False
  131. If dir(CurrentProject.Path & "\" & CurrentProject.name & ".old") <> "" Then
  132. Kill CurrentProject.Path & "\" & CurrentProject.name & ".old"
  133. End If
  134. Call cmd("copy " & Chr(34) & CurrentProject.Path & "\" & CurrentProject.name & Chr(34) & _
  135. " " & Chr(34) & CurrentProject.Path & "\" & CurrentProject.name & ".old" & Chr(34))
  136. logger "make_backup", "INFO", CurrentProject.Path & "\" & CurrentProject.name & " copied to " & CurrentProject.Path & "\" & CurrentProject.name & ".old"
  137. make_backup = True
  138. Exit Function
  139. err:
  140. logger "make_backup", "ERROR", "Error during the backup of " & CurrentProject.name & ": " & err.Description
  141. MsgBox "Error during the backup of " & CurrentProject.name & ": " & err.Description & vbNewLine & "Do it manually"
  142. End Function