Windows Installer API (SDK)

File Table

Referenz » File Table | Microsoft Docs


VBS class File


Class classFileTable
Private mFile, mComponent, mFileName, mFileSize, mVersion, mLanguage, mAttributes, mSequence

    Public Property Get pFile
        pFile = mFile
    End Property
    Public Property Let pFile(strFile)
        mFile = strFile
    End Property
    Public Property Get pComponent
        pComponent = mComponent
    End Property
    Public Property Let pComponent(strComponent)
        mComponent = strComponent
    End Property
    Public Property Get pFileName
        pFileName = mFileName
    End Property
    Public Property Let pFileName(strFileName)
        mFileName = strFileName
    End Property
    Public Property Get pFileSize
        pFileSize = mFileSize
    End Property
    Public Property Let pFileSize(intFileSize)
        mFileSize = intFileSize
    End Property
    Public Property Get pVersion
        pVersion = mVersion
    End Property
    Public Property Let pVersion(strVersion)
        mVersion = strVersion
    End Property
    Public Property Get pLanguage
        pLanguage = mLanguage
    End Property
    Public Property Let pLanguage(strLanguage)
        mLanguage = strLanguage
    End Property
    Public Property Get pAttributes
        pAttributes = mAttributes
    End Property
    Public Property Let pAttributes(intAttributes)
        mAttributes = intAttributes
    End Property
    Public Property Get pSequence
        pSequence = mSequence
    End Property
    Public Property Let pSequence(intSequence)
        mSequence = intSequence
    End Property

    Private Sub Class_Initialize

        If InStr(1, mFile, "{", vbTextCompare) Then '
            mFile = Replace(mFile, "{", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, "}", vbTextCompare) Then '
            mFile = Replace(mFile, "}", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, "‐", vbTextCompare) Then '
            mFile = Replace(mFile, "‐", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, "+", vbTextCompare) Then '
            mFile = Replace(mFile, "+", "Plus", 1, -1, vbTextCompare)
        If InStr(1, mFile, "'", vbTextCompare) Then '
            mFile = Replace(mFile, "'", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, " ", vbTextCompare) Then '
            mFile = Replace(mFile, " ", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, ".", vbTextCompare) Then '
            mFile = Replace(mFile, ".", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, "'", vbTextCompare) Then '
            mFile = Replace(mFile, "'", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, "´", vbTextCompare) Then '
            mFile = Replace(mFile, "´", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, "`", vbTextCompare) Then '
            mFile = Replace(mFile, "`", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, "(", vbTextCompare) Then '
            mFile = Replace(mFile, "(", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, ")", vbTextCompare) Then '
            mFile = Replace(mFile, ")", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, "@", vbTextCompare) Then '
            mFile = Replace(mFile, "@", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, ",", vbTextCompare) Then '
            mFile = Replace(mFile, ",", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, ";", vbTextCompare) Then '
            mFile = Replace(mFile, ";", "", 1, -1, vbTextCompare)
        If InStr(1, mFile, ":", vbTextCompare) Then '
            mFile = Replace(mFile, ":", "", 1, -1, vbTextCompare)

    End Sub
    ' -----------------------------------------------------------------
    
    Public Function ModifyFileRecord()
    Dim strSQL, objView, objTableRow

    strSQL = "SELECT * FROM File"

    Set objView = objDatabase.OpenView(strSQL)
    objView.Execute
    Do 
        Set objTableRow = objView.Fetch
        If objTableRow Is Nothing Then
            Set objTableRow = objInstaller.CreateRecord(8)
            objTableRow.StringData(1) = mFile
            objTableRow.StringData(2) = mComponent
            objTableRow.StringData(3) = mFileName
            objTableRow.IntegerData(4) = mFileSize
            objTableRow.StringData(5) = mVersion
            objTableRow.StringData(6) = mLanguage
            objTableRow.IntegerData(7) = mAttributes
            objTableRow.IntegerData(8) = mSequence
            objView.Modify msiViewModifyAssign, objTableRow
            Exit Do
        End If
            objTableRow.StringData(1) = mFile
            objTableRow.StringData(2) = mComponent
            objTableRow.StringData(3) = mFileName
            objTableRow.IntegerData(4) = mFileSize
            objTableRow.StringData(5) = mVersion
            objTableRow.StringData(6) = mLanguage
            objTableRow.IntegerData(7) = mAttributes
            objTableRow.IntegerData(8) = mSequence
            objView.Modify msiViewModifyAssign, objTableRow
    Loop
    objDatabase.Commit()
    objView.Close
    Set objView = Nothing

    End Function
    ' -----------------------------------------------------------------

    Public Function ExcludeDuplicateFileKeys(strFileKey)
    ' (Table.Field) File.File is the primary key and must be unique.
    Dim objView, objRecord, strSQL
    Dim intPOS, intCount, strTemp

    intCount = ""
    strTemp = ""
    strSQL = "SELECT File.File FROM File"

    Set objView = objDatabase.OpenView(strSQL)
    objView.Execute
    Do
        Set objRecord = objView.Fetch
        If objRecord Is Nothing Then Exit Do
    
        If Instr(1, objRecord.StringData(1), strFileKey & "_", vbTextCompare) Then
            intPOS = InStrRev(objRecord.StringData(1), "_", -1, 1)
            intCount = Mid(objRecord.StringData(1), intPOS + 1)
            If IsNumeric(intCount) AND intCount <> "" Then
                strTemp = strFileKey & "_" & CStr(CInt(intCount) + 1)
            End If
        ElseIf objRecord.StringData(1) = strFileKey Then
            If Right(objRecord.StringData(1), 2) <> "_1" Then
                strTemp = strFileKey & "_1"
            End If
        End If
    Loop
    If strTemp <> "" Then
        mFile = LCase(strTemp)
    Else
        mFile = LCase(strFileKey)
    End If

    If IsObject(objRecord) Then Set objRecord = Nothing
    Set objView = Nothing

    End Function
    ' -----------------------------------------------------------------
    
    Public Function GetLastSequence()
    Dim strSQL, objView, objTableRow

    strSQL = "SELECT File.Sequence FROM File ORDER BY File.Sequence"
    GetLastSequence = 0

    Set objView = objDatabase.OpenView(strSQL)
    objView.Execute
    Do 
        Set objTableRow = objView.Fetch
        If objTableRow Is Nothing Then Exit Do

        GetLastSequence = objTableRow.IntegerData(1)
    Loop

    objView.Close
    Set objView = Nothing

    End Function
    ' -----------------------------------------------------------------

    Public Function SetFileAttributesCompressed()
    Dim strSQL, objView, objTableRow, intAttribute

    strSQL = "SELECT File.Attributes,File.Sequence FROM File"

    Set objView = objDatabase.OpenView(strSQL)
    objView.Execute
    Do 
        Set objTableRow = objView.Fetch
        If objTableRow Is Nothing Then Exit Do
        
        If objTableRow.IntegerData(2) = GetLastSequence Then
        
            intAttribute = objTableRow.IntegerData(1)
            If intAttribute >= msiFileAttributesNoncompressed then
                If intAttribute < msiFileAttributesCompressed then
                    objRecord.IntegerData(1) = CInt(msiFileAttributesCompressed _
                                            + intAttribute _
                                            - msiFileAttributesNoncompressed)
                End If
            Else
                objRecord.IntegerData(1) = CInt(msiFileAttributesCompressed _
                                            + intAttribute)
            End If
            
        End If
    Loop

    objView.Close
    Set objView = Nothing

    End Function
    ' -----------------------------------------------------------------

    Private Sub Class_Terminate()
        'Anweisungen
    End Sub
End Class
' ---------------------------------------------------------------------