// SdFinish -----------------------------------------------------------------
function  SdFinish( szTitle, szMsg, szMsg2, szOpt1, szOpt2, bOpt1, bOpt2 )
    string  szDlg, szTemp;
    number  nId, list, nSdDialog;
    BOOL    bDone;
    HWND    hwndDlg, hwndRbut, hwndFbut;
begin

    szDlg     = SD_DLG_FINISH;
    nSdDialog = SD_NDLG_FINISH;

    // record data produced by this dialog
    if(MODE=SILENTMODE) then
        SdMakeName( szAppKey, szDlg, szTitle, nSdFinish );
        SilentReadData( szAppKey, "Result", DATA_NUMBER, szTemp, nId );
        if((nId != BACK) && (nId != CANCEL)) then
            SilentReadData( szAppKey, "bOpt1", DATA_NUMBER, szTemp, bOpt1 );
            SilentReadData( szAppKey, "bOpt2", DATA_NUMBER, szTemp, bOpt2 );
        endif;
        return nId;
    endif;

    // ensure general initialization is complete
    if(!bSdInit) then
        SdInit();
    endif;

    if(EzDefineDialog( szDlg, "", "", SD_NDLG_FINISH) = DLG_ERR) then
        return -1;
    endif;

    // Loop in dialog until the user selects a standard button
    Disable( BACKBUTTON );
    Disable( CANCELBUTTON );
    bDone = FALSE;

    while (!bDone)

        nId = WaitOnDialog( szDlg );

        switch (nId)
     
        case DLG_INIT:

            hwndDlg = CmdGetHwndDlg( szDlg );

            if(szMsg != "") then
                SdSetStatic( szDlg, 50, szMsg );
            endif;

            if(szMsg2 != "") then
                SdSetStatic( szDlg, 51, szMsg2 );
            endif;

          // set or hide radiobutton information
            if(szOpt1 != "") then
                CtrlSetText( szDlg, SD_RBUT_LAUNCHREADME, szOpt1 );
            else
                hwndRbut = CtrlGetDlgItem("",  hwndDlg, SD_RBUT_LAUNCHREADME );
                ShowWindow( hwndRbut, SW_HIDE );
                bOpt1 = FALSE;
            endif;

            if(szOpt2 != "") then
                CtrlSetText( szDlg, SD_RBUT_LAUNCHAPP, szOpt2 );
            else
                hwndRbut = CtrlGetDlgItem("",  hwndDlg, SD_RBUT_LAUNCHAPP );
                ShowWindow( hwndRbut, SW_HIDE );
                bOpt2 = FALSE;
            endif;

            // general initialization
            SdGeneralInit( szDlg, hwndDlg, 0, szSdProduct );

            SdSetDlgTitle(szDlg, hwndDlg, szTitle);

            // set radiobuttons
            if(bOpt1) then
                CtrlSetState( szDlg, SD_RBUT_LAUNCHREADME, BUTTON_CHECKED );
            endif;

            if(bOpt2) then
                CtrlSetState( szDlg, SD_RBUT_LAUNCHAPP, BUTTON_CHECKED );
            endif;

            if((szOpt1 = "") && (szOpt2 = "")) then
                hwndFbut = CtrlGetDlgItem("",  hwndDlg, SD_PBUT_CONTINUE );
                SetFocus( hwndFbut );
            else
                // force product name in radiobuttons
                SdPlugInProductName( szDlg, hwndDlg, szSdProduct, SD_RBUT_LAUNCHREADME, 2 );
            endif;
            if !(gListOfSucssesInstalls = "") then
                CtrlSetText( szDlg, 1302, gListOfSucssesInstalls );
            endif;
        case SD_PBUT_CONTINUE:     // Finish button

            nId   = NEXT;
            bDone = TRUE;

            bOpt1 = FALSE; bOpt2 = FALSE;
            if(CtrlGetState( szDlg, SD_RBUT_LAUNCHREADME) = BUTTON_CHECKED) then
                bOpt1 = TRUE;
            endif;

            if(CtrlGetState( szDlg, SD_RBUT_LAUNCHAPP) = BUTTON_CHECKED) then
                bOpt2 = TRUE;
            endif;

        case BACK:

            nId = BACK; // should be disabled

        case DLG_ERR:

            SdError( -1, szDlg );
            nId   = -1;
            bDone = TRUE;

        case DLG_CLOSE:

            SdCloseDlg( hwndDlg, nId, bDone );

        default:

            // check standard handling
            if(SdIsStdButton( nId ) && SdDoStdButton( nId )) then
                bDone = TRUE;
            endif;

        endswitch;

    endwhile;

    // Cleanup Dialog
    EndDialog( szDlg );
    ReleaseDialog( szDlg );
    SdUnInit();
    Enable( BACKBUTTON );
    Enable( CANCELBUTTON );

    // record data produced by this dialog
    if(MODE=RECORDMODE) then
        SdMakeName( szAppKey, szDlg, szTitle, nSdFinish );
        SilentWriteData( szAppKey, "Result", DATA_NUMBER, "", nId );
        SilentWriteData( szAppKey, "bOpt1", DATA_NUMBER, "", bOpt1 );
        SilentWriteData( szAppKey, "bOpt2", DATA_NUMBER, "", bOpt2 );
    endif;

    return nId;

end;
// SdFinishReboot -----------------------------------------------------------
function  SdFinishReboot( szTitle, szMsg, nDefOption, szMsg2, nReserved )
    string  szDlg, szTemp;
    number  nId, list, nType, nOS, nResult, nSdDialog, nChoice;
    HWND    hwndRbut, hwndDlg;
    BOOL    bDone;
begin

    szDlg     = SD_DLG_FINISHREBOOT;
    nSdDialog = SD_NDLG_FINISHREBOOT;

    // record data produced by this dialog
    if(MODE=SILENTMODE) then
        SdMakeName( szAppKey, szDlg, szTitle, nSdFinishReboot );
        SilentReadData( szAppKey, "Result", DATA_NUMBER, szTemp, nId );
        SilentReadData( szAppKey, "BootOption", DATA_NUMBER, szTemp, nChoice );

        if(nChoice = SYS_BOOTMACHINE) then
            nResult = System( nChoice );

            if(nResult < ISERR_SUCCESS) then 
                nId = nResult; 
            endif;
        endif;

        return nId;

    endif;

    // ensure general initialization is complete
    if(!bSdInit) then
        SdInit();
    endif;

    if(EzDefineDialog( szDlg, "", "", SD_NDLG_FINISHREBOOT) = DLG_ERR) then
        return -1;
    endif;

    // Loop in dialog until the user selects a standard button
    Disable( BACKBUTTON );
    Disable( CANCELBUTTON );

    bDone = FALSE;

    while (!bDone)

        nId = WaitOnDialog( szDlg );

        switch (nId)

        case DLG_INIT:

            if(szMsg != "") then
                SdSetStatic( szDlg, SD_STA_MSG1, szMsg );
            endif;

            if(szMsg2 != "") then
                SdSetStatic( szDlg, SD_STA_MSG2, szMsg2 );
            endif;

            hwndDlg = CmdGetHwndDlg( szDlg );
            SdGeneralInit( szDlg, hwndDlg, 0, szSdProduct );

            SdSetDlgTitle(szDlg, hwndDlg, szTitle);

            // set radiobutton
            CtrlSetState( szDlg, SD_RBUT_RESTARTMACHINE, 0 );
            CtrlSetState( szDlg, SD_RBUT_NONE, 0 );
            switch (nDefOption)
        
            case SYS_BOOTMACHINE:
                CtrlSetState( szDlg, SD_RBUT_RESTARTMACHINE, BUTTON_CHECKED );
                hwndRbut = CtrlGetDlgItem("",  hwndDlg, SD_RBUT_RESTARTMACHINE );
      
            default:
                CtrlSetState( szDlg, SD_RBUT_NONE, BUTTON_CHECKED );
                hwndRbut = CtrlGetDlgItem("",  hwndDlg, SD_RBUT_NONE );

            endswitch;
            if !(gListOfSucssesInstalls = "") then
                CtrlSetText( szDlg, 1301, gListOfSucssesInstalls );
            endif;
            SetFocus( hwndRbut );

        case SD_PBUT_CONTINUE:     // Finish button

            nId   = NEXT;
            bDone = TRUE;

            nResult = 0;
            nChoice = NO;

            if(CtrlGetState( szDlg, SD_RBUT_RESTARTMACHINE ) = BUTTON_CHECKED) then
                nChoice = SYS_BOOTMACHINE;
                nResult = System( SYS_BOOTMACHINE );

                if(nResult < ISERR_SUCCESS) then
                    nId = nResult;
                else
                    nId = WILL_REBOOT;
                endif;
            endif;

        case SD_PBUT_BACK:

            nId = BACK; // should be disabled

        case DLG_ERR:

            SdError( -1, szDlg );
            nId   = -1;
            bDone = TRUE;

        case DLG_CLOSE:

            SdCloseDlg( hwndDlg, nId, bDone );

        default:

            // check standard handling
            if(SdIsStdButton( nId ) && SdDoStdButton( nId )) then
                bDone = TRUE;
            endif;
 
        endswitch;

    endwhile;

    // Cleanup Dialog
    EndDialog( szDlg );
    ReleaseDialog( szDlg );
    SdUnInit();
    Enable( BACKBUTTON );
    Enable( CANCELBUTTON );

    // record data produced by this dialog
    if(MODE=RECORDMODE) then
        SdMakeName( szAppKey, szDlg, szTitle, nSdFinishReboot );
        SilentWriteData( szAppKey, "Result", DATA_NUMBER, "", nId );
        SilentWriteData( szAppKey, "BootOption", DATA_NUMBER, "", nChoice );
    endif;

    return nId;

end;