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
// Include header files /////////////////////////////////////////////////////
3
 
4
#include "ishieldlib.h"          
5
 
6
 
7
 
8
 
9
/*-------------------------------------------------------------------------*/
10
/*   FileStrReplace - Search and replace a string in a file                */
11
/*     Mark Kendzior - mrk@amlibs.com                                     */
12
/*                                                                         */
13
/*   Function: FileStrReplace(svFileName, //Full path of file to be updated*/
14
/*                            szSubStr, //String to be replaced            */
15
/*                            szReplaceStr) //String to replace            */
16
/*                                                                         */
17
/*   Descrip:  Convienence procedure to replace the szSubStr with          */
18
/*             with szRelpaceStr in the file specified.                    */
19
/*             Return Values:                                              */
20
/*               1 - String replace worked.                                */
21
/*               0 - String replace failed.                                */
22
/*                                                                         */
23
/*   Update: 05 August 1999 - Fixed endless loop when the original string  */
24
/*           is replaced with a string that contains the original string.  */
25
/*                                                                         */
26
/*-------------------------------------------------------------------------*/
27
 
28
function islib_FileStrReplace (svFileName, szSubStr, szReplaceStr)
29
    NUMBER nvPos, nResult;
30
    STRING svString, svSubStr1, svSubStr2, svNewString;
31
    BOOL   bListUpdated, bFound;
32
    LIST   listID, listNew;    
33
 
34
begin
35
  // create lists
36
   listID = ListCreate(STRINGLIST);
37
   listNew = ListCreate(STRINGLIST);
38
   if (ListReadFromFile(listID, svFileName) < 0) then // read list from file
39
      islib_MessageBox("ListReadFromFile failed.", SEVERE);
40
      return 0;
41
   endif;
42
//
43
//   SdShowInfoList ("", "Before replace", listID);
44
 
45
   bListUpdated = FALSE;
46
   nResult = ListGetFirstString (listID, svString);         // start at the top of the list
47
   while (nResult = 0)
48
 
49
     bFound = FALSE; svNewString = "";
50
     nvPos = StrFind (svString, szSubStr);        // find position in string
51
     while (nvPos >= 0)
52
       StrSub (svSubStr1, svString, 0, nvPos);    // replace string
53
       StrSub (svSubStr2, svString, nvPos+StrLength (szSubStr), StrLength (svString));
54
       svNewString = svNewString + svSubStr1 + szReplaceStr;
55
       svString = svSubStr2;
56
       bFound = TRUE;
57
       nvPos = StrFind (svString, szSubStr);        // find position in string
58
     endwhile;
59
     if bFound = TRUE then
60
       svNewString = svNewString + svString;      // append rest of line
61
       ListAddString (listNew, svNewString, AFTER);  // insert new string into new list
62
       bListUpdated = TRUE;                       // flag to write new list to file
63
     else // Add unchanged string to new list
64
       ListAddString (listNew, svString, AFTER);  // insert string into new list
65
     endif;
66
 
67
     nResult = ListGetNextString (listID, svString);
68
   endwhile;
69
 
70
   if bListUpdated then
71
     ListWriteToFile (listNew, svFileName);        // write list to file
72
   endif;
73
//
74
//   SdShowInfoList ("", "After replace", listNew);
75
 
76
   ListDestroy (listID);
77
   ListDestroy (listNew);
78
   return 1;
79
end;
80
 
81
 
82
 
83
 
84
 
85
//////////////////////////////////////////////////////////////////////////////////////////
86
//
87
// Function: 	islib_ModString
88
//
89
// Purpose: 	Function to search and replace text in a string. 
90
//				Handy for reversing forward slashes in path descriptions.
91
//
92
//////////////////////////////////////////////////////////////////////////////////////////
93
 
94
 
95
function islib_ModString( szSubStr, szReplaceStr, szTargetString)
96
 
97
STRING	szInputDirectory;   
98
STRING	szNewString, szSubStr1, szSubStr2, szString;
99
NUMBER	nError, nPos; 
100
BOOL	bFound;
101
 
102
begin  
103
	szString = szTargetString;         
104
	bFound = FALSE; 
105
	szNewString = "";
106
 
107
 	nPos = StrFind (szString, szSubStr);				// find position in string
108
 
109
    while (nPos >= 0)
110
    	StrSub (szSubStr1, szString, 0, nPos);			// replace string  	
111
    	StrSub (szSubStr2, szString, nPos+StrLength (szSubStr), StrLength (szString));
112
 
113
       	szNewString = szNewString + szSubStr1 + szReplaceStr;
114
       	szString = szSubStr2;
115
 
116
       	bFound = TRUE;
117
       	nPos = StrFind (szString, szSubStr);			// find position in string
118
     endwhile;
119
 
120
     if bFound = TRUE then
121
       szTargetString = szNewString + szString;			// append rest of line
122
     endif;
123
 
124
end;
125
 
126
 
127
 
128
///////////////////////////////////////////////////////////////////////////////
129
//
130
// Function: islib_UpdateIniFile
131
//
132
// Purpose: Add all configuration data to the properties files supplied.
133
//			General purpose function, calls specific functions to reduce code.
134
//
135
///////////////////////////////////////////////////////////////////////////////
136
 
137
function islib_UpdateIniFile(szMyFileName, szMyTag, szMyReplaceStr)
138
begin   
139
 
140
    if ( islib_FileStrReplace (szMyFileName, szMyTag, szMyReplaceStr) = 0 )
141
    then
142
        islib_MessageBox ( "Failed to update file=[" + szMyFileName + "], replace tag=[" +szMyTag+ "], update string=[" + szMyReplaceStr + "].\n" +
143
                     "Installation did not complete successfully.", SEVERE);                
144
    endif;                        
145
 
146
end;  
147
 
148
 
149
 
150
 
151
 
152
//////////////////////////////////////////////////////////////////////////////
153
//                                                                           
154
//  FUNCTION:   islib_LocalHostname                                            
155
//                                                                           
156
//  EVENT:      Function to extract the system hostname from the registry. It
157
//				may not be accurate however, if the system has 2 ethernet cards or
158
//				runs on DHCP.
159
//                                                                           
160
///////////////////////////////////////////////////////////////////////////////
161
 
162
function islib_LocalHostname( szHostname )
163
 
164
	STRING szRegKey;  
165
	NUMBER nvType, nvSize;
166
 
167
begin 
168
 
169
	szRegKey = "\\SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters";
170
 
171
	RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);
172
	if (RegDBKeyExist (szRegKey) = 1) then    
173
		RegDBGetKeyValueEx ( szRegKey, "Hostname", nvType, szHostname, nvSize );
174
		return 1;
175
	else
176
		return 0;
177
 	endif;
178
 
179
end;
180
 
181
 
182
 
183
//////////////////////////////////////////////////////////////////////////////
184
//                                                                           
185
//  FUNCTION:   islib_Interbase                                         
186
//                                                                           
187
//  EVENT:      Function to extract the install location of Borland or Firebird
188
//				Interbase from the registry. Function provides 2 strings of data
189
//				- first the location of the Interbase, and then the specific type.
190
//                                                                           
191
///////////////////////////////////////////////////////////////////////////////
192
 
193
function islib_Interbase( szIBType, szIBDir )
194
 
195
	STRING szRegKey;  
196
	NUMBER nvType, nvSize;
197
 
198
begin 
199
 
200
    RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);
201
	szRegKey = "\\SOFTWARE\\Borland\\InterBase\\CurrentVersion";
202
 
203
	if (RegDBKeyExist (szRegKey) = 1) then
204
		RegDBGetKeyValueEx ( szRegKey, "RootDirectory", nvType, szIBDir, nvSize );
205
		szIBType = "BORLAND"; 
206
		return 1;
207
 	else
208
 		szRegKey = "\\SOFTWARE\\FirebirdSQL\\Firebird\\CurrentVersion";
209
 
210
 		if (RegDBKeyExist (szRegKey) = 1) then 
211
 			RegDBGetKeyValueEx ( szRegKey, "RootDirectory", nvType, szIBDir, nvSize );
212
 			szIBType = "FIREBIRD";
213
 			return 1;
214
 		else
215
 			return 0;
216
  		endif; 
217
	 endif;
218
end;
219
 
220
 
221
 
222
 
223
//////////////////////////////////////////////////////////////////////////////
224
//                                                                           
225
//  FUNCTION:   islib_AccessControl                                         
226
//                                                                           
227
//  EVENT:      Function to extract the install location of the access control
228
//				client and return the value.
229
//                                                                           
230
///////////////////////////////////////////////////////////////////////////////
231
 
232
function islib_AccessControl( szACDir )
233
 
234
	STRING szRegKey;  
235
	NUMBER nvType, nvSize;
236
 
237
begin 
238
 
239
    RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);
240
	szRegKey = ERGAFC_PKG_REGISTRY_BASE + "ERGacclnt";
241
 
242
	if (RegDBKeyExist (szRegKey) = 1) then
243
		RegDBGetKeyValueEx ( szRegKey, "BaseInstallDir", nvType, szACDir, nvSize );
244
		return 1;
245
 	else  				
246
		return 0;
247
 	endif; 
248
 
249
end;
250
 
251
 
252
//////////////////////////////////////////////////////////////////////////////
253
//                                                                           
254
//  FUNCTION:   islib_setErgAfcPkgRegistryKeys       
255
//
256
//  This function sets the predefined registry key
257
//  for an ERG AFC package.
258
//
259
//  We assume the key(s) shall exist in the following
260
//  default location of the registry:
261
//  
262
//  HKEY_LOCAL_MACHINE\SOFTWARE\ERG\AFC
263
//
264
//  the key name shall be defined by the 
265
//  InstallShield project string ID_STING2.
266
//
267
//  i.e. PKG_NAME = "ERGpxyif"
268
//
269
//  The function shall also create the following string
270
//  parameters under this key these shall incllude:
271
//  
272
//  PkgName         = PKG_NAME 
273
//  PkgNameLong     = PKG_NAMELONG 
274
//  PkgVersion      = PKG_VERSION 
275
//  PkgBuilbNum     = PKG_BUILDNUM
276
//  PkgProjAcronym  = PKG_PROJECTACRONYM
277
//  PkgDesc         = PKG_DESC
278
//  BaseInstallDir  = [INSTALLDIR]
279
//  PkgInstalled    = Date/Time Package was installed
280
//
281
//  Return Values:
282
//
283
//   SUCCESS: 1
284
//   ERROR:  -1
285
//
286
//   The function shall abort the installation if the 
287
//   package subject string is greater that the predefined
288
//   allowable length size @MAX_PKGNAME_LENGTH.
289
//
290
//////////////////////////////////////////////////////////////////////////////                       
291
function islib_setErgAfcPkgRegistryKeys( nzType )  
292
 
293
    STRING  szKey;
294
    STRING  szItem;
295
    STRING  szValue;
296
    STRING  szClass;             
297
    STRING  szMaxPkgNameLength;
298
    STRING  szTime;
299
    STRING  szDate;              
300
 
301
    NUMBER nzResult;
302
    NUMBER nzERROR;
303
    NUMBER nzSUCCESS; 
304
    NUMBER nzMaxPkgNameLength;         
305
 
306
begin 
307
 
308
 
309
    if ( nzType != DEVICE_REGTYPE && nzType != PKG_REGTYPE )
310
    then  
311
 
312
        islib_MessageBox("Invalid parameter passed to islib_setErgAfcPkgRegistryKeys().", SEVERE);
313
        abort;
314
 
315
    endif; 
316
 
317
 
318
    // now we just check to see if the project version numbers entered match
319
    // if they do not we warn, it not good to exit at this point we need to ensure the rest of 
320
    // the install completes so we have a chnace of uninstall.
321
    //
322
    // we canot however check the build number and project acronym easily.
323
    //                    
324
    if ( PKG_VERSION != @PRODUCT_VERSION )
325
    then
326
 
327
         islib_MessageBox("The build.pl PKG_VERSION=[" +PKG_VERSION+ "] property does not match the Ishield PRODUCT_VERSION=["+@PRODUCT_VERSION+"] property.\n" +
328
                          "Please review the IShield Product Properties with the local build.pl details before compiling.", SEVERE);            
329
 
330
    endif; 
331
 
332
 
333
    // Define my local return values.                  
334
    //
335
    nzMaxPkgNameLength = MAX_PKGNAME_LENGTH;  
336
    NumToStr ( szMaxPkgNameLength, nzMaxPkgNameLength );             
337
 
338
 
339
    // we shall check to ensure the package name
340
    // that is stored in the ID_STRING2 string
341
    // does not exceed the predeifned 10 character limit.
342
    if ( StrLengthChars ( PKG_NAME ) < 0 )
343
    then       
344
 
345
        islib_MessageBox ("ERROR: Installation could not determine the package subject [" +
346
                     PKG_NAME + "].", SEVERE);
347
        return ISLIB_ERROR;      
348
 
349
    endif;
350
 
351
    if ( StrLengthChars ( PKG_NAME ) > nzMaxPkgNameLength )
352
    then       
353
 
354
        islib_MessageBox ("ERROR: The package subject [" +
355
                     PKG_NAME + "] exceeds the max allowable length of " + 
356
                     szMaxPkgNameLength + " characters.", SEVERE);
357
        return ISLIB_ERROR;       
358
 
359
    endif;
360
 
361
 
362
 
363
    // lets define the base key root location
364
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
365
 
366
 
367
    // lets stop the logging of this change
368
    // as we do not want to remove it on uninstall.
369
    //          
370
    Disable(LOGGING); 
371
 
372
 
373
    // lets deal with the reg type we have been
374
    // told about.    
375
    if ( nzType = DEVICE_REGTYPE )
376
    then    
377
        szKey = ERGAFC_DEVICE_REGISTRY_BASE;        
378
    else
379
        szKey = ERGAFC_PKG_REGISTRY_BASE;
380
    endif;    
381
 
382
 
383
    szClass = "";
384
    if(RegDBCreateKeyEx (szKey, szClass) < 0)
385
    then                                  
386
 
387
    	islib_MessageBox( "ERROR creating registry.", SEVERE );
388
        return ISLIB_ERROR;
389
 
390
    endif;
391
 
392
    // re-enable logging.
393
    //  
394
    Enable(LOGGING);  
395
 
396
 
397
 
398
    // lets deal with the reg type we have been
399
    // told about.
400
    if ( nzType = DEVICE_REGTYPE )
401
    then    
402
        szKey   = ERGAFC_DEVICE_REGISTRY_BASE + PKG_NAME + "_" + PKG_VERSION + "-" + PKG_BUILDNUM + "." + PKG_PROJACRONYM;        
403
    else
404
        szKey   = ERGAFC_PKG_REGISTRY_BASE + PKG_NAME;
405
    endif; 
406
 
407
    szClass = "";
408
    if(RegDBCreateKeyEx (szKey, szClass) < 0)
409
    then                                  
410
 
411
    	islib_MessageBox( "ERROR creating registry key=["+szKey+"].", SEVERE );
412
        return ISLIB_ERROR;
413
 
414
    else
415
 
416
        // Check if the newly created multi-level key exists.
417
        //
418
        if (RegDBKeyExist (szKey) < 0)
419
        then          
420
 
421
            islib_MessageBox ("ERROR: [" + szKey + "] registry key does not exist.", SEVERE);
422
            return ISLIB_ERROR;
423
 
424
        else      	
425
 
426
 
427
            // lets create the Version item.
428
            szItem  = "PkgVersion"; 
429
 
430
            // lets verify the version string before we set it. 
431
            if ( islib_verifyVersionFormat( PKG_VERSION ) < 0 )
432
            then  
433
 
434
                islib_MessageBox ("ERROR: PKG_VERSION field [" + PKG_VERSION + "] failed verification.", SEVERE);
435
                return ISLIB_ERROR;
436
 
437
            endif;
438
 
439
            szValue = PKG_VERSION;
440
            if (RegDBSetKeyValueEx(
441
                 szKey,
442
                 szItem,
443
                 REGDB_STRING,
444
                 szValue, -1 ) < 0)
445
            then  
446
 
447
                islib_MessageBox( "Error creating [" + 
448
    	                    szKey + "\\" +  szItem +
449
    	                    "] registry key, value [" +
450
    	                    szValue +
451
    	                    "].", SEVERE );
452
 
453
                return ISLIB_ERROR; 
454
 
455
            endif; 
456
 
457
 
458
            // lets create the PkgBuildNum item.
459
            szItem  = "PkgBuildNum";
460
            szValue = PKG_BUILDNUM;                  
461
            if (RegDBSetKeyValueEx(
462
                 szKey,
463
                 szItem,
464
                 REGDB_STRING,
465
                 szValue, -1 ) < 0)
466
            then  
467
 
468
                islib_MessageBox( "Error creating [" + 
469
    	                    szKey + "\\" +  szItem +
470
    	                    "] registry key, value [" +
471
    	                    szValue +
472
    	                    "].", SEVERE );
473
 
474
                return ISLIB_ERROR; 
475
 
476
            endif;  
477
 
478
 
479
            // lets create the PkgProjAcronym item.
480
            szItem  = "PkgProjAcronym";
481
            szValue = PKG_PROJACRONYM;       
482
            if (RegDBSetKeyValueEx(
483
                 szKey,
484
                 szItem,
485
                 REGDB_STRING,
486
                 szValue, -1 ) < 0)
487
            then  
488
 
489
                islib_MessageBox( "Error creating [" + 
490
    	                    szKey + "\\" +  szItem +
491
    	                    "] registry key, value [" +
492
    	                    szValue +
493
    	                    "].", SEVERE );
494
 
495
                return ISLIB_ERROR; 
496
 
497
            endif;            
498
 
499
 
500
            // lets create the PkgName item.
501
            szItem  = "PkgName";
502
            szValue = PKG_NAME;       
503
            if (RegDBSetKeyValueEx(
504
                 szKey,
505
                 szItem,
506
                 REGDB_STRING,
507
                 szValue, -1 ) < 0)
508
            then  
509
 
510
                islib_MessageBox( "Error creating [" + 
511
    	                    szKey + "\\" +  szItem +
512
    	                    "] registry key, value [" +
513
    	                    szValue +
514
    	                    "].", SEVERE );
515
 
516
                return ISLIB_ERROR; 
517
 
518
            endif;            
519
 
520
 
521
            // lets create the PkgNameLong item.
522
            szItem  = "PkgNameLong";
523
            szValue = PKG_NAMELONG;       
524
            if (RegDBSetKeyValueEx(
525
                 szKey,
526
                 szItem,
527
                 REGDB_STRING,
528
                 szValue, -1 ) < 0)
529
            then  
530
 
531
                islib_MessageBox( "Error creating [" + 
532
    	                    szKey + "\\" +  szItem +
533
    	                    "] registry key, value [" +
534
    	                    szValue +
535
    	                    "].", SEVERE );
536
 
537
                return ISLIB_ERROR; 
538
 
539
            endif;                                     
540
 
541
 
542
            // lets create the PkgDesc item.
543
            szItem  = "PkgDesc";
544
            szValue = PKG_DESC;       
545
            if (RegDBSetKeyValueEx(
546
                 szKey,
547
                 szItem,
548
                 REGDB_STRING,
549
                 szValue, -1 ) < 0)
550
            then  
551
 
552
                islib_MessageBox( "Error creating [" + 
553
    	                    szKey + "\\" +  szItem +
554
    	                    "] registry key, value [" +
555
    	                    szValue +
556
    	                    "].", SEVERE );
557
 
558
                return ISLIB_ERROR; 
559
 
560
            endif; 
561
 
562
 
563
            // lets create the BaseInstallDir item.
564
            szItem  = "BaseInstallDir";
565
            szValue = INSTALLDIR;       
566
            if (RegDBSetKeyValueEx(
567
                 szKey,
568
                 szItem,
569
                 REGDB_STRING_EXPAND,
570
                 szValue, -1 ) < 0)
571
            then  
572
 
573
                islib_MessageBox( "Error creating [" + 
574
    	                    szKey + "\\" +  szItem +
575
    	                    "] registry key, value [" +
576
    	                    szValue +
577
    	                    "].", SEVERE );
578
 
579
                return ISLIB_ERROR; 
580
 
581
            endif;
582
 
583
 
584
            // lets create the Installed item.
585
            szItem  = "PkgInstalled";
586
            GetSystemInfo ( TIME, nzResult, szTime );
587
            GetSystemInfo ( DATE, nzResult, szDate );
588
 
589
            szValue = szDate + " " + szTime;       
590
            if (RegDBSetKeyValueEx(
591
                 szKey,
592
                 szItem,
593
                 REGDB_STRING,
594
                 szValue, -1 ) < 0)
595
            then  
596
 
597
                islib_MessageBox( "Error creating [" + 
598
    	                    szKey + "\\" +  szItem +
599
    	                    "] registry key, value [" +
600
    	                    szValue +
601
    	                    "].", SEVERE );
602
 
603
                return ISLIB_ERROR; 
604
 
605
            endif;
606
 
607
 
608
            // lets create the LatestPatchID item.
609
            szItem  = "LatestPatchID";
610
            szValue = "0000000000000-00";       
611
            if (RegDBSetKeyValueEx(
612
                 szKey,
613
                 szItem,
614
                 REGDB_STRING,
615
                 szValue, -1 ) < 0)
616
            then  
617
 
618
                islib_MessageBox( "Error creating [" + 
619
    	                    szKey + "\\" +  szItem +
620
    	                    "] registry key, value [" +
621
    	                    szValue +
622
    	                    "].", SEVERE );
623
 
624
                return ISLIB_ERROR; 
625
 
626
            endif;
627
 
628
 
629
            // lets create the Installed item.
630
            szItem  = "LatestPatchInstalled";
631
            szValue = "00-00-0000 0:00:00";       
632
            if (RegDBSetKeyValueEx(
633
                 szKey,
634
                 szItem,
635
                 REGDB_STRING,
636
                 szValue, -1 ) < 0)
637
            then  
638
 
639
                islib_MessageBox( "Error creating [" + 
640
    	                    szKey + "\\" +  szItem +
641
    	                    "] registry key, value [" +
642
    	                    szValue + "].", SEVERE );
643
 
644
                return ISLIB_ERROR; 
645
 
646
            endif;                                                           
647
 
648
        endif; 
649
 
650
    endif;
651
 
652
 
653
    // we are done dude.
654
    //
655
    return ISLIB_SUCCESS;                                          
656
 
657
end;  
658
 
659
 
660
 
661
//////////////////////////////////////////////////////////////////////////////
662
//
663
// FUNCTION:   islib_setSystemPathEntry  
664
//
665
// This function is used to maniplulate the System
666
// environement path variable, by adding a pre-specified
667
// entry to a pre-spcified location in the path variable.
668
//
669
// We pass:
670
// 1. the new path we wish to add to the system path.
671
// 2. the type of path (ie FULL, PARTIAL)
672
// 3. the position of the new path (i.e. BEFORE or AFTER)
673
//                                   
674
// In the event that a parameter is passed that is not supported
675
// shall result in the user being notified and the installation
676
// being aborted.
677
//
678
// Return Values:
679
//
680
// SUCCESSFULL PATH CREATION: 1
681
// PATH EXISTS: 2
682
// ERROR:  -1
683
//
684
//////////////////////////////////////////////////////////////////////////////  
685
function islib_setSystemPathEntry( szNewPathEntry, bType, bPosition )
686
 
687
    STRING szKey;
688
    STRING szName;
689
    STRING szPathBuff;
690
 
691
    NUMBER nType, nSize;  
692
    NUMBER nERROR, nSUCCESS1, nSUCCESS2;
693
 
694
begin  
695
 
696
    nSUCCESS1 = ISLIB_SUCCESS;
697
    nSUCCESS2 = 2;
698
    nERROR   = ISLIB_ERROR;
699
 
700
    // lets verify the supported parameters
701
    //
702
    if ( bPosition != BEFORE && bPosition != AFTER  )
703
    then      
704
 
705
        islib_MessageBox("ERROR: Incorrect parameter [bPosition] supplied to setSystemPathVariable(), check config. Installation aborting.", SEVERE );
706
        abort;
707
 
708
    endif;  
709
 
710
 
711
    // lets verify the supported parameters
712
    //
713
    if ( bType != FULL && bType != PARTIAL )
714
    then      
715
 
716
        islib_MessageBox("ERROR: Incorrect parameter [bType] supplied to setSystemPathVariable(), check config. Installation aborting.", SEVERE );
717
        abort;
718
 
719
    endif;  
720
 
721
 
722
    // first we need to get access to the current system
723
    // path.
724
    //
725
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
726
    szKey  = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
727
    szName = "Path";
728
 
729
    // Read the system path
730
    if (RegDBGetKeyValueEx(szKey, szName, nType, szPathBuff, nSize) < 0)
731
    then
732
 
733
        islib_MessageBox("ERROR: SYSTEM path environment variable not found. Installation aborting.", SEVERE );
734
        abort;
735
 
736
    endif;
737
 
738
 
739
    // Check whether or new entry has already been added
740
    // to the system path.
741
    //  
742
    if ( szPathBuff % ( szNewPathEntry ) = TRUE )
743
    then   
744
 
745
        //islib_MessageBox("System PATH already contains a reference to [" + szNewPathEntry + "], not updating.", INFORMATION);
746
        return nSUCCESS2; 
747
 
748
    endif;                                           
749
 
750
 
751
    // Initialize the path buffer.
752
    PathSet (szPathBuff); 
753
 
754
 
755
    // Add C:\MSOffice as the first path in the search path.
756
    if (PathAdd(szNewPathEntry, "", bType, bPosition) < 0) 
757
    then
758
 
759
        islib_MessageBox ("Unable to add [ " + szNewPathEntry + "] to path buffer.", SEVERE);
760
        abort;
761
 
762
    endif;
763
 
764
    // Get the search path from the path buffer; 
765
    // this call also releases the memory allocated 
766
    // for the path buffer.
767
    PathGet (szPathBuff);
768
 
769
 
770
    // lets stop the logging of this change
771
    // as we do not want to remove it on uninstall.
772
    //          
773
    Disable(LOGGING);  
774
 
775
 
776
    // Now we need to update the registry setting with 
777
    // our change.
778
    //
779
    if (RegDBSetKeyValueEx( szKey, szName, REGDB_STRING_EXPAND, szPathBuff, -1 ) < 0) 
780
    then   
781
 
782
          islib_MessageBox( "Error writing System PATH registry key. Installation aborting.", SEVERE );
783
          abort;
784
 
785
    endif;
786
 
787
 
788
    // re-enable logging.
789
    //          
790
    Enable(LOGGING);
791
 
792
 
793
    // done dude.
794
    return nSUCCESS1;               
795
 
796
end;    
797
 
798
 
799
//////////////////////////////////////////////////////////////////////////////
800
//
801
// FUNCTION:   islib_removeSystemPathEntry  
802
//
803
// This function is used to maniplulate the System
804
// environement path variable by deleting a pre-specified
805
// entry.
806
//
807
// We pass:
808
// 1. the new path we wish to add to the system path.
809
// 2. the type of path (ie FULL, PARTIAL)
810
//                                   
811
// In the event that a parameter is passed that is not supported
812
// shall result in the user being notified and the installation
813
// being aborted.
814
//
815
// Return Values:
816
//
817
// SUCCESS: 1
818
// ERROR:  -1
819
//
820
//////////////////////////////////////////////////////////////////////////////  
821
function islib_removeSystemPathEntry( szNewPathEntry, bType )
822
 
823
    STRING szKey;
824
    STRING szName;
825
    STRING szPathBuff;
826
 
827
    NUMBER nType, nSize;  
828
    NUMBER nERROR, nSUCCESS; 
829
 
830
begin  
831
 
832
    nSUCCESS = ISLIB_SUCCESS;
833
    nERROR   = ISLIB_ERROR;
834
 
835
    // lets verify the supported parameters
836
    //
837
    if ( bType != FULL && bType != PARTIAL )
838
    then      
839
 
840
        islib_MessageBox("ERROR: Incorrect parameter [bType] supplied to setSystemPathVariable(), check config. Installation aborting.", SEVERE );
841
        abort;
842
 
843
    endif;  
844
 
845
 
846
    // first we need to get access to the current system
847
    // path.
848
    //
849
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
850
    szKey  = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
851
    szName = "Path";
852
 
853
    // Read the system path
854
    if (RegDBGetKeyValueEx(szKey, szName, nType, szPathBuff, nSize) < 0)
855
    then
856
 
857
        islib_MessageBox("ERROR: SYSTEM path environment variable not found. Installation aborting.", SEVERE );
858
        abort;
859
 
860
    endif;
861
 
862
 
863
    // Check whether the entry is part of the buff
864
    //  
865
    if ( szPathBuff % ( szNewPathEntry ) != TRUE )
866
    then   
867
 
868
        //islib_MessageBox("System PATH does not contain a reference to [ " + szNewPathEntry + " ], not updating.", INFORMATION);             
869
        return nSUCCESS; 
870
 
871
    endif;                                           
872
 
873
 
874
    // Initialize the path buffer.
875
    PathSet (szPathBuff); 
876
 
877
 
878
    // Add C:\MSOffice as the first path in the search path.
879
    if (PathDelete(szNewPathEntry, bType) < 0) 
880
    then
881
 
882
        islib_MessageBox ("Unable to delete [ " + szNewPathEntry + " ] from path buffer.", SEVERE);
883
        abort;
884
 
885
    endif;
886
 
887
    // Get the search path from the path buffer; 
888
    // this call also releases the memory allocated 
889
    // for the path buffer.
890
    PathGet (szPathBuff);
891
 
892
 
893
    // lets stop the logging of this change
894
    // as we do not want to remove it on uninstall.
895
    //          
896
    Disable(LOGGING);  
897
 
898
 
899
    // Now we need to update the registry setting with 
900
    // our change.
901
    //
902
    if (RegDBSetKeyValueEx( szKey, szName, REGDB_STRING_EXPAND, szPathBuff, -1 ) < 0) 
903
    then   
904
 
905
          islib_MessageBox( "Error writing System PATH registry key. Installation aborting.", SEVERE );
906
          abort;
907
 
908
    endif;
909
 
910
 
911
    // re-enable logging.
912
    //          
913
    Enable(LOGGING);
914
 
915
 
916
    // done dude.
917
    return nSUCCESS;               
918
 
919
end;    
920
 
921
 
922
//////////////////////////////////////////////////////////////////////////////
923
//                                                                           
924
//  FUNCTION:   islib_setErgAfcPatchRegistryKeys       
925
//
926
//  This function sets the predefined registry key
927
//  for an ERG AFC patch.
928
//
929
//  We assume the key(s) shall exist in the following
930
//  default location of the registry:
931
//  
932
//  HKEY_LOCAL_MACHINE\SOFTWARE\ERG\AFC\patch
933
//
934
//  the key name shall be defined by PATCH_ID
935
//
936
//  i.e. PATCH_ID = "ERGCDXML050100-01"
937
//
938
//  The function shall also create the following
939
//  parameters under this key
940
//  
941
//  PatchNum          = The patch number (taken from the PATCH_ID, the last 2 characters).
942
//  ParentPkgVersion  = The version number of the parent package (PKG_VERSION).
943
//  Installed         = The date and time the patch was installed ().
944
//
945
//  Return Values:
946
//
947
//   ISLIB_SUCCESS: registry key set.
948
//   ISLIB_ERROR:   failed to set registry key.
949
//
950
//////////////////////////////////////////////////////////////////////////////                       
951
function islib_setErgAfcPatchRegistryKeys()  
952
 
953
    STRING szKey;
954
    STRING szItem;
955
    STRING szValue;
956
    STRING szClass;             
957
    STRING szDate;             
958
    STRING szTime;             
959
 
960
    STRING szPatchNumber;
961
 
962
    STRING szPkgBaseInstallDir;
963
    STRING szPkgVersion;
964
    STRING szPkgInstalled; 
965
    STRING szPkgLatestPatchID;
966
    STRING szPkgLatestPatchInstalled;
967
 
968
    STRING szPkgLatestPatchNumber;
969
    NUMBER nzPkgLatestPatchNumber;
970
 
971
    NUMBER nzResult;    
972
 
973
begin              
974
 
975
 
976
 
977
    // lets verify our PatchID
978
    //
979
    if ( islib_verifyPatchIDFormat( PATCH_ID ) < 0 )
980
    then     
981
 
982
        islib_MessageBox("ERROR: PatchID [" + PATCH_ID + 
983
                   "] failed verification.", SEVERE);
984
        return ISLIB_ERROR; 
985
 
986
    endif;
987
 
988
 
989
    // lets define the base key root location
990
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); 
991
    szKey   = ERGAFC_PATCH_REGISTRY_BASE + PATCH_ID;
992
    szClass = "";
993
    if(RegDBCreateKeyEx (szKey, szClass) < 0)
994
    then                                  
995
 
996
    	islib_MessageBox( "ERROR: updating registry.", SEVERE );
997
        return ISLIB_ERROR;
998
 
999
    else
1000
 
1001
        // Check if the newly created multi-level key exists.
1002
        //
1003
        if (RegDBKeyExist (szKey) < 0)
1004
        then          
1005
 
1006
            islib_MessageBox ("ERROR: [" + szKey + "] registry key does not exist.", SEVERE);
1007
            return ISLIB_ERROR;
1008
 
1009
        else      	                    
1010
 
1011
            // lets create the ParentPkgVersion item.
1012
            szItem  = "ParentPkgVersion";
1013
 
1014
            // lets verify the version string before we set it. 
1015
            if ( islib_verifyVersionFormat( PKG_VERSION ) < 0 )
1016
            then  
1017
 
1018
                islib_MessageBox ("ERROR: PKG_VERSION field [" + PKG_VERSION + "] failed verification.", SEVERE);
1019
                return ISLIB_ERROR;
1020
 
1021
            endif;
1022
 
1023
            szValue = PKG_VERSION;
1024
            if (RegDBSetKeyValueEx(
1025
                 szKey,
1026
                 szItem,
1027
                 REGDB_STRING,
1028
                 szValue, -1 ) < 0)
1029
            then  
1030
 
1031
                islib_MessageBox( "ERROR: creating [" + 
1032
    	                    szKey + "\\" +  szItem +
1033
    	                    "] registry key, value [" +
1034
    	                    szValue +
1035
    	                    "].", SEVERE );
1036
 
1037
                return ISLIB_ERROR; 
1038
 
1039
            endif;
1040
 
1041
 
1042
            // lets get the patch number identifier
1043
            //
1044
            if ( islib_getPatchNumber ( PATCH_ID , szPatchNumber ) < 0 )
1045
            then  
1046
 
1047
                islib_MessageBox("ERROR: islib_getPatchNumber() did not complete successfully.", SEVERE);
1048
                return ISLIB_ERROR;
1049
 
1050
            endif;
1051
 
1052
 
1053
            // lets create the PatchNum item.
1054
            szItem  = "PatchNumber";                      
1055
 
1056
            // lets write the reg item.
1057
            //
1058
            if (RegDBSetKeyValueEx(
1059
                 szKey,
1060
                 szItem,
1061
                 REGDB_STRING,
1062
                 szPatchNumber, -1 ) < 0)
1063
            then  
1064
 
1065
                islib_MessageBox( "ERROR: creating [" + 
1066
    	                    szKey + "\\" +  szItem +
1067
    	                    "] registry key, value [" +
1068
    	                    szPatchNumber +
1069
    	                    "].", SEVERE );
1070
 
1071
                return ISLIB_ERROR; 
1072
 
1073
            endif;                       
1074
 
1075
 
1076
            // lets create the Installed item.
1077
            szItem  = "PatchInstalled";
1078
            GetSystemInfo ( TIME, nzResult, szTime );
1079
            GetSystemInfo ( DATE, nzResult, szDate );
1080
 
1081
            szValue = szDate + " " + szTime;
1082
            if (RegDBSetKeyValueEx(
1083
                 szKey,
1084
                 szItem,
1085
                 REGDB_STRING_EXPAND,
1086
                 szValue, -1 ) < 0)
1087
            then 
1088
 
1089
                islib_MessageBox( "ERROR: creating [" +
1090
                            szKey + "\\" +  szItem +
1091
                            "] registry key, value [" +
1092
                            szValue +
1093
                            "].", SEVERE );
1094
 
1095
                return ISLIB_ERROR;
1096
 
1097
            endif;          
1098
 
1099
 
1100
            // lets create the obsoleted patch information.
1101
            //
1102
 
1103
            // first we need to get the current product patch number
1104
            // we are going to obsolete
1105
            //
1106
            if (islib_getErgAfcPkgLatestPatchIDRegistryDetails( szPkgLatestPatchID,                                                                                                       
1107
                                                                szPkgLatestPatchInstalled) < 0 )
1108
            then
1109
 
1110
                islib_MessageBox("ERROR: islib_getErgAfcPkgLatestPatchIDRegistryDetails() did not complete successfully.", SEVERE);
1111
                return ISLIB_ERROR;
1112
 
1113
            endif; 
1114
 
1115
 
1116
            // lets get our patch number.
1117
            //   
1118
            if ( islib_getPatchNumber( szPkgLatestPatchID, szPkgLatestPatchNumber ) < 0 )
1119
            then
1120
 
1121
                islib_MessageBox("ERROR: islib_getPatchNumber() did not complete successfully.", SEVERE); 
1122
                return ISLIB_ERROR;                                  
1123
 
1124
            endif;
1125
            StrToNum(nzPkgLatestPatchNumber, szPkgLatestPatchNumber);
1126
 
1127
 
1128
            // lets see what our latest patch is?
1129
            //
1130
            if ( nzPkgLatestPatchNumber = 0 )
1131
            then            
1132
                szValue = "0000000000-00";             
1133
            else            
1134
                szValue = szPkgLatestPatchID;            
1135
            endif;
1136
 
1137
 
1138
            // we have the product details lets update the
1139
            // our patch details.
1140
            // 
1141
            szItem  = "ObsoletedPatchID";                              
1142
            if (RegDBSetKeyValueEx(
1143
                 szKey,
1144
                 szItem,
1145
                 REGDB_STRING,
1146
                 szValue, -1 ) < 0)
1147
            then 
1148
 
1149
                islib_MessageBox( "ERROR: creating [" +
1150
                            szKey + "\\" +  szItem +
1151
                            "] registry key, value [" +
1152
                            szValue +
1153
                            "].", SEVERE );
1154
 
1155
                return ISLIB_ERROR;
1156
 
1157
            endif;     
1158
 
1159
 
1160
 
1161
            // lets see what our latest patch is?
1162
            //
1163
            if ( nzPkgLatestPatchNumber = 0 )
1164
            then            
1165
                szValue = "00-00-0000 0:00:00";                
1166
            else            
1167
                szValue = szPkgLatestPatchInstalled;           
1168
            endif;            
1169
 
1170
            szItem  = "ObsoletedPatchInstalled";                               
1171
            if (RegDBSetKeyValueEx(
1172
                 szKey,
1173
                 szItem,
1174
                 REGDB_STRING,
1175
                 szValue, -1 ) < 0)
1176
            then 
1177
 
1178
                islib_MessageBox( "ERROR: creating [" +
1179
                            szKey + "\\" +  szItem +
1180
                            "] registry key, value [" +
1181
                            szValue +
1182
                            "].", SEVERE );
1183
 
1184
                return ISLIB_ERROR;
1185
 
1186
            endif;                 
1187
 
1188
        endif; 
1189
 
1190
    endif;
1191
 
1192
 
1193
    // we are done dude.
1194
    //
1195
    return ISLIB_SUCCESS;                                          
1196
 
1197
end;          
1198
 
1199
 
1200
//////////////////////////////////////////////////////////////////////////////                       
1201
//
1202
//  FUNCTION:   islib_getPatchNumber
1203
//
1204
//  This function extracts the numeric section from the supplied
1205
//  PatchID.  It sets the szPatchNum variable thus returning the
1206
//  patch number to the calling function.
1207
//
1208
//  Return Value:
1209
//
1210
//  ISLIB_SUCCESS: ok
1211
//  ISLIB_ERROR:   encountered a problem.
1212
//
1213
//////////////////////////////////////////////////////////////////////////////                       
1214
function islib_getPatchNumber( szPatchID, szPatchIDNum )
1215
 
1216
    LIST   listID;
1217
 
1218
    STRING szPatchIDName;
1219
 
1220
begin
1221
 
1222
    // lets verify our PatchID passed in.
1223
    //
1224
    if ( islib_verifyPatchIDFormat( szPatchID ) < 0 )
1225
    then
1226
 
1227
        islib_MessageBox("ERROR: PatchID [" + 
1228
                   szPatchID +
1229
                   "] failed verification.", SEVERE);
1230
        return ISLIB_ERROR;
1231
 
1232
    endif;
1233
 
1234
 
1235
    // Create a list to hold the bits that make up the
1236
    // patch name.
1237
    listID = ListCreate (STRINGLIST);
1238
 
1239
 
1240
    // Get each bit from the passed value. 
1241
    // we have already verified that the format is ok
1242
    // from above.
1243
    //
1244
    StrGetTokens (listID, szPatchID, "-");
1245
 
1246
 
1247
    // lets get the patch number section.
1248
    ListGetFirstString ( listID, szPatchIDName );
1249
    ListGetNextString  ( listID, szPatchIDNum );
1250
 
1251
 
1252
    // Remove the list from memory.
1253
    ListDestroy (listID);
1254
 
1255
 
1256
    // we are done dure.
1257
    //
1258
    return ISLIB_SUCCESS;
1259
 
1260
end;
1261
 
1262
 
1263
//////////////////////////////////////////////////////////////////////////////                       
1264
//
1265
//  FUNCTION:   islib_verifyPatchIDFormat 
1266
//
1267
//  This function is used to verify the format of the parameter passed to that
1268
//  of a PatchID.  The format of a PatchID is defined in the Build & Release
1269
//  Guidelines document.
1270
//
1271
//  Return Values:
1272
//
1273
//  ISLIB_SUCCESS: format correct.
1274
//  ISLIB_ERROR:   format incorrect.
1275
//
1276
//  The function shall abort processing if it detects that the PatchId is
1277
//  of an incorrect format.  This information is critical to the configuration
1278
//  management and must be correct before proceeding.
1279
//
1280
//////////////////////////////////////////////////////////////////////////////                       
1281
function islib_verifyPatchIDFormat( szPatchID )
1282
 
1283
    LIST   listID;
1284
 
1285
    STRING  szSection1;             
1286
    STRING  szSection2;             
1287
 
1288
    STRING  szLengthSec1;             
1289
    STRING  szLengthSec2;             
1290
 
1291
    NUMBER nzLengthSec1;
1292
    NUMBER nzLengthSec2;
1293
 
1294
    NUMBER nzNumSections;
1295
 
1296
    NUMBER nzPatchIDLength;
1297
    NUMBER nzVar;
1298
 
1299
    BOOL bzReturnFlag;
1300
 
1301
begin
1302
 
1303
    // Make available the predefined 
1304
    // definitions.
1305
    //
1306
    nzPatchIDLength = MAX_PATCHID_FORMAT_LENGTH;
1307
    nzLengthSec1    = MAX_PATCHID_NAME_FORMAT_LENGTH;
1308
    nzLengthSec2    = MAX_PATCHID_NUMBER_FORMAT_LENGTH;
1309
    nzNumSections   = NUM_PATCHID_SECTIONS;
1310
 
1311
    bzReturnFlag = TRUE;
1312
 
1313
 
1314
    // Create a list to hold the bits that make up the
1315
    // patch name.
1316
    listID = ListCreate (STRINGLIST);
1317
 
1318
 
1319
    // Get each path from the search path into the list.
1320
    if (StrGetTokens (listID, szPatchID, "-") > 0)
1321
    then
1322
 
1323
        // Report the error.
1324
        islib_MessageBox ("Patch ID [" + szPatchID + 
1325
                    "] has an incorrect format." +
1326
                    "\n\n(Info: A PatchID MUST use the following format, PPPPPPPPPPNNNNNN-NN).",
1327
                    SEVERE);
1328
 
1329
        bzReturnFlag = FALSE;
1330
 
1331
    else
1332
 
1333
        // we have our bits lets verify them
1334
 
1335
        // how many bits did we get?
1336
        //
1337
        if ( ListCount ( listID ) != nzNumSections )
1338
        then
1339
 
1340
            islib_MessageBox ( "Patch ID [" +
1341
                         szPatchID    +
1342
                         "] has an incorrect format.\n\n(Info: A PatchID MUST use the following format, PPPPPPPPPPNNNNNN-NN) .",
1343
                         SEVERE );
1344
 
1345
            bzReturnFlag = FALSE;
1346
 
1347
        endif;
1348
 
1349
 
1350
        // lets go through the sections,
1351
 
1352
 
1353
        // lets check the patch name section.
1354
        ListGetFirstString ( listID, szSection1 );
1355
        if ( StrLengthChars ( szSection1 ) > nzLengthSec1 )
1356
        then
1357
 
1358
            NumToStr( szLengthSec1, nzLengthSec1 );
1359
            islib_MessageBox ("Patch ID [" + szPatchID +
1360
                        "] has an incorrectly formatted patch name component [" +
1361
                        szSection1 + 
1362
                        "].\n\n(Info: A PatchID name MUST use upto " + szLengthSec1 + 
1363
                        " alpha-numeric characters, PPPPPPPPPPNNNNNN).",
1364
                        SEVERE);
1365
 
1366
            bzReturnFlag = FALSE;
1367
 
1368
        endif;
1369
 
1370
 
1371
        // lets check the patch number section.
1372
        // first we check the length.
1373
        ListGetNextString  ( listID, szSection2 );
1374
        if ( StrLengthChars ( szSection2 ) != nzLengthSec2 )
1375
        then
1376
 
1377
            NumToStr( szLengthSec2, nzLengthSec2 );
1378
            islib_MessageBox ("Patch ID [" + szPatchID +
1379
                        "] has an incorrectly formatted patch number component [" +
1380
                        szSection2 + 
1381
                        "].\n\n(Info: A PatchID number MUST use " + szLengthSec2 + " numeric digits ONLY, NN).",
1382
                        SEVERE);
1383
 
1384
            bzReturnFlag = FALSE;
1385
 
1386
        endif;
1387
 
1388
        // second we check the contents to be numeric.
1389
        if ( StrToNum ( nzVar, szSection2 ) < 0 )
1390
        then
1391
 
1392
            islib_MessageBox ("Patch ID [" + szPatchID +
1393
                        "] has an non-numeric patch number component [" + szSection2 + 
1394
                        "].\n\n(Info: A PatchID number MUST use " + szLengthSec2 + 
1395
                        " numeric digits ONLY, NN).",
1396
                        SEVERE);
1397
 
1398
            bzReturnFlag = FALSE;
1399
 
1400
        endif;
1401
 
1402
    endif;
1403
 
1404
    // Remove the list from memory.
1405
    ListDestroy (listID);
1406
 
1407
 
1408
    // we are done, and things are ok.
1409
    if ( bzReturnFlag = TRUE )
1410
    then
1411
        return ISLIB_SUCCESS;
1412
    else
1413
        return ISLIB_ERROR;
1414
    endif;
1415
 
1416
end;
1417
 
1418
 
1419
//////////////////////////////////////////////////////////////////////////////                       
1420
//
1421
//  FUNCTION:   islib_verifyLocationIDFormat 
1422
//
1423
//  This function is used to ensure that the parameter passed is of the 
1424
//  required location ID format, i.e. PPPPPPPPPP-LLL-SSS-NNNNNNNN
1425
//
1426
//  Return Values:
1427
//    ISLIB_SUCCESS - correct format
1428
//    ISLIB_ERROR   - incorrect format
1429
//
1430
//////////////////////////////////////////////////////////////////////////////                       
1431
function islib_verifyLocationIDFormat ( szLocationID )
1432
 
1433
    LIST   listID;
1434
    STRING svSearchPath;
1435
    STRING szTitle, szMsg;
1436
    NUMBER nzNumberLocationIDSections;
1437
    STRING szSec1, szSec2, szSec3, szSec4;
1438
    NUMBER nzLengthSec1, nzLengthSec2, nzLengthSec3, nzLengthSec4;
1439
 
1440
begin
1441
 
1442
    nzNumberLocationIDSections = NUM_LOCATIONID_SECTIONS;
1443
    nzLengthSec1               = MAX_LOCATIONID_SECTION_1_FORMAT_LENGTH;
1444
    nzLengthSec2               = MAX_LOCATIONID_SECTION_2_FORMAT_LENGTH;
1445
    nzLengthSec3               = MAX_LOCATIONID_SECTION_3_FORMAT_LENGTH;
1446
    nzLengthSec4               = MAX_LOCATIONID_SECTION_4_FORMAT_LENGTH;
1447
 
1448
 
1449
    // Create a list to hold the bits that make up the
1450
    // location ID.
1451
    listID = ListCreate (STRINGLIST);
1452
 
1453
 
1454
    // Get each path from the search path into the list.
1455
    if (StrGetTokens (listID, szLocationID, "-") > 0)
1456
    then
1457
 
1458
        // Report the error.
1459
        islib_MessageBox ("Location ID [" + szLocationID + "] has incorrect format,\n(use PPPPPPPPPP-LLL-SSSSSS-NNNNNNNN).",
1460
                     WARNING);
1461
 
1462
    else
1463
 
1464
        // We have our bits lets just check to see
1465
        // if they are of the correct format.
1466
 
1467
        // how many bits did we get?
1468
        //
1469
        if ( ListCount ( listID ) != nzNumberLocationIDSections )
1470
        then
1471
 
1472
            islib_MessageBox ( "Location ID [" + 
1473
                         szLocationID    + 
1474
                         "] has incorrect number of sections,\n(i.e. does not follow format PPPPPPPPPP-LLL-SSSSSS-NNNNNNNN) .",
1475
                         WARNING );
1476
 
1477
        endif;
1478
 
1479
 
1480
        // lets go through the sections,
1481
        ListGetFirstString ( listID, szSec1 );
1482
        if ( StrLengthChars ( szSec1 ) != nzLengthSec1 )
1483
        then
1484
 
1485
            islib_MessageBox ("Location ID [" + szLocationID +
1486
                        "] has incorrectly formated section 1 [" +
1487
                        szSec1 + "],\n(use format PPPPPPPPPP-LLL-SSSSSS-NNNNNNNN).",
1488
                        WARNING);
1489
        endif;
1490
 
1491
 
1492
        ListGetNextString  ( listID, szSec2 );
1493
        if ( StrLengthChars ( szSec2 ) != nzLengthSec2 )
1494
        then
1495
 
1496
            islib_MessageBox ("Location ID [" + szLocationID +
1497
                        "] has incorrectly formated section 2 [" +
1498
                        szSec2 + "],\n(use format PPPPPPPPPP-LLL-SSSSSS-NNNNNNNN).",
1499
                        WARNING);
1500
        endif;
1501
 
1502
        ListGetNextString  ( listID, szSec3 );
1503
        if ( StrLengthChars ( szSec3 ) != nzLengthSec3 )
1504
        then
1505
 
1506
            islib_MessageBox ("Location ID [" + szLocationID +
1507
                        "] has incorrectly formated section 3 [" +
1508
                        szSec3 + "],\n(use format PPPPPPPPPP-LLL-SSSSSS-NNNNNNNN).",
1509
                        WARNING);
1510
        endif;
1511
 
1512
        ListGetNextString  ( listID, szSec4 );
1513
        if ( StrLengthChars ( szSec4 ) != nzLengthSec4 )
1514
        then
1515
 
1516
            islib_MessageBox ("Location ID [" + szLocationID +
1517
                        "] has incorrectly formated section 4 [" +
1518
                        szSec4 + "],\n(use format PPPPPPPPPP-LLL-SSSSSS-NNNNNNNN).",
1519
                        WARNING);
1520
        endif;
1521
 
1522
    endif;
1523
 
1524
    // Remove the list from memory.
1525
    ListDestroy (listID);
1526
 
1527
    return TRUE;
1528
 
1529
end;
1530
 
1531
 
1532
//////////////////////////////////////////////////////////////////////////////
1533
//
1534
//  FUNCTION: islib_patchPreInstall
1535
//
1536
//  1. initialise predefined parameters
1537
//  2. verifyPatchIDFormat.
1538
//  3. verifyPatch Installation can proceed.
1539
//  3. create patch save location
1540
//  4. extract the filelist                     
1541
//  5. create patchLog file
1542
//  6. copy old items and log original locations in patchLog file.
1543
//    
1544
//  Return Values:
1545
//    ISLIB_SUCCESS - completed
1546
//    ISLIB_ERROR   - error during processing.
1547
//
1548
//////////////////////////////////////////////////////////////////////////////
1549
function islib_patchPreInstall ()
1550
 
1551
    STRING szPatchIDDir;
1552
    STRING szPatchIDSaveDir;
1553
    STRING szPatchIDLogFileLocation;
1554
    STRING szPatchIDLogFileName;
1555
 
1556
    STRING szMySrcFile;
1557
    STRING szMyDstFile;
1558
 
1559
    STRING szResult;
1560
    NUMBER nzResult;    
1561
 
1562
    STRING szMsg;  
1563
    STRING szTitle;
1564
 
1565
    LIST PatchItemsListID;
1566
 
1567
    NUMBER nzRetVal;
1568
    NUMBER nzFileHandle;  
1569
 
1570
begin
1571
 
1572
    // lets initialse the predefined parameter
1573
    // so we can use them.
1574
    //
1575
    szPatchIDDir             = PATCHID_DIR;
1576
    szPatchIDSaveDir         = PATCHID_SAVE_DIR;
1577
    szPatchIDLogFileLocation = PATCHID_LOGFILE_LOCATION;        
1578
    szPatchIDLogFileName     = PATCHID_LOGFILE_NAME;        
1579
 
1580
 
1581
    //SprintfBox (INFORMATION, "Debug Information",
1582
    //           "id=[%s], save=[%s], file=[%s]. ",
1583
    //            szPatchIDDir, szPatchIDSaveDir, szPatchIDLogFileLocation);       
1584
 
1585
 
1586
    // we need to determine if we can install this patch based on the
1587
    // patching rules we have predefined.  These rules govern the
1588
    // patch sequencing and obseletion criteria.
1589
    //
1590
    if ( islib_checkInstallPatch () < 0 ) 
1591
    then
1592
 
1593
        islib_MessageBox("This patch cannot be installed on this system.", SEVERE);
1594
        return ISLIB_ERROR;  
1595
 
1596
    endif;
1597
 
1598
 
1599
    // disable the  logging 
1600
    // functions, we shall clean up later.
1601
    //               
1602
    Disable(LOGGING);    
1603
 
1604
 
1605
    // Lets get our list of items that we are going to patch.
1606
    //
1607
    PatchItemsListID = ListCreate (STRINGLIST);
1608
    if ( islib_getPatchItemsList(PatchItemsListID) < 0 )
1609
    then
1610
 
1611
        islib_MessageBox ("Error failed to create the patch items list.", SEVERE);                  
1612
        return ISLIB_ERROR;        
1613
 
1614
    endif;
1615
 
1616
 
1617
    // lets see if anyone has left any junk 
1618
    // behind.
1619
    //
1620
    if ( Is(PATH_EXISTS, szPatchIDSaveDir) = TRUE )
1621
    then 
1622
 
1623
         islib_MessageBox("Patch directory [" + szPatchIDDir + "] already exists." +
1624
                    "\nPlease rectify prior to installing patch.", SEVERE);
1625
         return ISLIB_ERROR;   
1626
 
1627
    endif;
1628
 
1629
 
1630
    // lets create our patch store
1631
    //           
1632
    if ( CreateDir ( szPatchIDSaveDir ) < 0 )
1633
    then      
1634
 
1635
         islib_MessageBox("Failed to create [" + szPatchIDSaveDir + "] dir.", SEVERE);
1636
         return ISLIB_ERROR;                    
1637
 
1638
    endif;                                                        
1639
 
1640
 
1641
    // lets populate our patch store
1642
    //
1643
    if ( islib_savePatchItems(PatchItemsListID) < 0 )
1644
    then
1645
 
1646
        islib_MessageBox ("ERROR: Failed to complete patch save action.", SEVERE); 
1647
        return ISLIB_ERROR;
1648
 
1649
    endif;
1650
 
1651
 
1652
    // lets free resources.
1653
    //
1654
    ListDestroy(PatchItemsListID);
1655
 
1656
 
1657
    // lets re-enable logging here.
1658
    // we have created our patch store
1659
    // we need to clean it up later.
1660
    //        
1661
    Enable(LOGGING);
1662
 
1663
 
1664
    // we are done. 
1665
    return ISLIB_SUCCESS;
1666
 
1667
end;
1668
 
1669
 
1670
//////////////////////////////////////////////////////////////////////////////
1671
//
1672
//  FUNCTION: islib_checkInstallPatch
1673
//
1674
//   This function is used to check if the patch can be installed.
1675
//   The rules that govern if a patch can be installed are:
1676
//
1677
//   1. A parent package that has a name equal that defined in the 
1678
//      project Subject field has already been installed on the system.
1679
//
1680
//      This condition shall be checked ensuring the BaseInstallDir registry key
1681
//      exists for the parent package defined in the project Subject setting.
1682
//
1683
//      If the parent package registry key does not exist the patch shall stop
1684
//      the patch installation.
1685
//
1686
//   2. The parent package version number is equal to that of the patch.
1687
//      The patch version number is defined in the PKG_VERSION variable.
1688
//
1689
//      (i.e. The patch MYPKG010001-0N can only be used to patch any item installed by the package
1690
//            MYPKG of version 1.0.1).
1691
//
1692
//      This check shall be completed by comparing the Version registry setting of the package
1693
//      with the PKG_VERSION variable of the patch.
1694
//
1695
//      A patch can only be used to update a pre-defined specific parent package version.
1696
//
1697
//   3. The same patch has not already been installed.
1698
//      (ie you cannot install MYPKG010001-01 twice.
1699
//
1700
//      This shall be ensured by the use of the OnMaintUIBefore() function.  This 
1701
//      function ensures that a package with the same product codes cannot be installed twice. 
1702
//
1703
//   4. The patch has a patch number that is greater in value that the most recently 
1704
//      applied patch. 
1705
//
1706
//      (ie the patch MYPKG010001-01 cannot be applied after MYPKG010001-02).
1707
//       
1708
//       This shall be checked by retrieving the most parent package registry key
1709
//       containing the patch number of the most recently installed patch and comparing it
1710
//       to the current patch number.  
1711
//
1712
//       You can apply patch MYPKG010001-06 to a parent package that has had all
1713
//       patches applied upto MYPKG010001-04.  
1714
//       
1715
//       You will not how ever be able to subsequnetly apply patch MYPKG010001-05
1716
//       as this patch has been obsoleted by MYPKG010001-06.
1717
//       
1718
//
1719
//  Return Values:                
1720
//
1721
//    ISLIB_SUCCESS - completed ok
1722
//    ISLIB_ERROR   - error during processing.
1723
//
1724
//////////////////////////////////////////////////////////////////////////////
1725
function islib_checkInstallPatch ()
1726
 
1727
    STRING szPkgName;            
1728
 
1729
    STRING szPatchID;     
1730
    STRING szPatchIDNumber; 
1731
    STRING szPatchPkgVersion; 
1732
    STRING szPatchPkgProjAcronym;    
1733
 
1734
    STRING szPkgBaseInstallDir; 
1735
    STRING szPkgVersion; 
1736
    STRING szPkgInstalled; 
1737
    STRING szPkgLatestPatchID;  
1738
    STRING szPkgLatestPatchInstalled;
1739
    STRING szPkgBuildNum;  
1740
    STRING szPkgProjAcronym;
1741
    STRING szPkgDesc;
1742
 
1743
    STRING szMyPkgLatestPatchNumber;
1744
 
1745
    NUMBER nzPatchIDNumber; 
1746
    NUMBER nzMyPkgLatestPatchNumber;
1747
 
1748
    NUMBER nResult;   
1749
 
1750
begin 
1751
 
1752
    // initialise local variables.
1753
    //             
1754
    szPatchID             = PATCH_ID;    
1755
    szPatchPkgVersion     = PKG_VERSION;
1756
    szPkgName             = PKG_NAME;
1757
    szPatchPkgProjAcronym = PKG_PROJACRONYM;    
1758
 
1759
 
1760
    // lets verify our PatchID format
1761
    //
1762
    if ( islib_verifyPatchIDFormat( szPatchID ) < 0 )
1763
    then     
1764
 
1765
        islib_MessageBox("PatchID [" + szPatchID + "] failed format verification.", SEVERE);                   
1766
        return ISLIB_ERROR; 
1767
 
1768
    endif;       
1769
 
1770
 
1771
    // 1. lets check to see if our parent package exists
1772
    //   
1773
    if ( islib_checkErgAfcPkgExists(szPkgName) < 0 )
1774
    then    
1775
 
1776
        // we could not confirm that the parent package exists
1777
        // so we assume that the package was removed.
1778
        // 
1779
        // This implies we cannot install this patch
1780
        //
1781
        islib_MessageBox("Failed to detect parent package, " + szPkgName + " on system.\n" +
1782
                         "Parent package may not be not installed.", SEVERE); 
1783
        return ISLIB_ERROR; 
1784
 
1785
    else
1786
 
1787
        // our parent package exists lets get its current details
1788
        //
1789
        if (islib_getErgAfcPkgRegistryDetails( szPkgBaseInstallDir, 
1790
                                               szPkgVersion,
1791
                                               szPkgInstalled, 
1792
                                               szPkgLatestPatchID,                                               
1793
                                               szPkgLatestPatchInstalled,
1794
                                               szPkgBuildNum,
1795
                                               szPkgProjAcronym,
1796
                                               szPkgDesc ) < 0 )
1797
        then                                       
1798
 
1799
            // we encountered an error getting the details
1800
            //
1801
            islib_MessageBox("ERROR: islib_getErgAfcPkgRegistryDetails() did not complete successfully.", SEVERE); 
1802
            return ISLIB_ERROR;                          
1803
 
1804
        endif; 
1805
 
1806
 
1807
        // lets get our patch number. 
1808
        //
1809
        if ( islib_getPatchNumber( szPatchID, szPatchIDNumber ) < 0 )
1810
        then
1811
 
1812
            islib_MessageBox("ERROR: islib_getPatchNumber() did not complete successfully.", SEVERE); 
1813
            return ISLIB_ERROR;                                  
1814
 
1815
        endif;  
1816
 
1817
 
1818
        // we got our details lets apply the business rules
1819
        // of our patch management strategy.
1820
        //         
1821
 
1822
        // 2. version numbers must be equal to install a patch
1823
        // 
1824
        if ( islib_verifyVersionFormat(szPkgVersion) < 0 )
1825
        then                   
1826
            islib_MessageBox("ERROR: Package version [" + szPkgVersion + "] failed format verification." +
1827
                       "\nCheck configuration.", SEVERE);
1828
 
1829
            return ISLIB_ERROR;
1830
 
1831
        endif;
1832
 
1833
        if ( islib_verifyVersionFormat(szPatchPkgVersion) < 0 )
1834
        then                   
1835
            islib_MessageBox("ERROR: Patch version [" + szPatchPkgVersion + "] failed format verification." +
1836
                       "\nCheck configuration.", SEVERE);
1837
 
1838
            return ISLIB_ERROR;
1839
 
1840
        endif; 
1841
 
1842
 
1843
        // lets check to see that the patch projects are ok
1844
        //
1845
        if (szPatchPkgProjAcronym != szPkgProjAcronym)
1846
        then                   
1847
            islib_MessageBox("ERROR: Patch project [" + szPatchPkgProjAcronym + 
1848
                             "] does not match parent package project [" + szPkgProjAcronym +
1849
                             "].\n" +
1850
                             "Check configuration.", SEVERE);
1851
 
1852
            return ISLIB_ERROR;
1853
        endif; 
1854
 
1855
 
1856
        // our versions are of the correct format lest
1857
        // compare them.
1858
        nResult = islib_compareVersions(szPkgVersion, szPatchPkgVersion);
1859
        if ( nResult != ISLIB_VERSION_EQUALS )
1860
        then    
1861
 
1862
            islib_MessageBox("The patch you trying to install does not have a compatible version number." +
1863
                       "\n\nThis patch [" + szPatchID + "] version [" + szPatchPkgVersion + "] is not the same as " +
1864
                       "\nthe [" + szPkgName + "] parent package version [" + szPkgVersion + "]." +                      
1865
                       "\n\nCheck patch configuration.", WARNING); 
1866
 
1867
            return ISLIB_ERROR;               
1868
 
1869
        endif;
1870
 
1871
 
1872
        // 3 and 4. the patch number is greater than the latest
1873
        // patch previously installed.  You cannot install the same 
1874
        // patch number again.
1875
        //
1876
 
1877
        // lets get the latest patch installed patch number.
1878
        //   
1879
        if ( islib_getPatchNumber( szPkgLatestPatchID, szMyPkgLatestPatchNumber ) < 0 )
1880
        then
1881
 
1882
            islib_MessageBox("ERROR: islib_getPatchNumber() did not complete successfully.", SEVERE); 
1883
            return ISLIB_ERROR;                                  
1884
 
1885
        endif; 
1886
 
1887
        StrToNum(nzPatchIDNumber, szPatchIDNumber);
1888
        StrToNum(nzMyPkgLatestPatchNumber, szMyPkgLatestPatchNumber);
1889
        if ( nzPatchIDNumber = nzMyPkgLatestPatchNumber )
1890
        then    
1891
 
1892
            islib_MessageBox("The patch you trying to install has already been installed on [" +
1893
                       szPkgLatestPatchInstalled + "].", WARNING); 
1894
 
1895
            return ISLIB_ERROR;               
1896
 
1897
        elseif (nzPatchIDNumber < nzMyPkgLatestPatchNumber )
1898
        then
1899
 
1900
            islib_MessageBox("The patch you trying to install [" + szPatchID + "] has been obsoleted " +
1901
                       "\nby a patch that has been previously installed." +
1902
                       "\n\nThe latest patch to be installed for the parent package [" + szPkgName + "] has " + 
1903
                       "\npatch ID [" + szPkgLatestPatchID + "], installed on [" +
1904
                       szPkgLatestPatchInstalled + "].", WARNING); 
1905
 
1906
            return ISLIB_ERROR;               
1907
 
1908
        endif;          
1909
 
1910
    endif;  
1911
 
1912
 
1913
    // if we got to here things are ok, we now need to ensure that the
1914
    // INSTALLDIR variable is set to the PkgBaseInstallDir variable
1915
    // we retieved from the registry.  this ensures that the patch 
1916
    // starts from the same point as the parent package.
1917
    //
1918
    INSTALLDIR = szPkgBaseInstallDir;
1919
 
1920
 
1921
    // done.
1922
    return ISLIB_SUCCESS;
1923
 
1924
end;
1925
 
1926
 
1927
//////////////////////////////////////////////////////////////////////////////
1928
//
1929
//  FUNCTION: islib_compareVersions
1930
//
1931
//  This function is used to compare two string that contain version numbers
1932
//  The version has a pre-defined format of M.M.M where M is any integer.
1933
//
1934
//  Version A is passed in as parameter 1,
1935
//  Version B is passed in as parameter 2.
1936
//
1937
//  The priority for comparision shall be left to right,
1938
//  (ie the left most integer is the major number, whilst the right mose integer
1939
//   is the minor number).
1940
//
1941
//   Return Values:
1942
//
1943
//   -1: encountered a processing error.
1944
//    0: versions are equal
1945
//    1: version A, is greater that version B
1946
//    2: version A, is less than version B
1947
//
1948
//////////////////////////////////////////////////////////////////////////////                                     
1949
function islib_compareVersions(szVersionA, szVersionB)
1950
 
1951
    LIST lzVersionA;
1952
    LIST lzVersionB; 
1953
 
1954
    STRING szVersionAMajor;
1955
    STRING szVersionAMiddle;
1956
    STRING szVersionAMinor;
1957
 
1958
    STRING szVersionBMajor;
1959
    STRING szVersionBMiddle;
1960
    STRING szVersionBMinor;
1961
 
1962
    NUMBER nzVersionAMajor;
1963
    NUMBER nzVersionAMiddle;
1964
    NUMBER nzVersionAMinor;
1965
 
1966
    NUMBER nzVersionBMajor;
1967
    NUMBER nzVersionBMiddle;
1968
    NUMBER nzVersionBMinor;        
1969
 
1970
begin                     
1971
 
1972
    // lets first verify that the format of each
1973
    // version string is ok.
1974
    //        
1975
    if ( islib_verifyVersionFormat(szVersionA) < 0 )
1976
    then                   
1977
        islib_MessageBox("ERROR: Version [" + szVersionA + "] failed format verification." +
1978
                   "\nCheck version configuration.", SEVERE);
1979
 
1980
        return ISLIB_ERROR;
1981
 
1982
    endif;
1983
 
1984
    if ( islib_verifyVersionFormat(szVersionB) < 0 )
1985
    then                   
1986
        islib_MessageBox("ERROR: Version [" + szVersionB + "] failed format verification." +
1987
                   "\nCheck version configuration.", SEVERE);
1988
 
1989
        return ISLIB_ERROR;
1990
 
1991
    endif;
1992
 
1993
 
1994
    // first we need to check the formaat of each
1995
    // version number 
1996
    lzVersionA = ListCreate(STRINGLIST);
1997
    // If an error occurred, report it.
1998
    if (lzVersionA = LIST_NULL) then
1999
        islib_MessageBox ("ERROR: Unable to create list lzVersionA.", SEVERE);
2000
        return ISLIB_ERROR;
2001
    endif;
2002
 
2003
    // lets parse our version A string. 
2004
    // and load our local variables.
2005
    StrGetTokens(lzVersionA, szVersionA, ".");     
2006
    ListGetFirstString( lzVersionA, szVersionAMajor );
2007
    ListGetNextString ( lzVersionA, szVersionAMiddle);
2008
    ListGetNextString ( lzVersionA, szVersionAMinor);
2009
 
2010
    StrToNum(nzVersionAMajor,  szVersionAMajor);
2011
    StrToNum(nzVersionAMiddle, szVersionAMiddle);
2012
    StrToNum(nzVersionAMinor,  szVersionAMinor);
2013
 
2014
 
2015
    lzVersionB = ListCreate(STRINGLIST);
2016
    // If an error occurred, report it.
2017
    if (lzVersionB = LIST_NULL) then
2018
        islib_MessageBox ("ERROR: Unable to create list lzVersionB.", SEVERE);
2019
        return ISLIB_ERROR;
2020
    endif;           
2021
 
2022
    // lets parse our version B string. 
2023
    // and load our local variables.
2024
    //
2025
    StrGetTokens(lzVersionB, szVersionB, ".");
2026
    ListGetFirstString( lzVersionB, szVersionBMajor );
2027
    ListGetNextString ( lzVersionB, szVersionBMiddle);
2028
    ListGetNextString ( lzVersionB, szVersionBMinor);
2029
 
2030
    StrToNum(nzVersionBMajor,  szVersionBMajor);
2031
    StrToNum(nzVersionBMiddle, szVersionBMiddle);
2032
    StrToNum(nzVersionBMinor,  szVersionBMinor); 
2033
 
2034
 
2035
    // now we are ready to do the comparision. 
2036
    // remember we are comparing A to B 
2037
    // lets check the major numbers first
2038
    //
2039
    if ( nzVersionAMajor = nzVersionBMajor )
2040
    then
2041
 
2042
        // we need to check the middle numbers
2043
        if ( nzVersionAMiddle = nzVersionBMiddle)
2044
        then   
2045
 
2046
            // we need to check the minor numbers
2047
            if ( nzVersionAMinor = nzVersionBMinor)
2048
            then           
2049
                // if we get here the versions are equal
2050
                //
2051
                return  ISLIB_VERSION_EQUALS;
2052
            elseif(nzVersionAMinor > nzVersionBMinor)
2053
            then 
2054
                // here version A minor is greater than version B minor
2055
                // this implies the version A is greater than version B.
2056
                //
2057
                return ISLIB_VERSION_GREATER_THAN;                                        
2058
            else   
2059
                // here version A minor is less than version B minor
2060
                // this implies the version A is less than version B.
2061
                //
2062
                return ISLIB_VERSION_LESS_THAN;              
2063
            endif;                              
2064
 
2065
        elseif (nzVersionAMiddle > nzVersionBMiddle)
2066
        then
2067
            // here version A middle is greater than version B middle
2068
            // this implies the version A is greater than version B.
2069
            //
2070
            return ISLIB_VERSION_GREATER_THAN;
2071
        else 
2072
            // here version A middle is less than version B middle
2073
            // this implies that version A is less than version B.
2074
            return ISLIB_VERSION_LESS_THAN;
2075
        endif;                                                     
2076
 
2077
    elseif (nzVersionAMajor > nzVersionBMajor) 
2078
    then   
2079
        // here version A major is greater than version B major
2080
        // this implies the version A is greater than version B.
2081
        //
2082
        return ISLIB_VERSION_GREATER_THAN;
2083
    else
2084
        // here version A major is less than version B major
2085
        // this implies that version A is less than version B.
2086
        return ISLIB_VERSION_LESS_THAN;
2087
    endif;
2088
 
2089
 
2090
 
2091
    // free resources.
2092
    //                               
2093
    ListDestroy(lzVersionA);      
2094
    ListDestroy(lzVersionB);   
2095
 
2096
    // done. but we should never get here.                         
2097
    return ISLIB_SUCCESS;
2098
 
2099
end;                                
2100
 
2101
 
2102
//////////////////////////////////////////////////////////////////////////////
2103
//
2104
//  FUNCTION: islib_verifyVersionFormat 
2105
//
2106
//  This function is used to verify the format of version number.
2107
//  A version has a pre-defined format of M.M.M where M is any integer.
2108
//
2109
//  Return Values:
2110
//    ISLIB_SUCCESS - format ok
2111
//    ISLIB_ERROR   - format NOT ok.
2112
//
2113
//////////////////////////////////////////////////////////////////////////////
2114
function islib_verifyVersionFormat( szVersion )
2115
 
2116
    LIST   lzVersionID;                
2117
    NUMBER nzCount;
2118
    NUMBER nzRetVal; 
2119
 
2120
    STRING szBit;    
2121
    NUMBER nzBit;    
2122
 
2123
begin                               
2124
 
2125
    lzVersionID = ListCreate(STRINGLIST);
2126
    // If an error occurred, report it.
2127
    if (lzVersionID = LIST_NULL) then
2128
        islib_MessageBox ("ERROR: Unable to create list lzVersionID.", SEVERE);
2129
        return ISLIB_ERROR;
2130
    endif;
2131
 
2132
    // lets parse our version string.
2133
    StrGetTokens(lzVersionID, szVersion, "."); 
2134
 
2135
 
2136
    // Count the number of program folders in the list.
2137
    nzCount = ListCount (lzVersionID); 
2138
    if (  nzCount != MAX_NUM_VERSION_FORMAT_SECTIONS )
2139
    then
2140
 
2141
         islib_MessageBox ("ERROR: Version [" + szVersion + "] has an incorrect format, " +
2142
                     "(i.e. use N.N.N).", SEVERE);
2143
         return ISLIB_ERROR;
2144
 
2145
    endif; 
2146
 
2147
 
2148
    // lets confirm all the bits are numeric.
2149
    //
2150
    nzRetVal = ListGetFirstString ( lzVersionID, szBit );
2151
    while ( nzRetVal != END_OF_LIST )              
2152
 
2153
        if ( StrToNum(nzBit, szBit) < 0 )
2154
        then
2155
 
2156
            islib_MessageBox ("Version ["+szVersion+"] contains non-numeric component.", SEVERE); 
2157
            return ISLIB_ERROR;
2158
 
2159
        endif;
2160
 
2161
        // get next bit.
2162
        nzRetVal = ListGetNextString ( lzVersionID, szBit );   
2163
 
2164
    endwhile;          
2165
 
2166
 
2167
    // lets free resources.
2168
    ListDestroy(lzVersionID);
2169
 
2170
    // done.                        
2171
    return ISLIB_SUCCESS;
2172
 
2173
end;
2174
 
2175
 
2176
 
2177
 
2178
//////////////////////////////////////////////////////////////////////////////
2179
//
2180
//  FUNCTION: islib_getPatchItemsList
2181
//
2182
//   This function is used to retireive all file items to be delivered by this
2183
//   patch package.
2184
//
2185
//   We make use of the information avaiable in the installshield config
2186
//   An we populate a List variable that can be accessed by the calling
2187
//   function later.
2188
//
2189
//
2190
//  Return Values:
2191
//    ISLIB_SUCCESS - completed
2192
//    ISLIB_ERROR   - error during processing.
2193
//
2194
//////////////////////////////////////////////////////////////////////////////
2195
function islib_getPatchItemsList ( lzPatchItemsListID )
2196
 
2197
    NUMBER nzResult;
2198
    NUMBER nzTmpVar;
2199
 
2200
    LIST lzTopFeatureListID;
2201
    LIST lzSubFeatureListID; 
2202
    LIST lzSubFeatureItemListID; 
2203
    LIST lzParseFeatureListID;
2204
 
2205
    STRING szTmpVar;    
2206
    STRING szTopFeature;
2207
    STRING szSubFeature; 
2208
    STRING szSubFeatureOnlyStr;
2209
    STRING szTmpVar1;    
2210
    STRING szSubFeatureItem; 
2211
    STRING szSubFeatureItem_lc;
2212
    STRING szSubFeatureDescField; 
2213
    STRING szSubFeatureDescType; 
2214
    STRING szSubFeatureItemsLocation; 
2215
    STRING szString;
2216
 
2217
    NUMBER nzSubFeatureItemRetVal;    
2218
    NUMBER nzTopFeatureCount;
2219
    NUMBER nzSubFeatureCount;
2220
    NUMBER nzSubFeatureItemCount;  
2221
    NUMBER nzTopFeatureRetVal;
2222
    NUMBER nzSubFeatureRetVal;
2223
 
2224
begin
2225
 
2226
    // Initialize the string list.
2227
    lzTopFeatureListID = ListCreate (STRINGLIST); 
2228
    if (lzTopFeatureListID = LIST_NULL) 
2229
    then  
2230
 
2231
        islib_MessageBox ("System error, unable to create top-level feature list.", SEVERE);
2232
        return ISLIB_ERROR;        
2233
 
2234
    endif;
2235
 
2236
 
2237
    // Create a list of top-level features in the specified media.
2238
    if ( FeatureListItems (MEDIA, "", lzTopFeatureListID) < 0 )
2239
    then      
2240
 
2241
        islib_MessageBox ("System error, failed to get top-level feature list.", SEVERE);
2242
        return ISLIB_ERROR;                    
2243
 
2244
    endif;
2245
 
2246
 
2247
    // Count the number of program folders in the list.
2248
    nzTopFeatureCount = ListCount (lzTopFeatureListID); 
2249
    if (  nzTopFeatureCount <= 0 )
2250
    then
2251
 
2252
        islib_MessageBox ("Failed to detect any top-level features in patch configuration." +
2253
                    "\nCheck patch configuration.", SEVERE);
2254
        return ISLIB_ERROR;
2255
 
2256
    endif;  
2257
 
2258
 
2259
    // check to see if we exceed the max supported top-level
2260
    // features
2261
    //
2262
    if (  nzTopFeatureCount > MAX_NUM_TOP_LEVEL_FEATURES )
2263
    then
2264
 
2265
        nzTmpVar =  MAX_NUM_TOP_LEVEL_FEATURES;
2266
        NumToStr(szTmpVar, nzTmpVar);          
2267
        islib_MessageBox ("ERROR: current patch strategy ONLY supports [" +
2268
                    szTmpVar + "] top-level feature. Check patch features configuration.", SEVERE);
2269
        return ISLIB_ERROR;
2270
 
2271
    endif;  
2272
 
2273
 
2274
    // lets process the top level list.
2275
    // now we need to get the sub-features of each top-level feature.   
2276
    //
2277
    nzTopFeatureRetVal = ListGetFirstString ( lzTopFeatureListID, szTopFeature );     
2278
    while ( nzTopFeatureRetVal != END_OF_LIST )           
2279
 
2280
        // Now for each top-level feature we need to get the associated
2281
        // sub features. 
2282
 
2283
        // Initialize the string list.
2284
        lzSubFeatureListID = ListCreate (STRINGLIST);                                
2285
        if (lzSubFeatureListID = LIST_NULL) 
2286
        then  
2287
 
2288
            islib_MessageBox ("System error, unable to create sub-feature list.", SEVERE);
2289
            return ISLIB_ERROR;
2290
 
2291
        endif;
2292
 
2293
 
2294
        // Create a list of sub-features in the specified media.
2295
        if ( FeatureListItems (MEDIA, szTopFeature, lzSubFeatureListID) < 0 )
2296
        then      
2297
 
2298
            islib_MessageBox ("System error, failed to get sub-feature list.", SEVERE);
2299
            return ISLIB_ERROR;                    
2300
 
2301
        endif;
2302
 
2303
 
2304
        // Count the number of program folders in the list.
2305
        nzSubFeatureCount = ListCount (lzSubFeatureListID); 
2306
        if (  nzSubFeatureCount <= 0 )
2307
        then
2308
 
2309
            islib_MessageBox ("Failed to detect any sub-features in patch configuration." +
2310
                        "\nCheck patch configuration.", SEVERE);
2311
            return ISLIB_ERROR; 
2312
 
2313
        endif;
2314
 
2315
 
2316
        // now we need to get the sub-features of each top-level
2317
        // feature.   
2318
        nzSubFeatureRetVal = ListGetFirstString ( lzSubFeatureListID, szSubFeature );            
2319
        while ( nzSubFeatureRetVal != END_OF_LIST )   
2320
 
2321
            // we need to process each sub-feature, tht directly relates to
2322
            // a component that delivers a file.
2323
            // 
2324
            // first we need to extract the sub-feature from the string we have,
2325
            // the format is "topfeature\subfeature" 
2326
            lzParseFeatureListID = ListCreate(STRINGLIST);
2327
            StrGetTokens (lzParseFeatureListID, szSubFeature, "\\"); 
2328
 
2329
            // Count the number of program folders in the list.
2330
            nzResult = ListCount (lzParseFeatureListID); 
2331
            if (  nzResult != MAX_NUM_FEATURE_LEVELS )
2332
            then
2333
 
2334
                islib_MessageBox ("ERROR: [" + szSubFeature + "] feature exceedes 2 levels." +
2335
                            "\nCheck patch features configuration.", SEVERE);
2336
                return ISLIB_ERROR;
2337
 
2338
            endif; 
2339
 
2340
            ListGetFirstString ( lzParseFeatureListID, szTmpVar1 );
2341
            ListGetNextString  ( lzParseFeatureListID, szSubFeatureOnlyStr );                                   
2342
 
2343
 
2344
            // lets create the list to contain all sub-feature items
2345
            //  
2346
            lzSubFeatureItemListID = ListCreate(STRINGLIST);                   
2347
 
2348
 
2349
            // let extract all the items for my sub-feature
2350
            //
2351
            FeatureFileEnum ( MEDIA, szTopFeature, szSubFeatureOnlyStr+"\\*.*", lzSubFeatureItemListID, NO_SUBDIR );    
2352
 
2353
 
2354
            // Count the number of sub-feature component items in the list.
2355
            nzSubFeatureItemCount = ListCount (lzSubFeatureItemListID); 
2356
            if (  nzSubFeatureItemCount <= 0 )
2357
            then
2358
 
2359
                islib_MessageBox ("Failed to detect any items to patch in configuration. " +
2360
                            "\nCheck [" + szSubFeature + "] features/components relationship in patch configuration.", SEVERE);
2361
                return ISLIB_ERROR;
2362
 
2363
            endif;                        
2364
 
2365
 
2366
            // Get the description property for sub-feature.   
2367
            // This field contains the relative path from the INSTALLDIR
2368
            // for the items in the component == subFeature.
2369
            //
2370
            FeatureGetData (MEDIA, szSubFeature, FEATURE_FIELD_DESCRIPTION, nzResult, szSubFeatureDescField);
2371
            if ( szSubFeatureDescField = "" )
2372
            then 
2373
 
2374
                islib_MessageBox (szSubFeature + " feature description field is blank." + 
2375
                            "Check feature in patch configuration.", SEVERE);
2376
                return ISLIB_ERROR;
2377
 
2378
            endif;
2379
 
2380
 
2381
            // we need to determine if the description field is relative or
2382
            // absolute.  This is done by looking for ":\" in the contents
2383
            // if find this then it must be absolute, else it is a relative path
2384
            // evaluated from INSTALLDIR.
2385
            //                             
2386
            if ( szSubFeatureDescField % ":\\" ) 
2387
            then            
2388
                szSubFeatureDescType = "Absolute";                
2389
            else                                              
2390
                szSubFeatureDescType = "Relative";            
2391
            endif;
2392
 
2393
 
2394
            // lets determine the location of our items
2395
            //
2396
            if ( szSubFeatureDescType = "Absolute" )
2397
            then              
2398
                szSubFeatureItemsLocation =  szSubFeatureDescField;            
2399
            else                                                               
2400
                szSubFeatureItemsLocation =  INSTALLDIR ^ szSubFeatureDescField;            
2401
            endif;
2402
 
2403
 
2404
            // for each item in the list we need to add it to the
2405
            // larger list in a pre-defined format.
2406
            //
2407
            // the format being:
2408
            //
2409
            // item;location
2410
            //          
2411
            //
2412
            nzSubFeatureItemRetVal = ListGetFirstString ( lzSubFeatureItemListID, szSubFeatureItem );            
2413
            while ( nzSubFeatureItemRetVal != END_OF_LIST )   
2414
 
2415
                // we will only add an item to the list if it exist
2416
                // on disk.  a patch by definition cannot add new files
2417
                // to a distribution.
2418
                //
2419
                // !!!! Need to think about libraries.  these files
2420
                // break the rule!!!!
2421
                //                        
2422
                szString =  szSubFeatureItemsLocation ^ szSubFeatureItem;             
2423
                if ( Is (FILE_EXISTS, szString) = FALSE )
2424
                then    
2425
 
2426
                    // there is a special case for dll items
2427
                    // if we do not locate them on disk we can still 
2428
                    // proceed with the patch
2429
                    // 
2430
                    StrToLower(szSubFeatureItem_lc, szSubFeatureItem);
2431
                    if ( (szSubFeatureItem_lc % ".dll") != TRUE  )
2432
                    then
2433
 
2434
                        islib_MessageBox ("Failed to locate pre-installed package item [" +
2435
                                    szString + "] on disk." +
2436
                                    "\nA patch cannot add new items to an existing installation.", SEVERE);
2437
                        return ISLIB_ERROR;
2438
 
2439
                    else                                                    
2440
 
2441
                        islib_MessageBox ("Patch is changing default installation by delivering new dll item [" +
2442
                                    szSubFeatureItem + "].", INFORMATION);                                                                                                                    
2443
 
2444
                    endif;
2445
 
2446
                else                                                                    
2447
 
2448
                    // we located the item on our disk
2449
                    // lets log it for patching.
2450
                    //
2451
                    szString = szSubFeatureItem+ ";" + szSubFeatureItemsLocation;
2452
                    if (ListAddString (lzPatchItemsListID, szString, AFTER) < 0) 
2453
                    then
2454
 
2455
                        islib_MessageBox ("System error, failed to add entry to item list.", INFORMATION);
2456
                        return ISLIB_ERROR;
2457
 
2458
                    endif;
2459
 
2460
                endif;
2461
 
2462
                // get next top-level feature.              
2463
                nzSubFeatureItemRetVal = ListGetNextString ( lzSubFeatureItemListID, szSubFeatureItem );
2464
 
2465
            endwhile;                
2466
 
2467
 
2468
            // lets free system resources
2469
            //
2470
            ListDestroy(lzSubFeatureItemListID);
2471
            ListDestroy(lzParseFeatureListID);
2472
 
2473
 
2474
            // get next top-level feature.              
2475
            nzSubFeatureRetVal = ListGetNextString ( lzSubFeatureListID, szSubFeature );
2476
 
2477
        endwhile;                                             
2478
 
2479
        // Clear list for next cycle.
2480
        //                                      
2481
        ListDestroy( lzSubFeatureListID );                                     
2482
 
2483
        // get next top-level feature.              
2484
        nzTopFeatureRetVal = ListGetNextString ( lzTopFeatureListID, szTopFeature );
2485
 
2486
    endwhile;
2487
 
2488
    // Clear list for next cycle.
2489
    //                                      
2490
    ListDestroy( lzTopFeatureListID );        
2491
 
2492
    return ISLIB_SUCCESS;
2493
 
2494
end;
2495
 
2496
 
2497
//////////////////////////////////////////////////////////////////////////////
2498
//
2499
//  FUNCTION: islib_patchSaveItems
2500
//
2501
//   This function is used to create a copy of all items
2502
//   that are to be updated by the patch.
2503
//
2504
//   We pass the list of items to be saved and the location of the
2505
//   directory to save the item in.
2506
//
2507
//  Return Values:
2508
//    ISLIB_SUCCESS - completed
2509
//    ISLIB_ERROR   - error during processing.
2510
//
2511
//////////////////////////////////////////////////////////////////////////////                              
2512
function islib_savePatchItems(lzPatchItemsListID )
2513
 
2514
    NUMBER  nzTmpVar; 
2515
    NUMBER  nzRetVal;
2516
    NUMBER  nzItemCount; 
2517
    NUMBER  nzItemRetVal;
2518
 
2519
    STRING  szTmpVar;
2520
    STRING  szRetVal;            
2521
    STRING  szMySrcFile;
2522
    STRING  szMyDstFile;
2523
    STRING  szListItem;
2524
 
2525
    STRING  szItemName;
2526
    STRING  szItemLocation; 
2527
 
2528
    STRING  szPatchIDSaveDir;
2529
 
2530
    LIST    lzParseItemListID;
2531
 
2532
begin  
2533
 
2534
    // we do not wnat to record 
2535
    // what we save in InstallShiell.
2536
    // 
2537
    // we manage this stuff our-selves.
2538
    //                           
2539
    Disable(LOGGING); 
2540
 
2541
    // we know where our save dir is
2542
    // it is predefined.
2543
    //
2544
    szPatchIDSaveDir = PATCHID_SAVE_DIR;
2545
 
2546
    // lets count the number of items we have to save
2547
    // 
2548
    nzItemCount = ListCount (lzPatchItemsListID);      
2549
    if ( nzItemCount = 0 )
2550
    then
2551
 
2552
        // we have nothing to save the patch
2553
        // must contain new dlls only
2554
        //
2555
        return ISLIB_SUCCESS;
2556
 
2557
    else
2558
 
2559
        // we have work to do.              
2560
        // Lets get our first item.
2561
        //
2562
        nzItemRetVal = ListGetFirstString ( lzPatchItemsListID, szListItem );            
2563
        while ( nzItemRetVal != END_OF_LIST )  
2564
 
2565
            // lets parse the item from our list, we know
2566
            // it contains item name and location delimited by a ";"
2567
            //                      
2568
            lzParseItemListID = ListCreate(STRINGLIST);
2569
            StrGetTokens (lzParseItemListID, szListItem, ";"); 
2570
 
2571
 
2572
            // lets load the bits so we can use the information
2573
            //                               
2574
            ListGetFirstString ( lzParseItemListID, szItemName );
2575
            ListGetNextString  ( lzParseItemListID, szItemLocation );                          
2576
 
2577
 
2578
            // lets setup the source and destination items
2579
            //                         
2580
            szMySrcFile = szItemLocation ^  szItemName;
2581
            szMyDstFile = szPatchIDSaveDir ^ szItemName;
2582
 
2583
 
2584
            // lets save the item in our predefined
2585
            // patch save dir.
2586
            //
2587
            nzRetVal = CopyFile (szMySrcFile, szMyDstFile );              
2588
            if ( nzRetVal < 0 )
2589
            then 
2590
 
2591
                NumToStr(szRetVal, nzRetVal);
2592
    	        islib_MessageBox("Failed to copy (save) item to be patched [" +
2593
    	                   szMySrcFile + 
2594
                           "], retVal: [" + 
2595
                           szRetVal + 
2596
                           "].", SEVERE);
2597
                return ISLIB_ERROR;
2598
 
2599
            endif;
2600
 
2601
 
2602
            // now we need to record the fact that we saved something
2603
            //
2604
            if ( islib_updatePatchLog(szItemName, szItemLocation) < 0 )
2605
            then 
2606
 
2607
                islib_MessageBox("Failed to update patch log item.", SEVERE);            
2608
                return ISLIB_ERROR;
2609
 
2610
            endif;
2611
 
2612
 
2613
            // lets free resources for the next item
2614
            // 
2615
            ListDestroy(lzParseItemListID); 
2616
 
2617
 
2618
            // lets get the next item.
2619
            //
2620
            nzItemRetVal = ListGetNextString ( lzPatchItemsListID, szListItem );            
2621
 
2622
        endwhile; 
2623
 
2624
    endif;        
2625
 
2626
 
2627
    // lets enable the log.
2628
    //                 
2629
    Enable(LOGGING); 
2630
 
2631
 
2632
    return ISLIB_SUCCESS;
2633
 
2634
end;
2635
 
2636
 
2637
//////////////////////////////////////////////////////////////////////////////
2638
//
2639
//  FUNCTION: islib_updatePatchLog
2640
//
2641
//   This function is used to create a copy of all items
2642
//   that are to be updated by the patch.
2643
//
2644
//   We pass the list of items to be saved and the location of the
2645
//   directory to save the item in.
2646
//
2647
//  Return Values:
2648
//    ISLIB_SUCCESS - completed
2649
//    ISLIB_ERROR   - error during processing.
2650
//
2651
//////////////////////////////////////////////////////////////////////////////               
2652
 
2653
function islib_updatePatchLog(szItemName, szItemLocation)
2654
 
2655
    STRING szPatchIDDir;
2656
    STRING szPatchIDLogFileLocation;
2657
    STRING szPatchIDLogFileName; 
2658
    STRING szLine;
2659
 
2660
    NUMBER nzFileHandle;
2661
 
2662
begin   
2663
 
2664
    // lets initialise where we believe the
2665
    // patch log file exists
2666
    //         
2667
    szPatchIDDir             = PATCHID_DIR;
2668
    szPatchIDLogFileLocation = PATCHID_LOGFILE_LOCATION;        
2669
    szPatchIDLogFileName     = PATCHID_LOGFILE_NAME;        
2670
 
2671
 
2672
    // now we need to create the patchinfo file
2673
    // that shall contain the details of what
2674
    // we save abd where it goes back to.
2675
    // format:
2676
    // item;putBackLocation
2677
    //
2678
 
2679
    // Set the file mode to read-write
2680
    //
2681
    OpenFileMode (FILE_MODE_APPEND);
2682
 
2683
    // lets check to see if the file
2684
    // already exists.
2685
    //        
2686
    if ( Is (EXISTS,szPatchIDLogFileLocation) = TRUE )
2687
    then                         
2688
 
2689
        // Open the text file.
2690
        if (OpenFile (nzFileHandle, szPatchIDDir, szPatchIDLogFileName) < 0) 
2691
        then
2692
 
2693
            // Report the error.
2694
            islib_MessageBox ("System error, failed to open patch log file.", SEVERE);
2695
            return ISLIB_ERROR;
2696
 
2697
       endif;                         
2698
 
2699
   else          
2700
 
2701
       // Create a new file and leave it open.
2702
       if (CreateFile (nzFileHandle, szPatchIDDir, szPatchIDLogFileName) < 0) 
2703
       then
2704
 
2705
           // Report the error.
2706
           islib_MessageBox ("System error, failed to create patch log file.", SEVERE);
2707
           return ISLIB_ERROR;
2708
 
2709
       endif;       
2710
 
2711
    endif;
2712
 
2713
 
2714
    // Set the message to write to the file.
2715
    //
2716
    szLine = szItemName + ";" + szItemLocation;    
2717
 
2718
 
2719
    // Write a line to the end of our file.
2720
    //
2721
    if (WriteLine(nzFileHandle, szLine) < 0) 
2722
    then      
2723
 
2724
        // Report the error.
2725
        islib_MessageBox ("System error, failed to write line to patch log.", SEVERE);
2726
        return ISLIB_ERROR;
2727
 
2728
    endif;
2729
 
2730
 
2731
    // Close the file.
2732
    CloseFile (nzFileHandle);                                                    
2733
 
2734
 
2735
    // we are done.
2736
    return  ISLIB_SUCCESS;
2737
 
2738
end;
2739
 
2740
 
2741
//////////////////////////////////////////////////////////////////////////////
2742
//
2743
//  FUNCTION: islib_patchPostRemove
2744
//
2745
//  1. initialise predefined parameters 
2746
//
2747
//  2. determine if patch can be removed.
2748
//
2749
//  3. if patch can be removed determine type of patch removal
2750
//     (ie restore or no-restore) 
2751
//
2752
//  4. if we are to restore, 
2753
//     4.1 we need to load our patch log and put back each item.
2754
//
2755
//  5. remove patch store.
2756
//    
2757
//  Return Values:
2758
//    ISLIB_SUCCESS - completed
2759
//    ISLIB_ERROR   - error during processing.
2760
//
2761
//////////////////////////////////////////////////////////////////////////////
2762
function islib_patchPostRemove()
2763
 
2764
    STRING szPatchIDDir;
2765
    STRING szPatchIDSaveDir;
2766
    STRING szPatchIDLogFileLocation;
2767
    STRING szPatchIDLogFileName;  
2768
 
2769
    STRING szRemovalType; 
2770
 
2771
    NUMBER nzSaveItemsCount;
2772
 
2773
    LIST   lzPatchSavedItemsListID;
2774
 
2775
begin   
2776
 
2777
    // lets initialise info we are going to need
2778
    //
2779
    szPatchIDDir             = PATCHID_DIR;
2780
    szPatchIDSaveDir         = PATCHID_SAVE_DIR;
2781
    szPatchIDLogFileLocation = PATCHID_LOGFILE_LOCATION;          
2782
 
2783
 
2784
    // lets verify we can remove the package just in-case
2785
    // we didn't do it in the preremove phase 
2786
    //
2787
    // The type of removal is based on the parent package
2788
    // if it still exist on the system then we need to rollback.
2789
    // if the parent package for whatever reason has been removed
2790
    // we can just need to clean-up.
2791
    // 
2792
    if ( islib_checkRemovePatch(szRemovalType) < 0 )
2793
    then
2794
 
2795
        islib_MessageBox("This patch cannot be removed from this system yet.", SEVERE);                
2796
        return ISLIB_ERROR;  
2797
 
2798
    endif;                    
2799
 
2800
 
2801
    // we can remove the patch and we must restore
2802
    // the save items
2803
    //
2804
    if ( szRemovalType = "Restore" )
2805
    then   
2806
 
2807
        // lets create save list 
2808
        //                               
2809
        lzPatchSavedItemsListID = ListCreate(STRINGLIST);
2810
 
2811
        // If an error occurred, report it; then terminate.
2812
        if (lzPatchSavedItemsListID = LIST_NULL) then
2813
 
2814
            islib_MessageBox ("ERROR: Unable to create lzPatchSavedItemsListID.", SEVERE);
2815
            return ISLIB_ERROR;
2816
 
2817
        endif;
2818
 
2819
 
2820
 
2821
        // lets get all the items we previously saved
2822
        // into a manageble list
2823
        //
2824
        if ( islib_getPatchSaveItemsList(lzPatchSavedItemsListID) < 0 )
2825
        then  
2826
 
2827
            islib_MessageBox("ERROR: islib_getPatchSaveItemsList() did not complete successfully.", SEVERE);
2828
            return ISLIB_ERROR;        
2829
 
2830
        endif; 
2831
 
2832
 
2833
        // lets restore the items in our list if we have some
2834
        //
2835
        nzSaveItemsCount = ListCount (lzPatchSavedItemsListID);
2836
        if (nzSaveItemsCount > 0)
2837
        then                
2838
 
2839
            // we have work to do.
2840
            //    
2841
            if ( islib_restorePatchItems(lzPatchSavedItemsListID) < 0 )
2842
            then  
2843
 
2844
                islib_MessageBox("ERROR: islib_restorePatchItems() did not complete successfully.", SEVERE);
2845
                return ISLIB_ERROR;        
2846
 
2847
            endif;  
2848
 
2849
        endif;            
2850
 
2851
 
2852
        // we have restored lets now putback 
2853
        // the parent pkg patch details.
2854
        //
2855
        if ( islib_updatePkgPatchRegistryKeys("Restore", svRestorePatchID, svRestorePatchInstalled) < 0 )
2856
        then  
2857
 
2858
            islib_MessageBox("ERROR: islib_updatePkgPatchRegistryKeys() did not complete successfully.", SEVERE);
2859
            return ISLIB_ERROR;        
2860
 
2861
        endif;
2862
 
2863
 
2864
        // lets free resources.  
2865
        //
2866
        ListDestroy(lzPatchSavedItemsListID);                         
2867
 
2868
    endif;             
2869
 
2870
 
2871
    // everything is ok upto here
2872
    // lets delete the evidence.
2873
    //                      
2874
    if ( islib_deletePatchIDDir() < 0 )
2875
    then 
2876
 
2877
        islib_MessageBox("islib_deletePatchDir() did not complete successfully.", WARNING);        
2878
 
2879
    endif;                               
2880
 
2881
 
2882
    // we are done!
2883
    return ISLIB_SUCCESS;
2884
 
2885
end;
2886
 
2887
 
2888
//////////////////////////////////////////////////////////////////////////////
2889
//
2890
//  FUNCTION: islib_restorePatchItems
2891
//
2892
//  This function restores all items in the saved list
2893
//  back to the original location.
2894
//
2895
//  Return Values:
2896
//    ISLIB_SUCCESS - completed
2897
//    ISLIB_ERROR   - error during processing.
2898
//
2899
//////////////////////////////////////////////////////////////////////////////
2900
function islib_restorePatchItems(lzPatchSavedItemsListID)
2901
 
2902
    STRING szPatchIDSaveDir; 
2903
    STRING szListItem; 
2904
    STRING szItemName;
2905
    STRING szItemLocation; 
2906
    STRING szMySrcFile;
2907
    STRING szMyDstFile;
2908
 
2909
    NUMBER nzItemCount;
2910
    NUMBER nzItemRetVal;
2911
 
2912
    STRING szRetVal;
2913
    NUMBER nzRetVal;
2914
 
2915
    LIST lzParseItemListID;
2916
 
2917
begin                   
2918
 
2919
    // Stop recording of any
2920
    // of these actions.
2921
    //                   
2922
    Disable(LOGGING);
2923
 
2924
 
2925
    // we know where our save dir is
2926
    // it is predefined.
2927
    //
2928
    szPatchIDSaveDir = PATCHID_SAVE_DIR;
2929
 
2930
    // lets count the number of items we have to restore
2931
    // 
2932
    nzItemCount = ListCount (lzPatchSavedItemsListID);      
2933
    if ( nzItemCount = 0 )
2934
    then
2935
 
2936
        // we have nothing to restore the patch
2937
        //
2938
        return ISLIB_SUCCESS;
2939
 
2940
    else
2941
 
2942
        // we have work to do.              
2943
        // Lets get our first item.
2944
        //
2945
        nzItemRetVal = ListGetFirstString ( lzPatchSavedItemsListID, szListItem );            
2946
        while ( nzItemRetVal != END_OF_LIST )  
2947
 
2948
            // lets create a list to parse the retireved item.
2949
            //                  
2950
            lzParseItemListID = ListCreate(STRINGLIST); 
2951
 
2952
            // If an error occurred, report it, and return error.
2953
            if (lzParseItemListID = LIST_NULL) then
2954
 
2955
                islib_MessageBox ("ERROR: Unable to create lzParseItemListID.", SEVERE);
2956
                return ISLIB_ERROR;
2957
 
2958
            endif;
2959
 
2960
            // lets parse the item from our list, we know
2961
            // it contains item name and location delimited by a ";"
2962
            //
2963
            StrGetTokens (lzParseItemListID, szListItem, ";");               
2964
 
2965
            // lets load the bits so we can use the information
2966
            //                               
2967
            ListGetFirstString ( lzParseItemListID, szItemName );
2968
            ListGetNextString  ( lzParseItemListID, szItemLocation );                          
2969
 
2970
 
2971
            // lets setup the source and destination items
2972
            //                         
2973
            szMySrcFile = szPatchIDSaveDir ^ szItemName;
2974
            szMyDstFile = szItemLocation ^ szItemName;
2975
 
2976
 
2977
            // lets restore the item from patch save dir.
2978
            //
2979
            nzRetVal = CopyFile (szMySrcFile, szMyDstFile );              
2980
            if ( nzRetVal < 0 )
2981
            then 
2982
 
2983
                NumToStr(szRetVal, nzRetVal);
2984
    	        islib_MessageBox("Failed to copy (restore) item [" +
2985
    	                   szMySrcFile + 
2986
                           "], retVal: [" + 
2987
                           szRetVal + 
2988
                           "].", SEVERE);
2989
                return ISLIB_ERROR;
2990
 
2991
            endif;                
2992
 
2993
            // lets free resources for the next item
2994
            // 
2995
            ListDestroy(lzParseItemListID);               
2996
 
2997
            // lets get the next item.
2998
            //
2999
            nzItemRetVal = ListGetNextString ( lzPatchSavedItemsListID, szListItem );            
3000
 
3001
        endwhile; 
3002
 
3003
    endif;        
3004
 
3005
 
3006
    // lets enable the log.
3007
    //                 
3008
    Enable(LOGGING);            
3009
 
3010
 
3011
    // we are done.    
3012
    return ISLIB_SUCCESS;
3013
 
3014
end;    
3015
 
3016
 
3017
//////////////////////////////////////////////////////////////////////////////
3018
//
3019
//  FUNCTION: islib_getPatchSaveItemsList
3020
//
3021
//  This function generates a manageable list of all
3022
//  saved items.
3023
//
3024
//  Return Values:
3025
//    ISLIB_SUCCESS - completed
3026
//    ISLIB_ERROR   - error during processing.
3027
//
3028
//////////////////////////////////////////////////////////////////////////////
3029
function islib_getPatchSaveItemsList(lzPatchSavedItemsListID)
3030
 
3031
    STRING szPatchIDDir;    
3032
    STRING szPatchIDLogFileName;  
3033
    STRING szPatchIDLogFileLocation;
3034
 
3035
    STRING szLine; 
3036
 
3037
    NUMBER nzFileHandle;
3038
    NUMBER nzRetVal;
3039
 
3040
begin
3041
 
3042
    // initialise local variables.
3043
    //
3044
    szPatchIDDir             = PATCHID_DIR;    
3045
    szPatchIDLogFileLocation = PATCHID_LOGFILE_LOCATION;
3046
    szPatchIDLogFileName     = PATCHID_LOGFILE_NAME;
3047
 
3048
 
3049
    // Set the file mode to read-write
3050
    //
3051
    OpenFileMode (FILE_MODE_NORMAL);
3052
 
3053
 
3054
    // lets check to see if the file
3055
    // already exists.
3056
    //        
3057
    if ( Is (EXISTS,szPatchIDLogFileLocation) = TRUE )
3058
    then                                 
3059
 
3060
        // Open the text file.
3061
        if (OpenFile (nzFileHandle, szPatchIDDir, szPatchIDLogFileName) < 0) 
3062
        then
3063
 
3064
            // Report the error.
3065
            islib_MessageBox ("ERROR: Failed to open patch log file.", SEVERE);
3066
            return ISLIB_ERROR;
3067
 
3068
        endif;                         
3069
 
3070
 
3071
        // Get lines from the file into the list.
3072
        // 
3073
        nzRetVal = GetLine (nzFileHandle, szLine);
3074
        while (nzRetVal = 0)
3075
 
3076
            ListAddString (lzPatchSavedItemsListID, szLine, AFTER);                                                                                       
3077
            nzRetVal = GetLine (nzFileHandle, szLine);
3078
 
3079
        endwhile;                                            
3080
 
3081
 
3082
        // Close the file.
3083
        CloseFile (nzFileHandle);    
3084
 
3085
    else                      
3086
 
3087
       // no save file, there is nothing to restore.
3088
       //                             
3089
       return ISLIB_SUCCESS;
3090
 
3091
    endif;
3092
 
3093
 
3094
    // we are done. 
3095
    return ISLIB_SUCCESS;
3096
 
3097
end;    
3098
 
3099
 
3100
//////////////////////////////////////////////////////////////////////////////
3101
//
3102
//  FUNCTION: islib_deletePatchIDDir
3103
//
3104
//  This function deletes the predefined 
3105
//  patch directory and all its contents.
3106
//
3107
//  Return Values:
3108
//    ISLIB_SUCCESS - completed
3109
//
3110
//    we do not return an error if the directory is not removed
3111
//    it may have been removed previously.
3112
//
3113
//////////////////////////////////////////////////////////////////////////////
3114
function islib_deletePatchIDDir() 
3115
 
3116
    STRING szPatchIDDir;
3117
 
3118
begin
3119
 
3120
    szPatchIDDir = PATCHID_DIR;
3121
 
3122
    // lets check to see if the dir exists
3123
    // before we try to remove it.
3124
    //
3125
    if ( Is (PATH_EXISTS, szPatchIDDir) = TRUE )
3126
    then
3127
 
3128
        if (DeleteDir (szPatchIDDir, ALLCONTENTS) < 0) 
3129
        then
3130
 
3131
            islib_MessageBox ("ERROR: Unable to delete patch directory [" +
3132
                         szPatchIDDir + "].", SEVERE);                                                                
3133
 
3134
            // we still proceed...
3135
            return ISLIB_SUCCESS;                                     
3136
 
3137
        endif;             
3138
 
3139
    endif;        
3140
 
3141
    // done.                         
3142
    return ISLIB_SUCCESS;
3143
 
3144
end;    
3145
 
3146
 
3147
 
3148
//////////////////////////////////////////////////////////////////////////////
3149
//
3150
//  FUNCTION: islib_checkRemovePatch
3151
//
3152
//   This function is used to check if the patch can be removed.
3153
//   The rules that govern if a patch can be removed are:
3154
//
3155
//   1. A parent package that has a name equal to that defined in the 
3156
//      project Subject field does not exists on the system.
3157
//
3158
//      This condition shall be checked by ensuring the BaseInstallDir registry key
3159
//      does not exist for the parent package defined in the project Subject setting.
3160
//
3161
//   2. If the a parent package exists see item 1) and the associated version number
3162
//      is not equal to that that of the patch.
3163
//
3164
//      The patch version number is defined in the PKG_VERSION variable.
3165
//
3166
//      (i.e. The preinstalled patch MYPKG010001-0N can be removed if the parent package
3167
//            MYPKG is of version 1.0.2).
3168
//
3169
//      This check shall be completed by comparing the Version registry setting of the package
3170
//      with the PKG_VERSION variable of the patch.
3171
//
3172
//      This case implies a CLEAN install as the version number link no longer
3173
//      exists. 
3174
//
3175
//      A patch can only be removed and thus used to restore a pre-defined specific 
3176
//      parent package version.
3177
//
3178
//   3. An obsoleted patch cannot be removed until the patch that obsoletes
3179
//      it is removed first.                                 
3180
//
3181
//      (ie you cannot remove patch MYPKG010001-01 before patch MYPKG010001-02).
3182
//
3183
//   4. A patch can be removed and restored if it the most recently applied patch to an 
3184
//      existing parent package of the correct version number.
3185
//
3186
//
3187
//  Return Values:
3188
//    ISLIB_SUCCESS - completed
3189
//    ISLIB_ERROR   - error during processing.
3190
//
3191
//  The function also sets a variable  szRemovalType to be one of
3192
//  two possible values "Restore" or "Clean", this refers to the type of
3193
//  removal action, assuming we can procceed.
3194
//
3195
//////////////////////////////////////////////////////////////////////////////
3196
function islib_checkRemovePatch ( szRemovalType )
3197
 
3198
    STRING szPatchID; 
3199
    STRING szPkgName;            
3200
    STRING szPatchIDNumber;
3201
    STRING szPatchVersion;
3202
 
3203
    STRING szPkgBaseInstallDir; 
3204
    STRING szPkgVersion; 
3205
    STRING szPkgInstalled;  
3206
    STRING szPkgLatestPatchID; 
3207
    STRING szPkgLatestPatchInstalled; 
3208
    STRING szPkgLatestPatchNumber;
3209
    STRING szPkgBuildNum;
3210
    STRING szPkgProjAcronym;
3211
    STRING szPkgDesc; 
3212
 
3213
    NUMBER nzPkgLatestPatchNumber; 
3214
    NUMBER nzPatchIDNumber;
3215
    NUMBER nResult;      
3216
 
3217
begin  
3218
 
3219
    // initialise local variables.
3220
    //
3221
    szRemovalType = "Restore";
3222
    szPatchID     = PATCH_ID;
3223
    szPatchVersion= PKG_VERSION;
3224
    szPkgName     = PKG_NAME;
3225
 
3226
 
3227
    // 1. lets extract my parent packages details
3228
    //   
3229
    if ( islib_checkErgAfcPkgExists(szPkgName) < 0 )
3230
    then    
3231
 
3232
        // we could not confirm that the parent package exists
3233
        // so we assume that the package was removed.
3234
        // 
3235
        // This implies we need to simply cleanup our installation
3236
        // 
3237
        islib_MessageBox("The patch you trying to remove [" + szPatchID + "] has no parent package." +
3238
                   "\n\nPatch shall not attempt to restore any previously saved items.", INFORMATION);        
3239
        szRemovalType = "Clean";
3240
        return ISLIB_SUCCESS; 
3241
 
3242
    else
3243
 
3244
        // our parent package exists lets get its current details
3245
        //
3246
        if (islib_getErgAfcPkgRegistryDetails( szPkgBaseInstallDir, 
3247
                                               szPkgVersion,
3248
                                               szPkgInstalled,
3249
                                               szPkgLatestPatchID,                                                                                              
3250
                                               szPkgLatestPatchInstalled,                                               
3251
                                               szPkgBuildNum,
3252
                                               szPkgProjAcronym,
3253
                                               szPkgDesc ) < 0 )
3254
        then                                       
3255
 
3256
            // we encountered an error getting the details
3257
            //
3258
            islib_MessageBox("ERROR: islib_getErgAfcPkgRegistryDetails() did not complete successfully.", SEVERE);  
3259
            return ISLIB_ERROR;                          
3260
 
3261
        endif;  
3262
 
3263
 
3264
        // lets get our patch number.
3265
        //   
3266
        if ( islib_getPatchNumber( szPatchID, szPatchIDNumber ) < 0 )
3267
        then
3268
 
3269
            islib_MessageBox("ERROR: islib_getPatchNumber() did not complete successfully.", SEVERE); 
3270
            return ISLIB_ERROR;                                  
3271
 
3272
        endif;
3273
        StrToNum(nzPatchIDNumber, szPatchIDNumber);
3274
 
3275
 
3276
        // lets get the previous latest patch number.
3277
        //   
3278
        if ( islib_getPatchNumber( szPkgLatestPatchID, szPkgLatestPatchNumber ) < 0 )
3279
        then
3280
 
3281
            islib_MessageBox("ERROR: islib_getPatchNumber() did not complete successfully.", SEVERE); 
3282
            return ISLIB_ERROR;                                  
3283
 
3284
        endif;
3285
        StrToNum(nzPkgLatestPatchNumber, szPkgLatestPatchNumber);                        
3286
 
3287
 
3288
        // we got our details lets apply the business rules
3289
        // of our patch management strategy.
3290
        //
3291
 
3292
        // 2. we assume that our version are of the correct format
3293
        //    lets compare them.
3294
        //
3295
        //    if the version differ then we can assume the version 
3296
        //    of parent package we previously patched no longer
3297
        //    exists and we cannot restore anything we saved.
3298
        //    It is no longer relevant.
3299
        //
3300
        nResult = islib_compareVersions(szPkgVersion, szPatchVersion);
3301
        if ( nResult != ISLIB_VERSION_EQUALS )
3302
        then    
3303
 
3304
            // we could not confirm that the parent package exists
3305
            // so we assume that the package was removed.
3306
            // 
3307
            // This implies we need to simply cleanup our installation
3308
            // 
3309
             islib_MessageBox("The patch you trying to remove [" + szPatchID + "] has an incompatible version number" +
3310
                        "\nwith the current parent package." +
3311
                        "\n\nPatch shall not attempt to restore any previously saved items.", INFORMATION);         
3312
            szRemovalType = "Clean";
3313
            return ISLIB_SUCCESS;  
3314
 
3315
        endif;
3316
 
3317
 
3318
        // our versions must equal so now we need to use the patch
3319
        // number we have versus the lastest number install 
3320
        // for our package.
3321
        //
3322
        // 3. A patch cannot be removed if it is obsoleted.
3323
        //
3324
        //    A patch is deemed obsoleted if an installed patch 
3325
        //    has a patch number less than that of the latest patch 
3326
        //    applied to the parent package.
3327
        //
3328
        if ( nzPatchIDNumber < nzPkgLatestPatchNumber )
3329
        then                                  
3330
 
3331
            // the patch we are trying to remove is obsolete
3332
            // therefore we should not remove it until
3333
            // all other patches that obsolete this patch
3334
            // have sequentially been removed.
3335
            //
3336
            islib_MessageBox("The patch you trying to remove [" + szPatchID + "] has been obsoleted " +
3337
                       "by a patch that has been \npreviously installed." +
3338
 
3339
                       "\n\nThis patch cannot be removed until all other patches that obsolete this " +
3340
                       "patch have been sequentially \nremoved." + 
3341
 
3342
                       "\n\nThis patch is currently obsoleted by patch [" + szPkgLatestPatchID + "], installed on [" +
3343
                       szPkgLatestPatchInstalled + "].", WARNING); 
3344
 
3345
            return ISLIB_ERROR; 
3346
 
3347
        elseif ( nzPatchIDNumber = nzPkgLatestPatchNumber )
3348
        then  
3349
 
3350
            // we are the lastest pkg patch
3351
            // we can proceed with restore and removal
3352
            //
3353
            szRemovalType = "Restore";
3354
            return ISLIB_SUCCESS; 
3355
 
3356
        else
3357
 
3358
            // this is an impossible error
3359
            islib_MessageBox("ERROR: You have probably not updated your package GUIs, patches must be unique.", SEVERE);
3360
            return ISLIB_ERROR;
3361
 
3362
        endif;                 
3363
 
3364
    endif;   
3365
 
3366
 
3367
    // if we got to here things are ok, we now need to ensure that the
3368
    // INSTALLDIR variable is set to the PkgBaseInstallDir variable
3369
    // we retieved from the registry.  this ensures that the patch 
3370
    // starts from the same point as the parent package.
3371
    //
3372
    INSTALLDIR = szPkgBaseInstallDir;     
3373
 
3374
 
3375
    // done.
3376
    return ISLIB_SUCCESS;
3377
 
3378
end;
3379
 
3380
 
3381
//////////////////////////////////////////////////////////////////////////////
3382
//
3383
//  FUNCTION: islib_updatePkgPatchRegistryKeys    
3384
//
3385
//  This function is used to update the parent package
3386
//  patch registry keys so we can identiffy the latest
3387
//  patch that has been installed.                
3388
//
3389
//  It is passed 3 parameters, these include:
3390
//  szUpdateType, szPatchNumber, szPatchInstalled,
3391
//
3392
//  If the  szUpdateType parameter == "Restore" then the
3393
//  fuction uses the other two parameters to update the registry.
3394
//
3395
//  If the szUpdateType != "Restore" the function uses the Patch configuration PATCH_ID and
3396
//  current date/time values to upadte the registry.
3397
//
3398
//  Return Values:
3399
//    ISLIB_SUCCESS - completed
3400
//    ISLIB_ERROR   - error during processing.
3401
//                                                                             
3402
//////////////////////////////////////////////////////////////////////////////
3403
function islib_updatePkgPatchRegistryKeys( szUpdateType, szPatchID, szPatchInstalled)
3404
 
3405
    STRING szPkgName;
3406
    STRING szTime;
3407
    STRING szDate; 
3408
    STRING szMyPatchID; 
3409
    STRING szMyPatchInstalled;
3410
 
3411
    STRING szKey;
3412
    STRING szClass;
3413
    STRING szItem; 
3414
    STRING szValue;
3415
 
3416
    NUMBER nzResult;
3417
 
3418
begin   
3419
 
3420
    // we do not want to record this
3421
    //
3422
    Disable(LOGGING);
3423
 
3424
 
3425
    szPkgName = PKG_NAME;  
3426
 
3427
 
3428
    // what type of action are we
3429
    // performing.
3430
    //             
3431
    if ( szUpdateType = "Restore" )
3432
    then                         
3433
 
3434
        // use the passed values.
3435
        szMyPatchInstalled = szPatchInstalled; 
3436
        szMyPatchID        = szPatchID;
3437
 
3438
    else
3439
 
3440
        // this is a normal install lets
3441
        // evaluate the information
3442
 
3443
        // lets extract the patch ID from the config
3444
        //
3445
        szMyPatchID = PATCH_ID;                              
3446
 
3447
        // use now as our instllation date/time
3448
        //
3449
        GetSystemInfo ( TIME, nzResult, szTime );
3450
        GetSystemInfo ( DATE, nzResult, szDate ); 
3451
        szMyPatchInstalled = szDate + " " + szTime;                        
3452
 
3453
    endif;
3454
 
3455
 
3456
    // lets define the base key root location
3457
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); 
3458
    szKey   = ERGAFC_PKG_REGISTRY_BASE + szPkgName;
3459
    szClass = "";   
3460
 
3461
 
3462
    // we assume here that the key must exist to
3463
    // get this far. we check for it anyway.
3464
    // 
3465
    // we do NOT create the key, if it happens
3466
    // not to exist we need to report an error.          
3467
    //
3468
    if (RegDBKeyExist (szKey) < 0)
3469
    then          
3470
 
3471
        islib_MessageBox ("ERROR: [" + szKey + "] registry key does not exist.", SEVERE);
3472
        return ISLIB_ERROR;
3473
 
3474
    else  
3475
 
3476
        // lets update the LatestPatchID item. 
3477
        //    
3478
        szItem  = "LatestPatchID";
3479
        szValue = szMyPatchID;
3480
        if (RegDBSetKeyValueEx(
3481
                 szKey,
3482
                 szItem,
3483
                 REGDB_STRING,
3484
                 szValue, -1 ) < 0)
3485
        then  
3486
 
3487
            islib_MessageBox( "Error updating [" + 
3488
    	                 szKey + "\\" +  szItem +
3489
    	                 "] registry key, with value [" +
3490
    	                 szValue +
3491
    	                 "].", SEVERE );
3492
 
3493
            return ISLIB_ERROR; 
3494
 
3495
        endif;     	                    
3496
 
3497
 
3498
        // lets update the LatestPatchInstalled item.
3499
        szItem  = "LatestPatchInstalled"; 
3500
        GetSystemInfo ( TIME, nzResult, szTime );
3501
        GetSystemInfo ( DATE, nzResult, szDate );
3502
        szValue = szMyPatchInstalled;
3503
        if (RegDBSetKeyValueEx(
3504
                 szKey,
3505
                 szItem,
3506
                 REGDB_STRING,
3507
                 szValue, -1 ) < 0)
3508
        then  
3509
 
3510
            islib_MessageBox( "Error updating [" + 
3511
    	                 szKey + "\\" +  szItem +
3512
    	                 "] registry key, with value [" +
3513
    	                 szValue +
3514
    	                 "].", SEVERE );
3515
 
3516
            return ISLIB_ERROR; 
3517
 
3518
        endif;  
3519
 
3520
    endif;        
3521
 
3522
 
3523
    // lets enable the logging again.
3524
    //
3525
    Enable(LOGGING);
3526
 
3527
 
3528
    return ISLIB_SUCCESS;
3529
 
3530
end;
3531
 
3532
 
3533
//////////////////////////////////////////////////////////////////////////////
3534
//
3535
//  FUNCTION: islib_patchPostInstall 
3536
//
3537
//  1. Set the patch registry key information
3538
//
3539
//  2. Update the product patch registry key information  
3540
//
3541
//  3. Create the obsolete.txt file that shall contain the
3542
//     details of the patch that we are obsoleting.
3543
//
3544
//
3545
//  Return Values:
3546
//    ISLIB_SUCCESS - completed
3547
//    ISLIB_ERROR   - error during processing.
3548
//                                                                             
3549
//////////////////////////////////////////////////////////////////////////////
3550
function islib_patchPostInstall()
3551
 
3552
begin                       
3553
 
3554
    // lets update our product registry setting.
3555
    //
3556
    if ( islib_setErgAfcPatchRegistryKeys() < 0 )
3557
    then    
3558
 
3559
        islib_MessageBox("ERROR: islib_setErgAfcPatchRegistryKeys() did not complete successfully.", SEVERE);
3560
        return ISLIB_ERROR;
3561
 
3562
    endif;                                                      
3563
 
3564
 
3565
    // lets update the parent pkg patch registry keys
3566
    //
3567
    if ( islib_updatePkgPatchRegistryKeys("Install", "", "") < 0 )
3568
    then    
3569
 
3570
        islib_MessageBox("ERROR: islib_updatePkgPatchRegistryKeys() did not complete successfully.", SEVERE);
3571
        return ISLIB_ERROR;
3572
 
3573
    endif;
3574
 
3575
 
3576
    return ISLIB_SUCCESS;
3577
 
3578
end;
3579
 
3580
 
3581
//////////////////////////////////////////////////////////////////////////////
3582
//
3583
//  FUNCTION: islib_patchPreRemove 
3584
//
3585
//  1. Determine if we can remove the patch
3586
//    
3587
//  2. Determine if we are going to restore the
3588
//     previous patch
3589
//
3590
//  3. If we are to restore, determine the patch number that was 
3591
//     previously obsoloeted so we can restore its details.
3592
//
3593
//
3594
//  Return Values:
3595
//    ISLIB_SUCCESS - completed
3596
//    ISLIB_ERROR   - error during processing.
3597
//                                                                             
3598
//////////////////////////////////////////////////////////////////////////////
3599
function islib_patchPreRemove()
3600
 
3601
    STRING szRemovalType;
3602
 
3603
begin                   
3604
 
3605
    // initialse local variables. 
3606
    szRemovalType = "Restore";
3607
 
3608
 
3609
    // assuming we are going to restore
3610
    //
3611
    if (islib_checkRemovePatch(szRemovalType) < 0 )
3612
    then 
3613
 
3614
        islib_MessageBox("This patch cannot be removed from this system yet.", SEVERE);        
3615
        return ISLIB_ERROR;
3616
 
3617
    else
3618
 
3619
        // Display the AskYesNo dialog box.  The default is set to Yes.
3620
        if (AskYesNo("This patch can be removed. Would you like to proceed?", YES) = NO)
3621
        then
3622
 
3623
            islib_MessageBox("User has terminated installation.", SEVERE);
3624
            abort;
3625
 
3626
        endif;  
3627
 
3628
    endif;
3629
 
3630
 
3631
    // lets get the details of the patch we are going to
3632
    // restore
3633
    //
3634
    if ( szRemovalType = "Restore" )
3635
    then
3636
 
3637
        if ( islib_getPatchDetailsToRestore(svRestorePatchID,
3638
                                            svRestorePatchInstalled) < 0 )
3639
        then  
3640
 
3641
            islib_MessageBox("ERROR: islib_getPatchDetailsToRestore() did not complete successfully.", SEVERE);
3642
            return ISLIB_ERROR;
3643
 
3644
        endif;      
3645
 
3646
    endif;
3647
 
3648
 
3649
    // done.
3650
    return ISLIB_SUCCESS;
3651
 
3652
end;  
3653
 
3654
//////////////////////////////////////////////////////////////////////////////
3655
//
3656
//  FUNCTION: islib_getPatchDetailsToRestore
3657
//
3658
//  this function is used to get the patch number and installed date
3659
//  recorded in the patch registry settings for the patch we
3660
//  previously obsoleted.
3661
//
3662
//  The items of interest are: 
3663
//  ObsoletedPatchInstalled, and ObsoletedPatchNumber
3664
//
3665
//  Return Values:
3666
//    ISLIB_SUCCESS - completed
3667
//    ISLIB_ERROR   - error, product registry does not exist.
3668
//                                                                             
3669
//////////////////////////////////////////////////////////////////////////////
3670
function islib_getPatchDetailsToRestore(szRestorePatchID, szRestorePatchInstalled)
3671
 
3672
    STRING szPatchID;
3673
 
3674
    STRING szKey;
3675
    STRING szClass;
3676
    STRING szItem; 
3677
 
3678
    NUMBER nzType;
3679
    NUMBER nzSize;
3680
 
3681
begin  
3682
 
3683
    szPatchID = PATCH_ID;
3684
 
3685
    // lets define the base key root location
3686
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); 
3687
    szKey   =  ERGAFC_PATCH_REGISTRY_BASE + szPatchID;
3688
    szClass = "";
3689
 
3690
 
3691
    // Check if the newly created multi-level key exists.
3692
    //
3693
    if (RegDBKeyExist (szKey) < 0)
3694
    then          
3695
 
3696
        islib_MessageBox ("ERROR: [" + szKey + "] registry key does not exist.", SEVERE);                    
3697
        return ISLIB_ERROR;
3698
 
3699
    else    
3700
 
3701
 
3702
        // Retrieve ObsoletedPatchID information. 
3703
        szItem = "ObsoletedPatchID";
3704
        if (RegDBGetKeyValueEx (szKey, szItem, nzType , szRestorePatchID, nzSize) < 0) 
3705
        then  
3706
 
3707
            islib_MessageBox( "Error reading [" + 
3708
    	                szKey + "\\" +  szItem +
3709
    	                "] registry key.", SEVERE );
3710
            return ISLIB_ERROR;
3711
 
3712
        endif; 
3713
 
3714
 
3715
        // Retrieve ObsoletedPatchInstalled information. 
3716
        szItem = "ObsoletedPatchInstalled";
3717
        if (RegDBGetKeyValueEx (szKey, szItem, nzType , szRestorePatchInstalled, nzSize) < 0) 
3718
        then  
3719
 
3720
            islib_MessageBox( "Error reading [" + 
3721
    	                szKey + "\\" +  szItem +
3722
    	                "] registry key.", SEVERE );
3723
            return ISLIB_ERROR;
3724
 
3725
        endif;                    
3726
 
3727
    endif;
3728
 
3729
    // we are done.          
3730
    return ISLIB_SUCCESS;
3731
 
3732
end;
3733
 
3734
 
3735
//////////////////////////////////////////////////////////////////////////////
3736
//
3737
//  FUNCTION: islib_checkErgAfcPkgExists  
3738
//
3739
//  This function is used to determine if a parent package
3740
//  exists.  It check for the base registry key.
3741
//
3742
//  Return Values:
3743
//    ISLIB_SUCCESS - completed
3744
//    ISLIB_ERROR   - error, product registry does not exist.
3745
//                                                                             
3746
//////////////////////////////////////////////////////////////////////////////
3747
 
3748
function islib_checkErgAfcPkgExists(szPkgName)
3749
 
3750
    STRING szKey, szClass, szItem;
3751
    STRING szTmpVar;
3752
    NUMBER nSize, nType;
3753
 
3754
begin  
3755
 
3756
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); 
3757
    szKey   =  ERGAFC_PKG_REGISTRY_BASE + szPkgName;
3758
    szClass = "";
3759
 
3760
    // Check if the base key exists.
3761
 
3762
    if (RegDBKeyExist (szKey) < 0)
3763
    then          
3764
        /* The message box is only usefull when debugging. 
3765
        It becomes confusing to the operator in a production install. */
3766
 
3767
        // islib_MessageBox ("ERROR: Failed to access [" + szKey + "] registry key does not exist.", SEVERE);
3768
        return ISLIB_ERROR;  
3769
    endif;  
3770
 
3771
 
3772
    /* We have found our base key. Lets check for the BaseInstallDir subkey
3773
       Retrieve BaseInstallDir information. */
3774
 
3775
    szItem = "BaseInstallDir";
3776
    if (RegDBGetKeyValueEx (szKey, szItem, nType , szTmpVar, nSize) < 0) 
3777
    then     
3778
        // islib_MessageBox( "ERROR: Failed to access [" + szKey + "\\" +  szItem + "] registry key.", SEVERE );
3779
        return ISLIB_ERROR;
3780
    endif; 
3781
 
3782
    // We have confirmed the package has a registry key, and is probably installed correctly.
3783
    return ISLIB_SUCCESS;
3784
 
3785
end;    
3786
 
3787
 
3788
 
3789
 
3790
//////////////////////////////////////////////////////////////////////////////
3791
//
3792
//  FUNCTION: islib_preinstallCheckErgAfcPkgExists  
3793
//
3794
//  This function is used to display a message box
3795
//  if the parent package does not exists.
3796
//                                                                             
3797
//////////////////////////////////////////////////////////////////////////////
3798
 
3799
function islib_preinstallCheckErgAfcPkgExists(szPkgName, szPkgDesc)
3800
 
3801
 
3802
begin  
3803
    if ( islib_checkErgAfcPkgExists(szPkgName) < 0 )
3804
    then    
3805
 
3806
        islib_MessageBox("The installer could not locate the prerequisite " + szPkgDesc + " package ("+szPkgName+"). Install will now abort.", SEVERE);
3807
        abort;
3808
 
3809
    endif;
3810
end;     
3811
 
3812
 
3813
 
3814
 
3815
//////////////////////////////////////////////////////////////////////////////
3816
//
3817
//  FUNCTION: islib_preinstallCheckJavaJREExists  
3818
//
3819
//  This function is used to display a message box
3820
//  if the JRE package does not exist.
3821
//                                                                             
3822
//////////////////////////////////////////////////////////////////////////////
3823
 
3824
function islib_preinstallCheckJavaJREExists()
3825
begin  
3826
    islib_preinstallCheckJavaJREExists2("");    
3827
end;
3828
 
3829
 
3830
 
3831
//////////////////////////////////////////////////////////////////////////////
3832
//
3833
//  FUNCTION: islib_preinstallCheckJavaJREExists2
3834
//
3835
//  This function is used to display a message box
3836
//  if the JRE package does not exist.
3837
//                                                                             
3838
//////////////////////////////////////////////////////////////////////////////
3839
 
3840
function islib_preinstallCheckJavaJREExists2(szJavaVer)
3841
 
3842
STRING  szKey;
3843
 
3844
begin  
3845
 
3846
    if ( szJavaVer = "" )
3847
    then
3848
        szJavaVer = JAVA_JRE_VERSION;
3849
    endif;
3850
 
3851
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
3852
    szKey   =  "SOFTWARE\\JavaSoft\\Java Runtime Environment\\"+szJavaVer;
3853
 
3854
    if (RegDBKeyExist (szKey) < 0)
3855
    then          
3856
        islib_MessageBox("The installer could not locate Java JRE version "+szJavaVer+". Install will now abort.", SEVERE);
3857
        abort;  
3858
    endif; 
3859
 
3860
end;
3861
 
3862
 
3863
 
3864
//////////////////////////////////////////////////////////////////////////////
3865
//
3866
//  FUNCTION: islib_preinstallCheckJavaExists
3867
//
3868
//  This function is used to display a message box
3869
//  if the JRE package does not exist.
3870
// 
3871
//  islib_preinstallCheckJavaExists ( JRE|J2SDK|J2EE , VERSION , ABORT|WARN );  
3872
//  
3873
//  Default values are JRE, 1.4 & WARN
3874
//
3875
//  Return Values:
3876
//    ISLIB_SUCCESS - completed
3877
//    ISLIB_ERROR   - error, product registry does not exist.
3878
//  
3879
//                                                                             
3880
//////////////////////////////////////////////////////////////////////////////
3881
 
3882
function islib_preinstallCheckJavaExists(szJavaType, szJavaVer, szResponse)
3883
 
3884
STRING  szKey;
3885
STRING  szRegPath; 
3886
STRING  szMessage;
3887
 
3888
begin  
3889
 
3890
    if ( szJavaVer = "" )
3891
    then
3892
        szJavaVer = JAVA_JRE_VERSION;
3893
    endif;
3894
 
3895
    switch (szJavaType)
3896
    	case "J2SDK":
3897
    		szRegPath = "SOFTWARE\\JavaSoft\\Java Development Kit";
3898
    		szMessage = "The installer could not locate Java SDK version " + szJavaVer + ".";
3899
    	case "J2EE":         
3900
    		szRegPath = "SOFTWARE\\SUNW\\Java 2 SDK, Enterprise Edition";
3901
    		szMessage = "The installer could not locate the Java 2 Enterprise Edition SDK.";
3902
    	default:
3903
    		 szJavaType = "JRE";
3904
    		 szRegPath = "SOFTWARE\\JavaSoft\\Java Runtime Environment";    
3905
    		 szMessage = "The installer could not locate Java JRE version " + szJavaVer + ".";
3906
    endswitch;
3907
 
3908
    if ( szResponse != "ABORT" )
3909
    then
3910
    	szResponse = "WARN";
3911
    endif;
3912
 
3913
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
3914
    szKey = szRegPath ^ szJavaVer;
3915
 
3916
    if (RegDBKeyExist (szKey) < 0)
3917
    then
3918
        islib_MessageBox( szMessage, SEVERE);
3919
 
3920
        if (szResponse = "ABORT")
3921
        then
3922
        	abort;
3923
        endif;
3924
 
3925
        return ISLIB_ERROR;        
3926
    else  
3927
    	return ISLIB_SUCCESS;
3928
    endif;     
3929
 
3930
end;
3931
 
3932
 
3933
 
3934
 
3935
//////////////////////////////////////////////////////////////////////////////
3936
//
3937
//  FUNCTION: islib_getErgAfcPkgLatestPatchIDRegistryDetails
3938
//
3939
//
3940
//  Return Values:
3941
//    ISLIB_SUCCESS - completed
3942
//    ISLIB_ERROR   - error, product registry does not exist.
3943
//                                                                             
3944
//////////////////////////////////////////////////////////////////////////////
3945
function islib_getErgAfcPkgLatestPatchIDRegistryDetails
3946
(         
3947
    szLatestPatchID, szPatchLatestInstalled          
3948
)
3949
 
3950
    STRING szKey;
3951
    STRING szClass;
3952
    STRING szItem; 
3953
 
3954
    NUMBER nzSize;  
3955
    NUMBER nzType;
3956
 
3957
begin      
3958
 
3959
    // lets define the base key root location
3960
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); 
3961
    szKey   =  ERGAFC_PKG_REGISTRY_BASE + PKG_NAME;
3962
    szClass = "";
3963
 
3964
    // Check if the newly created multi-level key exists.
3965
    //
3966
    if (RegDBKeyExist (szKey) < 0)
3967
    then          
3968
 
3969
        islib_MessageBox ("ERROR: [" + szKey + "] registry key does not exist.", SEVERE);                                                                              
3970
        return ISLIB_ERROR;
3971
 
3972
    else              
3973
 
3974
        // Retrieve key value information. 
3975
        szItem = "LatestPatchID";
3976
        if (RegDBGetKeyValueEx (szKey, szItem, nzType , szLatestPatchID, nzSize) < 0) 
3977
        then  
3978
 
3979
            islib_MessageBox( "Error reading [" + 
3980
    	                szKey + "\\" +  szItem +
3981
    	                "] registry key.", SEVERE );
3982
            return ISLIB_ERROR;
3983
 
3984
        endif; 
3985
 
3986
 
3987
        // Retrieve key value information. 
3988
        szItem = "LatestPatchInstalled";
3989
        if (RegDBGetKeyValueEx (szKey, szItem, nzType , szPatchLatestInstalled, nzSize) < 0) 
3990
        then  
3991
 
3992
            islib_MessageBox( "Error reading [" + 
3993
    	                szKey + "\\" +  szItem +
3994
    	                "] registry key.", SEVERE );
3995
            return ISLIB_ERROR;
3996
 
3997
        endif;         
3998
 
3999
    endif; 
4000
 
4001
    // we are done.
4002
    return ISLIB_SUCCESS;
4003
 
4004
end;
4005
 
4006
 
4007
//////////////////////////////////////////////////////////////////////////////
4008
//
4009
//  FUNCTION: islib_getErgAfcPkgRegistryDetails
4010
//
4011
//
4012
//  Return Values:
4013
//    ISLIB_SUCCESS - completed
4014
//    ISLIB_ERROR   - error, product registry does not exist.
4015
//                                                                             
4016
//////////////////////////////////////////////////////////////////////////////
4017
function islib_getErgAfcPkgRegistryDetails
4018
( 
4019
    szPkgBaseInstallDir , szPkgVersion, szPkgInstalled, 
4020
    szLatestPatchID, szPatchLatestInstalled, 
4021
    szPkgBuildNum,  szPkgProjAcronym, szPkgDesc
4022
)
4023
 
4024
    STRING szKey;
4025
    STRING szClass;
4026
    STRING szItem; 
4027
 
4028
    NUMBER nzSize;  
4029
    NUMBER nzType;
4030
 
4031
begin      
4032
 
4033
    // lets define the base key root location
4034
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); 
4035
    szKey   =  ERGAFC_PKG_REGISTRY_BASE + PKG_NAME;
4036
    szClass = "";
4037
 
4038
    // Check if the newly created multi-level key exists.
4039
    //
4040
    if (RegDBKeyExist (szKey) < 0)
4041
    then          
4042
 
4043
        islib_MessageBox ("ERROR: [" + szKey + "] registry key does not exist.", SEVERE);                                                                             
4044
        return ISLIB_ERROR;
4045
 
4046
    else              
4047
 
4048
          // Retrieve key value information. 
4049
          szItem = "BaseInstallDir";
4050
          if (RegDBGetKeyValueEx (szKey, szItem, nzType, szPkgBaseInstallDir, nzSize) < 0) 
4051
          then  
4052
 
4053
              islib_MessageBox( "Error reading [" + 
4054
    	                  szKey + "\\" +  szItem +
4055
    	                  "] registry key.", SEVERE );
4056
              return ISLIB_ERROR;
4057
 
4058
          endif; 
4059
 
4060
 
4061
          // Retrieve key value information. 
4062
          szItem = "PkgVersion";
4063
          if (RegDBGetKeyValueEx (szKey, szItem, nzType , szPkgVersion, nzSize) < 0) 
4064
          then  
4065
 
4066
              islib_MessageBox( "Error reading [" + 
4067
    	                  szKey + "\\" +  szItem +
4068
    	                  "] registry key.", SEVERE );
4069
              return ISLIB_ERROR;
4070
 
4071
          endif; 
4072
 
4073
 
4074
          // Retrieve key value information. 
4075
          szItem = "PkgInstalled";
4076
          if (RegDBGetKeyValueEx (szKey, szItem, nzType , szPkgInstalled, nzSize) < 0) 
4077
          then  
4078
 
4079
              islib_MessageBox( "Error reading [" + 
4080
    	                  szKey + "\\" +  szItem +
4081
    	                  "] registry key.", SEVERE );    	                  
4082
              return ISLIB_ERROR;
4083
 
4084
          endif; 
4085
 
4086
 
4087
          // Retrieve key value information. 
4088
          szItem = "LatestPatchID";
4089
          if (RegDBGetKeyValueEx (szKey, szItem, nzType , szLatestPatchID, nzSize) < 0) 
4090
          then  
4091
 
4092
              islib_MessageBox( "Error reading [" + 
4093
    	                  szKey + "\\" +  szItem +
4094
    	                  "] registry key.", SEVERE );
4095
              return ISLIB_ERROR;
4096
 
4097
          endif; 
4098
 
4099
 
4100
          // Retrieve key value information. 
4101
          szItem = "LatestPatchInstalled";
4102
          if (RegDBGetKeyValueEx (szKey, szItem, nzType , szPatchLatestInstalled, nzSize) < 0) 
4103
          then  
4104
 
4105
              islib_MessageBox( "Error reading [" + 
4106
    	                  szKey + "\\" +  szItem +
4107
    	                  "] registry key.", SEVERE );
4108
              return ISLIB_ERROR;
4109
 
4110
          endif; 
4111
 
4112
 
4113
          // Retrieve key value information. 
4114
          szItem = "PkgBuildNum";
4115
          if (RegDBGetKeyValueEx (szKey, szItem, nzType , szPkgBuildNum, nzSize) < 0) 
4116
          then  
4117
 
4118
              islib_MessageBox( "Error reading [" + 
4119
    	                  szKey + "\\" +  szItem +
4120
    	                  "] registry key.", SEVERE );
4121
              return ISLIB_ERROR;
4122
 
4123
          endif; 
4124
 
4125
 
4126
          // Retrieve key value information. 
4127
          szItem = "PkgProjAcronym";
4128
          if (RegDBGetKeyValueEx (szKey, szItem, nzType , szPkgProjAcronym, nzSize) < 0) 
4129
          then  
4130
 
4131
              islib_MessageBox( "Error reading [" + 
4132
    	                  szKey + "\\" +  szItem +
4133
    	                  "] registry key.", SEVERE );
4134
              return ISLIB_ERROR;
4135
 
4136
          endif; 
4137
 
4138
          // Retrieve key value information. 
4139
          szItem = "PkgDesc";
4140
          if (RegDBGetKeyValueEx (szKey, szItem, nzType , szPkgDesc, nzSize) < 0) 
4141
          then  
4142
 
4143
              islib_MessageBox( "Error reading [" + 
4144
    	                  szKey + "\\" +  szItem +
4145
    	                  "] registry key.", SEVERE );
4146
              return ISLIB_ERROR;
4147
 
4148
          endif;                               
4149
 
4150
    endif; 
4151
 
4152
 
4153
    // we are done.
4154
    return ISLIB_SUCCESS;
4155
 
4156
end;
4157
 
4158
 
4159
 
4160
 
4161
//////////////////////////////////////////////////////////////////////////////
4162
//
4163
//  FUNCTION: islib_pkgPreRemove 
4164
//
4165
//  1. Determine if we can remove the pkg by checking to
4166
//     see if the LatestPatchID number is equal to "00".
4167
//
4168
//  Return Values:
4169
//    ISLIB_SUCCESS - completed
4170
//    ISLIB_ERROR   - error during processing.
4171
//                                                                             
4172
//////////////////////////////////////////////////////////////////////////////
4173
function islib_pkgPreRemove()
4174
 
4175
begin                            
4176
 
4177
    // assuming we are going to restore
4178
    //
4179
    if (islib_checkRemovePkg() < 0 )
4180
    then 
4181
 
4182
        islib_MessageBox("This package cannot be removed from this system yet.", SEVERE);        
4183
        return ISLIB_ERROR;  
4184
 
4185
    endif;                      
4186
 
4187
    // done.
4188
    return ISLIB_SUCCESS;
4189
 
4190
end; 
4191
 
4192
 
4193
 
4194
//////////////////////////////////////////////////////////////////////////////
4195
//
4196
//  FUNCTION: islib_checkRemovePkg
4197
//
4198
//   This function is used to check if the pkg can be removed.
4199
//   The rules that govern if a pkg can be removed are:
4200
//
4201
//   1. It does not have any patches currently installed.
4202
//      Patches should be removed prior to the package being removed.
4203
//
4204
//  Return Values:
4205
//    ISLIB_SUCCESS - completed
4206
//    ISLIB_ERROR   - error during processing.
4207
//
4208
//////////////////////////////////////////////////////////////////////////////
4209
function islib_checkRemovePkg()
4210
 
4211
    STRING szPkgLatestPatchID; 
4212
    STRING szPkgLatestPatchInstalled; 
4213
    STRING szPkgLatestPatchNumber; 
4214
 
4215
    NUMBER nzPkgLatestPatchNumber; 
4216
    NUMBER nResult;      
4217
 
4218
begin 
4219
 
4220
 
4221
    // our parent package exists lets get its current details
4222
    //
4223
    if (islib_getErgAfcPkgLatestPatchIDRegistryDetails( szPkgLatestPatchID,                                                                                                       
4224
                                                        szPkgLatestPatchInstalled) < 0 )
4225
    then                                       
4226
 
4227
        // we encountered an error getting the details
4228
        // if we are in maintenance mode anyway lets just remove the package.
4229
        //
4230
        if (MAINTENANCE) 
4231
        then
4232
            return ISLIB_SUCCESS;
4233
        else
4234
 
4235
            islib_MessageBox("ERROR: islib_getErgAfcPkgLatestPatchIDRegistryDetails() did not complete successfully.", SEVERE);  
4236
            return ISLIB_ERROR;     
4237
 
4238
        endif;
4239
 
4240
    endif;          
4241
 
4242
 
4243
    // lets get our patch number.
4244
    //   
4245
    if ( islib_getPatchNumber( szPkgLatestPatchID, szPkgLatestPatchNumber ) < 0 )
4246
    then
4247
 
4248
        islib_MessageBox("ERROR: islib_getPatchNumber() did not complete successfully.", SEVERE); 
4249
        return ISLIB_ERROR;                                  
4250
 
4251
    endif;
4252
    StrToNum(nzPkgLatestPatchNumber, szPkgLatestPatchNumber);
4253
 
4254
    // lets see what our latest patch is?
4255
    //
4256
    if ( nzPkgLatestPatchNumber != 0 )
4257
    then
4258
 
4259
        // a patch must still be installed
4260
        //
4261
        islib_MessageBox("This package has an associated patch still installed." +
4262
                   "\n\nThe latest patch for this package is [" + szPkgLatestPatchID + "], " +
4263
                   "installed on [" + szPkgLatestPatchInstalled + "]." +
4264
                   "\n\nAll patches applied to a package must be sequentially removed prior to removing " +
4265
                   "the package.", WARNING);
4266
        return ISLIB_ERROR;        
4267
 
4268
    endif;
4269
 
4270
    // we are done.                         
4271
    return ISLIB_SUCCESS;      
4272
 
4273
end;   
4274
 
4275
 
4276
//////////////////////////////////////////////////////////////////////////////
4277
//
4278
// FUNCTION:   islib_setSystemEnvironmentVariable  
4279
//
4280
// This function is used to set a System environment
4281
// variable.
4282
//
4283
// We pass:
4284
// 1. the name of the variable to be set (ie created).
4285
// 2. the value to set the new variable.
4286
//                                   
4287
// In the event that a parameter is passed that is not supported
4288
// shall result in the user being notified and the installation
4289
// being aborted.
4290
//
4291
// Return Values:
4292
//
4293
// SUCCESSFULL ENVIRONMENT CREATION: 1
4294
// ENVIRONMENT ALREADY EXISTS: 2
4295
// ERROR:  -1
4296
//
4297
//////////////////////////////////////////////////////////////////////////////  
4298
 
4299
function islib_setSystemEnvironmentVariable( szNewVar, szNewVal )
4300
 
4301
    STRING szKey;
4302
    STRING szName;
4303
    STRING szPathBuff;
4304
 
4305
    NUMBER nType, nSize;  
4306
    NUMBER nSUCCESS1, nSUCCESS2;
4307
 
4308
begin      
4309
 
4310
    nSUCCESS1 = ISLIB_SUCCESS;
4311
    nSUCCESS2 = 2;
4312
 
4313
    // first we need to get access to the current system
4314
    // path.
4315
    //
4316
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
4317
    szKey  = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
4318
    szName = szNewVar;
4319
 
4320
 
4321
    // Read the system variable if it exists
4322
    //
4323
    if (RegDBGetKeyValueEx(szKey, szName, nType, szPathBuff, nSize) < 0)
4324
    then
4325
 
4326
        // we did not find it so lets create it
4327
        //
4328
        if (RegDBSetKeyValueEx( szKey, szName, REGDB_STRING_EXPAND, szNewVal, -1 ) < 0) 
4329
        then   
4330
 
4331
            islib_MessageBox( "ERROR: Failed to create System variable registry key:\n" +
4332
                        "[" + szKey + "\\" + szName + "]=[" + szNewVal + "].", SEVERE );
4333
 
4334
            return ISLIB_ERROR;
4335
 
4336
        endif;
4337
 
4338
    else
4339
 
4340
        // we found the variable.
4341
        //
4342
        islib_MessageBox("INFO: SYSTEM environment variable previously created.\n" +
4343
                   "[" + szKey + "\\" + szName + "]=[" + szNewVal + "].", INFORMATION );
4344
        return nSUCCESS2;
4345
 
4346
    endif;
4347
 
4348
 
4349
    // done dude.
4350
    return nSUCCESS1;               
4351
 
4352
end;           
4353
 
4354
 
4355
 
4356
//////////////////////////////////////////////////////////////////////////////
4357
//
4358
// FUNCTION:   islib_forceSetSystemEnvironmentVariable  
4359
//
4360
// Added by D.Greeve - 24/10/05
4361
//
4362
// This function is used to set a System environment
4363
// variable - code is based on islib_setSystemEnvironmentVariable.
4364
// 
4365
// Unlike islib_setSystemEnvironmentVariable this 
4366
// function will always overwrite an existing environment variable 
4367
// and flag the change so that it is not uninstalled.
4368
//
4369
// We pass:
4370
// 1. the name of the variable to be set (ie created).
4371
// 2. the value to set the new variable.
4372
//                                   
4373
// In the event that a parameter is passed that is not supported
4374
// shall result in the user being notified and the installation
4375
// being aborted.
4376
//
4377
// Return Values:
4378
//
4379
// SUCCESSFULL ENVIRONMENT CREATION: 1
4380
// ENVIRONMENT ALREADY EXISTS: 2
4381
// ERROR:  -1
4382
//
4383
//////////////////////////////////////////////////////////////////////////////  
4384
 
4385
function islib_forceSetSystemEnvironmentVariable( szNewVar, szNewVal )
4386
 
4387
    STRING szKey;
4388
    STRING szName;
4389
    STRING szPathBuff;
4390
 
4391
    NUMBER nType, nSize;  
4392
    NUMBER nSUCCESS1, nSUCCESS2;
4393
 
4394
begin      
4395
 
4396
    nSUCCESS1 = ISLIB_SUCCESS;
4397
    nSUCCESS2 = 2;
4398
 
4399
    // first we need to get access to the current system
4400
    // path.
4401
    //
4402
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
4403
    szKey  = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
4404
    szName = szNewVar;
4405
 
4406
 
4407
    // Read the system variable if it exists
4408
    //
4409
    if (RegDBGetKeyValueEx(szKey, szName, nType, szPathBuff, nSize) < 0)
4410
    then
4411
 
4412
        // we did not find it so lets create it
4413
        //
4414
        if (RegDBSetKeyValueEx( szKey, szName, REGDB_STRING_EXPAND, szNewVal, -1 ) < 0) 
4415
        then   
4416
 
4417
            islib_MessageBox( "ERROR: Failed to create System variable registry key:\n" +
4418
                        "[" + szKey + "\\" + szName + "]=[" + szNewVal + "].", SEVERE );
4419
 
4420
            return ISLIB_ERROR;
4421
 
4422
        endif;
4423
 
4424
    else
4425
 
4426
    	// we found the variable.
4427
        //
4428
 
4429
        Disable(LOGGING);       
4430
 
4431
        if (RegDBSetKeyValueEx( szKey, szName, REGDB_STRING_EXPAND, szNewVal, -1 ) < 0) 
4432
        then   
4433
 
4434
            islib_MessageBox( "ERROR: Failed to create System variable registry key:\n" +
4435
                        "[" + szKey + "\\" + szName + "]=[" + szNewVal + "].", SEVERE );
4436
 
4437
            return ISLIB_ERROR;
4438
 
4439
        endif;	
4440
 
4441
        Enable(LOGGING);
4442
        return nSUCCESS2;
4443
 
4444
    endif;
4445
 
4446
 
4447
    // done dude.
4448
    return nSUCCESS1;               
4449
 
4450
end;           
4451
 
4452
 
4453
 
4454
//////////////////////////////////////////////////////////////////////////////
4455
//
4456
// FUNCTION:   islib_addAtItem  
4457
//
4458
// This function is used to add an item to the system AT manager
4459
//
4460
// We pass:
4461
// 1. a tag to match against any possible existing items
4462
// 2. the item to be added
4463
//                                   
4464
// Return Values:
4465
//
4466
// SUCCESS: ISLIB_SUCCESS
4467
// ERROR:   ISLIB_ERROR
4468
//
4469
//////////////////////////////////////////////////////////////////////////////  
4470
function islib_addAtItem( szTag, szItem )
4471
 
4472
    STRING szListItem;  
4473
 
4474
    STRING szItemNo;
4475
 
4476
    NUMBER nzItemRetVal;
4477
 
4478
    LIST   lzAtItemsListID; 
4479
    LIST   lzParseItemListID;  
4480
 
4481
begin     
4482
 
4483
    // lets remove any existing
4484
    // entries that match our tag before
4485
    // we add our new item
4486
    //           
4487
    if ( islib_removeAtItem( szTag ) < 0 )
4488
    then
4489
 
4490
        islib_MessageBox("ERROR: returned by islib_removeAtItem().", SEVERE);
4491
        return ISLIB_ERROR;    
4492
 
4493
    endif;
4494
 
4495
    // if we get to here we should be able to
4496
    // load our new AT item
4497
    //     
4498
    LaunchAppAndWait ( "at", szItem, WAIT );                                                                                               
4499
 
4500
    // done dude.
4501
    return ISLIB_SUCCESS;     
4502
 
4503
end; 
4504
 
4505
 
4506
//////////////////////////////////////////////////////////////////////////////
4507
//
4508
// FUNCTION:   islib_removeAtItem  
4509
//
4510
// This function is used to remove an item to the system AT manager
4511
//
4512
// We pass:
4513
// 1. a tag to match against the item you wish to remove.
4514
//                                   
4515
// Return Values:
4516
//
4517
// SUCCESS: ISLIB_SUCCESS
4518
// ERROR:   ISLIB_ERROR
4519
//
4520
//////////////////////////////////////////////////////////////////////////////  
4521
function islib_removeAtItem( szTag )
4522
 
4523
    STRING szListItem;  
4524
 
4525
    STRING szItemNo;
4526
 
4527
    NUMBER nzItemRetVal;
4528
 
4529
    LIST   lzAtItemsListID; 
4530
    LIST   lzParseItemListID;  
4531
 
4532
    STRING szMyCmd;
4533
 
4534
begin        
4535
 
4536
    szMyCmd = "at";                      
4537
 
4538
    // lets create save list.
4539
    // if an error occurred, report it; then terminate.
4540
    //
4541
    lzAtItemsListID = ListCreate(STRINGLIST);
4542
    if (lzAtItemsListID = LIST_NULL) 
4543
    then
4544
 
4545
        islib_MessageBox ("ERROR: Unable to create lzAtItemsListID.", SEVERE);
4546
        return ISLIB_ERROR;
4547
 
4548
    endif;                                        
4549
 
4550
    // lets get a listing of what the AT mgr currently
4551
    // contains.
4552
    //   
4553
    if ( islib_getCmdOutputItemList(lzAtItemsListID, szMyCmd) < 0 )
4554
    then                      
4555
 
4556
        // we could not get a listing so i will assume 
4557
        // there was nothing in the AT manager
4558
        //                                                   
4559
        islib_MessageBox ("ERROR: returned by islib_getAtItemList().", SEVERE);        
4560
 
4561
    else              
4562
 
4563
        // we have a list at this point.
4564
        // 
4565
        //SdShowInfoList ("Debug Display", "Current AT mgr listing...", lzAtItemsListID);
4566
 
4567
        // we have work to do.              
4568
        // Lets get our first item.
4569
        //  
4570
        // the first two strings are not required in our 
4571
        // listing, they are just some frilly bit as seen below.
4572
        // the good stuff usually begins at line 3.
4573
        //
4574
        // line1: There are no entries in the list.
4575
        //
4576
        // or
4577
        // 
4578
        // line1: Status ID   Day                     Time          Command Line
4579
        // line2: -------------------------------------------------------------------------------
4580
        //
4581
        ListGetFirstString ( lzAtItemsListID, szListItem );            
4582
 
4583
        nzItemRetVal = ListGetNextString ( lzAtItemsListID, szListItem );                    
4584
        if ( szListItem != "" && nzItemRetVal != END_OF_LIST )
4585
        then  
4586
 
4587
            // now lets deal with any content.
4588
            //
4589
            nzItemRetVal = ListGetNextString ( lzAtItemsListID, szListItem );                                
4590
            while ( nzItemRetVal != END_OF_LIST )  
4591
 
4592
                // lets create a list to parse the retireved item.
4593
                //                  
4594
                lzParseItemListID = ListCreate(STRINGLIST); 
4595
 
4596
                // If an error occurred, report it, and return error.
4597
                if (lzParseItemListID = LIST_NULL) 
4598
                then
4599
 
4600
                    islib_MessageBox ("ERROR: Unable to create lzParseItemListID.", SEVERE);
4601
                    return ISLIB_ERROR;
4602
 
4603
                endif;                   
4604
 
4605
                // we want to know if the item we are trying to add
4606
                // already exists in the AT listing so we need to compare
4607
                // our tag to the line, if we find a match we shall
4608
                // proceed to delete the entry and add our new one.
4609
                // This should not happen in normal practice as
4610
                // when packages get removed they should remove the 
4611
                // AT items that belong to them.
4612
                //                                
4613
                if ( szListItem % (szTag) )
4614
                then
4615
 
4616
                    //islib_MessageBox("matched szListItem=[" + szListItem + "], szItemNo=[" + szItemNo + "].", INFORMATION);                
4617
 
4618
                    // we have found a match between my tag
4619
                    // and a list item (ie an AT entry).
4620
                    // lets parse the item, we know
4621
                    // it contains the item number as the first field 
4622
                    // delimited by a whitespace or " "
4623
                    //
4624
                    StrGetTokens (lzParseItemListID, szListItem, " ");               
4625
 
4626
                    // lets load the bits so we can use the information
4627
                    //                               
4628
                    ListGetFirstString ( lzParseItemListID, szItemNo );                                                                
4629
 
4630
                    // what do we do with this item.
4631
                    //                                                    
4632
                    LaunchApp("at", szItemNo + " /delete" );
4633
                    //islib_MessageBox ("INFO: we have deleted AT item number " + szItemNo, INFORMATION);                    
4634
 
4635
                    // lets free resources for the next item
4636
                    // 
4637
                    ListDestroy(lzParseItemListID);               
4638
 
4639
                endif;
4640
 
4641
                // lets get the next item.
4642
                //
4643
                nzItemRetVal = ListGetNextString ( lzAtItemsListID, szListItem );            
4644
 
4645
            endwhile;                                      
4646
 
4647
        endif;            
4648
 
4649
    endif;
4650
 
4651
    // lets free resources for the next item
4652
    // 
4653
    ListDestroy(lzAtItemsListID);       
4654
 
4655
 
4656
    // done dude.
4657
    return ISLIB_SUCCESS;               
4658
 
4659
end;
4660
 
4661
 
4662
 
4663
 
4664
 
4665
//////////////////////////////////////////////////////////////////////////////
4666
//
4667
// FUNCTION:   islib_updateRegistryKey  
4668
//
4669
// This function is used to add a a registry key. Current version is
4670
// just an extention of the RegDBSetKeyValueEx function - with better 
4671
// interaction for the user if the entry fails.
4672
//
4673
// We pass:
4674
// - The key name
4675
// - The specific key entry
4676
// - The type of key to be generated
4677
// - The value of the key we are changing/creating
4678
// - The size of the value. 
4679
//
4680
//	For further information check the help menus.
4681
//                                   
4682
// Return Values:
4683
//
4684
// SUCCESS: ISLIB_SUCCESS
4685
// ERROR:   ISLIB_ERROR
4686
//
4687
//////////////////////////////////////////////////////////////////////////////  
4688
 
4689
function islib_updateRegistryKey (szKey, szName, nType, szValue, nSize )
4690
 
4691
begin  
4692
 
4693
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
4694
 
4695
    if (RegDBSetKeyValueEx( szKey, szName, nType, szValue, nSize  ) < 0)
4696
    then  
4697
        islib_MessageBox( "Error updating [" + szKey + "\\" +  szName + "] registry key, with value [" + szValue + "].", SEVERE );
4698
        return ISLIB_ERROR;
4699
    endif;
4700
 
4701
    return ISLIB_SUCCESS;
4702
 
4703
end;     
4704
 
4705
 
4706
 
4707
//////////////////////////////////////////////////////////////////////////////
4708
//
4709
// FUNCTION:   islib_getHostIPAddress  
4710
//
4711
// This function is used to determine the host's primary
4712
// IP Address as returned by the 'ipconfig /all' system command
4713
//
4714
// We pass:
4715
// 1. a tag to match against the item you wish to remove.
4716
//                                   
4717
// Return Values:
4718
//
4719
// Set the string szIPAddress and return.
4720
//
4721
// SUCCESS: ISLIB_SUCCESS
4722
// ERROR:   ISLIB_ERROR
4723
//
4724
//////////////////////////////////////////////////////////////////////////////  
4725
function islib_getHostIPAddress( szIPAddress )
4726
 
4727
    STRING szListItem;  
4728
    STRING szItemNo;
4729
 
4730
    NUMBER nzItemRetVal;
4731
 
4732
    LIST   lzIpconfigItemsListID; 
4733
    LIST   lzParseItemListID;  
4734
 
4735
    STRING szMyCmd;
4736
    STRING szTmpStr, szTmpIPAddress;
4737
    NUMBER nzStrLength;
4738
 
4739
begin              
4740
 
4741
    szMyCmd = "ipconfig /all";         
4742
 
4743
    // lets create save list.
4744
    // if an error occurred, report it; then terminate.
4745
    //
4746
    lzIpconfigItemsListID = ListCreate(STRINGLIST);
4747
    if (lzIpconfigItemsListID = LIST_NULL) 
4748
    then
4749
 
4750
        islib_MessageBox ("ERROR: Unable to create lzIpconfigItemsListID.", SEVERE);
4751
        return ISLIB_ERROR;
4752
 
4753
    endif;                                        
4754
 
4755
 
4756
    // lets get a listing of what the 'ipconfig /all' command
4757
    //   
4758
    if ( islib_getCmdOutputItemList(lzIpconfigItemsListID, szMyCmd) < 0 )
4759
    then                      
4760
 
4761
        // something went wrong with the command execution.
4762
        //                                                   
4763
        islib_MessageBox ("ERROR: returned by islib_getCmdOutputItemList().", SEVERE);        
4764
 
4765
    else              
4766
 
4767
        // we have a list at this point.
4768
        // 
4769
        //SdShowInfoList ("Debug Display", "Current command listing...", lzIpconfigItemsListID);
4770
 
4771
        // we have work to do.              
4772
        // we are looking for the line that contains the follwing
4773
        // string "IP Address".        
4774
        //                
4775
        nzItemRetVal = ListGetFirstString ( lzIpconfigItemsListID, szListItem );                    
4776
        if ( szListItem != "" && nzItemRetVal != END_OF_LIST )
4777
        then  
4778
 
4779
            // now lets deal with any content.
4780
            //
4781
            nzItemRetVal = ListGetNextString ( lzIpconfigItemsListID, szListItem );                                
4782
            while ( nzItemRetVal != END_OF_LIST )  
4783
 
4784
                // lets create a list to parse the retireved item.
4785
                //                  
4786
                lzParseItemListID = ListCreate(STRINGLIST); 
4787
 
4788
                // If an error occurred, report it, and return error.
4789
                if (lzParseItemListID = LIST_NULL) 
4790
                then
4791
 
4792
                    islib_MessageBox ("ERROR: Unable to create lzParseItemListID.", SEVERE);
4793
                    return ISLIB_ERROR;
4794
 
4795
                endif;                   
4796
 
4797
                // we are searching for the line with the "IP Address...                               
4798
                if ( szListItem % ("IP Address.") )
4799
                then
4800
 
4801
                    // Debug help
4802
                    //islib_MessageBox("matched szListItem=[" + szListItem + "].", INFORMATION);                
4803
 
4804
                    // we have found a match between my tag
4805
                    // and a list item.
4806
                    // lets parse the item, we know something about the format.
4807
                    // it contains two bits delimited by a colon or ":"
4808
                    //
4809
                    StrGetTokens (lzParseItemListID, szListItem, ":");               
4810
 
4811
                    // lets load the bits so we can use the information
4812
                    //                               
4813
                    ListGetFirstString ( lzParseItemListID, szTmpStr );                                                                                                                                             
4814
                    ListGetNextString ( lzParseItemListID, szTmpIPAddress );                                                                                                                                                                                                           
4815
 
4816
                    // we have our ip address but it contain some doggy
4817
                    // newline characters that we do not like
4818
                    //
4819
                    nzStrLength = StrLength(szTmpIPAddress);
4820
                    StrSub(szIPAddress,szTmpIPAddress,1,nzStrLength-2);
4821
 
4822
                    // lets free resources for the next item
4823
                    // 
4824
                    ListDestroy(lzParseItemListID); 
4825
 
4826
                    // done dude.
4827
                    return ISLIB_SUCCESS;                                     
4828
 
4829
                endif;
4830
 
4831
                // lets get the next item.
4832
                //
4833
                nzItemRetVal = ListGetNextString ( lzIpconfigItemsListID, szListItem );            
4834
 
4835
            endwhile;                                      
4836
 
4837
        endif;            
4838
 
4839
    endif;
4840
 
4841
    // lets free resources for the next item
4842
    // 
4843
    ListDestroy(lzIpconfigItemsListID);       
4844
 
4845
 
4846
    // done dude.
4847
    return ISLIB_SUCCESS;               
4848
 
4849
end;
4850
 
4851
 
4852
//////////////////////////////////////////////////////////////////////////////
4853
//
4854
// FUNCTION:   islib_getCmdOutputItemList  
4855
//
4856
// This function is used to get a listing of the current
4857
// content of the "ipconfig" system command.  
4858
// It populates a string list that we pass by reference.
4859
//
4860
// We pass:
4861
// 1. a List (by ref) to populate.
4862
//                                   
4863
// Return Values:
4864
//
4865
// SUCCESS: ISLIB_SUCCESS
4866
// ERROR:   ISLIB_ERROR
4867
//
4868
//////////////////////////////////////////////////////////////////////////////
4869
function   islib_getCmdOutputItemList (lzListID, szCmd)  
4870
 
4871
    STRING szCmdDir;
4872
    STRING szCmdOutputFileName; 
4873
    STRING szCmdFileName;
4874
    STRING szCmdOutputFileLocation;   
4875
    STRING szCmdFileLocation;
4876
 
4877
    STRING szLine; 
4878
 
4879
    NUMBER nzFileHandle;
4880
    NUMBER nzRetVal;      
4881
 
4882
begin 
4883
 
4884
    // lets initialise our variables.                               
4885
    //
4886
    szCmdDir                = WINDIR^"temp\\xx_var\\";
4887
    szCmdOutputFileName     = "xx_cmd.txt"; 
4888
    szCmdFileName           = "xx_cmd.bat"; 
4889
    szCmdOutputFileLocation =  szCmdDir +  szCmdOutputFileName;      
4890
    szCmdFileLocation       =  szCmdDir +  szCmdFileName;            
4891
 
4892
 
4893
    // if the CmdDir does not already exist lets create
4894
    // it for free 
4895
    //
4896
    if (ExistsDir (szCmdDir) != EXISTS) 
4897
    then
4898
 
4899
        // lets create our cmd dir
4900
        //           
4901
        if ( CreateDir ( szCmdDir ) < 0 )
4902
        then      
4903
 
4904
             islib_MessageBox("Failed to create [" + szCmdDir + "] dir.", SEVERE);
4905
             return ISLIB_ERROR;                    
4906
 
4907
        endif;   
4908
 
4909
    endif;       
4910
 
4911
 
4912
    // we need to create an interim file to capture
4913
    // a listing of the cmd.  Trying to re-direct the output
4914
    // using the LaunchApp command does not appear to work???
4915
    // anyway...
4916
    // 
4917
    OpenFileMode (FILE_MODE_APPEND);
4918
 
4919
 
4920
    // Create a new file and leave it open.
4921
    if (CreateFile (nzFileHandle, szCmdDir, szCmdFileName) < 0) 
4922
    then
4923
 
4924
        // Report the error.
4925
        islib_MessageBox ("System error, failed to create file " + szCmdFileLocation, SEVERE);
4926
        return ISLIB_ERROR;
4927
 
4928
    endif;       
4929
 
4930
 
4931
    // Write a line to the end of our file.
4932
    //
4933
    if (WriteLine(nzFileHandle, szCmd + " > " + szCmdOutputFileLocation) < 0) 
4934
    then      
4935
 
4936
        // Report the error.
4937
        islib_MessageBox ("System error, failed to write line to " + szCmdFileLocation, SEVERE);
4938
        return ISLIB_ERROR;
4939
 
4940
    endif;
4941
 
4942
 
4943
    // Close the file.
4944
    CloseFile (nzFileHandle); 
4945
 
4946
 
4947
    // lets create the current view of the AT manager
4948
    // by running our tmp bat file.
4949
    //                                     
4950
    LaunchAppAndWait ( szCmdFileLocation, "", WAIT );    
4951
 
4952
 
4953
    // Set the file mode to read-only
4954
    //
4955
    OpenFileMode (FILE_MODE_NORMAL);
4956
 
4957
 
4958
    // lets check to see if the output file
4959
    // exists.
4960
    //        
4961
    if ( Is (EXISTS,szCmdOutputFileLocation) = TRUE )
4962
    then                         
4963
 
4964
        // Open the text file.
4965
        if (OpenFile (nzFileHandle, szCmdDir, szCmdOutputFileName) < 0) 
4966
        then
4967
 
4968
            // Report the error.
4969
            islib_MessageBox ("System error, failed to open file [" +
4970
                        szCmdOutputFileLocation + "].", SEVERE);
4971
            return ISLIB_ERROR;
4972
 
4973
        endif;  
4974
 
4975
 
4976
        // Get lines from the file into the list.
4977
        // 
4978
        nzRetVal = GetLine (nzFileHandle, szLine);
4979
        while (nzRetVal = 0)                                               
4980
 
4981
            ListAddString (lzListID, szLine, AFTER);                                                                                       
4982
            nzRetVal = GetLine (nzFileHandle, szLine);
4983
 
4984
        endwhile; 
4985
 
4986
 
4987
        // Close the file.
4988
        CloseFile (nzFileHandle);                                                                
4989
 
4990
    else                                 
4991
 
4992
         // output file does not exist...
4993
         //
4994
         islib_MessageBox ("System error, failed to find command output file [" +
4995
                      szCmdOutputFileLocation + "].", SEVERE);
4996
 
4997
         return ISLIB_ERROR;
4998
 
4999
    endif;
5000
 
5001
 
5002
    // we are done.
5003
    return ISLIB_SUCCESS;                   
5004
 
5005
end;  
5006
 
5007
 
5008
 
5009
 
5010
//////////////////////////////////////////////////////////////////////////////
5011
//
5012
// FUNCTION:   islib_MessageBox  
5013
//
5014
// This function is an alternative to the MessageBox funtion.
5015
// It prevents errant warning messages from breaking Silent Installs.
5016
// 
5017
//
5018
//////////////////////////////////////////////////////////////////////////////
5019
 
5020
function islib_MessageBox (szMsg, nType)     
5021
 
5022
begin 
5023
 
5024
    // If we are running in silent mode or record mode we do not want 
5025
    // messages to pop up
5026
 
5027
    if ( MODE = NORMALMODE ) then
5028
    	MessageBox( szMsg, nType);
5029
    endif;                                    
5030
 
5031
end;
5032
 
5033
 
5034
 
5035
 
5036
 
5037
//////////////////////////////////////////////////////////////////////////////
5038
//
5039
// FUNCTION:   islib_CheckCSTrace 
5040
//
5041
// 			This function checks for the existance/correctness of the DRWatson
5042
//			debugger in the registry. If it finds an inconsistancy with the
5043
//			default WinNT settings - it returns a failure code.
5044
//
5045
//			Return Values:
5046
//
5047
// 			SUCCESS: ISLIB_SUCCESS
5048
//			ERROR:   ISLIB_ERROR  
5049
// 
5050
//
5051
//////////////////////////////////////////////////////////////////////////////
5052
 
5053
function islib_CheckCSTrace ()     
5054
 
5055
NUMBER	nResult, nType, nSize;
5056
STRING	szAuto, szDebugger;
5057
STRING	szAutoValue, szDebuggerValue;
5058
STRING  szKey;
5059
 
5060
begin 
5061
 
5062
	szAuto = DEFAULT_DEBUGGER_AUTO;
5063
	szDebugger = DEFAULT_DEBUGGER;          
5064
	szKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug";
5065
 
5066
	RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
5067
 
5068
    // Check for the basic key. The system is in a bad way if this isnt here.
5069
    // We also check for the two key values and return the appropriate error codes.
5070
    //
5071
    if ( (RegDBGetKeyValueEx (szKey, "Auto", nType , szAutoValue, nSize) < 0) ||
5072
    	 (RegDBGetKeyValueEx (szKey, "Debugger", nType , szDebuggerValue, nSize) < 0) )
5073
	then
5074
	    islib_MessageBox ("ERROR: Failed to locate [" + szKey + "] Registry key does not exist.", SEVERE);
5075
        abort;           	
5076
    else
5077
        // If we get to here then both keys exist. Now to compare with the defaults.
5078
        //
5079
        if ( szAuto = szAutoValue) && ( szDebugger = szDebuggerValue)
5080
        then
5081
        	return ISLIB_SUCCESS;
5082
        else
5083
        	return ISLIB_ERROR;
5084
        endif;
5085
    endif;  
5086
 
5087
end;                                            
5088
 
5089
 
5090
 
5091
 
5092
//////////////////////////////////////////////////////////////////////////////
5093
//
5094
// FUNCTION:   islib_SetCSTrace 
5095
//
5096
// 			This function sets the DRWatson debugger in the registry. 
5097
//			It sets the two important values to what is required by
5098
//			ERG's core services system (which is coincidentally the same
5099
//			as the NT4 default.    
5100
//
5101
//			This is an irreversible system change. Logging is disabled.
5102
//
5103
//			Return Values:
5104
//
5105
// 			SUCCESS: ISLIB_SUCCESS
5106
//			ERROR:   ABORT  
5107
// 
5108
//
5109
//////////////////////////////////////////////////////////////////////////////
5110
 
5111
function islib_SetCSTrace ()     
5112
 
5113
STRING	szAuto, szDebugger;
5114
STRING  szKey;
5115
 
5116
begin
5117
 
5118
	szAuto = DEFAULT_DEBUGGER_AUTO;
5119
	szDebugger = DEFAULT_DEBUGGER;          
5120
	szKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug";
5121
 
5122
	RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
5123
 
5124
    /* 
5125
    We wont check for the presence of the keys first. Two things are assumed.
5126
    1. islib_CheckCSTrace() has been run first so you know the keys are there/need to be changed
5127
    2. You are running this function because you _want_ the keys to be created/changed 
5128
    */
5129
 
5130
	Disable (LOGGING);
5131
 
5132
	if ( RegDBSetKeyValueEx ( szKey, "Auto", REGDB_STRING, szAuto, -1 ) < 0 )
5133
	then
5134
		MessageBox ("ERROR: Failed to set [" + szKey + " - Auto]", SEVERE);
5135
		abort;
5136
    endif;
5137
 
5138
    if ( RegDBSetKeyValueEx ( szKey, "Debugger", REGDB_STRING, szDebugger, -1 ) < 0 )
5139
	then
5140
		MessageBox ("ERROR: Failed to set [" + szKey + " - Debugger]", SEVERE);
5141
		abort;
5142
    endif;
5143
 
5144
	Enable (LOGGING);
5145
 
5146
	return ISLIB_SUCCESS;
5147
 
5148
end;      
5149
 
5150
//////////////////////////////////////////////////////////////////////////////
5151
//
5152
// FUNCTION:   islib_checkActiveStatePerl 
5153
//
5154
// 	This function is used to check for the existence of a
5155
//  specific version of PERL on the system.
5156
//
5157
//  Parameters:
5158
//
5159
//  1) Build Version,
5160
//     the perl build version number (ie "635"), 
5161
//     it is recorded as a registry value string under the base key,
5162
//     
5163
//     HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl\\CurrentVersion
5164
//                   
5165
//  2) PERL install dir,
5166
//     the location of the PERL install, this is recored as a default regestry
5167
//     value string entry under the base registry key,                                      
5168
//
5169
//     HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl\\<BuildVersion>
5170
//
5171
//	Return Values:
5172
//
5173
// 	SUCCESS: ISLIB_SUCCESS
5174
//	ERROR:   abort  
5175
//
5176
//////////////////////////////////////////////////////////////////////////////
5177
function islib_checkActiveStatePerl(nzMinRequiredVersion, szInstallDir)
5178
 
5179
    NUMBER nzType, nzSize; 
5180
    STRING szCurrentVersion, szMinRequiredVersion;
5181
    NUMBER nzCurrentVersion;   
5182
 
5183
    STRING szCurrentInstallDir;
5184
    STRING szCurrentInstallDir_lc;
5185
 
5186
    STRING szInstallDir_lc;
5187
 
5188
    STRING szRegKey;
5189
 
5190
begin                                             
5191
 
5192
    NumToStr(szMinRequiredVersion, nzMinRequiredVersion);  	                                                 	                                                
5193
 
5194
    RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);
5195
	szRegKey = "\\SOFTWARE\\ActiveState\\ActivePerl";
5196
 
5197
	if (RegDBKeyExist (szRegKey) < 0) 
5198
	then                            
5199
 
5200
	    // we did not find the key		
5201
	    islib_MessageBox("The installer could not locate the prerequisite package, ActiveState PERL [" +szMinRequiredVersion+ "]. Install will now abort.", SEVERE);
5202
        abort;		
5203
 
5204
 	else                        
5205
 
5206
 	    // we found the key                        
5207
 	    // lets see what version of perl is installed
5208
 	    RegDBGetKeyValueEx ( szRegKey, "CurrentVersion", nzType, szCurrentVersion, nzSize ); 	                                                
5209
 
5210
        // need to convert the strings into numbers for comparison
5211
        StrToNum(nzCurrentVersion, szCurrentVersion);  	                                                 	                                                
5212
 	    if(  nzMinRequiredVersion > nzCurrentVersion )
5213
 	    then  
5214
 
5215
 	        // current version of perl required is not current
5216
 	        // we assume that they are both the same version, though
5217
 	        //
5218
 	        islib_MessageBox("The installer has located and earlier version of ActiveState PERL " 
5219
 	                         +szCurrentVersion+ "].\n" +
5220
 	                         "The recommended version of ActiveState PERL is [" +szMinRequiredVersion+ "].", WARNING);          		
5221
 
5222
 	    endif;
5223
 
5224
 
5225
 	    // perl is installed, now lets check where...
5226
 	    //
5227
 	    szRegKey = "\\SOFTWARE\\ActiveState\\ActivePerl\\" + szCurrentVersion;
5228
        RegDBGetKeyValueEx ( szRegKey, "", nzType, szCurrentInstallDir, nzSize );
5229
 
5230
        // lets make the string lower case so we can compare them
5231
        //
5232
        StrToLower(szCurrentInstallDir_lc, szCurrentInstallDir);
5233
        StrToLower(szInstallDir_lc, szInstallDir);
5234
 
5235
 		if ( szCurrentInstallDir_lc != szInstallDir_lc )
5236
 		then 
5237
 
5238
 	    	// default install is not where we expected it.
5239
 	    	//
5240
	        islib_MessageBox("The installer has detected that ActiveState PERL has been previously incorrectly installed in [" 
5241
	                         +szCurrentInstallDir_lc+ 
5242
	                         "].\n" +
5243
	                         "The required default install location is [" 
5244
	                         +szInstallDir_lc+ 
5245
	                         "]. Install will now abort.", SEVERE);
5246
            abort;		
5247
 
5248
 		endif;	
5249
 
5250
 
5251
	 endif;   
5252
 
5253
end;
5254
 
5255
 
5256
///////////////////////////////////////////////////////////////////////////////
5257
//
5258
// FUNCTION:   islib_verifyIPAddressStrFormat (STRING)
5259
//
5260
// This function is used to verify that the input parameter has
5261
// a correct format of an IP address.
5262
//
5263
// We know the string is delimeted by a "."s
5264
// We know that the string must have 4 components
5265
// We know that each components are integers
5266
// We know that each integer can have a value of 0 to 254
5267
// If any discrepancy is detected we return an error. 
5268
//
5269
// Return Values:
5270
//    ISLIB_SUCCESS = string has correct IP address format.
5271
//    ISLIB_ERROR   = string does NOT have a correct
5272
//                    IP address format.
5273
//
5274
///////////////////////////////////////////////////////////////////////////////
5275
 
5276
function islib_verifyIPAddressStrFormat(szIPAdress)
5277
 
5278
    LIST lzIPAddressComponents;
5279
    NUMBER nCount;
5280
    NUMBER nResult;
5281
 
5282
    STRING szItem;
5283
    NUMBER nzItem;
5284
 
5285
begin  
5286
 
5287
    //islib_MessageBox("input szIPAdress=[" +szIPAdress+ "].", INFORMATION); 
5288
 
5289
    // we need to break the input string into the 4 components
5290
    // that define an IPAddress. 
5291
 
5292
    // Create an empty number list.
5293
    lzIPAddressComponents = ListCreate (STRINGLIST);
5294
 
5295
    // If an error occurred, report it; then terminate.
5296
    if (lzIPAddressComponents = LIST_NULL) 
5297
    then
5298
 
5299
        // Report the error.
5300
        islib_MessageBox ("Unable to create list.", SEVERE);
5301
        return ISLIB_ERROR; 
5302
 
5303
    endif; 
5304
 
5305
    // Get each path from the search path into the list.
5306
    if (StrGetTokens (lzIPAddressComponents, szIPAdress, "\.") > 0) 
5307
    then
5308
 
5309
        // Report the error.
5310
        islib_MessageBox ("StrGetTokens failed.", SEVERE);
5311
        return ISLIB_ERROR;
5312
 
5313
    endif;
5314
 
5315
 
5316
    // Count the number of program folders in the list.
5317
    nCount = ListCount (lzIPAddressComponents);
5318
 
5319
    // Report error or display the folder count.
5320
    if (nCount < 0) 
5321
    then
5322
 
5323
        islib_MessageBox ("ListCount failed.", SEVERE);
5324
        return ISLIB_ERROR;
5325
 
5326
    elseif (nCount != 4)
5327
    then
5328
 
5329
        islib_MessageBox ("IP address supplied [" +szIPAdress+ "] has an incorrect format.\n" +
5330
                    "\nNote:\trequired IP address format: [NNN.NNN.NNN.NNN]\n" +
5331
                    "\twhere NNN is an integer 0 to 254.", WARNING);
5332
        return ISLIB_ERROR;        
5333
 
5334
    endif;
5335
 
5336
    // we have the correct number of sections
5337
    // now lets check to see each segment is
5338
    // a number and falls within the rewuired
5339
    // range. 
5340
    // 
5341
    nResult = ListGetFirstString (lzIPAddressComponents, szItem);
5342
 
5343
    // Loop while not at end of list.
5344
    while (nResult != END_OF_LIST)
5345
 
5346
        // check to see if the item is a number
5347
        //
5348
        if ( StrToNum(nzItem, szItem) < 0 )
5349
        then  
5350
 
5351
            islib_MessageBox ("IP address supplied [" +szIPAdress+ "] has a NON-numeric " + 
5352
                        "section ["+szItem+"].\n" +
5353
                        "\nNote:\trequired IP address format: [NNN.NNN.NNN.NNN]\n" +
5354
                        "\twhere NNN is an integer 0 to 254.", WARNING);                                           
5355
            return ISLIB_ERROR;
5356
 
5357
        endif;
5358
 
5359
        // we have a numeric section lets check to see if
5360
        // it exists within the allowed range
5361
        //
5362
        if ( nzItem < 0 || nzItem > 254 )
5363
        then
5364
 
5365
            islib_MessageBox ("IP address supplied [" +szIPAdress+ 
5366
                        "] has a section ["+szItem+"] that is outside the allowable \nbounds of 0 to 254.\n" +
5367
                        "\nNote:\trequired IP address format: [NNN.NNN.NNN.NNN]\n" +
5368
                        "\twhere NNN is an integer 0 to 254.", WARNING);                                           
5369
            return ISLIB_ERROR;        
5370
 
5371
        endif;
5372
 
5373
 
5374
        // Get the next number from the list.
5375
        nResult = ListGetNextString (lzIPAddressComponents, szItem);
5376
    endwhile;
5377
 
5378
 
5379
    // if we get to here things are ok.
5380
 
5381
 
5382
    // Remove the list from memory.
5383
    ListDestroy (lzIPAddressComponents);
5384
 
5385
 
5386
    // we are done.                         
5387
    return ISLIB_SUCCESS;
5388
 
5389
end;
5390
 
5391
 
5392
///////////////////////////////////////////////////////////////////////////////
5393
//
5394
// Function: islib_WriteLineToEndOfFile
5395
//
5396
// Purpose: This function is used to write a line to the end of a file
5397
//          and trap the error if the action does not succeed.
5398
//
5399
//  Return Values:
5400
//  ISLIB_ERROR   : write fails
5401
//  ISLIB_SUCCESS : write succeeds.
5402
//   
5403
//
5404
///////////////////////////////////////////////////////////////////////////////                  
5405
function islib_WriteLineToEndOfFile(szDir, szFile, szLine)
5406
 
5407
    NUMBER nzFileHandle;
5408
 
5409
begin  
5410
 
5411
    // Set the file mode to read-write
5412
    //
5413
    OpenFileMode (FILE_MODE_APPEND);
5414
 
5415
 
5416
    // lets check to see if the file
5417
    // already exists.
5418
    //        
5419
    if ( Is (EXISTS,szDir + szFile) = TRUE )
5420
    then                         
5421
 
5422
        // Open the text file.
5423
        if (OpenFile (nzFileHandle, szDir, szFile) < 0) 
5424
        then
5425
 
5426
            // Report the error.
5427
            islib_MessageBox ("System error, failed to open " + szDir + szFile + " file.", SEVERE);
5428
            return ISLIB_ERROR;
5429
 
5430
       endif;                         
5431
 
5432
    else          
5433
 
5434
       // Create a new file and leave it open.
5435
       if (CreateFile (nzFileHandle, szDir, szFile) < 0) 
5436
       then
5437
 
5438
           // Report the error.
5439
           islib_MessageBox ("System error, failed to create " + szDir + szFile + " file.", SEVERE);
5440
           return ISLIB_ERROR;
5441
 
5442
       endif;       
5443
 
5444
    endif;                 
5445
 
5446
    // lets update the file
5447
    //      
5448
    if (WriteLine(nzFileHandle, szLine) < 0) 
5449
    then      
5450
 
5451
        // Report the error.
5452
        islib_MessageBox ("System error, failed to write line to " + szFile + "] file.", SEVERE);
5453
        return ISLIB_ERROR;
5454
 
5455
    endif; 
5456
 
5457
 
5458
    // Close the file.
5459
    CloseFile (nzFileHandle);      
5460
 
5461
 
5462
    // we are done.
5463
    return  ISLIB_SUCCESS;   
5464
 
5465
end;       
5466
 
5467
 
5468
/////////////////////////////////////////////////////////////////////////////
5469
//
5470
//  FUNCTION: islib_pkgPreInstall 
5471
//
5472
//  Determine if we can install the pkg by:
5473
//
5474
//  1. checking to see if the PKG_VERSION definition == @PRODUCT_VERSION string.
5475
//
5476
//  Return Values:
5477
//    ISLIB_SUCCESS - completed
5478
//    ISLIB_ERROR   - error during processing.
5479
//                                                                             
5480
//////////////////////////////////////////////////////////////////////////////
5481
function islib_pkgPreInstall()
5482
 
5483
begin
5484
 
5485
    // now we just check to see if the project version numbers entered match
5486
    // if they do not we need to exit.
5487
    // we canot however check the build number and project acronym easily.
5488
    //                    
5489
    if ( PKG_VERSION != @PRODUCT_VERSION )
5490
    then
5491
 
5492
         islib_MessageBox("The build.pl PKG_VERSION=[" +PKG_VERSION+ "] property does not match the Ishield PRODUCT_VERSION=["+@PRODUCT_VERSION+"] property.\n" +
5493
                          "Please review the IShield Product Properties with the local build.pl details before proceeding.", SEVERE);            
5494
         return ISLIB_ERROR;
5495
 
5496
    endif; 
5497
 
5498
    // done.
5499
    return ISLIB_SUCCESS;
5500
 
5501
end;   
5502
 
5503
 
5504
/////////////////////////////////////////////////////////////////////////////
5505
//
5506
//  FUNCTION: islib_verifyProcmgrInstall 
5507
//
5508
//  Determine if we have successfully updated the Registry when registering
5509
//  the pmsi service.
5510
//
5511
//  1. The service information exists in the CurrentControl set, under the
5512
//     registry key:
5513
//
5514
//     HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services
5515
//
5516
//     The Procmgr service is called "ERG Process Manager" if this key exists
5517
//     we would be reasonably confident that the installation has
5518
//     succeeded.
5519
//
5520
//     Therefore we are looking for:
5521
//
5522
//     HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\ERG Process Manager\\Parameters    
5523
//
5524
//
5525
//  Return Values:
5526
//    ISLIB_SUCCESS - completed
5527
//    ISLIB_ERROR   - error during processing.
5528
//                                                                             
5529
//////////////////////////////////////////////////////////////////////////////
5530
function islib_verifyProcmgrInstall()
5531
 
5532
    NUMBER nzType, nzSize; 
5533
    STRING szRegKey;
5534
 
5535
begin
5536
 
5537
 
5538
    RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);
5539
    szRegKey = "\\SYSTEM\\CurrentControlSet\\Services\\ERG Process Manager\\Parameters";
5540
 
5541
    if (RegDBKeyExist (szRegKey) < 0) 
5542
    then                            
5543
 
5544
        // we did not find the key		
5545
        islib_MessageBox("ERROR: Failed to verify ERG Process Manager Service Installation.\n" +
5546
                         "The service did not install successfully!", SEVERE);
5547
        return ISLIB_ERROR;		
5548
 
5549
    endif;
5550
 
5551
 
5552
    // we are done and all went well
5553
    //
5554
    return ISLIB_SUCCESS;
5555
 
5556
end;
5557
 
5558
 
5559
 
5560
 
5561
//////////////////////////////////////////////////////////////////////////////
5562
//                                                                   
5563
// FUNCTION:  islib_validateHexString(STRING)								  
5564
//	                                                                 
5565
// DESCRIPTION:                                           			 
5566
//				This function validates a Hexadecimal string. If the string isnt hex,
5567
//				it returns an appropriate code.      
5568
//				This function also performs lowercase conversion.
5569
//            
5570
//  Return Values:
5571
//    ISLIB_SUCCESS - It's a Hex string
5572
//    ISLIB_ERROR   - error during processing or it's not hex.
5573
//                                                                             
5574
//                                                                   
5575
//////////////////////////////////////////////////////////////////////////////
5576
 
5577
function islib_validateHexString (szString)
5578
 
5579
NUMBER	nSequence, nLength;
5580
STRING	szElement;
5581
 
5582
begin
5583
    nSequence = 0;
5584
 
5585
    // Convert it to lowercase
5586
    if (StrToLower ( szElement, szString ) < 0)
5587
    then
5588
       	islib_MessageBox ("ERROR: Conversion of szString to lowercase failed.", WARNING);
5589
    endif;
5590
 
5591
    szString = szElement;
5592
 
5593
    // Get the string's length in characters...
5594
    //
5595
    nLength = StrLengthChars (szString) - 1;
5596
 
5597
    // Check it character by character...
5598
    //	
5599
    for nSequence = 0 to nLength 
5600
 
5601
    	StrSub ( szElement, szString, nSequence, 1 );
5602
 
5603
    	switch (szElement)
5604
    		case "0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","x":
5605
            	    // This is okay  
5606
 		default:  
5607
            	   // This is not.
5608
	           return ISLIB_ERROR;
5609
    	endswitch;	
5610
   endfor;
5611
 
5612
	return ISLIB_SUCCESS;
5613
end;
5614
 
5615
 
5616
 
5617
 
5618
//////////////////////////////////////////////////////////////////////////////
5619
//                                                                   
5620
// FUNCTION:  islib_convertHexStringToIntString(STRING)								  
5621
//	                                                                 
5622
// DESCRIPTION:                                           			 
5623
//				This function converts a Hexadecimal string into an Integer string.      
5624
//            
5625
//  Return Values:
5626
//    ISLIB_SUCCESS - completed
5627
//    ISLIB_ERROR   - error during processing.
5628
//                                                                             
5629
//                                                                   
5630
//////////////////////////////////////////////////////////////////////////////
5631
 
5632
 
5633
function islib_convertHexStringToIntString (szHexString)
5634
 
5635
NUMBER  nInteger;
5636
BOOL    bResult;
5637
 
5638
begin
5639
 
5640
  bResult = StrToIntExA ( szHexString, STIF_SUPPORT_HEX, &nInteger);
5641
 
5642
  // Verify conversion worked.
5643
  if ( bResult = FALSE ) 
5644
  then 
5645
  	return ISLIB_ERROR;
5646
  endif;
5647
 
5648
  // verify conversion from Int to Str worked.
5649
  if ( NumToStr ( szHexString, nInteger ) < 0 )
5650
  then
5651
  	return ISLIB_ERROR;
5652
  endif;
5653
 
5654
  return ISLIB_SUCCESS;
5655
 
5656
end; 	                      	                   
5657