Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1530 dpurdie 1
/////////////////////////////////////////////////////////////////////////////
2
//                                                                            
3
//  File Name:    GetMassInstId.rul                                                   
4
//                                                                            
5
//  Description:  InstallShield script                                          
6
//                                                                            
7
//  Comments:     This contains the script to drive the GetMassInstId Dialog.
8
//                The dialog is defined in the GetMassInstId.isd file and must
9
//                be imported into the project for use.
10
//              
11
//                The GetMassInstId function simply accepts a string with an initial
12
//				  value for the ID and a flag to indicate whether to test the id against 
13
//				  the hostname of the machine being installed on.
14
//			 	  If Verify hostname is true it will try to use the hostname as the initial
15
//				  installation id if valid, if not will use the value in Parameter 1 if valid
16
//				  otherwise if not valid will use an internal default.
17
//			 	  If Verify hostname is false will use the value in Parameter 1 if valid
18
//				  otherwise if not valid will use an internal default.
19
//				  Internal checks are done on each component of the ID and NEXT is only
20
//				  allowed if all check are OK.
21
//				  Also if VerifyHostname is true it will display a message if the current
22
//				  installation id does not match the hostname, but will still allow the ID.
23
//                Return values are standard BACK, NEXT values, with the Installation id
24
//				  returned in the 1st parameter.
25
//
26
//  Usage:        On the dialogs section right click on the All Dialogs Folder
27
//                and select import dialog from the pop up menu.  Navigate to the
28
//                installshield source dir for the package being built and select
29
//                the GetMassInstId.isd file.  
30
//				  Then on the Files Folder of the Installscript section and select
31
//				  Insert script file and select the GetMassInstId.rul file.
32
//				  #include the GetMassInstId.rul file in setup.rul and call 
33
//				  GetMassInstId with appropriate parameters.
34
//      
35
/////////////////////////////////////////////////////////////////////////////
36
 
37
#define DLG_GETMASSINSTID       "GetMassInstId"
38
 
39
#define MASSSITEID_FIELDS		4
40
#define MASSSITEID_PARTLEN		10
41
#define MASSSITEID_LOCLEN		3
42
#define MASSSITEID_TYPELEN		6
43
#define MASSSITEID_NUMLEN		8
44
 
45
#define GETMASSINSTID_NEXT		1
46
#define GETMASSINSTID_EDIT		4
47
#define GETMASSINSTID_CANCEL	9
48
#define GETMASSINSTID_BACK		12
49
#define GETMASSINSTID_PARTID	301
50
#define GETMASSINSTID_LOCID		302
51
#define GETMASSINSTID_TYPEID	303
52
#define GETMASSINSTID_DEVID		304
53
#define GETMASSINSTID_MSG		903
54
 
55
NUMBER  g_nDlgGetMassInstId;
56
 
57
prototype NUMBER GetMassInstId( BYREF STRING, BOOL );
58
prototype BOOL _GetMassInstIdTokens(STRING, BYREF STRING, BYREF STRING, BYREF STRING, BYREF STRING);
59
prototype NUMBER _VerifyFields(BOOL, BOOL, STRING);
60
 
61
 
62
function NUMBER GetMassInstId( MassInstId, VerifyHostname )
63
    BOOL    bDone, gotFields, hostNameValid;
64
    NUMBER  nReturn, nControl, nResult;
65
    STRING	hostName;
66
    STRING	svPart, svLoc, svType, svNum;
67
    STRING  szAppKey;
68
    NUMBER  nNil;
69
    STRING  szNil;
70
begin
71
 
72
    // Read recorded data produced by this dialog
73
    if (MODE = SILENTMODE) then
74
        SdMakeName(szAppKey, DLG_GETMASSINSTID, "", g_nDlgGetMassInstId);
75
        SilentReadData(szAppKey, "Result", DATA_NUMBER, szNil, nReturn);
76
        if ((nReturn != BACK) && (nReturn != CANCEL)) then
77
            SilentReadData(szAppKey, "svPart", DATA_STRING, svPart, nNil);
78
            SilentReadData(szAppKey, "svLoc",  DATA_STRING, svLoc,  nNil);
79
            SilentReadData(szAppKey, "svType", DATA_STRING, svType, nNil);
80
            SilentReadData(szAppKey, "svNum",  DATA_STRING, svNum,  nNil);
81
            MassInstId = svPart + "-" + svLoc + "-" + svType + "-" + svNum;    
82
        endif;
83
        return nReturn;
84
    endif;
85
 
86
    islib_LocalHostname(hostName);
87
 
88
	gotFields = FALSE;
89
	hostNameValid = FALSE;
90
 
91
	// if verify hostname then we try to get values from hostname
92
	if ( VerifyHostname = TRUE ) then
93
		// if hostname is not valid it will return FALSE
94
		gotFields = _GetMassInstIdTokens(hostName, svPart, svLoc, svType, svNum);
95
		hostNameValid = gotFields;
96
	endif;
97
 
98
	// if we dont have fields here then we try to get from passed in MasInstID    
99
	if ( gotFields = FALSE ) then
100
		gotFields = _GetMassInstIdTokens(MassInstId, svPart, svLoc, svType, svNum);
101
	endif;		
102
 
103
	// if we dont have fields here then we just use our defaults
104
	if ( gotFields = FALSE ) then
105
	    svPart 	= "0000000100";
106
	    svLoc	= "ABC";
107
	    svType  = "000SCS";
108
	    svNum	= "00000001";
109
	endif;		
110
 
111
    EzDefineDialog(DLG_GETMASSINSTID, ISUSER, DLG_GETMASSINSTID, 0);
112
 
113
    bDone = FALSE;
114
 
115
    while (!bDone)
116
 
117
        nControl = WaitOnDialog(DLG_GETMASSINSTID);
118
 
119
        switch (nControl)
120
            case DLG_INIT:
121
                CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_PARTID, svPart);
122
                CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_LOCID, svLoc);
123
                CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_TYPEID, svType);
124
                CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_DEVID, svNum);
125
                CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_MSG, "");
126
				_VerifyFields(VerifyHostname, hostNameValid, hostName);
127
 
128
            case GETMASSINSTID_BACK:
129
                // user clicked Back
130
                nReturn = GETMASSINSTID_BACK;
131
                bDone = TRUE;
132
 
133
            case GETMASSINSTID_NEXT:
134
                // user clicked Next
135
                nResult = _VerifyFields(VerifyHostname, hostNameValid, hostName);
136
                if ( nResult = 0 ) then
137
                	nReturn = GETMASSINSTID_NEXT;
138
                	bDone = TRUE;
139
                else
140
                    CtrlSelectText(DLG_GETMASSINSTID, nResult);
141
                endif;
142
 
143
            case GETMASSINSTID_CANCEL:
144
                // user clicked Cancel; ask user to verify cancellation
145
                Do(EXIT);
146
 
147
			case GETMASSINSTID_PARTID:
148
                _VerifyFields(VerifyHostname, hostNameValid, hostName);
149
 
150
			case GETMASSINSTID_LOCID:
151
                _VerifyFields(VerifyHostname, hostNameValid, hostName);
152
 
153
			case GETMASSINSTID_TYPEID:
154
                _VerifyFields(VerifyHostname, hostNameValid, hostName);
155
 
156
			case GETMASSINSTID_DEVID:
157
                _VerifyFields(VerifyHostname, hostNameValid, hostName);
158
 
159
        endswitch;
160
 
161
    endwhile;
162
 
163
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_PARTID, svPart);
164
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_LOCID, svLoc);
165
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_TYPEID, svType);
166
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_DEVID, svNum);
167
	MassInstId = svPart + "-" + svLoc + "-" + svType + "-" + svNum;    
168
 
169
    EndDialog(DLG_GETMASSINSTID);
170
    ReleaseDialog(DLG_GETMASSINSTID);
171
 
172
    // record data produced by this dialog
173
    if (MODE = RECORDMODE) then
174
        SdMakeName(szAppKey, DLG_GETMASSINSTID, "", g_nDlgGetMassInstId);
175
        SilentWriteData(szAppKey, "svNum",  DATA_STRING, svNum,  nNil);
176
        SilentWriteData(szAppKey, "svType", DATA_STRING, svType, nNil);
177
        SilentWriteData(szAppKey, "svLoc",  DATA_STRING, svLoc,  nNil);
178
        SilentWriteData(szAppKey, "svPart", DATA_STRING, svPart, nNil);
179
        SilentWriteData(szAppKey, "Result", DATA_NUMBER, szNil, nReturn);
180
    endif;
181
 
182
    return nReturn;
183
end;
184
 
185
 
186
function BOOL _GetMassInstIdTokens(input, part, loc, type, num)
187
    LIST	listID;
188
    STRING	svPart, svLoc, svType, svNum;
189
    BOOL	retval;
190
begin
191
 
192
	retval = FALSE;
193
    listID = ListCreate (STRINGLIST);
194
 
195
    // Get each path from the search path into the list.
196
    if (StrGetTokens (listID, input, "-") != 0 ) goto exitfunc;
197
    if ( ListCount ( listID ) != MASSSITEID_FIELDS ) goto exitfunc;
198
 
199
    ListGetFirstString ( listID, svPart );
200
    if ( StrLengthChars ( svPart ) != MASSSITEID_PARTLEN ) goto exitfunc;
201
 
202
    ListGetNextString  ( listID, svLoc );
203
    if ( StrLengthChars ( svLoc ) != MASSSITEID_LOCLEN ) goto exitfunc;
204
 
205
    ListGetNextString  ( listID, svType );
206
    if ( StrLengthChars ( svType ) != MASSSITEID_TYPELEN ) goto exitfunc;
207
 
208
    ListGetNextString  ( listID, svNum );
209
    if ( StrLengthChars ( svNum ) != MASSSITEID_NUMLEN ) goto exitfunc;
210
 
211
	retval = TRUE;
212
	part = svPart;
213
	loc = svLoc;
214
	type = svType;
215
	num = svNum;
216
 
217
exitfunc:
218
	ListDestroy(listID);
219
	return retval;
220
end;
221
 
222
 
223
function NUMBER _VerifyFields(VerifyHostname, hostNameValid, hostName)
224
    STRING	svPart, svLoc, svType, svNum, svTmp;
225
    STRING  errMsg;
226
	NUMBER	retval;
227
begin
228
 
229
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_PARTID, svPart);
230
	if ( StrLengthChars ( svPart ) != MASSSITEID_PARTLEN ) then
231
		NumToStr(errMsg, MASSSITEID_PARTLEN);
232
		errMsg = "ERROR: Participant must be " + errMsg + " digits";
233
		goto exitVerifyFields;
234
	endif;
235
 
236
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_LOCID, svLoc);
237
	if ( StrLengthChars ( svLoc ) != MASSSITEID_LOCLEN ) then
238
		NumToStr(errMsg, MASSSITEID_LOCLEN);
239
		errMsg = "ERROR: Location must be " + errMsg + " digits";
240
		retval = GETMASSINSTID_LOCID;
241
		goto exitVerifyFields;
242
	endif;
243
 
244
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_TYPEID, svType);
245
	if ( StrLengthChars ( svType ) != MASSSITEID_TYPELEN ) then
246
		NumToStr(errMsg, MASSSITEID_TYPELEN);
247
		errMsg = "ERROR: Device Type must be " + errMsg + " digits";
248
		retval = GETMASSINSTID_TYPEID;
249
		goto exitVerifyFields;
250
	endif;
251
 
252
    CtrlGetText(DLG_GETMASSINSTID, GETMASSINSTID_DEVID, svNum);
253
	if ( StrLengthChars ( svNum ) != MASSSITEID_NUMLEN ) then
254
		NumToStr(errMsg, MASSSITEID_NUMLEN);
255
		errMsg = "ERROR: Location must be " + errMsg + " digits";
256
		retval = GETMASSINSTID_DEVID;
257
		goto exitVerifyFields;
258
	endif;
259
 
260
	// lets check hostname
261
	if ( VerifyHostname = TRUE ) then
262
		svTmp = svPart + "-" + svLoc + "-" + svType + "-" + svNum;
263
		if ( svTmp != hostName ) then
264
			errMsg = "WARNING: Installation ID does not match hostname [" + hostName + "]";
265
			if ( hostNameValid = FALSE ) then
266
				errMsg = errMsg + ", which itself is not a valid installation ID.";
267
			else
268
				errMsg = errMsg + ".";
269
			endif;
270
			// return OK as this is just a warning
271
			retval = 0;
272
			goto exitVerifyFields;
273
		endif;
274
	endif;
275
 
276
	errMsg = "";
277
	retval = 0;
278
 
279
exitVerifyFields:
280
    CtrlSetText(DLG_GETMASSINSTID, GETMASSINSTID_MSG, errMsg);
281
	return retval;
282
end;