Windows Installer API (SDK)

Media Table

Referenz » Media Table | Microsoft Docs


VBS class Media


Class classMediaTable
Private mDiskId, mLastSequence, mDiskPrompt, mCabinet, mVolumeLabel, mSource

    Public Property Get pDiskId
        pDiskId = mDiskId
    End Property
    Public Property Let pDiskId(intDiskId)
        mDiskId = intDiskId
    End Property
    Public Property Get pLastSequence
        pLastSequence = mLastSequence
    End Property
    Public Property Let pLastSequence(intLastSequence)
        mLastSequence = intLastSequence
    End Property
    Public Property Get pDiskPrompt
        pDiskPrompt = mDiskPrompt
    End Property
    Public Property Let pDiskPrompt(strDiskPrompt)
        mDiskPrompt = strDiskPrompt
    End Property
    Public Property Get pCabinet
        pCabinet = mCabinet
    End Property
    Public Property Let pCabinet(strCabinet)
        mCabinet = strCabinet
    End Property
    Public Property Get pVolumeLabel
        pVolumeLabel = mVolumeLabel
    End Property
    Public Property Let pVolumeLabel(strVolumeLabel)
        mVolumeLabel = strVolumeLabel
    End Property
    Public Property Get pSource
        pSource = mSource
    End Property
    Public Property Let pSource(strSource)
        mSource = strSource
    End Property
    
    Private Sub Class_Initialize
        'Anweisungen
    End Sub
    ' -----------------------------------------------------------------
    
    Public Function ModifyMediaRecord()
    Dim strSQL, objView, objTableRow

    strSQL = "SELECT * FROM Media"

    Set objView = objDatabase.OpenView(strSQL)
    objView.Execute
    Do 
        Set objTableRow = objView.Fetch
        If objTableRow Is Nothing Then
            Set objTableRow = objInstaller.CreateRecord(6)
            objTableRow.IntegerData(1) = mDiskId
            objTableRow.IntegerData(2) = mLastSequence
            objTableRow.StringData(3) = mDiskPrompt
            objTableRow.StringData(4) = mCabinet
            objTableRow.StringData(5) = mVolumeLabel
            objTableRow.StringData(6) = mSource
            objView.Modify msiViewModifyAssign, objTableRow
            Exit Do
        End If
            objTableRow.IntegerData(1) = mDiskId
            objTableRow.IntegerData(2) = mLastSequence
            objTableRow.StringData(3) = mDiskPrompt
            objTableRow.StringData(4) = mCabinet
            objTableRow.StringData(5) = mVolumeLabel
            objTableRow.StringData(6) = mSource
            objView.Modify msiViewModifyAssign, objTableRow
    Loop
    objDatabase.Commit()
    objView.Close
    Set objView = Nothing

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

    strSQL = "SELECT Media.DiskId,Media.LastSequence,Media.Cabinet FROM Media ORDER BY Media.DiskId"
    GetLastSequence = 0
    
    Set objView = objDatabase.OpenView(strSQL)
    objView.Execute
    Do 
        Set objTableRow = objView.Fetch
        If objTableRow Is Nothing Then Exit Do

        mDiskId = CInt(objTableRow.IntegerData(1))
        mLastSequence = CInt(objTableRow.IntegerData(2))
        mCabinet = objTableRow.StringData(3)
    Loop
    
    objView.Close
    Set objView = Nothing

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

    Public Function FinalizeMediaTable()
    Dim objFSO, objFileINF, strLinetoParse, intMediaFileCounter
    Dim FirstArray, SecArray, ThirdArray
    Dim intDiskCounter, intSequCounter
    Dim GetLastDiskIDFromMediaTable, GetLastSequenceFromMediaTable
    Dim GetActCabName, GetLastCabName
    
    ' collect some information from Media Table
    GetLastSequence
    GetLastDiskIDFromMediaTable   = CInt(mDiskId)
    GetLastSequenceFromMediaTable = CInt(mLastSequence)
    GetLastCabName = mCabinet
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(PathOfRepackageSource & "\" & strNameOfCAB & ".INF") Then
        Set objFileINF = objFSO.OpenTextFile(PathOfRepackageSource & "\" & strNameOfCAB & ".INF",ForReading,False,TristateFalse)
        Do While Not objFileINF.AtEndOfStream
            strLinetoParse = objFileINF.Readline
            
            If InStr(1,strLinetoParse, ",", vbTextCompare) Then
                FirstArray = split(strLinetoParse, ",", -1, vbTextCompare)
                If UBound(FirstArray) > 1 Then
                    GetActCabName = FirstArray(2)
                End If
            End If
                        
            If InStr(1,strLinetoParse, ":", vbTextCompare) Then
                SecArray = split(strLinetoParse, ":", -1, vbTextCompare)
                ThirdArray = split(SecArray(0), " ", -1, vbTextCompare)
                
                intDiskCounter = CInt(Mid(ThirdArray(0), 2, InStr(1,ThirdArray(0), ")", vbTextCompare) - 2))
                intSequCounter = CInt(ThirdArray(1))
                
                mDiskId = intDiskCounter + GetLastDiskIDFromMediaTable
                mLastSequence = intSequCounter + GetLastSequenceFromMediaTable

                If GetActCabName <> GetLastCabName Then
                    mCabinet = GetActCabName
                End If

            End If
            If mDiskId <> "" AND mLastSequence <> "" AND mCabinet <> "" Then ModifyMediaRecord
        Loop
    End If
    objFileINF.Close
    Set objFileINF = Nothing
    
    If objFSO.FileExists(PathOfRepackageSource & "\" & strNameOfCAB & ".CAB") Then
        objFSO.CopyFile PathOfRepackageSource & "\*.cab", _
                        PathOfRepackageResults & "\", _
                        OverwriteIfExist
    End If
    
    ' clean up
    If objFSO.FileExists(PathOfRepackageSource & "\" & strNameOfCAB & ".DDF") Then _
        objFSO.DeleteFile PathOfRepackageSource & "\" & strNameOfCAB & ".DDF"
    If objFSO.FileExists(PathOfRepackageSource & "\" & strNameOfCAB & ".RPT") Then _
        objFSO.DeleteFile PathOfRepackageSource & "\" & strNameOfCAB & ".RPT"
    If objFSO.FileExists(PathOfRepackageSource & "\" & strNameOfCAB & ".INF") Then _
        objFSO.DeleteFile PathOfRepackageSource & "\" & strNameOfCAB & ".INF"

    Set objFSO = Nothing
    
    End Function
    ' -----------------------------------------------------------------

    Public Function GetLastCABFile()
    Dim objFSO, objFolders, foundFiles, objFile
    Dim intCabCounter

    intCabCounter = 1
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FolderExists(PathOfRepackageSource) Then
        Set objFolders = objFSO.GetFolder(PathOfRepackageSource)
        For Each foundFiles in objFolders.Files
            Set objFile = objFSO.GetFile(foundFiles)
            Select Case UCase(objFSO.GetExtensionName(objFile.Name))
                Case "CAB"
                    intCabCounter = intCabCounter + 1
                Case Else
                    ' do nothing
            End Select
        Next
    End If
    GetLastCABFile = intCabCounter
    
    End Function
    ' -----------------------------------------------------------------

    Public Function DeleteAllRecords()
    Dim strSQL, objView

    strSQL = "DELETE FROM Media"

    Set objView = objDatabase.OpenView(strSQL)
        objView.Execute
    objDatabase.Commit()
        objView.Close
    Set objView = Nothing

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

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