OA_Main.bas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 = "Following objects do not exist in the sources, do you want to delete them?" & _
  79. "" & CleanApp(True)
  80. If MsgBox(msg, vbYesNo, "Cleaning" = vbYes) Then
  81. Call CleanApp
  82. End If
  83. ' new sources date to keep the optimizer working
  84. step = "Updates sources date"
  85. logger "update_from_sources", "INFO", step
  86. Call update_sources_date
  87. update_from_sources = opCompleted
  88. Exit Function
  89. err:
  90. MsgBox "Unknown error - " & err.Description & " (#" & err.number & ")" & vbNewLine & "See the log file for more information", vbCritical, "CRITICAL ERROR"
  91. If err.number <> "60000" Then
  92. logger "update_from_sources", "CRITICAL", "Unknown error at: " & step & " - " & err.Description & "(#" & err.number & ")"
  93. End If
  94. Exit Function
  95. cancelOp:
  96. update_from_sources = opCancelled
  97. Exit Function
  98. End Function
  99. Public Function zip_app_file() As Boolean
  100. On Error GoTo UnknownErr
  101. Dim command, shortname As String
  102. zip_app_file = False
  103. shortname = Split(CurrentProject.name, ".")(0)
  104. 'run the shell comand
  105. Call cmd("cd " & CurrentProject.Path & " & " & _
  106. "zip tmp_" & shortname & ".zip " & CurrentProject.name & _
  107. " & exit")
  108. 'remove the old zip file
  109. If dir(CurrentProject.Path & "\" & shortname & ".zip") <> "" Then
  110. Kill CurrentProject.Path & "\" & shortname & ".zip"
  111. End If
  112. 'rename the temporary zip
  113. Call cmd("cd " & CurrentProject.Path & " & " & _
  114. "ren tmp_" & shortname & ".zip" & " " & shortname & ".zip" & _
  115. " & exit")
  116. logger "zip_app_file", "INFO", CurrentProject.Path & "\" & CurrentProject.name & " zipped to " & CurrentProject.Path & "\" & shortname & ".zip"
  117. zip_app_file = True
  118. end_:
  119. Exit Function
  120. UnknownErr:
  121. logger "zip_app_file", "ERROR", "Unable to zip " & CurrentProject.Path & "\" & CurrentProject.name & " - " & err.Description
  122. MsgBox "Unknown error: unable to ZIP the app file, do it manually"
  123. GoTo end_
  124. End Function
  125. Public Function make_backup() As Boolean
  126. On Error GoTo err
  127. make_backup = False
  128. If dir(CurrentProject.Path & "\" & CurrentProject.name & ".old") <> "" Then
  129. Kill CurrentProject.Path & "\" & CurrentProject.name & ".old"
  130. End If
  131. Call cmd("copy " & Chr(34) & CurrentProject.Path & "\" & CurrentProject.name & Chr(34) & _
  132. " " & Chr(34) & CurrentProject.Path & "\" & CurrentProject.name & ".old" & Chr(34))
  133. logger "make_backup", "INFO", CurrentProject.Path & "\" & CurrentProject.name & " copied to " & CurrentProject.Path & "\" & CurrentProject.name & ".old"
  134. make_backup = True
  135. Exit Function
  136. err:
  137. logger "make_backup", "ERROR", "Error during the backup of " & CurrentProject.name & ": " & err.Description
  138. MsgBox "Error during the backup of " & CurrentProject.name & ": " & err.Description & vbNewLine & "Do it manually"
  139. End Function