Subversion Repositories DevTools

Rev

Rev 1606 | Details | Compare with Previous | Last modification | View Log | RSS feed

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