@@ -47,6 +47,7 @@ Implements IDbComponent
47
47
Private Sub IDbComponent_Export (Optional strAlternatePath As String )
48
48
49
49
Dim strContent As String
50
+ Dim strBasePath As String
50
51
Dim strJsonPath As String
51
52
Dim strFormPath As String
52
53
Dim strBinaryPath As String
@@ -55,30 +56,33 @@ Private Sub IDbComponent_Export(Optional strAlternatePath As String)
55
56
' Get the JSON representation of the current database object
56
57
strContent = GetSource
57
58
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"
66
64
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))
72
70
End If
73
71
74
72
' 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
76
75
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
78
78
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
82
86
End If
83
87
84
88
' Update index with a hash of the serialized content. (Since the binary content changes frequently)
@@ -97,17 +101,33 @@ End Sub
97
101
Private Sub IDbComponent_Import (strFile As String )
98
102
99
103
Dim proj As VBProject
104
+ Dim strTestFile As String
100
105
101
106
If DebugMode(True ) Then On Error GoTo 0 Else On Error Resume Next
102
107
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
105
124
125
+ ' With the files verified, we can move forward with the actual import
106
126
Set proj = CurrentVBProject
107
127
With proj.VBComponents
108
128
109
- ' Import the source file
110
- .Import strFile
129
+ ' Import the VBE source file
130
+ .Import SwapExtension( strFile, "frm" )
111
131
112
132
' Set reference to form after import
113
133
Set m_Form = .Item(GetObjectNameFromFileName(strFile))
@@ -127,8 +147,9 @@ Private Sub IDbComponent_Import(strFile As String)
127
147
End With
128
148
129
149
' Update index (based on serialized representation)
130
- VCSIndex.Update Me, eatImport, GetDictionaryHash(GetDictionary )
150
+ VCSIndex.Update Me, eatImport, GetStringHash(GetSource, True )
131
151
152
+ ' Log any errors while importing the VBE form
132
153
CatchAny eelError, "Error importing " & strFile, ModuleName(Me) & ".Import"
133
154
134
155
End Sub
@@ -179,8 +200,8 @@ End Sub
179
200
'
180
201
Private Sub IDbComponent_MoveSource (strFromFolder As String , strToFolder As String )
181
202
MoveFileIfExists strFromFolder & FSO.GetFileName(IDbComponent_SourceFile), strToFolder
203
+ MoveFileIfExists strFromFolder & FSO.GetBaseName(IDbComponent_SourceFile) & ".frm" , strToFolder
182
204
MoveFileIfExists strFromFolder & FSO.GetBaseName(IDbComponent_SourceFile) & ".frx" , strToFolder
183
- MoveFileIfExists strFromFolder & FSO.GetBaseName(IDbComponent_SourceFile) & ".json" , strToFolder
184
205
End Sub
185
206
186
207
@@ -249,7 +270,7 @@ End Function
249
270
'---------------------------------------------------------------------------------------
250
271
'
251
272
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 " )
253
274
Set IDbComponent_GetFileList = m_FileList
254
275
End Function
255
276
@@ -366,7 +387,7 @@ End Property
366
387
'
367
388
Private Property Get IDbComponent_SourceFile() As String
368
389
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 "
370
391
End Property
371
392
372
393
0 commit comments