-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathACLibFileManager.cls
More file actions
1885 lines (1469 loc) · 59.4 KB
/
ACLibFileManager.cls
File metadata and controls
1885 lines (1469 loc) · 59.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "ACLibFileManager"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Description = "Import/Export der Access-Objekte in/aus lokaler Code-Bibliothek"
'---------------------------------------------------------------------------------------
' Class: ACLibFileManager
'---------------------------------------------------------------------------------------
'
' Import/export of Access objects to/from local code library
'
' Author:
' Josef Poetzl
'
' Remarks:
'---------------------------------------------------------------------------------------
'| In m_ImportFileCollection an array is used for storage
'| (0) - File object
'| (1) - Import mod
'| Reason: Type could not be used and an extra class is (still) too cumbersome
'---------------------------------------------------------------------------------------
'
Option Compare Text
Option Explicit
Private Const EXTENSION_KEY As String = "ACLibFileManager"
' Integrated extensions
Private Const EXTENSION_KEY_ACLIBCONFIG As String = "ACLibConfiguration"
Private Const EXTENSION_PROPNAME_LOCALREPOSITORYROOT As String = "LocalRepositoryRoot"
Private Const EXTENSION_PROPNAME_PRIVATEREPOSITORYROOT As String = "PrivateRepositoryRoot"
#Const DEBUGMODE = 0
#Const EARLYBINDING = 0
#If EARLYBINDING = 1 Then
Private m_CurrentVbProject As VBIDE.VBProject
#Else
Private m_CurrentVbProject As Object
#End If
Private Const SEARCHSTRING_CODELIB_BEGIN As String = "<codelib>"
Private Const SEARCHSTRING_CODELIB_END As String = "</codelib>"
Private Const SEARCHSTRING_FILE_BEGIN As String = "<file>"
Private Const SEARCHSTRING_FILE_END As String = "</file>"
Private Const SEARCHSTRING_PACKAGE_BEGIN As String = "<package>"
Private Const SEARCHSTRING_PACKAGE_END As String = "</package>"
Private Const SEARCHSTRING_LICENSE_BEGIN As String = "<license>"
Private Const SEARCHSTRING_LICENSE_END As String = "</license>"
Private Const SEARCHSTRING_DESCRIPTION_BEGIN As String = "<description>"
Private Const SEARCHSTRING_DESCRIPTION_END As String = "</description>"
Private Const SEARCHSTRING_USE_BEGIN As String = "<use>"
Private Const SEARCHSTRING_USE_END As String = "</use>"
Private Const SEARCHSTRING_REF_BEGIN As String = "<ref>"
Private Const SEARCHSTRING_REF_END As String = "</ref>"
Private Const SEARCHSTRING_REF_NAME_BEGIN As String = "<name>"
Private Const SEARCHSTRING_REF_NAME_END As String = "</name>"
Private Const SEARCHSTRING_REF_MAJOR_BEGIN As String = "<major>"
Private Const SEARCHSTRING_REF_MAJOR_END As String = "</major>"
Private Const SEARCHSTRING_REF_MINOR_BEGIN As String = "<minor>"
Private Const SEARCHSTRING_REF_MINOR_END As String = "</minor>"
Private Const SEARCHSTRING_REF_GUID_BEGIN As String = "<guid>"
Private Const SEARCHSTRING_REF_GUID_END As String = "</guid>"
Private Const SEARCHSTRING_TEST_BEGIN As String = "<test>"
Private Const SEARCHSTRING_TEST_END As String = "</test>"
Private Const SEARCHSTRING_EXAMPLE_BEGIN As String = "<example>"
Private Const SEARCHSTRING_EXAMPLE_END As String = "</example>"
Private Const SEARCHSTRING_EXECUTE_BEGIN As String = "<execute>"
Private Const SEARCHSTRING_EXECUTE_END As String = "</execute>"
Private Const SEARCHSTRING_REPLACE_BEGIN As String = "<replace>"
Private Const SEARCHSTRING_REPLACE_END As String = "</replace>"
Private Const SEARCHSTRING_ATTRIBUTNAME_BEGIN As String = "Attribute VB_Name = """
Private Const SEARCHSTRING_ATTRIBUTNAME_END As String = """"
Private Const SEARCHSTRING_FORMIDENTIFER As String = "BEGIN FORM"
Private Const SEARCHSTRING_REPORTIDENTIFER As String = "Begin Report"
Private Const MODULNAME_CONFIG_APPLICATION As String = "_config_Application"
Private Const REPOSTITORY_ROOT_CODE_WithoutCodeLibInfoExportFolder As String = "source"
Private Const REPOSTITORY_ROOT_CODE_APPLICATIONROOT As String = "%AppFolder%"
Private Const REPOSTITORY_ROOT_CODE_PRIVATEROOT As String = "%PrivateRoot%"
Private Const REPOSTITORY_ROOT_CODE_GITHUBROOT As String = "%GitHub%"
Private m_ImportFileCollection As Collection
Private m_ReplacedFilesCollection As Collection
Private m_CLI As CodeLibInfo
#If EARLYBINDING = 1 Then
Private m_FSO As FileSystemObject
#Else
Private m_FSO As Object
'Private Const ForReading As Long = 1
#End If
'
Private m_LocalRepositoryRootDirectory As String ' Local root directory for repository export to CodeLib
Private m_PrivateRepositoryRootDirectory As String ' Local root directory for private repository export
Private m_ExportAllToApplicationSourceFolder As Boolean
' Events
Public Event PropertyMissingLocalRepositoryRootDirectory(ByRef NewValue As String)
Public Event MissingLocalRepositoryFile(ByVal ACLibPath As String, ByVal FullFilePath As String)
Public Event ImportRepositoryFile(ByVal ObjectName As String, ByVal RepositoryFile As String, _
ByVal ElementType As CodeLibElementType, ByRef Dependency As Variant, _
ByRef ImportFile As Object, ByRef Cancel As Integer)
'---------------------------------------------------------------------------------------
' Standard initialization of extensions
'---------------------------------------------------------------------------------------
Private WithEvents m_ApplicationHandler As ApplicationHandler
Attribute m_ApplicationHandler.VB_VarHelpID = -1
Public Property Set ApplicationHandlerRef(ByRef ObjRef As Object) ' as ApplicationHandler
Set m_ApplicationHandler = ObjRef
End Property
Public Property Get ExtensionKey() As String
ExtensionKey = EXTENSION_KEY
End Property
Private Sub Class_Terminate()
Dispose
End Sub
'---------------------------------------------------------------------------------------
' Standard event handling of extensions
'---------------------------------------------------------------------------------------
' CheckExtension
Private Sub m_ApplicationHandler_CheckExtension(ByVal ExtensionKeyToCheck As String, ByRef Exists As Boolean)
If ExtensionKeyToCheck = EXTENSION_KEY Then Exists = True
End Sub
' ExtensionLookup
Private Sub m_ApplicationHandler_ExtensionLookup(ByVal ExtensionKeyToCheck As String, ByRef ExtensionReference As Object)
If ExtensionKeyToCheck = EXTENSION_KEY Then
Set ExtensionReference = Me
End If
End Sub
'ExtensionPropertyLookup
Private Sub m_ApplicationHandler_ExtensionPropertyLookup( _
ByVal ExtensionKeyToCheck As String, ByVal PropertyName As String, _
ByRef ResumeMode As ApplicationHandlerResumeModes, ByRef ResumeMessage As Variant)
If ExtensionKeyToCheck = EXTENSION_KEY Then
GetExtensionPropertyLookup PropertyName, ResumeMode, ResumeMessage
End If
End Sub
' AfterDispose
Private Sub m_ApplicationHandler_AfterDispose(ByRef ResumeMode As ApplicationHandlerResumeModes, _
ByRef ResumeMessage As Variant)
Set m_ApplicationHandler = Nothing
End Sub
'---------------------------------------------------------------------------------------
' Additions for extension: ACLibFileManager
'---------------------------------------------------------------------------------------
Private Sub GetExtensionPropertyLookup(ByVal PropertyName As String, _
ByRef ResumeMode As ApplicationHandlerResumeModes, _
ByRef ResumeMessage As Variant)
ResumeMode = AppResumeMode_Completed
Select Case PropertyName
Case Else 'Property was not recognized
ResumeMode = AppResumeMode_Error
ResumeMessage = "Property '" & PropertyName & "' is not supported"
End Select
End Sub
Private Sub Dispose()
On Error Resume Next
RemoveTempFiles
Set m_ImportFileCollection = Nothing
Set m_FSO = Nothing
Set m_CurrentVbProject = Nothing
End Sub
Private Sub RemoveTempFiles()
If FileTools.DirExists(GitHubTempRepositoryPath) Then
CreateObject("Scripting.FileSystemObject").DeleteFolder GitHubTempRepositoryPath, True
End If
End Sub
Public Property Let ExportAllToApplicationSourceFolder(ByVal NewValue As Boolean)
m_ExportAllToApplicationSourceFolder = NewValue
End Property
Public Sub ExportAll()
Dim ExportComponentsWithoutCodeLibInfo As Boolean
ExportComponentsWithoutCodeLibInfo = m_ExportAllToApplicationSourceFolder
ExportAllModules ExportComponentsWithoutCodeLibInfo
ExportAllForms
ExportAllReports
End Sub
Public Sub ExportAllModules(Optional ExportComponentsWithoutCodeLibInfo As Boolean = False)
Dim ao As AccessObject
ActivateCurrentProject
DoCmd.RunCommand acCmdCompileAndSaveAllModules
For Each ao In CurrentProject.AllModules
ExportVbComponent ao.Name, ExportComponentsWithoutCodeLibInfo
Next
#If DEBUGMODE Then
Debug.Print "Module export completed"
#End If
End Sub
Public Sub ExportAllForms()
Dim ao As AccessObject
ActivateCurrentProject
DoCmd.RunCommand acCmdCompileAndSaveAllModules
For Each ao In CurrentProject.AllForms
ExportAccessObject AcObjectType.acForm, ao.Name
Next
#If DEBUGMODE Then
Debug.Print "Form export completed"
#End If
End Sub
Public Sub ExportAllReports()
Dim ao As AccessObject
ActivateCurrentProject
DoCmd.RunCommand acCmdCompileAndSaveAllModules
For Each ao In CurrentProject.AllReports
ExportAccessObject AcObjectType.acReport, ao.Name
Next
#If DEBUGMODE Then
Debug.Print "Bericht-Export abgeschlossen"
#End If
End Sub
Public Sub ImportAllFilesFromRepository(Optional ByVal ImportMode As CodeLibImportMode = clim_ImportMissingItems, _
Optional ByVal ImportTestFiles As Boolean = False, _
Optional ByVal ImportExampleFiles As Boolean = False)
Dim FolderCol As Collection
#If EARLYBINDING Then
Dim CheckFolder As Folder
Dim TempFolder As Folder
Dim TempFile As File
#Else
Dim CheckFolder As Object
Dim TempFolder As Object
Dim TempFile As Object
#End If
Set FolderCol = New Collection
Set m_ImportFileCollection = New Collection
Set TempFolder = fso.GetFolder(LocalRepositoryRootDirectory)
FolderCol.Add TempFolder, TempFolder.Path
Do While FolderCol.Count > 0
Set CheckFolder = FolderCol(1)
For Each TempFile In CheckFolder.Files
If Not IgnoreFile(TempFile) Then
AddMissingFile TempFile, ImportMode
End If
Next
For Each TempFolder In CheckFolder.SubFolders
If Not IgnoreFolder(TempFolder) Then
FolderCol.Add TempFolder, TempFolder.Path
End If
Next
FolderCol.Remove 1
Loop
Set TempFile = Nothing
Set FolderCol = Nothing
ImportFilesFromImportCollection True, ImportTestFiles, ImportExampleFiles
End Sub
Public Sub ImportRepositoryFile(ByVal RepositoryPath As String, _
Optional ByVal ImportMode As CodeLibImportMode = clim_ImportMissingItems, _
Optional ByVal ImportTestFiles As Boolean = False, _
Optional ByVal ImportExampleFiles As Boolean = False)
Dim PathString As String
PathString = GetRepositoryFullPath(RepositoryPath)
Dim TempFile As Object
Set TempFile = fso.GetFile(PathString)
AddMissingFile TempFile, ImportMode
Set TempFile = Nothing
ImportFilesFromImportCollection True, ImportTestFiles, ImportExampleFiles
End Sub
Public Sub ImportRepositoryFiles(ByRef RepositoryPathArray() As String, _
Optional ByVal ImportMode As CodeLibImportMode = clim_ImportMissingItems, _
Optional ByVal ImportTestFiles As Boolean = False, _
Optional ByVal ImportExampleFiles As Boolean = False)
Dim ArraySize As Long
Dim i As Long
Dim PathString As String
Dim TempFile As Object
Dim DownloadBase As String
ArraySize = UBound(RepositoryPathArray)
For i = LBound(RepositoryPathArray) To ArraySize - 1
DownloadBase = vbNullString
PathString = GetRepositoryFullPath(RepositoryPathArray(i), DownloadBase)
Set TempFile = fso.GetFile(PathString)
AddMissingFile TempFile, ImportMode, DownloadBase
Next
Set TempFile = Nothing
ImportFilesFromImportCollection True, ImportTestFiles, ImportExampleFiles
End Sub
Private Sub ImportFilesFromImportCollection( _
Optional ByRef CompileAfterImport As Boolean = True, _
Optional ByVal ImportTestFiles As Boolean = False, _
Optional ByVal ImportExampleFiles As Boolean = False)
Dim TempFile As Object
Dim FileImportMode As CodeLibImportMode
Dim DownloadBase As String
Dim i As Long
Dim MaxCnt As Long
Dim ColItem As Variant
' Activate a VB module from CurrentVbProject,
' otherwise RunCommand acCmdCompileAndSaveAllModules may work in the wrong VBProject.
' (For safety with On error resume next, because it is not absolutely necessary and does not disturb the flow.)
On Error Resume Next
ActivateCurrentProject
On Error GoTo 0
If CurrentProject.AllModules.Count > 0 Then
DoCmd.RunCommand acCmdCompileAndSaveAllModules
End If
MaxCnt = m_ImportFileCollection.Count
'/*
' * TODO: Determination of the number of all files (incl. dependencies) before the import
' * TODO: Conversion AccessProgressBar to single pass (Init only once)
' */
i = 1
Do While i <= MaxCnt
ColItem = m_ImportFileCollection(i)
Set TempFile = ColItem(0)
FileImportMode = ColItem(1)
DownloadBase = ColItem(2)
AccessProgressBar.Init "Importiere " & TempFile & "...", 2, 1
AccessProgressBar.PerformStep
ImportFile TempFile, FileImportMode, ImportTestFiles, ImportExampleFiles, DownloadBase
AccessProgressBar.PerformStep
MaxCnt = m_ImportFileCollection.Count
i = i + 1
Loop
If CompileAfterImport Then
ActivateCurrentProject
CurrentProject.Application.DoCmd.RunCommand acCmdCompileAndSaveAllModules
End If
'Run Executes
If (0 / 1) + (Not Not m_CLI.ExecuteList) Then
AccessProgressBar.Init "Run executes ...", UBound(m_CLI.ExecuteList) + 1, 1
For i = 0 To UBound(m_CLI.ExecuteList)
AccessProgressBar.PerformStep
If StringTools.Contains(m_CLI.ExecuteList(i), REPOSTITORY_ROOT_CODE_PRIVATEROOT) Then
Eval VBA.Strings.Replace(m_CLI.ExecuteList(i), REPOSTITORY_ROOT_CODE_PRIVATEROOT, LocalRepositoryRootDirectory())
Else
Eval (m_CLI.ExecuteList(i))
End If
Next
If AccessProgressBar.IsInitialized Then AccessProgressBar.Clear
End If
'Clean up module variables, since import process is completed at this point
Set m_ImportFileCollection = Nothing
Set m_ReplacedFilesCollection = Nothing
Set m_FSO = Nothing
#If DEBUGMODE Then
Debug.Print "Import abgeschlossen"
#End If
End Sub
Private Function IgnoreFolder(ByRef TestFolder As Object) As Boolean
'/*
' * @todo Make exclusion list for directories more flexible
'**/
Select Case TestFolder.Name
Case ".svn", "_codelib"
IgnoreFolder = True
Case Else
'
End Select
End Function
Private Function IgnoreFile(ByRef TestFile As Object) As Boolean
'/*
' * @todo Make exclusion list for files more flexible
'**/
Select Case TestFile.Name
Case "_info.txt", "_config_Application.bas"
IgnoreFile = True
Case Else
'
End Select
End Function
#If EARLYBINDING Then
Public Property Get CurrentVbProject() As VBIDE.VBProject
#Else
Public Property Get CurrentVbProject() As Object
#End If
#If EARLYBINDING Then
Dim Proj As VBProject
#Else
Dim Proj As Object
#End If
Dim CurrentDbName As String
If m_CurrentVbProject Is Nothing Then
Set m_CurrentVbProject = VBE.ActiveVBProject
'Check if the correct VbProject is selected (must be the one from CurrentDb):
CurrentDbName = UncPath(CurrentDb.Name)
If m_CurrentVbProject.FileName <> CurrentDbName Then
Set m_CurrentVbProject = Nothing
For Each Proj In VBE.VBProjects
If Proj.FileName = CurrentDbName Then
Set m_CurrentVbProject = Proj
Exit For
End If
Next
End If
End If
Set CurrentVbProject = m_CurrentVbProject
End Property
Private Sub ActivateCurrentProject()
Dim Activated As Boolean
#If EARLYBINDING Then
Dim vbc As VBComponent
#Else
Dim vbc As Object
#End If
If CurrentVbProject.VBComponents.Count > 0 Then
'first use only code modules, otherwise forms/reports will be opened in the draft
For Each vbc In CurrentVbProject.VBComponents
If vbc.Type <> vbext_ct_Document Then
vbc.Activate
Activated = True
Exit For
End If
Next
'if there are only vbext_ct_Document, use the first one
If Not Activated Then
CurrentVbProject.VBComponents(1).Activate
End If
End If
End Sub
#If EARLYBINDING Then
Private Property Get fso() As FileSystemObject
#Else
Private Property Get fso() As Object
#End If
If m_FSO Is Nothing Then
'Set m_FSO = New FileSystemObject
Set m_FSO = CreateObject("Scripting.FileSystemObject")
End If
Set fso = m_FSO
End Property
Private Property Get CurrentFileCollection() As Collection
If m_ImportFileCollection Is Nothing Then
Set m_ImportFileCollection = New Collection
End If
Set CurrentFileCollection = m_ImportFileCollection
End Property
Private Property Get CurrentReplacedFilesCollection() As Collection
If m_ReplacedFilesCollection Is Nothing Then
Set m_ReplacedFilesCollection = New Collection
End If
Set CurrentReplacedFilesCollection = m_ReplacedFilesCollection
End Property
Private Sub AddReplacedFilePath(ByVal RepFilePath As String)
Dim TempFile As Object
Dim TempFilePath As Variant
Dim i As Long
Dim MaxCount As Long
Dim col As Collection
MaxCount = CurrentFileCollection.Count
For i = 1 To MaxCount
'tempFile = varfileColItem(0) =>
'varfilColItem = m_ImportFileCollection(i) =>
Set TempFile = m_ImportFileCollection(i)(0)
If TempFile.Path = RepFilePath Then
m_ImportFileCollection.Remove TempFile.Path
Exit For
End If
Next
Set TempFile = Nothing
Set col = CurrentReplacedFilesCollection
For Each TempFilePath In col
If TempFilePath = RepFilePath Then
Exit Sub
End If
Next
CurrentReplacedFilesCollection.Add CVar(RepFilePath), RepFilePath
End Sub
Private Function IsReplacedFile(ByRef RepFile As Object) As Boolean
Dim TempFile As Variant
For Each TempFile In CurrentReplacedFilesCollection
If TempFile = RepFile.Path Then
IsReplacedFile = True
Exit Function
End If
Next
End Function
Private Property Get LocalRepositoryRootDirectory() As String
If Len(m_LocalRepositoryRootDirectory) = 0 Then
RaiseEvent PropertyMissingLocalRepositoryRootDirectory(m_LocalRepositoryRootDirectory)
If Len(m_LocalRepositoryRootDirectory) = 0 Then
m_LocalRepositoryRootDirectory = CurrentApplication.GetExtensionProperty(EXTENSION_KEY_ACLIBCONFIG, EXTENSION_PROPNAME_LOCALREPOSITORYROOT, vbNullString)
End If
End If
LocalRepositoryRootDirectory = m_LocalRepositoryRootDirectory
End Property
Private Property Let LocalRepositoryRootDirectory(ByVal LocalPath As String)
If Right$(LocalPath, 1) <> "\" Then
LocalPath = LocalPath & "\"
End If
m_LocalRepositoryRootDirectory = LocalPath
End Property
Private Property Get PrivateRepositoryRootDirectory() As String
If Len(m_PrivateRepositoryRootDirectory) = 0 Then
RaiseEvent PropertyMissingLocalRepositoryRootDirectory(m_PrivateRepositoryRootDirectory)
If Len(m_PrivateRepositoryRootDirectory) = 0 Then
m_PrivateRepositoryRootDirectory = CurrentApplication.GetExtensionProperty(EXTENSION_KEY_ACLIBCONFIG, EXTENSION_PROPNAME_PRIVATEREPOSITORYROOT, vbNullString)
End If
End If
PrivateRepositoryRootDirectory = m_PrivateRepositoryRootDirectory
End Property
Private Property Let PrivateRepositoryRootDirectory(ByVal PrivatePath As String)
If Right$(PrivatePath, 1) <> "\" Then
PrivatePath = PrivatePath & "\"
End If
m_PrivateRepositoryRootDirectory = PrivatePath
End Property
Public Function GetRepositoryFullPath(ByVal ReleativPath As String, Optional ByRef DownloadBase As String) As String
Dim RepPath As String
Dim FullPath As String
ReleativPath = Replace(ReleativPath, "/", "\")
If Left(ReleativPath, Len(REPOSTITORY_ROOT_CODE_APPLICATIONROOT)) = REPOSTITORY_ROOT_CODE_APPLICATIONROOT Then
RepPath = CurrentProject.Path & "\"
ReleativPath = Mid$(ReleativPath, Len(REPOSTITORY_ROOT_CODE_APPLICATIONROOT) + 1)
ElseIf Left(ReleativPath, Len(REPOSTITORY_ROOT_CODE_PRIVATEROOT)) = REPOSTITORY_ROOT_CODE_PRIVATEROOT Then
RepPath = PrivateRepositoryRootDirectory
If Len(RepPath) = 0 Then
Err.Raise vbObjectError, "getRepositoryFullPath", "Wert für privates Root-Verzeichnis fehlt (PrivateRepositoryRootDirectory = '')."
Exit Function
End If
ReleativPath = Mid$(ReleativPath, Len(REPOSTITORY_ROOT_CODE_PRIVATEROOT) + 1)
ElseIf Left(ReleativPath, Len(REPOSTITORY_ROOT_CODE_GITHUBROOT)) = REPOSTITORY_ROOT_CODE_GITHUBROOT Then
' %GITHUB%\owner\repo@branch\Path
ReleativPath = Replace(ReleativPath, "\", "/")
If Not DownLoadFromGitHub(ReleativPath, RepPath, DownloadBase) Then
Err.Raise vbObjectError, "getRepositoryFullPath", "Download aus GitHub ist fehlgeschlagen"
Exit Function
End If
If Len(RepPath) = 0 Then
Err.Raise vbObjectError, "getRepositoryFullPath", "Wert für lokales GitHub-Temp-Verzeichnis fehlt."
Exit Function
End If
ElseIf Len(DownloadBase) > 0 Then
' %GITHUB%\owner\repo@branch\Path
ReleativPath = Replace(ReleativPath, "/", "\")
If Not DownLoadFromGitHub(ReleativPath, RepPath, DownloadBase) Then
Err.Raise vbObjectError, "getRepositoryFullPath", "Download aus GitHub ist fehlgeschlagen"
Exit Function
End If
If Len(RepPath) = 0 Then
Err.Raise vbObjectError, "getRepositoryFullPath", "Wert für lokales GitHub-Temp-Verzeichnis fehlt."
Exit Function
End If
Else
If m_ExportAllToApplicationSourceFolder Then
RepPath = CurrentProject.Path & "\source\codelib\"
Else
RepPath = LocalRepositoryRootDirectory
End If
If Len(RepPath) = 0 Then
Err.Raise vbObjectError, "getRepositoryFullPath", "Wert für lokales Root-Verzeichnis fehlt (LocalRepositoryRootDirectory = '')."
Exit Function
End If
End If
Do While Left$(ReleativPath, 1) = "\"
ReleativPath = Mid$(ReleativPath, 2)
Loop
FullPath = RepPath & ReleativPath
If Len(VBA.Dir(FullPath)) = 0 Then
RaiseEvent MissingLocalRepositoryFile(ReleativPath, FullPath)
End If
GetRepositoryFullPath = FullPath
End Function
Private Function DownLoadFromGitHub(ByRef ReleativPath As String, ByRef RepPath As String, ByRef DownloadBase As String) As Boolean
' %GITHUB%/owner/repo@branch/Path
Dim FullFilePath As String
Dim GitHubDataCutPos As Long
Dim GitHubUrlDataString As String
Dim GitHubPath As String
Dim GitHubUrlData() As String
Dim RelativeFileUrl As String
If Len(DownloadBase) > 0 And InStr(1, ReleativPath, REPOSTITORY_ROOT_CODE_GITHUBROOT) = 0 Then
GitHubUrlDataString = DownloadBase
ReleativPath = Replace(ReleativPath, "/", "\")
If Left(ReleativPath, 1) = "\" Then
ReleativPath = Mid(ReleativPath, 2)
End If
RelativeFileUrl = Replace(ReleativPath, "\", "/")
Else
'%GITHUB%/owner/repo@branch/Path
GitHubPath = Mid(Replace(ReleativPath, "\", "/"), Len(REPOSTITORY_ROOT_CODE_GITHUBROOT) + 2)
GitHubDataCutPos = InStr(InStr(1, GitHubPath, "@") + 1, GitHubPath, "/")
GitHubUrlDataString = Left(GitHubPath, GitHubDataCutPos - 1)
RelativeFileUrl = Mid(GitHubPath, GitHubDataCutPos + 1)
ReleativPath = Replace(RelativeFileUrl, "/", "\")
GitHubUrlDataString = Replace(GitHubUrlDataString, "@", "/")
DownloadBase = GitHubUrlDataString
End If
GitHubUrlData = Split(GitHubUrlDataString, "/")
RepPath = GitHubTempRepositoryPath & "\" & Replace(GitHubUrlDataString, "/", "\") & "\"
FullFilePath = RepPath & ReleativPath
If Not FileTools.FileExists(FullFilePath) Then
With New ACLibGitHubImporter
.RepositoryOwner = GitHubUrlData(0)
.RepositoryName = GitHubUrlData(1)
.BranchName = GitHubUrlData(2)
CreateDirectoryIfMissing FileTools.PathFromFullFileName(FullFilePath)
.DownloadACLibFileFromWeb RelativeFileUrl, FullFilePath
End With
End If
DownLoadFromGitHub = True
End Function
Private Property Get GitHubTempRepositoryPath() As String
GitHubTempRepositoryPath = FileTools.TempPath & "ACLibTempRepo"
End Property
Private Sub ImportFile(ByRef ImportFile As Object, ByRef ImportMode As CodeLibImportMode, _
Optional ByVal ImportTestFiles As Boolean = False, Optional ByRef ImportExampleFiles As Boolean = False, _
Optional ByVal DownloadBase As String)
Dim i As Long
Dim TempFile As Object
Dim FilePath As String
Dim CancelImport As Integer
GetCodeLibInfoFromFile m_CLI, ImportFile, (ImportMode <> clim_ImportSelectedOnly)
If Len(m_CLI.RepositoryFileReplacement) > 0 Then
AddReplacedFilePath GetRepositoryFullPath(m_CLI.RepositoryFileReplacement)
End If
If Len(DownloadBase) > 0 Then
m_CLI.ForceRemoveIfExists = True
End If
'Enable abort
RaiseEvent ImportRepositoryFile(m_CLI.Name, m_CLI.RepositoryFile, m_CLI.Type, m_CLI.Dependency, ImportFile, CancelImport)
If CancelImport Then
Exit Sub
End If
'License (LICENSE block)
If Len(m_CLI.LicenseFile) > 0 Then
FilePath = GetRepositoryFullPath(m_CLI.LicenseFile, DownloadBase)
Set TempFile = fso.GetFile(FilePath)
AddMissingFile TempFile, clim_ImportMissingItems, DownloadBase
End If
'Required modules (USE block)
If ImportMode <> clim_ImportSelectedOnly Then
If (0 / 1) + (Not Not m_CLI.Dependency) Then
For i = 0 To UBound(m_CLI.Dependency)
FilePath = GetRepositoryFullPath(m_CLI.Dependency(i), DownloadBase)
If fso.FileExists(FilePath) Then
Set TempFile = fso.GetFile(FilePath)
AddMissingFile TempFile, ImportMode, DownloadBase
End If
Next
End If
End If
'First references
If (0 / 1) + (Not Not m_CLI.References) Then
For i = 0 To UBound(m_CLI.References)
AddMissingReference m_CLI.References(i)
Next
End If
'then code module
Select Case m_CLI.Type
Case CodeLibElementType.clet_ClassModule, CodeLibElementType.clet_StdModule
ImportVbComponent m_CLI, ImportFile, ImportMode
Case CodeLibElementType.clet_Form
ImportAccessObject acForm, m_CLI, ImportFile, ImportMode
Case CodeLibElementType.clet_Report
ImportAccessObject acReport, m_CLI, ImportFile, ImportMode
Case CodeLibElementType.clet_Package
' don't import package file
Case Else
' eventuell Fehler auslösen?
End Select
'possibly the tests
If ImportTestFiles Then
If (0 / 1) + (Not Not m_CLI.TestFiles) Then
For i = 0 To UBound(m_CLI.TestFiles)
FilePath = GetRepositoryFullPath(m_CLI.TestFiles(i), DownloadBase)
If fso.FileExists(FilePath) Then
Set TempFile = fso.GetFile(FilePath)
AddMissingFile TempFile, ImportMode, DownloadBase
End If
Next
End If
End If
'possibly the examples
If ImportExampleFiles Then
If (0 / 1) + (Not Not m_CLI.ExampleFiles) Then
For i = 0 To UBound(m_CLI.ExampleFiles)
FilePath = GetRepositoryFullPath(m_CLI.ExampleFiles(i), DownloadBase)
If fso.FileExists(FilePath) Then
Set TempFile = fso.GetFile(FilePath)
AddMissingFile TempFile, ImportMode, DownloadBase
End If
Next
End If
End If
#If DEBUGMODE Then
Debug.Print ImportFile.Path; " --> "; m_CLI.Name
#End If
End Sub
Private Sub AddMissingReference(ByRef NewCodeLibRef As CodeLibInfoReference)
Dim Refs As Access.References
Dim ref As Access.Reference
Dim ReplaceRef As Boolean
Set Refs = Access.References
For Each ref In Refs
If ref.Name = NewCodeLibRef.Name Then
If ref.Major < NewCodeLibRef.Major Then
ReplaceRef = True
ElseIf ref.Major = NewCodeLibRef.Major And ref.Minor < NewCodeLibRef.Minor Then
ReplaceRef = True
Else 'Do not replace, cancel
Exit Sub
End If
Exit For
End If
Next
If ReplaceRef Then
Refs.Remove ref
End If
Refs.AddFromGuid NewCodeLibRef.GUID, NewCodeLibRef.Major, NewCodeLibRef.Minor
End Sub
Private Sub AddMissingFile(ByVal UsedFile As Object, ByVal ImportMode As CodeLibImportMode, Optional ByVal DownloadBase As String = vbNullString)
Dim FileColItem As Variant
Dim TempFile As Object
Dim i As Long
Dim MaxCount As Long
If IsReplacedFile(UsedFile) Then Exit Sub
MaxCount = CurrentFileCollection.Count
For i = 1 To MaxCount
'tempFile = varfileColItem(0) =>
'varfilColItem = m_ImportFileCollection(i) =>
Set TempFile = m_ImportFileCollection(i)(0)
If TempFile.Path = UsedFile.Path Then
Exit Sub
End If
Next
FileColItem = Array(UsedFile, ImportMode, DownloadBase)
m_ImportFileCollection.Add FileColItem, UsedFile.Path
End Sub
Private Sub ExportAccessObject(ByRef AoType As AcObjectType, ByRef AoName As String)
Select Case AoType
Case AcObjectType.acModule
ExportVbComponent AoName
Case AcObjectType.acForm, AcObjectType.acReport
ExportAccessObjectCli AoType, AoName
Case Else
'
End Select
End Sub
Private Sub ExportAccessObjectCli(ByRef AoType As AcObjectType, ByRef AoName As String)
'/**
' * @todo What about forms and reports without a module?
'**/
Dim cli As CodeLibInfo
GetCodeLibInfoFromAccessObject cli, AoType, AoName
If Len(cli.RepositoryFile) > 0 Then
cli.LocalFile = GetRepositoryFullPath(cli.RepositoryFile)
CreateMissingFolder GetParentFolderPath(cli.LocalFile)
Application.SaveAsText AoType, AoName, cli.LocalFile
CleanAccessBugExport cli.LocalFile
End If ' Rest ignorieren .. wenn im Code nicht steht, wird auch nicht exportiert
#If DEBUGMODE Then
Debug.Print AoName; " --> ";
If Len(cli.RepositoryFile) > 0 Then
Debug.Print cli.LocalFile
Else
Debug.Print "nicht exportiert"
End If
#End If
End Sub
Private Sub CleanAccessBugExport(ByVal FilePath As String)
Dim IsAcc2010 As Boolean
On Error Resume Next
If Application.Version >= "12.0" Then
IsAcc2010 = True
End If
On Error GoTo 0
If Not IsAcc2010 Then
Exit Sub
End If
Dim CheckString As String
Dim TempString As String
Dim FileNumber As Long
FileNumber = FreeFile
Open FilePath For Binary Access Read As FileNumber
CheckString = String$(LOF(FileNumber), 0)
Get FileNumber, , CheckString
Close FileNumber
TempString = Replace(CheckString, "NoSaveCTIWhenDisabled =1", vbNullString)
If StrComp(TempString, CheckString, vbBinaryCompare) = 0 Then
Exit Sub
End If
Kill FilePath
FileNumber = FreeFile
Open FilePath For Binary Access Write As FileNumber
Put FileNumber, , TempString
Close FileNumber
End Sub
Private Sub ExportVbComponent(ByRef VbcName As String, Optional ExportComponentsWithoutCodeLibInfo As Boolean = False)