Subversion Repositories DevTools

Rev

Rev 1530 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/////////////////////////////////////////////////////////////////////////////
//                                                                            
//  File Name:    GetMassInstId.rul                                                   
//                                                                            
//  Description:  InstallShield script                                          
//                                                                            
//  Comments:     This contains the script to drive the GetMassInstId Dialog.
//                The dialog is defined in the GetMassInstId.isd file and must
//                be imported into the project for use.
//              
//                The GetMassInstId function simply accepts a string with an initial
//                                value for the ID and a flag to indicate whether to test the id against 
//                                the hostname of the machine being installed on.
//                                If Verify hostname is true it will try to use the hostname as the initial
//                                installation id if valid, if not will use the value in Parameter 1 if valid
//                                otherwise if not valid will use an internal default.
//                                If Verify hostname is false will use the value in Parameter 1 if valid
//                                otherwise if not valid will use an internal default.
//                                Internal checks are done on each component of the ID and NEXT is only
//                                allowed if all check are OK.
//                                Also if VerifyHostname is true it will display a message if the current
//                                installation id does not match the hostname, but will still allow the ID.
//                Return values are standard BACK, NEXT values, with the Installation id
//                                returned in the 1st parameter.
//
//  Usage:        On the dialogs section right click on the All Dialogs Folder
//                and select import dialog from the pop up menu.  Navigate to the
//                installshield source dir for the package being built and select
//                the GetMassInstId.isd file.  
//                                Then on the Files Folder of the Installscript section and select
//                                Insert script file and select the GetMassInstId.rul file.
//                                #include the GetMassInstId.rul file in setup.rul and call 
//                                GetMassInstId with appropriate parameters.
//      
/////////////////////////////////////////////////////////////////////////////

#define DLG_GETMASSINSTID       "GetMassInstId"

#define MASSSITEID_FIELDS               4
#define MASSSITEID_PARTLEN              10
#define MASSSITEID_LOCLEN               3
#define MASSSITEID_TYPELEN              6
#define MASSSITEID_NUMLEN               8

#define GETMASSINSTID_NEXT              1
#define GETMASSINSTID_EDIT              4
#define GETMASSINSTID_CANCEL    9
#define GETMASSINSTID_BACK              12
#define GETMASSINSTID_PARTID    301
#define GETMASSINSTID_LOCID             302
#define GETMASSINSTID_TYPEID    303
#define GETMASSINSTID_DEVID             304
#define GETMASSINSTID_MSG               903

NUMBER  g_nDlgGetMassInstId;

prototype NUMBER GetMassInstId( BYREF STRING, BOOL );
prototype BOOL _GetMassInstIdTokens(STRING, BYREF STRING, BYREF STRING, BYREF STRING, BYREF STRING);
prototype NUMBER _VerifyFields(BOOL, BOOL, STRING);


function NUMBER GetMassInstId( MassInstId, VerifyHostname )
    BOOL    bDone, gotFields, hostNameValid;
    NUMBER  nReturn, nControl, nResult;
    STRING      hostName;
    STRING      svPart, svLoc, svType, svNum;
    STRING  szAppKey;
    NUMBER  nNil;
    STRING  szNil;
begin
    
    // Read recorded data produced by this dialog
    if (MODE = SILENTMODE) then
        SdMakeName(szAppKey, DLG_GETMASSINSTID, "", g_nDlgGetMassInstId);
        SilentReadData(szAppKey, "Result", DATA_NUMBER, szNil, nReturn);
        if ((nReturn != BACK) && (nReturn != CANCEL)) then
            SilentReadData(szAppKey, "svPart", DATA_STRING, svPart, nNil);
            SilentReadData(szAppKey, "svLoc",  DATA_STRING, svLoc,  nNil);
            SilentReadData(szAppKey, "svType", DATA_STRING, svType, nNil);
            SilentReadData(szAppKey, "svNum",  DATA_STRING, svNum,  nNil);
            MassInstId = svPart + "-" + svLoc + "-" + svType + "-" + svNum;    
        endif;
        return nReturn;
    endif;

    islib_LocalHostname(hostName);
        
        gotFields = FALSE;
        hostNameValid = FALSE;
        
        // if verify hostname then we try to get values from hostname
        if ( VerifyHostname = TRUE ) then
                // if hostname is not valid it will return FALSE
                gotFields = _GetMassInstIdTokens(hostName, svPart, svLoc, svType, svNum);
                hostNameValid = gotFields;
        endif;
        
        // if we dont have fields here then we try to get from passed in MasInstID    
        if ( gotFields = FALSE ) then
                gotFields = _GetMassInstIdTokens(MassInstId, svPart, svLoc, svType, svNum);
        endif;          
        
        // if we dont have fields here then we just use our defaults
        if ( gotFields = FALSE ) then
            svPart      = "0000000100";
            svLoc       = "ABC";
            svType  = "000SCS";
            svNum       = "00000001";
        endif;          
        
    EzDefineDialog(DLG_GETMASSINSTID, ISUSER, DLG_GETMASSINSTID, 0);
    
    bDone = FALSE;
    
    while (!bDone)

        nControl = WaitOnDialog(DLG_GETMASSINSTID);

        switch (nControl)
            case DLG_INIT:
                CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_PARTID, svPart);
                CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_LOCID, svLoc);
                CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_TYPEID, svType);
                CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_DEVID, svNum);
                CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_MSG, "");
                                _VerifyFields(VerifyHostname, hostNameValid, hostName);
                                
            case GETMASSINSTID_BACK:
                // user clicked Back
                nReturn = GETMASSINSTID_BACK;
                bDone = TRUE;
        
            case GETMASSINSTID_NEXT:
                // user clicked Next
                nResult = _VerifyFields(VerifyHostname, hostNameValid, hostName);
                if ( nResult = 0 ) then
                        nReturn = GETMASSINSTID_NEXT;
                        bDone = TRUE;
                else
                    CtrlSelectText(DLG_GETMASSINSTID, nResult);
                endif;
        
            case GETMASSINSTID_CANCEL:
                // user clicked Cancel; ask user to verify cancellation
                Do(EXIT);
    
                        case GETMASSINSTID_PARTID:
                _VerifyFields(VerifyHostname, hostNameValid, hostName);
                                
                        case GETMASSINSTID_LOCID:
                _VerifyFields(VerifyHostname, hostNameValid, hostName);
                
                        case GETMASSINSTID_TYPEID:
                _VerifyFields(VerifyHostname, hostNameValid, hostName);
                
                        case GETMASSINSTID_DEVID:
                _VerifyFields(VerifyHostname, hostNameValid, hostName);
                
        endswitch;
    
    endwhile;

    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_PARTID, svPart);
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_LOCID, svLoc);
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_TYPEID, svType);
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_DEVID, svNum);
        MassInstId = svPart + "-" + svLoc + "-" + svType + "-" + svNum;    

    EndDialog(DLG_GETMASSINSTID);
    ReleaseDialog(DLG_GETMASSINSTID);

    // record data produced by this dialog
    if (MODE = RECORDMODE) then
        SdMakeName(szAppKey, DLG_GETMASSINSTID, "", g_nDlgGetMassInstId);
        SilentWriteData(szAppKey, "svNum",  DATA_STRING, svNum,  nNil);
        SilentWriteData(szAppKey, "svType", DATA_STRING, svType, nNil);
        SilentWriteData(szAppKey, "svLoc",  DATA_STRING, svLoc,  nNil);
        SilentWriteData(szAppKey, "svPart", DATA_STRING, svPart, nNil);
        SilentWriteData(szAppKey, "Result", DATA_NUMBER, szNil, nReturn);
    endif;

    return nReturn;
end;


function BOOL _GetMassInstIdTokens(input, part, loc, type, num)
    LIST        listID;
    STRING      svPart, svLoc, svType, svNum;
    BOOL        retval;
begin

        retval = FALSE;
    listID = ListCreate (STRINGLIST);

    // Get each path from the search path into the list.
    if (StrGetTokens (listID, input, "-") != 0 ) goto exitfunc;
    if ( ListCount ( listID ) != MASSSITEID_FIELDS ) goto exitfunc;
    
    ListGetFirstString ( listID, svPart );
    if ( StrLengthChars ( svPart ) != MASSSITEID_PARTLEN ) goto exitfunc;
    
    ListGetNextString  ( listID, svLoc );
    if ( StrLengthChars ( svLoc ) != MASSSITEID_LOCLEN ) goto exitfunc;

    ListGetNextString  ( listID, svType );
    if ( StrLengthChars ( svType ) != MASSSITEID_TYPELEN ) goto exitfunc;
    
    ListGetNextString  ( listID, svNum );
    if ( StrLengthChars ( svNum ) != MASSSITEID_NUMLEN ) goto exitfunc;

        retval = TRUE;
        part = svPart;
        loc = svLoc;
        type = svType;
        num = svNum;
        
exitfunc:
        ListDestroy(listID);
        return retval;
end;
        
        
function NUMBER _VerifyFields(VerifyHostname, hostNameValid, hostName)
    STRING      svPart, svLoc, svType, svNum, svTmp;
    STRING  errMsg;
        NUMBER  retval;
begin

    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_PARTID, svPart);
        if ( StrLengthChars ( svPart ) != MASSSITEID_PARTLEN ) then
                NumToStr(errMsg, MASSSITEID_PARTLEN);
                errMsg = "ERROR: Participant must be " + errMsg + " digits";
                goto exitVerifyFields;
        endif;
        
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_LOCID, svLoc);
        if ( StrLengthChars ( svLoc ) != MASSSITEID_LOCLEN ) then
                NumToStr(errMsg, MASSSITEID_LOCLEN);
                errMsg = "ERROR: Location must be " + errMsg + " digits";
                retval = GETMASSINSTID_LOCID;
                goto exitVerifyFields;
        endif;
                                
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_TYPEID, svType);
        if ( StrLengthChars ( svType ) != MASSSITEID_TYPELEN ) then
                NumToStr(errMsg, MASSSITEID_TYPELEN);
                errMsg = "ERROR: Device Type must be " + errMsg + " digits";
                retval = GETMASSINSTID_TYPEID;
                goto exitVerifyFields;
        endif;
                
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_DEVID, svNum);
        if ( StrLengthChars ( svNum ) != MASSSITEID_NUMLEN ) then
                NumToStr(errMsg, MASSSITEID_NUMLEN);
                errMsg = "ERROR: Location must be " + errMsg + " digits";
                retval = GETMASSINSTID_DEVID;
                goto exitVerifyFields;
        endif;
        
        // lets check hostname
        if ( VerifyHostname = TRUE ) then
                svTmp = svPart + "-" + svLoc + "-" + svType + "-" + svNum;
                if ( svTmp != hostName ) then
                        errMsg = "WARNING: Installation ID does not match hostname [" + hostName + "]";
                        if ( hostNameValid = FALSE ) then
                                errMsg = errMsg + ", which itself is not a valid installation ID.";
                        else
                                errMsg = errMsg + ".";
                        endif;
                        // return OK as this is just a warning
                        retval = 0;
                        goto exitVerifyFields;
                endif;
        endif;
        
        errMsg = "";
        retval = 0;
        
exitVerifyFields:
    CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_MSG, errMsg);
        return retval;
end;