Skip to content

Commit d6cabcf

Browse files
authored
38 install access add in compile error if tlb exists and has missing interfaces (#40)
Check dll version/tlb file date + remove file if new version exists
1 parent 89c2e36 commit d6cabcf

16 files changed

+483
-39
lines changed

access-add-in/AccUnitLoader.accda

8 KB
Binary file not shown.

access-add-in/source/modules/AccUnitLoaderConfigProcedures.bas

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ Public Property Get AccUnitFileNames() As Variant()
128128
ACCUNIT_DLL_FILE, _
129129
"AccessCodeLib.Common.Tools.dll", _
130130
"AccessCodeLib.Common.VBIDETools.dll", _
131-
"AccessCodeLib.Common.VBIDETools.XmlSerializers.dll", _
132131
"Microsoft.Vbe.Interop.dll")
133-
' "Interop.VBA.dll"
132+
134133
End Property
135134

136135
Public Sub ExportAccUnitFiles(Optional ByVal lBit As Long = 0)
@@ -142,7 +141,7 @@ Public Sub ExportAccUnitFiles(Optional ByVal lBit As Long = 0)
142141
On Error GoTo HandleErr
143142

144143
If lBit = 0 Then
145-
lBit = GetCurrentAccessBitSystem
144+
lBit = GetCurrentVbaBitSystem
146145
End If
147146

148147
sBit = CStr(lBit)
@@ -172,7 +171,7 @@ Public Sub ImportAccUnitFiles(Optional ByVal lBit As Long = 0)
172171
Dim DllPath As String
173172

174173
If lBit = 0 Then
175-
lBit = GetCurrentAccessBitSystem
174+
lBit = GetCurrentVbaBitSystem
176175
End If
177176

178177
sBit = CStr(lBit)
@@ -192,16 +191,16 @@ Public Sub ImportAccUnitFiles(Optional ByVal lBit As Long = 0)
192191

193192
End Sub
194193

195-
Public Function GetCurrentAccessBitSystem() As Long
194+
Public Function GetCurrentVbaBitSystem() As Long
196195

197196
#If VBA7 Then
198197
#If Win64 Then
199-
GetCurrentAccessBitSystem = 64
198+
GetCurrentVbaBitSystem = 64
200199
#Else
201-
GetCurrentAccessBitSystem = 32
200+
GetCurrentVbaBitSystem = 32
202201
#End If
203202
#Else
204-
GetCurrentAccessBitSystem = 32
203+
GetCurrentVbaBitSystem = 32
205204
#End If
206205

207206
End Function

access-add-in/source/modules/ApplicationHandler_AppFile.cls

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ End Sub
199199
Public Function SaveAppFile(ByVal FileID As String, ByVal FileName As String, _
200200
Optional ByVal SaveVersion As Boolean = False, _
201201
Optional ByVal ExtFieldName As String, Optional ByVal ExtFieldValue As Variant, _
202-
Optional ByVal ExtFilterFieldName As String, Optional ExtFilterValue As Variant) As Boolean
202+
Optional ByVal ExtFilterFieldName As String, Optional ByVal ExtFilterValue As Variant) As Boolean
203203

204204
Dim FileNo As Integer
205205
Dim Binfile() As Byte
@@ -295,6 +295,28 @@ Private Function CreateAppFileTable() As Boolean
295295

296296
End Function
297297

298+
Public Function GetStoredAppFileVersion(ByVal FileID As String, _
299+
Optional ByVal ExtFilterFieldName As String, _
300+
Optional ByVal ExtFilterValue As Variant) As String
301+
302+
Dim SelectSql As String
303+
Dim rst As DAO.Recordset
304+
305+
SelectSql = "select version from " & TABLE_APPFILES & " where id='" & Replace(FileID, "'", "''") & "'"
306+
If Len(ExtFilterFieldName) > 0 Then
307+
SelectSql = SelectSql & " and " & ExtFilterFieldName & " = '" & Replace(ExtFilterValue, "'", "''") & "'"
308+
End If
309+
310+
Set rst = CodeDb.OpenRecordset(SelectSql, dbOpenForwardOnly)
311+
With rst
312+
If Not .EOF Then
313+
GetStoredAppFileVersion = Nz(.Fields(0).Value, vbNullString)
314+
End If
315+
.Close
316+
End With
317+
318+
End Function
319+
298320

299321
'---------------------------------------------------------------------------------------
300322
' Event handling of m_ApplicationHandler

access-add-in/source/modules/DebugPrintTestResultReporter.cls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Private Sub PrintTestDetailSummary(ByRef TestResults() As AccUnit.ITestResult)
7272
i = i + 1
7373
If TypeOf r Is AccUnit.TestResultCollection Then
7474
If i > 1 Then Debug.Print String(20, "-")
75-
Debug.Print CStr(i), r.test.FullName & ":", r.Result, "..."
75+
Debug.Print CStr(i), r.Test.FullName & ":", r.Result, "..."
7676
Debug.Print String(3, " ") & String(17, "-")
7777
PrintSubResults i, r
7878
LastTestIsRowTest = True
@@ -81,7 +81,7 @@ Private Sub PrintTestDetailSummary(ByRef TestResults() As AccUnit.ITestResult)
8181
LastTestIsRowTest = False
8282
If i > 1 Then Debug.Print String(20, "-")
8383
End If
84-
Debug.Print CStr(i), r.test.FullName & ":", r.Result, r.Message
84+
Debug.Print CStr(i), r.Test.FullName & ":", r.Result, r.Message
8585
End If
8686
Next
8787

@@ -97,10 +97,10 @@ Private Sub PrintSubResults(ByVal mainId As String, ByVal resultCol As AccUnit.T
9797
Set r = resultCol.Item(i - 1)
9898
ResultID = mainId & "." & i
9999
If TypeOf r Is AccUnit.ITestResultSummary Then
100-
Debug.Print String(3, " ") & ResultID, r.test.FullName & "-", r.Result, "..."
100+
Debug.Print String(3, " ") & ResultID, r.Test.FullName & "-", r.Result, "..."
101101
PrintSubResults ResultID, r
102102
Else
103-
Debug.Print String(3, " ") & ResultID, r.test.FullName & "-", r.Result, r.Message
103+
Debug.Print String(3, " ") & ResultID, r.Test.FullName & "-", r.Result, r.Message
104104
End If
105105
Next
106106

access-add-in/source/modules/LogFileTestResultReporter.cls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Private Sub PrintTestDetailSummary(ByRef TestResults() As AccUnit.ITestResult)
8686
i = i + 1
8787
If TypeOf r Is AccUnit.TestResultCollection Then
8888
If i > 1 Then PrintToFile String(20, "-")
89-
PrintToFile CStr(i), r.test.FullName & ":", r.Result, "..."
89+
PrintToFile CStr(i), r.Test.FullName & ":", r.Result, "..."
9090
PrintToFile String(3, " ") & String(17, "-")
9191
PrintSubResults i, r
9292
LastTestIsRowTest = True
@@ -95,7 +95,7 @@ Private Sub PrintTestDetailSummary(ByRef TestResults() As AccUnit.ITestResult)
9595
LastTestIsRowTest = False
9696
If i > 1 Then PrintToFile String(20, "-")
9797
End If
98-
PrintToFile CStr(i), r.test.FullName & ":", r.Result, r.Message
98+
PrintToFile CStr(i), r.Test.FullName & ":", r.Result, r.Message
9999
End If
100100
Next
101101

@@ -111,10 +111,10 @@ Private Sub PrintSubResults(ByVal mainId As String, ByVal resultCol As AccUnit.T
111111
Set r = resultCol.Item(i - 1)
112112
ResultID = mainId & "." & i
113113
If TypeOf r Is AccUnit.ITestResultSummary Then
114-
PrintToFile String(3, " ") & ResultID, r.test.FullName, r.Result, "..."
114+
PrintToFile String(3, " ") & ResultID, r.Test.FullName, r.Result, "..."
115115
PrintSubResults ResultID, r
116116
Else
117-
PrintToFile String(3, " ") & ResultID, r.test.FullName, r.Result, r.Message
117+
PrintToFile String(3, " ") & ResultID, r.Test.FullName, r.Result, r.Message
118118
End If
119119
Next
120120

access-add-in/source/modules/_config_Application.bas

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
Option Compare Text
1818
Option Explicit
1919

20-
'Version nummer
21-
Private Const APPLICATION_VERSION As String = "0.9.25.240313"
20+
'Version number
21+
Private Const APPLICATION_VERSION As String = "0.9.26.240316"
2222

2323
Private Const APPLICATION_NAME As String = "ACLib AccUnit Loader"
2424
Private Const APPLICATION_FULLNAME As String = "Access Code Library - AccUnit Loader"
@@ -109,8 +109,6 @@ Private Sub SetAppFiles()
109109
Next
110110
End With
111111

112-
113-
114112
End Sub
115113

116114
Public Sub PrepareForVCS()
@@ -120,3 +118,11 @@ Public Sub PrepareForVCS()
120118
End If
121119
RemoveAccUnitTlbReference
122120
End Sub
121+
122+
Private Sub Test()
123+
With New WinApiFileInfo
124+
Debug.Print VBA.FileDateTime(CodeProject.Path & "\lib\x86\AccessCodeLib.AccUnit.tlb")
125+
Debug.Print "Version:", .GetFileVersion(CodeProject.Path & "\lib\x86\AccessCodeLib.AccUnit.tlb")
126+
End With
127+
128+
End Sub

access-add-in/source/modules/modTypeLibCheck.bas

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,27 @@ Public Property Get DefaultAccUnitLibFolder() As String
2121
DefaultAccUnitLibFolder = FilePath & "lib"
2222
End Property
2323

24-
Public Sub CheckAccUnitTypeLibFile(Optional ByVal VBProjectRef As VBProject = Nothing)
24+
Public Sub CheckAccUnitTypeLibFile(Optional ByVal VBProjectRef As VBProject = Nothing, Optional ByRef ReferenceFixed As Boolean)
2525

2626
Dim LibPath As String
2727
Dim LibFile As String
28+
Dim ExportFile As Boolean
29+
Dim FileFixed As Boolean
2830

2931
LibPath = GetAccUnitLibPath(True)
3032
LibFile = LibPath & ACCUNIT_TYPELIB_FILE
3133
FileTools.CreateDirectory LibPath
3234

33-
If Not FileTools.FileExists(LibFile) Then
35+
ExportFile = Not FileTools.FileExists(LibFile)
36+
If Not ExportFile Then
37+
If Not CheckAccUnitVersion(LibFile) Then
38+
RemoveAccUnitTlbReference VBProjectRef
39+
ExportFile = True
40+
End If
41+
End If
42+
43+
If ExportFile Then
44+
FileFixed = True
3445
ExportTlbFile LibFile
3546
End If
3647

@@ -39,7 +50,9 @@ On Error Resume Next
3950
Set VBProjectRef = CodeVBProject
4051
End If
4152

42-
CheckMissingReference VBProjectRef
53+
CheckMissingReference VBProjectRef, ReferenceFixed
54+
55+
ReferenceFixed = ReferenceFixed Or FileFixed
4356

4457
End Sub
4558

@@ -75,11 +88,11 @@ End Function
7588

7689
Private Sub ExportTlbFile(ByVal LibFile As String)
7790
With CurrentApplication.Extensions(EXTENSION_KEY_APPFILE)
78-
.CreateAppFile ACCUNIT_TYPELIB_FILE, LibFile
91+
.CreateAppFile ACCUNIT_TYPELIB_FILE, LibFile, "BitInfo", CStr(GetCurrentVbaBitSystem)
7992
End With
8093
End Sub
8194

82-
Private Sub CheckMissingReference(ByVal VBProjectRef As VBProject)
95+
Private Sub CheckMissingReference(ByVal VBProjectRef As VBProject, Optional ByRef ReferenceFixed As Boolean)
8396

8497
Dim AccUnitRefExists As Boolean
8598
Dim ref As Object
@@ -102,6 +115,7 @@ On Error GoTo 0
102115
End With
103116

104117
AddAccUnitTlbReference VBProjectRef
118+
ReferenceFixed = True
105119

106120
End Sub
107121

@@ -132,3 +146,75 @@ On Error GoTo 0
132146
Next
133147

134148
End Sub
149+
150+
Private Function CheckAccUnitVersion(ByVal AccUnitTlbFilePath As String) As Boolean
151+
152+
Dim AccUnitDllPath As String
153+
154+
AccUnitDllPath = VBA.Replace(AccUnitTlbFilePath, ".tlb", ".dll")
155+
156+
If FileTools.FileExists(AccUnitDllPath) Then
157+
CheckAccUnitVersion = CheckAccUnitDllVersion(AccUnitDllPath)
158+
Exit Function
159+
End If
160+
161+
CheckAccUnitVersion = CheckAccUnitTlbVersion(AccUnitTlbFilePath)
162+
163+
End Function
164+
165+
Private Function CheckAccUnitDllVersion(ByVal AccUnitDllFilePath As String) As Boolean
166+
167+
Dim InstalledFileVersion As String
168+
Dim SourceTableFileVersion As String
169+
170+
With New WinApiFileInfo
171+
InstalledFileVersion = .GetFileVersion(AccUnitDllFilePath)
172+
End With
173+
174+
With CurrentApplication.Extensions(EXTENSION_KEY_APPFILE)
175+
SourceTableFileVersion = .GetStoredAppFileVersion(ACCUNIT_DLL_FILE, "BitInfo", VBA.CStr(GetCurrentVbaBitSystem))
176+
End With
177+
178+
CheckAccUnitDllVersion = (CompareVersions(InstalledFileVersion, SourceTableFileVersion) >= 0)
179+
180+
End Function
181+
182+
Private Function CheckAccUnitTlbVersion(ByVal AccUnitTlbFilePath As String) As Boolean
183+
184+
Dim InstalledFileVersion As String
185+
Dim SourceTableFileVersion As String
186+
187+
InstalledFileVersion = VBA.Format(VBA.FileDateTime(AccUnitTlbFilePath), "yyyy\.mm\.dd")
188+
189+
With CurrentApplication.Extensions(EXTENSION_KEY_APPFILE)
190+
SourceTableFileVersion = .GetStoredAppFileVersion(ACCUNIT_TYPELIB_FILE, "BitInfo", VBA.CStr(GetCurrentVbaBitSystem))
191+
End With
192+
193+
CheckAccUnitTlbVersion = (CompareVersions(InstalledFileVersion, SourceTableFileVersion) >= 0)
194+
195+
End Function
196+
197+
Private Function CompareVersions(ByVal Version1 As String, ByVal Version2 As String) As Long
198+
199+
Dim Version1Parts() As String
200+
Dim Version2Parts() As String
201+
Dim i As Long
202+
203+
If VBA.StrComp(Version1, Version2, vbTextCompare) = 0 Then
204+
CompareVersions = 0
205+
Exit Function
206+
End If
207+
208+
Version1Parts = VBA.Split(Version1, ".")
209+
Version2Parts = VBA.Split(Version2, ".")
210+
211+
For i = 0 To UBound(Version1Parts)
212+
If VBA.Val(Version1Parts(i)) > VBA.Val(Version2Parts(i)) Then
213+
CompareVersions = 1
214+
Exit For
215+
End If
216+
Next
217+
218+
CompareVersions = -1
219+
220+
End Function

excel-add-in/AccUnitLoader.xlam

9.05 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)