Skip to content

Commit 8ad9074

Browse files
Improve export/import of VBE forms
VBE form export and import is now working correctly again. We have changed the primary source file for this component to be the serialized json file, which will highlight changes much better than the form definition (which doesn't actually include any of the control layout).
1 parent 964016c commit 8ad9074

File tree

5 files changed

+65
-29
lines changed

5 files changed

+65
-29
lines changed

Version Control.accda.src/dbs-properties.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"Type": 10
4242
},
4343
"AppVersion": {
44-
"Value": "4.0.21",
44+
"Value": "4.0.22",
4545
"Type": 10
4646
},
4747
"Auto Compact": {

Version Control.accda.src/modules/clsDbVbeForm.cls

+47-26
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Implements IDbComponent
4747
Private Sub IDbComponent_Export(Optional strAlternatePath As String)
4848

4949
Dim strContent As String
50+
Dim strBasePath As String
5051
Dim strJsonPath As String
5152
Dim strFormPath As String
5253
Dim strBinaryPath As String
@@ -55,30 +56,33 @@ Private Sub IDbComponent_Export(Optional strAlternatePath As String)
5556
' Get the JSON representation of the current database object
5657
strContent = GetSource
5758

58-
' Before exporting the file, let's see if the source files exist, just in case
59-
' the database object already matches the source file.
60-
If strAlternatePath = vbNullString Then
61-
62-
' Build out all three source file paths.
63-
strJsonPath = IDbComponent_BaseFolder & GetSafeFileName(m_Form.Name) & ".json"
64-
strBinaryPath = IDbComponent_BaseFolder & GetSafeFileName(m_Form.Name) & ".frx"
65-
strFormPath = IDbComponent_BaseFolder & GetSafeFileName(m_Form.Name) & ".frm"
59+
' Build out all three normal source file paths.
60+
strBasePath = IDbComponent_BaseFolder & GetSafeFileName(m_Form.Name)
61+
strJsonPath = strBasePath & ".json"
62+
strBinaryPath = strBasePath & ".frx"
63+
strFormPath = strBasePath & ".frm"
6664

67-
' See if all three files already exist.
68-
If FSO.FileExists(strJsonPath) And FSO.FileExists(strBinaryPath) And FSO.FileExists(strFormPath) Then
69-
' If so, compare the hash of the json file to the database object.
70-
blnUnchanged = (GetStringHash(strContent, True) = GetFileHash(strJsonPath))
71-
End If
65+
' Before exporting the VBE file, let's see if the source files exist, just in case
66+
' the database object already matches the source file.
67+
If FSO.FileExists(strJsonPath) And FSO.FileExists(strBinaryPath) And FSO.FileExists(strFormPath) Then
68+
' If so, compare the hash of the json file to the database object.
69+
blnUnchanged = (GetStringHash(strContent, True) = GetFileHash(strJsonPath))
7270
End If
7371

7472
' This is the serialized output file in JSON format to track changes in version control
75-
WriteFile strContent, Nz2(strAlternatePath, IDbComponent_BaseFolder & GetSafeFileName(m_Form.Name) & ".json")
73+
' Always ouput this file during an export
74+
WriteFile strContent, strJsonPath
7675

77-
' Only export the VBE object (including binary source) if the form has changed.
76+
' Only export the VBE object (including binary source) if the form has changed
77+
' or if the VBE files are missing in the original source location
7878
If Not blnUnchanged Then
79-
80-
' This is the binary export file used when building from source
81-
m_Form.Export IDbComponent_SourceFile
79+
If Len(strAlternatePath) Then
80+
' Save to alternate path
81+
m_Form.Export SwapExtension(strAlternatePath, "frm")
82+
Else
83+
' This is the binary export file used when building from source
84+
m_Form.Export strFormPath
85+
End If
8286
End If
8387

8488
' Update index with a hash of the serialized content. (Since the binary content changes frequently)
@@ -97,17 +101,33 @@ End Sub
97101
Private Sub IDbComponent_Import(strFile As String)
98102

99103
Dim proj As VBProject
104+
Dim strTestFile As String
100105

101106
If DebugMode(True) Then On Error GoTo 0 Else On Error Resume Next
102107

103-
' Only import files with the correct extension.
104-
If Not strFile Like "*.frm" Then Exit Sub
108+
' Only import files with the correct (primary) extension.
109+
If Not strFile Like "*.json" Then Exit Sub
110+
111+
' Make sure the other two companion files also exist
112+
strTestFile = SwapExtension(strFile, "frm")
113+
If Not FSO.FileExists(strTestFile) Then
114+
Log.Error eelError, "VBE Form definition file not found: " & strTestFile, ModuleName(Me) & ".Import"
115+
Exit Sub
116+
Else
117+
' Check binary file
118+
strTestFile = SwapExtension(strFile, "frx")
119+
If Not FSO.FileExists(strTestFile) Then
120+
Log.Error eelError, "VBE Form binary file not found: " & strTestFile, ModuleName(Me) & ".Import"
121+
Exit Sub
122+
End If
123+
End If
105124

125+
' With the files verified, we can move forward with the actual import
106126
Set proj = CurrentVBProject
107127
With proj.VBComponents
108128

109-
' Import the source file
110-
.Import strFile
129+
' Import the VBE source file
130+
.Import SwapExtension(strFile, "frm")
111131

112132
' Set reference to form after import
113133
Set m_Form = .Item(GetObjectNameFromFileName(strFile))
@@ -127,8 +147,9 @@ Private Sub IDbComponent_Import(strFile As String)
127147
End With
128148

129149
' Update index (based on serialized representation)
130-
VCSIndex.Update Me, eatImport, GetDictionaryHash(GetDictionary)
150+
VCSIndex.Update Me, eatImport, GetStringHash(GetSource, True)
131151

152+
' Log any errors while importing the VBE form
132153
CatchAny eelError, "Error importing " & strFile, ModuleName(Me) & ".Import"
133154

134155
End Sub
@@ -179,8 +200,8 @@ End Sub
179200
'
180201
Private Sub IDbComponent_MoveSource(strFromFolder As String, strToFolder As String)
181202
MoveFileIfExists strFromFolder & FSO.GetFileName(IDbComponent_SourceFile), strToFolder
203+
MoveFileIfExists strFromFolder & FSO.GetBaseName(IDbComponent_SourceFile) & ".frm", strToFolder
182204
MoveFileIfExists strFromFolder & FSO.GetBaseName(IDbComponent_SourceFile) & ".frx", strToFolder
183-
MoveFileIfExists strFromFolder & FSO.GetBaseName(IDbComponent_SourceFile) & ".json", strToFolder
184205
End Sub
185206

186207

@@ -249,7 +270,7 @@ End Function
249270
'---------------------------------------------------------------------------------------
250271
'
251272
Private Function IDbComponent_GetFileList() As Dictionary
252-
If m_FileList Is Nothing Then Set m_FileList = GetFilePathsInFolder(IDbComponent_BaseFolder, "*.frm")
273+
If m_FileList Is Nothing Then Set m_FileList = GetFilePathsInFolder(IDbComponent_BaseFolder, "*.json")
253274
Set IDbComponent_GetFileList = m_FileList
254275
End Function
255276

@@ -366,7 +387,7 @@ End Property
366387
'
367388
Private Property Get IDbComponent_SourceFile() As String
368389
If m_Form Is Nothing Then Exit Property
369-
IDbComponent_SourceFile = IDbComponent_BaseFolder & GetSafeFileName(m_Form.Name) & ".frm"
390+
IDbComponent_SourceFile = IDbComponent_BaseFolder & GetSafeFileName(m_Form.Name) & ".json"
370391
End Property
371392

372393

Version Control.accda.src/modules/modFunctions.bas

+15
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,21 @@ Public Function DeDupString(strText As String, strDuplicated As String) As Strin
877877
End Function
878878

879879

880+
'---------------------------------------------------------------------------------------
881+
' Procedure : SwapExtension
882+
' Author : Adam Waller
883+
' Date : 8/9/2023
884+
' Purpose : Return the file path with a different file extension.
885+
' : I.e. c:\test.bas > c:\test.cls
886+
'---------------------------------------------------------------------------------------
887+
'
888+
Public Function SwapExtension(strFilePath As String, strNewExtension As String) As String
889+
Dim strCurrentExt As String
890+
strCurrentExt = FSO.GetExtensionName(strFilePath)
891+
SwapExtension = Left(strFilePath, Len(strFilePath) - Len(strCurrentExt)) & strNewExtension
892+
End Function
893+
894+
880895
'---------------------------------------------------------------------------------------
881896
' Procedure : LikeAny
882897
' Author : Adam Waller

Version Control.accda.src/vbe-project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"Items": {
77
"Name": "MSAccessVCS",
8-
"Description": "Version 4.0.21 deployed on 9/6/2023",
8+
"Description": "Version 4.0.22 deployed on 9/20/2023",
99
"FileName": "Version Control.accda",
1010
"HelpFile": "",
1111
"HelpContextId": 0,

Version Control.accda.src/vcs-options.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Info": {
3-
"AddinVersion": "4.0.21",
3+
"AddinVersion": "4.0.22",
44
"AccessVersion": "14.0 32-bit"
55
},
66
"Options": {

0 commit comments

Comments
 (0)