VCS_Main.bas 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. Option Compare Database
  2. '****
  3. '*
  4. '* Main methods for VCS 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 vcsprompt()
  12. DoCmd.OpenForm "frm_vcs"
  13. End Function
  14. Public Function make_sources(Optional ByVal options As String = "") As Integer
  15. 'exports the source-code of the app
  16. On Error GoTo err
  17. Dim step As String
  18. make_sources = opInterrupted
  19. step = "Initialization"
  20. ' backup of the sources date, in case of error
  21. Dim old_sources_date As Date
  22. old_sources_date = vcs_param("sources_date", #1/1/1900#)
  23. '*** If '-f' is not in the options: set the optimizer on
  24. If Not InStr(options, "-f") > 0 Then
  25. Dim msg As String
  26. If old_sources_date > #1/1/1900# Then
  27. msg = msg_list_modified()
  28. If Not Len(msg) > 0 Then
  29. msg = "** VCS OPTIMIZER **" & vbNewLine & ">> Nothing new to export" & vbNewLine & _
  30. "Only the following will be exported:" & vbNewLine & _
  31. " - included table data" & vbNewLine & _
  32. " - relations" & vbNewLine & vbNewLine & _
  33. "TIP: use 'makesources -f' to force a complete export (could be long)."
  34. Else
  35. msg = "** VCS OPTIMIZER **" & vbNewLine & ">> Following objects will be exported:" & vbNewLine & msg
  36. End If
  37. Call activate_optimizer
  38. Else
  39. ' no sources date recorded, it may be the first export
  40. msg = "FIRST EXPORT: " & vbNewLine & vbNewLine & _
  41. "Everything will be exported, it could be quite long..."
  42. End If
  43. If MsgBox(msg, vbOKCancel + vbExclamation, "Export") = vbCancel Then GoTo cancelOp
  44. End If
  45. ' new sources date, before export so that date will be exported with tbl_vsc
  46. step = "Updates sources date"
  47. Debug.Print step
  48. Call update_sources_date
  49. Debug.Print "> done"
  50. ' zip the app file
  51. step = "Zip the app file"
  52. Debug.Print step
  53. Call zip_app_file
  54. Debug.Print "> done"
  55. ' run the export
  56. step = "Run VCS Export"
  57. Debug.Print step
  58. Call ExportAllSource
  59. Debug.Print "> done"
  60. make_sources = opCompleted
  61. Exit Function
  62. err:
  63. Call update_vcs_param("sources_date", CStr(old_sources_date))
  64. MsgBox "make_sources - Unknown error at: " & step & vbNewLine & err.Description, vbCritical, "Error"
  65. Exit Function
  66. cancelOp:
  67. make_sources = opCancelled
  68. Exit Function
  69. End Function
  70. Public Function update_from_sources(Optional ByVal options As String = "") As Integer
  71. 'updates the application from the sources
  72. Dim backup As Boolean
  73. Dim step, msg As String
  74. update_from_sources = opInterrupted
  75. step = "Creates a backup of the app file"
  76. Debug.Print step
  77. backup = make_backup()
  78. If backup Then
  79. Debug.Print "> done"
  80. Else
  81. MsgBox "Error: unable to backup the app file, do it manually, then click OK", vbExclamation, "Backup"
  82. End If
  83. step = "Check for unexported work"
  84. Debug.Print step
  85. msg = msg_list_modified()
  86. If Len(msg) > 0 Then
  87. msg = "** IMPORT WARNING **" & vbNewLine & _
  88. UCase(CurrentProject.name) & " is going to be updated " & _
  89. "with the source files. " & vbNewLine & vbNewLine & _
  90. "FOLLOWING NON EXPORTED WORK WILL BE LOST: " & vbNewLine & _
  91. msg & vbNewLine & _
  92. "Are you sure you want to continue?"
  93. If MsgBox(msg, vbOKCancel + vbExclamation, "Warning") = vbCancel Then GoTo cancelOp
  94. End If
  95. step = "Run VCS Import"
  96. Debug.Print step
  97. Call ImportAllSource
  98. Debug.Print "> done"
  99. update_from_sources = opCompleted
  100. Exit Function
  101. err:
  102. MsgBox "update_from_sources - Unknown error at: " & vbNewLine & step & vbNewLine & err.Description, vbCritical, "Error"
  103. Exit Function
  104. cancelOp:
  105. update_from_sources = opCancelled
  106. Exit Function
  107. End Function
  108. Public Function config_git_repo()
  109. 'configure the application GIT repository for VCS use
  110. 'verify that it is a git repository
  111. If Not is_git_repo() Then
  112. MsgBox "Not a git repository, please use 'git init on this directory first"
  113. Exit Function
  114. End If
  115. ' complete the gitignore file
  116. Call complete_gitignore
  117. End Function
  118. Public Function sync()
  119. '[experimental] complete command to synchronize this app with the distant master branch
  120. 'verify that it is a git repository
  121. If Not is_git_repo() Then
  122. MsgBox "Not a git repository, please use 'git init on this directory first"
  123. Exit Function
  124. End If
  125. 'Call make_sources
  126. Call cmd("echo --ADD FILES-- & git add *" & "& timeout 2", vbNormalFocus)
  127. Dim msg As String
  128. msg = InputBox("Commit message:", "VCS")
  129. If Not Len(msg) > 0 Then GoTo err_msg
  130. Call cmd("echo --COMMIT-- & git commit -a -m " & Chr(34) & msg & Chr(34) & "& timeout 2", vbNormalFocus)
  131. Call cmd("echo --PULL-- & git pull origin master & pause", vbNormalFocus)
  132. Call update_from_sources
  133. Call cmd("echo --PUSH-- & git push origin master" & "& timeout 2", vbNormalFocus)
  134. Exit Function
  135. err_msg:
  136. MsgBox "Invalid value", vbExclamation
  137. End Function
  138. Public Function get_include_tables()
  139. If CurrentProject.name = "VCS.accda" Then
  140. get_include_tables = "tbl_commands,modele_ztbl_vcs"
  141. Else
  142. get_include_tables = vcs_param("include_tables")
  143. End If
  144. End Function
  145. Public Function vcs_param(ByVal key As String, Optional ByVal default_value As String = "") As String
  146. vcs_param = default_value
  147. On Error GoTo err_vcs_table
  148. vcs_param = DFirst("val", "ztbl_vcs", "[key]='" & key & "'")
  149. err_vcs_table:
  150. End Function
  151. Public Function zip_app_file() As Boolean
  152. On Error GoTo err
  153. Dim command, shortname As String
  154. zip_app_file = False
  155. shortname = Split(CurrentProject.name, ".")(0)
  156. 'run the shell comand
  157. Call cmd("cd " & CurrentProject.Path & " & " & _
  158. "zip tmp_" & shortname & ".zip " & CurrentProject.name & _
  159. " & exit")
  160. 'remove the old zip file
  161. If dir(CurrentProject.Path & "\" & shortname & ".zip") <> "" Then
  162. Kill CurrentProject.Path & "\" & shortname & ".zip"
  163. End If
  164. 'rename the temporary zip
  165. Call cmd("cd " & CurrentProject.Path & " & " & _
  166. "ren tmp_" & shortname & ".zip" & " " & shortname & ".zip" & _
  167. " & exit")
  168. zip_app_file = True
  169. fin:
  170. Exit Function
  171. UnknownErr:
  172. MsgBox "Unknown error: unable to ZIP the app file, do it manually"
  173. GoTo fin
  174. err:
  175. MsgBox "Error while zipping file app: " & err.Description
  176. GoTo fin
  177. End Function
  178. Public Function make_backup() As Boolean
  179. On Error GoTo err
  180. make_backup = False
  181. If dir(CurrentProject.Path & "\" & CurrentProject.name & ".old") <> "" Then
  182. Kill CurrentProject.Path & "\" & CurrentProject.name & ".old"
  183. End If
  184. Call cmd("copy " & Chr(34) & CurrentProject.Path & "\" & CurrentProject.name & Chr(34) & _
  185. " " & Chr(34) & CurrentProject.Path & "\" & CurrentProject.name & ".old" & Chr(34))
  186. make_backup = True
  187. Exit Function
  188. err:
  189. MsgBox "Error during backup: " & err.Description
  190. End Function