diff --git a/source/forms/InstallAddInForm.cls b/source/forms/InstallAddInForm.cls index 6949f1f..079b1e0 100644 --- a/source/forms/InstallAddInForm.cls +++ b/source/forms/InstallAddInForm.cls @@ -19,6 +19,8 @@ Attribute VB_Exposed = False ' _codelib/license.bas ' _codelib/addins/shared/AddInConfiguration.cls ' _codelib/addins/shared/AddInInstaller.cls +' base/modApplication.bas +' base/modErrorHandler.bas ' '--------------------------------------------------------------------------------------- ' diff --git a/source/modules/ACLibFileManager.cls b/source/modules/ACLibFileManager.cls index 397ed5f..7f210ad 100644 --- a/source/modules/ACLibFileManager.cls +++ b/source/modules/ACLibFileManager.cls @@ -1100,6 +1100,7 @@ Private Sub ImportVbComponent(ByRef CodeLibInf As CodeLibInfo, ByRef ImportFile End If If CodeModuleExists Then ' Change content via CodeModule so that MS add-in for source code management does not cause trouble + ' TODO: check if invisible properties changed Set cm = vbc.CodeModule cm.DeleteLines 1, cm.CountOfLines cm.AddFromFile ImportFile.Path @@ -1117,7 +1118,7 @@ Private Sub ImportVbComponent(ByRef CodeLibInf As CodeLibInfo, ByRef ImportFile Loop Else - VbcCol.import ImportFile.Path + VbcCol.Import ImportFile.Path End If End Sub @@ -1372,15 +1373,9 @@ Private Sub GetCodeLibInfoFromFile(ByRef CodeLibInf As CodeLibInfo, ByVal InputF Dim CheckString As String Dim TempString As String Dim i As Long - Dim FileNumber As Long Dim StringCutPos As Long - FileNumber = FreeFile - - Open InputFile.Path For Binary Access Read As FileNumber - CheckString = String$(LOF(FileNumber), 0) - Get FileNumber, , CheckString - Close FileNumber + CheckString = ReadSourceFile(InputFile) 'Determine names CodeLibInf.Name = FindSubString(CheckString, SEARCHSTRING_ATTRIBUTNAME_BEGIN, SEARCHSTRING_ATTRIBUTNAME_END, Pos) @@ -1462,6 +1457,61 @@ Private Sub GetCodeLibInfoFromFile(ByRef CodeLibInf As CodeLibInfo, ByVal InputF End Sub +Private Function ReadSourceFile(ByVal InputFile As Object) As String + + Dim FileNumber As Long + Dim StringCutPos As Long + Dim CheckString As String + + Dim CheckBytes(1 To 3) As Byte + Dim FileCharset As String + + FileNumber = FreeFile + + Open InputFile.Path For Binary Access Read As FileNumber + + If LOF(FileNumber) >= 3 Then + + Get #FileNumber, , CheckBytes + + If CheckBytes(1) = &HEF And CheckBytes(2) = &HBB And CheckBytes(3) = &HBF Then + FileCharset = "utf-8" + ElseIf (CheckBytes(1) = &HFF And CheckBytes(2) = &HFE) Or (CheckBytes(1) = &HFE And CheckBytes(2) = &HFF) Then + FileCharset = "utf-16" + Else + Seek #FileNumber, 1 + CheckString = String$(LOF(FileNumber), 0) + Get #FileNumber, , CheckString + End If + + End If + + Close FileNumber + + If Len(FileCharset) > 0 Then + CheckString = ReadUtfFileToString(InputFile, FileCharset) + End If + + ReadSourceFile = CheckString + +End Function + +Function ReadUtfFileToString(ByVal InputFile As Object, ByVal FileCharset As String) As String + + Dim Stream As Object ' Late Binding für ADODB.Stream + Set Stream = CreateObject("ADODB.Stream") + + With Stream + .Type = 2 ' Text + .Charset = FileCharset + .Open + .LoadFromFile InputFile.Path + ReadUtfFileToString = .ReadText + .Close + End With + +End Function + Private Sub GetCodeLibInfoPackage(ByRef CodeLibInf As CodeLibInfo, ByRef SourceString As String) Dim PackageName As String PackageName = Trim(FindSubString(SourceString, SEARCHSTRING_PACKAGE_BEGIN, SEARCHSTRING_PACKAGE_END)) diff --git a/source/modules/ACLibGitHubImporter.cls b/source/modules/ACLibGitHubImporter.cls index 18e23b4..69c5472 100644 --- a/source/modules/ACLibGitHubImporter.cls +++ b/source/modules/ACLibGitHubImporter.cls @@ -40,7 +40,7 @@ Private m_BranchName As String #If VBA7 Then Private Declare PtrSafe Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long -Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long +Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As LongPtr, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As LongPtr) As Long #Else Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long @@ -298,7 +298,59 @@ On Error GoTo 0 End Sub Private Sub DownloadFileFromWeb(ByVal Url As String, ByVal TargetPath As String) + If FileExists(TargetPath) Then Kill TargetPath DeleteUrlCacheEntry Url URLDownloadToFile 0, Url, TargetPath, 0, 0 + + If IsUTF16(TargetPath) Then 'Forms/Reports + Exit Sub + End If + + NormalizeDownloadFile TargetPath ' fix issues with import as module instead of Class + +End Sub + +Function IsUTF16(ByVal InputFile As String) As Boolean + + Dim FileNumber As Integer + Dim CheckByte(1 To 2) As Byte + FileNumber = FreeFile + Open InputFile For Binary Access Read As #FileNumber + If LOF(FileNumber) >= 2 Then + Get #FileNumber, , CheckByte + If (CheckByte(1) = &HFF And CheckByte(2) = &HFE) Or (CheckByte(1) = &HFE And CheckByte(2) = &HFF) Then + IsUTF16 = True + End If + End If + Close #FileNumber + +End Function + +Sub NormalizeDownloadFile(ByVal InputFile As String) + + Dim TextStreamIn As Scripting.TextStream, TextStreamOut As Scripting.TextStream + Dim TempFile As String + Dim TextLine As String + + TempFile = InputFile & ".temp" + + With New Scripting.FileSystemObject + + Set TextStreamIn = .OpenTextFile(InputFile, ForReading, False) + Set TextStreamOut = .OpenTextFile(TempFile, ForWriting, True, TristateUseDefault) + + Do While Not TextStreamIn.AtEndOfStream + TextLine = TextStreamIn.ReadLine + TextStreamOut.Write TextLine & vbCrLf + Loop + + TextStreamIn.Close + TextStreamOut.Close + + .DeleteFile InputFile + .MoveFile TempFile, InputFile + + End With + End Sub diff --git a/source/modules/AddInInstaller.cls b/source/modules/AddInInstaller.cls index 3297dde..72ce114 100644 --- a/source/modules/AddInInstaller.cls +++ b/source/modules/AddInInstaller.cls @@ -23,6 +23,7 @@ Attribute VB_Exposed = False ' _codelib/addins/shared/AddInInstaller.cls ' _codelib/license.bas ' _codelib/addins/shared/AddInConfiguration.cls +' file/FileTools.bas ' DAO50{00025E01-0000-0000-C000-000000000046} ' '--------------------------------------------------------------------------------------- diff --git a/source/nav-pane-groups.json b/source/nav-pane-groups.json index 6b42e35..5dff1ef 100644 --- a/source/nav-pane-groups.json +++ b/source/nav-pane-groups.json @@ -8,7 +8,7 @@ { "Name": "Benutzerdefiniert", "Flags": 0, - "Position": 3, + "Position": 2, "Groups": [ { "Name": "Benutzerdefinierte Gruppe 1",