Windows Installer API (SDK)

CreateFolder Table

Referenz » CreateFolder Table | Microsoft Docs


VBS class CreateFolder


Class classCreateFolderTable
Private mDirectory, mComponent

    Public Property Get pDirectory
        pDirectory = mDirectory
    End Property
    Public Property Let pDirectory(strDirectory)
        mDirectory = strDirectory
    End Property
    Public Property Get pComponent
        pComponent = mComponent
    End Property
    Public Property Let pComponent(strComponent)
        mComponent = strComponent
    End Property
    
    Private Sub Class_Initialize
        'Anweisungen
    End Sub
    ' -----------------------------------------------------------------
    
    Private Function CreateTable()
    Dim strSQL, objView

    strSQL = "CREATE TABLE " & Chr(96) & "CreateFolder" & Chr(96) & " (" & _
              Chr(96) & "Directory_" & Chr(96) & " CHAR(72) NOT NULL, " & _
              Chr(96) & "Component_" & Chr(96) & " CHAR(72) NOT NULL PRIMARY KEY " & _
              Chr(96) & "Directory_" & Chr(96) & "," & Chr(96) & "Component_" & Chr(96) & ")"

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

    msiValidation.pTable = "CreateFolder"
    msiValidation.pColumn = "Directory_"
    msiValidation.pNullable = "N"
    msiValidation.pMinValue = Null
    msiValidation.pMaxValue = Null
    msiValidation.pKeyTable = "Directory"
    msiValidation.pKeyColumn = cInt("1")
    msiValidation.pCategory = "Identifier"
    msiValidation.pSet = ""
    msiValidation.pDescription = "Primary key, could be foreign key into the Directory table."

        msiValidation.ModifyValidationRecord
        msiValidation.ResetValidationRecord

    msiValidation.pTable = "CreateFolder"
    msiValidation.pColumn = "Component_"
    msiValidation.pNullable = "N"
    msiValidation.pMinValue = Null
    msiValidation.pMaxValue = Null
    msiValidation.pKeyTable = "Component"
    msiValidation.pKeyColumn = cInt("1")
    msiValidation.pCategory = "Identifier"
    msiValidation.pSet = ""
    msiValidation.pDescription = "Foreign key into the Component table."

        msiValidation.ModifyValidationRecord
        msiValidation.ResetValidationRecord
    
    Set objView = Nothing
    
    End Function
    ' -----------------------------------------------------------------

    Public Function ModifyCreateFolderRecord()
    Dim strSQL, objView, objTableRow

    strSQL = "SELECT * FROM CreateFolder"

    Set objView = objDatabase.OpenView(strSQL)
    objView.Execute
    Do 
        Set objTableRow = objView.Fetch
        If objTableRow Is Nothing Then
            Set objTableRow = objInstaller.CreateRecord(2)
            objTableRow.StringData(1) = mDirectory
            objTableRow.StringData(2) = mComponent
            objView.Modify msiViewModifyAssign, objTableRow
            Exit Do
        End If
            objTableRow.StringData(1) = mDirectory
            objTableRow.StringData(2) = mComponent
            objView.Modify msiViewModifyAssign, objTableRow
    Loop
    objDatabase.Commit()
    objView.Close
    Set objView = Nothing

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

    Public Function FinalizeCreateFolderTable()
    ' calling from function EnumSubFolders
    Dim objView, objRecord, strTemp, CompleteOrCurrentUser

    strTemp = ""
    mDirectory = ""
    mComponent = ""
    CompleteOrCurrentUser = FolderDataInfo.Feature

    If CompleteOrCurrentUser = "Complete" Then _
        mComponent = "CreateEmptyFolder"
    If CompleteOrCurrentUser = "CurrentUser" Then _
        mComponent = "CreateEmptyUserFolder"

    If IsMissingTable("CreateFolder") Then CreateTable

    Set objView = objDatabase.OpenView("SELECT * FROM CreateFolder")
    objView.Execute
    Do
        Set objRecord = objView.Fetch
        If objRecord Is Nothing Then
            mDirectory = msiDirectory.pDirectory
            If mComponent <> "" AND mDirectory <> "" Then _
                ModifyCreateFolderRecord
            Exit Do
        End If
        If objRecord.StringData(1) = msiDirectory.pDirectory Then
            strTemp = ""
            Exit Do
        Else
            strTemp = msiDirectory.pDirectory
        End If
    Loop
    
    If strTemp <> "" Then
        mDirectory = strTemp
        If mComponent <> "" AND mDirectory <> "" Then _
            ModifyCreateFolderRecord
        
        If msiComponent.ThereAreDuplicateComponentRecords <> mComponent Then
            msiFeatureComponents.pFeature = FolderDataInfo.Feature ' "Complete or CurrentUser"
            msiFeatureComponents.pComponent = mComponent
            ' write in FeatureComponent table
                msiFeatureComponents.ModifyFeatureComponentsRecord

            msiComponent.pComponent = mComponent
            msiComponent.pComponentId = GenerateGUID
            msiComponent.pDirectory = "TARGETDIR"
            msiComponent.pAttributes = msiComponent.SetAttributesOfComponent
            msiComponent.pCondition = ""
            msiComponent.pKeyPath = ""
            ' write in Component table
                msiComponent.ModifyComponentRecord
        End If
    End If

    Set objView = Nothing

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

    Public Function DeleteCreateFolderRecord()
    Dim strSQL, objView, objTableRow

    strSQL = "SELECT * FROM CreateFolder"

    Set objView = objDatabase.OpenView(strSQL)
    objView.Execute
    Do 
        Set objTableRow = objView.Fetch
        If objTableRow Is Nothing Then Exit Do
        
        If objTableRow.StringData(2) = mComponent Then _
           objView.Modify msiViewModifyDelete, objTableRow
    Loop
    objDatabase.Commit()
    objView.Close
    Set objView = Nothing

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

    Public Function DeleteAllRecords()
    Dim strSQL, objView

    strSQL = "DELETE FROM CreateFolder"

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

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

    Public Function DropTable()
    Dim strSQL, objView

    strSQL = "DROP TABLE CreateFolder"

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

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

    Private Function GenerateGUID()
    Dim objGuid

    Set objGuid = CreateObject("Scriptlet.Typelib")
        GenerateGUID = Left(objGuid.Guid, 38)
    Set objGuid = Nothing
    
    End Function
    ' -----------------------------------------------------------------

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