Attribute VB_Name = "MOVE"

Function MoveAuth(ByVal SourcePath$, ByVal DestPath$, ByVal ShowCounts%, ByVal ConfirmMove%, ByVal AppName$) As Integer

    Dim mySB As SecureBlock
    Dim ret As Integer
    
    ' clear the initial contents of the SB structure
    ClearSB mySB

    ' setup to get the installation information
    mySB.SOURCE = SourcePath$ + Chr$(0)
    mySB.TARGET = DestPath$ + Chr$(0)
    
    ' turn on the hourglass cursor
    Screen.MousePointer = 11

    ' call the EVMOV32.DLL to prepare for installation
    mySB.FUNC = 0
    ret = EVMOV32(mySB)

    ' restore the original cursor
    Screen.MousePointer = 0

    ' verify the success of the EVMOVE function
    If ret <> 0 Then

        ' show the user the error
        MsgBox "EVMOV32.DLL Error " + Str$(ret) + "!", 16, AppName$

        ' set the error code return from this function
        MoveAuth = ret
        
        ' abort the move processing
        Exit Function

    ElseIf mySB.STAT1 <> 0 Then
            
        ' show the user the error
        MsgBox "Security Error: " + FormatError$(mySB), 16, AppName$

        ' set the error code return from this function
        MoveAuth = mySB.STAT1

        ' abort the move processing
        Exit Function
    End If
    
    ' turn on the hourglass cursor
    Screen.MousePointer = 11
    
    ' confirm the installation with the user
    If ConfirmMove% <> 0 Then
        
        ' setup the proper prompt for this move operation
        If mySB.UNINST = 0 Then
            Text$ = "Installing"
        Else
            Text$ = "Uninstalling"
        End If
    
        ' create the user prompt for the move operation
        Text$ = Text$ + " authorization from " + SourcePath$ + " to " + DestPath$ + Chr$(10) + Chr$(13)
        
        ' if we want the number of installation counts remaining add that prompt now
        If ShowCounts% <> 0 And mySB.UNINST = 0 Then
            Text$ = Text$ + "Number of install counts available:" + Str$(mySB.ICR) + Chr$(10) + Chr$(13)
        End If
        
    ' restore the original cursor
    Screen.MousePointer = 0

        Text$ = Text$ + Chr$(10) + Chr$(13) + "Select OK to continue or CANCEL to abort."

        ' ask the user to confirm the move operation
        ret = MsgBox(Text$, 33, AppName$)

        ' if the user wanted to abort the operation abort the operation
        If ret = 2 Then
            
            ' set the error code return from this function
            MoveAuth = ret

            ' abort the move processing
            Exit Function
        End If
    End If

    ' collect the registration information if necessary
    If mySB.REG <> 0 And mySB.UNINST = 0 Then

        ' load the registration information form
        Load RegInfoDlg

        ' set the inital value of the dialog's controls
        RegInfoDlg.Caption = AppName$

        ' display the form to get the registration information
        RegInfoDlg.Show 1

        ' get the results of the dialog box
        ret = Val(RegInfoDlg.Tag)
        mySB.RNAME = RegInfoDlg.txtName.Text
        mySB.RCOMP = RegInfoDlg.txtCompany.Text
        mySB.RLOC = RegInfoDlg.txtLocation.Text

        ' remove the registration information dialog from memory
        Unload RegInfoDlg

        ' if the user selected cancel abort the move
        If ret <> 0 Then

            ' set the return code for this function
            MoveAuth = 2

            ' abort the move processing
            Exit Function
        End If
    End If
    
    ' turn on the hourglass cursor
    Screen.MousePointer = 11

    ' actually perform the installation of the copy-protection
    mySB.FUNC = 1
    ret = EVMOV32(mySB)

    ' restore the original cursor
    Screen.MousePointer = 0

    ' verify the success of the EVMOVE function
    If ret <> 0 Then

        ' show the user the error
        MsgBox "EVMOV32.DLL Error " + Str$(ret) + "!", 16, AppName$

        ' set the error code return from this function
        MoveAuth = ret
        
        ' abort the move processing
        Exit Function

    ElseIf mySB.STAT1 <> 0 Then
            
        ' show the user the error
        MsgBox "Security Error: " + FormatError$(mySB), 16, AppName$

        ' set the error code return from this function
        MoveAuth = mySB.STAT1

        ' abort the move processing
        Exit Function
    End If
    
    ' if we end up here then the move was successfull
    MoveAuth = 0

End Function

