OA_Main.bas 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. SaveProject
  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. ' cleans the obsolete files (see CleanDirs in optimizer)
  44. msg = CleanDirs(True)
  45. If Len(msg) > 0 Then
  46. msg = "Following objects do not exist anymore, do you want to delete treir source files?" & vbNewLine & _
  47. "" & msg
  48. If OA_MsgBox(msg, vbYesNo, "Cleaning") = vbYes Then
  49. Call CleanDirs
  50. End If
  51. End If
  52. make_sources = opCompleted
  53. Exit Function
  54. err:
  55. OA_MsgBox "Unknown error - " & err.Description & " (#" & err.Number & ")" & vbNewLine & "See the log file for more information", vbCritical, "CRITICAL ERROR"
  56. If err.Number <> "60000" Then
  57. logger "make_sources", "ERROR", "Unknown error at: " & step & " - " & err.Description & "(#" & err.Number & ")"
  58. End If
  59. Call update_oa_param("sources_date", CStr(old_sources_date))
  60. Exit Function
  61. cancelOp:
  62. make_sources = opCancelled
  63. Exit Function
  64. End Function
  65. Public Function update_from_sources(Optional ByVal backup As Boolean) As Integer
  66. 'updates the application from the sources
  67. Dim backup_ok As Boolean
  68. Dim step, msg As String
  69. update_from_sources = opInterrupted
  70. If backup Then
  71. step = "Creates a backup of the app file"
  72. logger "update_from_sources", "INFO", step
  73. backup_ok = make_backup()
  74. If Not backup_ok Then
  75. logger "update_from_sources", "ERROR", "Error: unable to backup the app file, do it manually, then click OK"
  76. OA_MsgBox "Error: unable to backup the app file, do it manually, then click OK", vbExclamation, "Backup"
  77. End If
  78. End If
  79. step = "Prompt for confirmation"
  80. If Not prompt_for_import_confirmation Then
  81. GoTo cancelOp
  82. End If
  83. step = "Run VCS Import"
  84. logger "update_from_sources", "INFO", step
  85. Call ImportAllSource
  86. step = "Cleaning obsolete objects in app"
  87. msg = CleanApp(True)
  88. If Len(msg) > 0 Then
  89. msg = "Following objects do not exist in the sources, do you want to delete them?" & vbNewLine & _
  90. "" & msg
  91. If OA_MsgBox(msg, vbYesNo, "Cleaning") = vbYes Then
  92. Call CleanApp
  93. End If
  94. End If
  95. ' new sources date to keep the optimizer working
  96. step = "Updates sources date"
  97. logger "update_from_sources", "INFO", step
  98. Call update_sources_date
  99. update_from_sources = opCompleted
  100. Exit Function
  101. err:
  102. OA_MsgBox "Unknown error - " & err.Description & " (#" & err.Number & ")" & vbNewLine & "See the log file for more information", vbCritical, "CRITICAL ERROR"
  103. If err.Number <> "60000" Then
  104. logger "update_from_sources", "CRITICAL", "Unknown error at: " & step & " - " & err.Description & "(#" & err.Number & ")"
  105. End If
  106. Exit Function
  107. cancelOp:
  108. update_from_sources = opCancelled
  109. Exit Function
  110. End Function
  111. Public Function zip_app_file() As Boolean
  112. On Error GoTo UnknownErr
  113. Dim command, shortname As String
  114. zip_app_file = False
  115. shortname = Split(CurrentProject.name, ".")(0)
  116. 'run the shell comand
  117. Call cmd("cd " & CurrentProject.path & " & " & _
  118. "zip tmp_" & shortname & ".zip " & CurrentProject.name & _
  119. " & exit")
  120. 'remove the old zip file
  121. If dir(CurrentProject.path & "\" & shortname & ".zip") <> "" Then
  122. Kill CurrentProject.path & "\" & shortname & ".zip"
  123. End If
  124. 'rename the temporary zip
  125. Call cmd("cd " & CurrentProject.path & " & " & _
  126. "ren tmp_" & shortname & ".zip" & " " & shortname & ".zip" & _
  127. " & exit")
  128. logger "zip_app_file", "INFO", CurrentProject.path & "\" & CurrentProject.name & " zipped to " & CurrentProject.path & "\" & shortname & ".zip"
  129. zip_app_file = True
  130. end_:
  131. Exit Function
  132. UnknownErr:
  133. logger "zip_app_file", "ERROR", "Unable to zip " & CurrentProject.path & "\" & CurrentProject.name & " - " & err.Description
  134. OA_MsgBox "Unknown error: unable to ZIP the app file, do it manually"
  135. GoTo end_
  136. End Function
  137. Public Function make_backup() As Boolean
  138. On Error GoTo err
  139. make_backup = False
  140. If dir(CurrentProject.path & "\" & CurrentProject.name & ".old") <> "" Then
  141. Kill CurrentProject.path & "\" & CurrentProject.name & ".old"
  142. End If
  143. Call cmd("copy " & Chr(34) & CurrentProject.path & "\" & CurrentProject.name & Chr(34) & _
  144. " " & Chr(34) & CurrentProject.path & "\" & CurrentProject.name & ".old" & Chr(34))
  145. logger "make_backup", "INFO", CurrentProject.path & "\" & CurrentProject.name & " copied to " & CurrentProject.path & "\" & CurrentProject.name & ".old"
  146. make_backup = True
  147. Exit Function
  148. err:
  149. logger "make_backup", "ERROR", "Error during the backup of " & CurrentProject.name & ": " & err.Description
  150. OA_MsgBox "Error during the backup of " & CurrentProject.name & ": " & err.Description & vbNewLine & "Do it manually"
  151. End Function
  152. Public Function silent_export()
  153. 'used for tests
  154. OA_Msg.activate_SilentMode
  155. OA_Log.set_debug_mode
  156. Dim result As Variant
  157. result = make_sources(optimizer:=False, zip:=True)
  158. logger "silent_export", "INFO", "make_sources returned " & result
  159. End Function
  160. Public Function silent_import()
  161. 'used for tests
  162. OA_Msg.activate_SilentMode
  163. OA_Log.set_debug_mode
  164. Dim result As Variant
  165. result = update_from_sources(backup:=True)
  166. logger "silent_export", "INFO", "update_from_sources returned " & result
  167. End Function