vcs.bas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. Option Compare Database
  2. Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal Milliseconds As LongPtr)
  3. Public Function vcsprompt()
  4. Dim prompt, prompttext, warning As String
  5. prompttext = "Write your command here:" & vbNewLine & _
  6. "> 'makesources' to create or update the source files" & vbNewLine & _
  7. "> 'update' to update the current application within the source files" & vbNewLine & _
  8. "(see docs for more commands)"
  9. prompt = InputBox(prompttext, "VCS")
  10. Select Case prompt
  11. Case "makesources"
  12. Call make_sources
  13. Case "update"
  14. Call update_from_sources
  15. Case ""
  16. MsgBox "Operation cancelled"
  17. Case Else
  18. MsgBox "Unknown command"
  19. End Select
  20. End Function
  21. Public Function make_sources()
  22. 'creates the source-code of the app
  23. Debug.Print "Zip the app file"
  24. Call zip_app_file
  25. Debug.Print "> done"
  26. Debug.Print get_include_tables
  27. Debug.Print "Run VCS Export"
  28. Call ExportAllSource
  29. Debug.Print "> done"
  30. MsgBox "Done"
  31. End Function
  32. Public Function update_from_sources()
  33. 'updates the application from the sources
  34. Debug.Print "Creates a backup of the app file"
  35. Call make_backup
  36. Debug.Print "> done"
  37. If MsgBox("WARNING: the current application is going to be updated " & _
  38. "with the source files. " & _
  39. "Any non committed work would be lost, " & _
  40. "are you sure you want to continue?" & _
  41. "", vbOKCancel) = vbCancel Then Exit Function
  42. Debug.Print "Run VCS Import"
  43. Call ImportAllSource
  44. Debug.Print "> done"
  45. MsgBox "Done"
  46. End Function
  47. Public Function config_git_repo()
  48. 'configure the application GIT repository for VCS use
  49. 'verify that it is a git repository
  50. If Dir(CurrentProject.Path & "\.git") = "" Then
  51. MsgBox "Not a git repository, please use 'git init on this directory first"
  52. Exit Function
  53. End If
  54. ' complete the gitignore file
  55. Call complete_gitignore
  56. End Function
  57. Public Function get_include_tables()
  58. get_include_tables = vcs_param("include_tables")
  59. End Function
  60. Public Function vcs_param(ByVal key As String, Optional ByVal default_value As String = "") As String
  61. vcs_param = default_value
  62. On Error GoTo err_vcs_table
  63. vcs_param = DFirst("val", "ztbl_vcs", "[key]='" & key & "'")
  64. err_vcs_table:
  65. End Function
  66. Public Function zip_app_file() As Boolean
  67. On Error GoTo err
  68. Dim command As String
  69. zip_app_file = False
  70. 'run the shell comand
  71. command = "cmd.exe /k cd " & CurrentProject.Path & " & " & _
  72. "zip tmp_" & CurrentProject.name & ".zip " & CurrentProject.name & _
  73. " & exit"
  74. Shell command, vbHide
  75. ' waits for the compression ends
  76. Dim count As Integer
  77. count = 0
  78. Do Until Dir(CurrentProject.Path & "\tmp_" & CurrentProject.name & ".zip") <> ""
  79. Sleep (0.01)
  80. count = count + 1
  81. If count > 5000 Then GoTo UnknownErr
  82. Loop
  83. 'remove the old zip file
  84. If Dir(CurrentProject.Path & "\" & CurrentProject.name & ".zip") <> "" Then
  85. Kill CurrentProject.Path & "\" & CurrentProject.name & ".zip"
  86. End If
  87. 'rename the temporary zip
  88. command = "cmd.exe /k cd " & CurrentProject.Path & " & " & _
  89. "ren tmp_" & CurrentProject.name & ".zip" & " " & CurrentProject.name & ".zip" & _
  90. " & exit"
  91. Shell command, vbHide
  92. zip_app_file = True
  93. fin:
  94. Exit Function
  95. UnknownErr:
  96. MsgBox "Unknown error: unable to ZIP the app file, do it manually"
  97. GoTo fin
  98. err:
  99. MsgBox "Error while zipping file app: " & err.Description
  100. GoTo fin
  101. End Function
  102. Public Function make_backup() As Boolean
  103. On Error GoTo err
  104. make_backup = True
  105. If Dir(CurrentProject.Path & "\" & CurrentProject.name & ".old") <> "" Then
  106. Kill CurrentProject.Path & "\" & CurrentProject.name & ".old"
  107. End If
  108. FileCopy CurrentProject.Path & "\" & CurrentProject.name, CurrentProject.Path & "\" & CurrentProject.name & ".old"
  109. make_backup = True
  110. Exit Function
  111. err:
  112. MsgBox "Error during backup:" & err.Description
  113. End Function
  114. Public Function complete_gitignore()
  115. ' creates or complete the .gitignore file of the repo
  116. Dim gitignore_path As String
  117. Dim keys() As String
  118. keys = Split("*.accdb;*.laccdb;*.mdb;*.ldb", ";")
  119. gitignore_path = CurrentProject.Path & "\.gitignore"
  120. Dim fso As Object
  121. Set fso = CreateObject("Scripting.FileSystemObject")
  122. Dim oFile As Object
  123. If Dir(gitignore_path) = "" Then
  124. Set oFile = fso.CreateTextFile(gitignore_path)
  125. Else
  126. Set oFile = fso.OpenTextFile(gitignore_path, ForAppending)
  127. End If
  128. oFile.WriteBlankLines (2)
  129. oFile.WriteLine ("#[ automatically added by VCS")
  130. For Each key In keys
  131. oFile.WriteLine key
  132. Next key
  133. oFile.WriteLine "#]"
  134. oFile.WriteBlankLines (2)
  135. oFile.Close
  136. Set fso = Nothing
  137. Set oFile = Nothing
  138. End Function