remove empty dir
[ghc-hetmet.git] / InstallShield / Script Files / setup.rul
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IIIIIII SSSSSS
4 //    II    SS                          InstallShield (R)
5 //    II    SSSSSS      (c) 1996-1997, InstallShield Software Corporation
6 //    II        SS      (c) 1990-1996, InstallShield Corporation
7 //  IIIIIII SSSSSS                     All Rights Reserved.
8 //
9 //
10 //  This code is generated as a starting setup template.  You should
11 //  modify it to provide all necessary steps for your setup.
12 //
13 //
14 //    File Name:  Setup.rul
15 //
16 //  Description:  InstallShield script
17 //
18 //     Comments:  This template script performs a basic setup on a
19 //                Windows 95 or Windows NT 4.0 platform. With minor
20 //                modifications, this template can be adapted to create
21 //                new, customized setups.
22 //
23 ////////////////////////////////////////////////////////////////////////////////
24
25
26   // Include header file
27 #include "ifx.h"
28
29 ////////////////////// string defines ////////////////////////////
30
31 #define UNINST_LOGFILE_NAME      "Uninst.isu"
32
33 //////////////////// installation declarations ///////////////////
34
35   // ----- DLL prototypes -----
36
37
38      // your DLL prototypes
39
40
41   // ---- script prototypes -----
42
43      // generated
44      prototype ShowDialogs();
45      prototype MoveFileData();
46      prototype HandleMoveDataError( NUMBER );
47      prototype ProcessBeforeDataMove();
48      prototype ProcessAfterDataMove();
49      prototype SetupRegistry();
50      prototype SetupFolders();
51      prototype CleanUpInstall();
52      prototype SetupInstall();
53      prototype SetupScreen();
54      prototype CheckListScreen();
55      prototype CheckRequirements();
56      prototype DialogShowSdWelcome();
57      prototype DialogShowSdShowInfoList();
58      prototype DialogShowSdAskDestPath();
59      prototype DialogShowSdSetupType();
60      prototype DialogShowSdComponentDialog2();
61      prototype DialogShowSdSelectFolder();
62      prototype DialogShowSdFinishReboot();
63
64      // your prototypes
65      prototype MyParsePath ( STRING );
66      prototype ForwardSlashify ( STRING, BYREF STRING );
67      prototype CreateExecPerlScript ( STRING, STRING );
68      prototype DropSuffix ( STRING, BYREF STRING );
69      prototype BaseName   ( STRING, BYREF STRING );
70
71   // ----- global variables ------
72
73      // generated
74      BOOL        bWinNT, bIsShellExplorer, bInstallAborted, bIs32BitSetup;
75      STRING      svDir;
76      STRING      svName, svCompany, svSerial;
77      STRING      szAppPath;
78      STRING      svSetupType;
79      LIST        listPath;
80
81
82      // your global variables
83      //STRING      szRawCpp
84      STRING      szPerlPath;
85      STRING      szBinDir, szBinDirUnslashed,
86                  szLibDir, szLibDirUnslashed,
87                  szDataDir, szLibExecDir;
88
89
90 ///////////////////////////////////////////////////////////////////////////////
91 //
92 //   MAIN PROGRAM
93 //
94 //      The setup begins here by hiding the visible setup
95 //      window.  This is done to allow all the titles, images, etc. to
96 //      be established before showing the main window.  The following
97 //      logic then performs the setup in a series of steps.
98 //
99 ///////////////////////////////////////////////////////////////////////////////
100 program
101     Disable( BACKGROUND );
102
103     CheckRequirements();
104
105     SetupInstall();
106
107     SetupScreen();
108
109     if (ShowDialogs()<0) goto end_install;
110
111     if (ProcessBeforeDataMove()<0) goto end_install;
112
113     if (MoveFileData()<0) goto end_install;
114
115     if (ProcessAfterDataMove()<0) goto end_install;
116
117     if (SetupRegistry()<0) goto end_install;
118
119     if (SetupFolders()<0) goto end_install;
120
121     CheckListScreen();
122     
123   end_install:
124
125     CleanUpInstall();
126
127      // If an unrecoverable error occurred, clean up the partial installation.
128      // Otherwise, exit normally.
129
130     if (bInstallAborted) then
131         abort;
132     endif;
133
134 endprogram
135
136 ///////////////////////////////////////////////////////////////////////////////
137 //                                                                           //
138 // Function:  ShowDialogs                                                    //
139 //                                                                           //
140 //  Purpose:  This function manages the display and navigation               //
141 //            the standard dialogs that exist in a setup.                    //
142 //                                                                           //
143 ///////////////////////////////////////////////////////////////////////////////
144 function ShowDialogs()
145     NUMBER  nResult;
146  begin
147
148     Dlg_Start:
149         // beginning of dialogs label
150
151     Dlg_SdWelcome:
152         nResult = DialogShowSdWelcome();
153         if (nResult = BACK) goto Dlg_Start;
154
155     Dlg_SdShowInfoList:
156         nResult = DialogShowSdShowInfoList();
157         if (nResult = BACK) goto Dlg_SdWelcome;
158
159     Dlg_SdAskDestPath:
160         nResult = DialogShowSdAskDestPath();
161         if (nResult = BACK) goto Dlg_SdShowInfoList;
162
163     Dlg_SdSetupType:
164         nResult = DialogShowSdSetupType();
165         if (nResult = BACK) goto Dlg_SdAskDestPath;
166
167     Dlg_SdComponentDialog2:
168         if ((nResult = BACK) && (svSetupType != "Custom") && (svSetupType != "")) then
169            goto Dlg_SdSetupType;
170         endif;
171         nResult = DialogShowSdComponentDialog2();
172         if (nResult = BACK) goto Dlg_SdSetupType;
173
174     Dlg_SdSelectFolder:
175         //nResult = DialogShowSdSelectFolder();
176         //if (nResult = BACK) goto Dlg_SdComponentDialog2;
177
178     return 0;
179
180  end;
181
182 ///////////////////////////////////////////////////////////////////////////////
183 //                                                                           //
184 // Function: ProcessBeforeDataMove                                           //
185 //                                                                           //
186 //  Purpose: This function performs any necessary operations prior to the    //
187 //           actual data move operation.                                     //
188 //                                                                           //
189 ///////////////////////////////////////////////////////////////////////////////
190 function ProcessBeforeDataMove()
191     STRING svLogFile;
192     NUMBER nResult;
193  begin
194
195   InstallationInfo( @COMPANY_NAME, @PRODUCT_NAME, @PRODUCT_VERSION, @PRODUCT_KEY );
196
197   svLogFile = UNINST_LOGFILE_NAME;
198
199   nResult = DeinstallStart( svDir, svLogFile, @UNINST_KEY, 0 );
200   if (nResult < 0) then
201       MessageBox( @ERROR_UNINSTSETUP, WARNING );
202   endif;
203
204   szAppPath = TARGETDIR; // TODO : if your application .exe is in a subdir of TARGETDIR then add subdir
205
206   if ((bIs32BitSetup) && (bIsShellExplorer)) then
207       RegDBSetItem( REGDB_APPPATH, szAppPath );
208       RegDBSetItem( REGDB_APPPATH_DEFAULT, szAppPath ^ @PRODUCT_KEY );
209       RegDBSetItem( REGDB_UNINSTALL_NAME, @UNINST_DISPLAY_NAME );
210   endif;
211   // TODO : update any items you want to process before moving the data
212   //
213
214   ComponentSetTarget( MEDIA, "<DOCDIR>", TARGETDIR ^ "\\doc" );
215
216   return 0;
217  end;
218
219 ///////////////////////////////////////////////////////////////////////////////
220 //                                                                           //
221 // Function:  MoveFileData                                                   //
222 //                                                                           //
223 //  Purpose:  This function handles the data movement for                    //
224 //            the setup.                                                     //
225 //                                                                           //
226 ///////////////////////////////////////////////////////////////////////////////
227 function MoveFileData()
228     NUMBER nResult, nDisk;
229  begin
230
231   nDisk = 1;
232   SetStatusWindow( 0, "" );
233   Disable( DIALOGCACHE );
234   Enable( STATUS );
235   StatusUpdate( ON, 100 );
236   nResult = ComponentMoveData( MEDIA, nDisk, 0 );
237
238   HandleMoveDataError( nResult );
239
240   Disable( STATUS );
241
242   return nResult;
243
244  end;
245
246
247 ///////////////////////////////////////////////////////////////////////////////
248 //                                                                           //
249 // Function: HandleMoveDataError                                             //
250 //                                                                           //
251 //  Purpose: This function handles the error (if any) during the move data   //
252 //           operation.                                                      //
253 //                                                                           //
254 ///////////////////////////////////////////////////////////////////////////////
255 function HandleMoveDataError( nResult )
256     STRING szErrMsg, svComponent , svFileGroup , svFile;
257  begin
258
259   svComponent = "";
260   svFileGroup = "";
261   svFile = "";
262
263   switch (nResult)
264   case 0:
265        return 0;
266   default:
267        ComponentError ( MEDIA , svComponent , svFileGroup , svFile , nResult );
268        szErrMsg = @ERROR_MOVEDATA  + "\n\n" +
269                   @ERROR_COMPONENT + " " + svComponent + "\n" +
270                   @ERROR_FILEGROUP + " " + svFileGroup + "\n" +
271                   @ERROR_FILE      + " " + svFile;
272        SprintfBox( SEVERE, @TITLE_CAPTIONBAR, szErrMsg, nResult );
273        bInstallAborted = TRUE;
274        return nResult;
275   endswitch;
276
277  end;
278
279
280 ///////////////////////////////////////////////////////////////////////////////
281 //                                                                           //
282 // Function: ProcessAfterDataMove                                            //
283 //                                                                           //
284 //  Purpose: This function performs any necessary operations needed after    //
285 //           all data has been moved.                                        //
286 //                                                                           //
287 ///////////////////////////////////////////////////////////////////////////////
288 function ProcessAfterDataMove()
289   STRING szPath, szGcc, szGccDir;
290   STRING szTemp, szRes, szPathEntry, szDrive;
291   NUMBER nvSize,nvType, nResult, nPos, nSuccess;
292   LIST   listDirs;
293  begin
294
295   RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );
296   RegDBGetKeyValueEx ( "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" ,
297                        "path" , nvType, szPath , nvSize );
298
299   // Spin through path looking for perl.exe.
300   // Our task is made considerably harder since the
301   // the free version of InstallShield doesn't support
302   // functions such as StrGetTokens() or ParsePath().
303   // TODO: Convert this back to IS Prof Edn
304
305   MyParsePath ( szPath );
306   nResult = ListGetFirstString ( listPath, szPathEntry);
307   szPathEntry = ""; szPerlPath="";
308   while ( nResult != END_OF_LIST )
309      if ( FindFile (szPathEntry, "perl.exe", szRes ) = 0 ) then
310        szPerlPath = szPathEntry + "/" + szRes;
311        nResult = END_OF_LIST;
312      else
313        nResult = ListGetNextString ( listPath, szPathEntry );
314      endif;
315   endwhile;
316   if ( StrCompare ( szPerlPath, "" ) = 0 ) then
317     // If not found in global env. block, look in the
318     // user-specific part.
319     RegDBSetDefaultRoot ( HKEY_CURRENT_USER );
320     RegDBGetKeyValueEx ( "Environment", "path", nvType, szPath, nvSize);
321     MyParsePath ( szPath );
322     nResult = ListGetFirstString ( listPath, szPathEntry);
323     szPathEntry = ""; szPerlPath="";
324     while ( nResult != END_OF_LIST )
325       if ( FindFile (szPathEntry, "perl.exe", szRes ) = 0 ) then
326         szPerlPath = szPathEntry + "/" + szRes;
327         nResult = END_OF_LIST;
328       else
329         nResult = ListGetNextString ( listPath, szPathEntry );
330       endif;
331     endwhile;
332   endif;
333
334   if ( StrCompare ( szPerlPath, "" ) = 0 ) then
335      // Default it to /bin/perl
336      MessageBox ("Unable to find perl in your PATH. Not to worry, this installer includes a version that should be useable." +
337                  "When the installer has finished, please copy it from the bin/ directory of the ghc installation to /bin/perl",
338                  INFORMATION);
339      szPerlPath = "/bin/perl.exe";
340   else
341      // strip initial drive spec.
342      GetDir ( szPerlPath, szTemp);
343      ForwardSlashify ( szTemp, szPerlPath );
344   endif;
345   DropSuffix (szPerlPath, szTemp);
346   szPerlPath = szTemp;
347
348   ListDestroy (listPath);
349
350   return 0;
351  end;
352
353 ///////////////////////////////////////////////////////////////////////////////
354 //                                                                           //
355 // Function: SetupRegistry                                                   //
356 //                                                                           //
357 //  Purpose: This function makes the registry entries for this setup.        //
358 //                                                                           //
359 ///////////////////////////////////////////////////////////////////////////////
360 function SetupRegistry()
361  NUMBER nResult,nWays,i;
362  STRING szProjectDir, szProjectVersionDir, szTargetDir;
363  STRING szSyslib, szWay, szSyslibsDir;
364  STRING szLib, szSyslibsKey;
365  //LIST   syslib_list, way_list;
366  begin
367
368   // TODO : Add all your registry entry keys here
369   //
370   //
371
372   nResult = CreateRegistrySet( "" );
373
374   // By now, we will have had the following Registry
375   // entries generated (see ProcessBeforeDataMove() ):
376   //
377   // HK_L_M\Software\Glasgow University\GHC\<version no.>
378   //
379   // For GHC, we store and use the install info inside
380   //  HK_L_M\Software\Haskell\GHC (== %ROOT%)
381
382   // So, we perform the following tasks here:
383   //
384   //  * Checks to see if %ROOT% is defined.
385   //    If not, creates it.
386   //  * Checks for %ROOT%\Version is defined.
387   //  * Create %ROOT%\<version>.
388   //  * Create %ROOT%\<version>\libdir
389   //    (This key will be given a value later.)
390   //  * Create %ROOT%\syslib\  and fill it in
391   //    with the syslibs that has been installed.
392   //  * %ROOT%\syslib\name\<way>
393   //    is added for each kind (e.g., seq, conc)
394   //    syslib we're installing.
395
396   // When we eventually reach the end, the registry
397   // should be ready for use by the installed app.
398
399   // Check to see if we've already installed
400   // a version of GHC on this box..
401   RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );
402
403   szProjectDir = @HASKELL_REG_ROOT ^ @PRODUCT_NAME;
404
405   // check whether we've already got the Registry sub-tree we're
406   // about to add to. If not, then we create it
407   // level-by-level, so as to ensure that the uninstaller
408   // can clean up after us.
409   if ( RegDBKeyExist ( @HASKELL_REG_ROOT ) < 0) then
410      RegDBCreateKeyEx (@HASKELL_REG_ROOT, "");
411   endif;
412   if ( RegDBKeyExist  ( szProjectDir ) < 0 ) then
413      RegDBCreateKeyEx ( szProjectDir, "");
414   endif;
415
416   // Note: we overwrite any existing value.
417   RegDBSetKeyValueEx( szProjectDir, "Version", REGDB_STRING,
418                        @PRODUCT_KEY, -1);
419
420   szProjectVersionDir = szProjectDir ^ @PRODUCT_KEY;
421
422   if ( RegDBKeyExist ( szProjectVersionDir ) < 0) then
423      RegDBCreateKeyEx ( szProjectVersionDir, "");
424   endif;
425
426   // Here starts the GHC specific part
427
428   ForwardSlashify (TARGETDIR, szTargetDir);
429   // fill in the all-important path to where the archives
430   // and interface files have been parked.
431   szLibDir = szTargetDir + "/lib";
432   szLibDirUnslashed = TARGETDIR ^ "\\lib";
433   RegDBSetKeyValueEx ( szProjectVersionDir, "libdir", REGDB_STRING,
434                        szLibDir , -1);
435   // libexecdir
436   szLibExecDir = szTargetDir + "/lib";
437   RegDBSetKeyValueEx ( szProjectVersionDir, "libexecdir", REGDB_STRING,
438                        szLibExecDir , -1);
439   // bindir
440   szBinDir = szTargetDir + "/bin";
441   szBinDirUnslashed = TARGETDIR ^ "\\bin";
442   RegDBSetKeyValueEx ( szProjectVersionDir, "bindir", REGDB_STRING,
443                        szBinDir , -1);
444   
445   return 0;
446  end;
447
448
449 ///////////////////////////////////////////////////////////////////////////////
450 //
451 // Function: SetupFolders
452 //
453 //  Purpose: This function creates all the folders and shortcuts for the
454 //           setup.  This includes program groups and items for Windows 3.1.
455 //
456 ///////////////////////////////////////////////////////////////////////////////
457 function SetupFolders()
458  NUMBER nResult;
459  begin
460
461
462   // TODO : Add all your folder (program group) along with shortcuts (program items)
463   //
464   //
465   //    CreateProgramFolder, AddFolderIcon....
466   //
467
468   CreateExecPerlScript ( szBinDirUnslashed, "ghc-" + @PRODUCT_VERSION );
469   CreateExecPerlScript ( szBinDirUnslashed, "stat2resid" );
470   CreateExecPerlScript ( szLibDirUnslashed, "hscpp" );
471   CreateExecPerlScript ( szLibDirUnslashed, "mkdependHS" );
472
473   VarSave (SRCTARGETDIR);
474   SRCDIR = szBinDirUnslashed;
475   TARGETDIR = szBinDirUnslashed;
476   CopyFile( "ghc-" + @PRODUCT_VERSION, "ghc");
477   VarRestore (SRCTARGETDIR);
478
479   nResult = CreateShellObjects( "" );
480
481   return nResult;
482  end;
483
484 ///////////////////////////////////////////////////////////////////////////////
485 //                                                                           //
486 // Function: CleanUpInstall                                                  //
487 //                                                                           //
488 //  Purpose: This cleans up the setup.  Anything that should                 //
489 //           be released or deleted at the end of the setup should           //
490 //           be done here.                                                   //
491 //                                                                           //
492 ///////////////////////////////////////////////////////////////////////////////
493 function CleanUpInstall()
494  begin
495
496
497   if (bInstallAborted) then
498       return 0;
499   endif;
500
501   DialogShowSdFinishReboot();
502
503   if (BATCH_INSTALL) then // ensure locked files are properly written
504       CommitSharedFiles(0);
505   endif;
506
507   return 0;
508  end;
509
510 ///////////////////////////////////////////////////////////////////////////////
511 //                                                                           //
512 // Function: SetupInstall                                                    //
513 //                                                                           //
514 //  Purpose: This will setup the installation.  Any general initialization   //
515 //           needed for the installation should be performed here.           //
516 //                                                                           //
517 ///////////////////////////////////////////////////////////////////////////////
518 function SetupInstall()
519
520  begin
521
522   Enable( CORECOMPONENTHANDLING );
523
524   bInstallAborted = FALSE;
525
526   GetDisk(WINDIR, svDir);
527
528   if (bIs32BitSetup) then
529       svDir = svDir + "\\" ^ @PRODUCT_NAME_SHORT ^ @PRODUCT_KEY;
530   else
531       // We're (=>ghc) 32 through and through, but for the sake of
532       // completenes.
533       svDir = svDir + "\\" ^ @PRODUCT_NAME_SHORT ^ @PRODUCT_NAME16;
534   endif;
535
536   TARGETDIR  = svDir;
537
538   SdProductName( @PRODUCT_NAME );
539
540   Enable( DIALOGCACHE );
541
542   return 0;
543  end;
544
545 ///////////////////////////////////////////////////////////////////////////////
546 //                                                                           //
547 // Function:  SetupScreen                                                    //
548 //                                                                           //
549 //  Purpose:  This function establishes  the screen look.  This includes     //
550 //            colors, fonts, and text to be displayed.                       //
551 //                                                                           //
552 ///////////////////////////////////////////////////////////////////////////////
553 function SetupScreen()
554  begin
555
556   SetColor ( BACKGROUND, BLUE );
557   Enable( FULLWINDOWMODE );
558   Enable( INDVFILESTATUS );
559
560   SetTitle( @TITLE_MAIN, 24, WHITE );
561
562   SetTitle( @TITLE_CAPTIONBAR, 0, BACKGROUNDCAPTION ); // Caption bar text.
563
564   Enable( BACKGROUND );
565
566   Delay( 1 );
567  end;
568
569 ///////////////////////////////////////////////////////////////////////////////
570 //                                                                           //
571 // Function:  CheckRequirements                                              //
572 //                                                                           //
573 //  Purpose:  This function checks all minimum requirements for the          //
574 //            application being installed.  If any fail, then the user       //
575 //            is informed and the setup is terminated.                       //
576 //                                                                           //
577 ///////////////////////////////////////////////////////////////////////////////
578 function CheckRequirements()
579     NUMBER  nvDx, nvDy, nvResult;
580     STRING  svResult;
581
582  begin
583
584   bWinNT           = FALSE;
585   bIsShellExplorer = FALSE;
586
587   // Check screen resolution.
588   GetExtents( nvDx, nvDy );
589
590   if (nvDy < 480) then
591       MessageBox( @ERROR_VGARESOLUTION, WARNING );
592       abort;
593   endif;
594
595   // set 'setup' operation mode
596   bIs32BitSetup = TRUE;
597   GetSystemInfo( ISTYPE, nvResult, svResult );
598   if (nvResult = 16) then
599       bIs32BitSetup = FALSE; // running 16-bit setup
600       return 0; // no additional information required
601   endif;
602
603   // --- 32-bit testing after this point ---
604
605   // Determine the target system's operating system.
606   GetSystemInfo( OS, nvResult, svResult );
607
608   if (nvResult =  IS_WINDOWSNT) then
609       // Running Windows NT.
610       bWinNT = TRUE;
611
612       // Check to see if the shell being used is EXPLORER shell.
613       if (GetSystemInfo( OSMAJOR, nvResult, svResult ) = 0) then
614           if (nvResult >= 4) then
615               bIsShellExplorer = TRUE;
616           endif;
617       endif;
618
619   elseif (nvResult = IS_WINDOWS95 ) then
620       bIsShellExplorer = TRUE;
621
622   endif;
623
624 end;
625
626
627 ///////////////////////////////////////////////////////////////////////////////
628 //                                                                           //
629 // Function: DialogShowSdWelcome                                             //
630 //                                                                           //
631 //  Purpose: This function handles the standard welcome dialog.              //
632 //                                                                           //
633 //                                                                           //
634 ///////////////////////////////////////////////////////////////////////////////
635 function DialogShowSdWelcome()
636     NUMBER nResult;
637     STRING szTitle, szMsg;
638  begin
639
640   szTitle = "";
641   szMsg   = "";
642   nResult = SdWelcome( szTitle, szMsg );
643
644   return nResult;
645  end;
646                          
647 ///////////////////////////////////////////////////////////////////////////////
648 //                                                                           //
649 // Function: DialogShowSdShowInfoList                                        //
650 //                                                                           //
651 //  Purpose: This function displays the general information list dialog.     //
652 //                                                                           //
653 //                                                                           //
654 ///////////////////////////////////////////////////////////////////////////////
655 function DialogShowSdShowInfoList()
656     NUMBER nResult;
657     LIST   list;
658     STRING szTitle, szMsg, szFile;
659  begin
660
661   szFile = SUPPORTDIR ^ "announce";
662
663   list = ListCreate( STRINGLIST );
664   ListReadFromFile( list, szFile );
665   szTitle  = "";
666   szMsg    = " ";
667   nResult  = SdShowInfoList( szTitle, szMsg, list );
668
669   ListDestroy( list );
670
671   return nResult;
672  end;
673
674
675 ///////////////////////////////////////////////////////////////////////////////
676 //                                                                           //
677 // Function: DialogShowSdAskDestPath                                         //
678 //                                                                           //
679 //  Purpose: This function asks the user for the destination directory.      //
680 //                                                                           //
681 ///////////////////////////////////////////////////////////////////////////////
682 function DialogShowSdAskDestPath()
683     NUMBER nResult;
684     STRING szTitle, szMsg;
685  begin
686
687   szTitle = "";
688   szMsg   = "WARNING! The path must not contain spaces.";
689   nResult = SdAskDestPath( szTitle, szMsg, svDir, 0 );
690
691   TARGETDIR = svDir;
692
693   return nResult;
694  end;
695
696
697 ///////////////////////////////////////////////////////////////////////////////
698 //                                                                           //
699 // Function: DialogShowSdSetupType                                           //
700 //                                                                           //
701 //  Purpose: This function displays the standard setup type dialog.          //
702 //                                                                           //
703 ///////////////////////////////////////////////////////////////////////////////
704 function DialogShowSdSetupType()
705     NUMBER nResult, nType;
706     STRING szTitle, szMsg;
707  begin
708
709   switch (svSetupType)
710   case "Typical":
711        nType = TYPICAL;
712   case "Custom":
713        nType = CUSTOM;
714   case "Compact":
715        nType = COMPACT;
716   case "":
717        svSetupType = "Typical";
718        nType = TYPICAL;
719   endswitch;
720
721   szTitle = "";
722   szMsg   = "";
723   nResult = SetupType( szTitle, szMsg, "", nType, 0 );
724
725   switch (nResult)
726   case COMPACT:
727        svSetupType = "Compact";
728   case TYPICAL:
729        svSetupType = "Typical";
730   case CUSTOM:
731        svSetupType = "Custom";
732   endswitch;
733
734   return nResult;
735  end;
736
737
738 ///////////////////////////////////////////////////////////////////////////////
739 //                                                                           //
740 // Function: DialogShowSdComponentDialog2                                    //
741 //                                                                           //
742 //  Purpose: This function displays the custom component dialog.             //
743 //                                                                           //
744 //                                                                           //
745 ///////////////////////////////////////////////////////////////////////////////
746 function DialogShowSdComponentDialog2()
747     NUMBER nResult;
748     STRING szTitle, szMsg;
749  begin
750
751   if ((svSetupType != "Custom") && (svSetupType != "")) then
752       return 0;
753   endif;
754
755   szTitle  = "";
756   szMsg    = "";
757   nResult  = SdComponentDialog2( szTitle, szMsg, svDir, "" );
758
759   return nResult;
760  end;
761
762 ///////////////////////////////////////////////////////////////////////////////
763 //                                                                           //
764 // Function: CheckListScreen                                                 //
765 //                                                                           //
766 //  Purpose: Show a check-list of post-install user actions.                 //
767 //                                                                           //
768 ///////////////////////////////////////////////////////////////////////////////
769 function CheckListScreen()   
770         BOOL bDone;
771         NUMBER nCmdValue;
772  begin   
773         EzDefineDialog("CHECKLIST", "", "", 30001);
774
775     bDone = FALSE;   
776     while (bDone=FALSE)   
777        nCmdValue = WaitOnDialog("CHECKLIST");   
778           switch (nCmdValue)      
779               case DLG_INIT:               
780               // Process the Next button.         
781               case SD_PBUT_CONTINUE:         
782                   bDone = TRUE;           
783               // Process the Cancel button.         
784               case SD_PBUT_EXITSETUP:
785                   bDone = TRUE;            
786               // Process the close dialog box button.
787               case DLG_CLOSE:         
788                   bDone = TRUE;         
789               // Process dialog box errors.            
790               case DLG_ERR:
791                   MessageBox("Internal dialog box error", SEVERE);         
792                   bDone = TRUE;         
793           endswitch;            
794     endwhile;           
795     // Identify the end of dialog box processing.  
796     EndDialog("CHECKLIST");   
797     // Free the dialog box and list from memory.
798     ReleaseDialog("CHECKLIST");   
799  end;                    
800
801 ///////////////////////////////////////////////////////////////////////////////
802 //                                                                           //
803 // Function: DialogShowSdFinishReboot                                        //
804 //                                                                           //
805 //  Purpose: This function will show the last dialog of the product.         //
806 //           It will allow the user to reboot and/or show some readme text.  //
807 //                                                                           //
808 ///////////////////////////////////////////////////////////////////////////////
809 function DialogShowSdFinishReboot()
810     NUMBER nResult, nDefOptions;
811     STRING szTitle, szMsg1, szMsg2, szOption1, szOption2;
812     NUMBER bOpt1, bOpt2;
813  begin
814
815   if (!BATCH_INSTALL) then
816       bOpt1 = FALSE;
817       bOpt2 = FALSE;
818       szMsg1 = "";
819       szMsg2 = "";
820       szOption1 = "";
821       szOption2 = "";
822       szTitle = "Installation is now complete.";
823       nResult = SdFinish( szTitle, szMsg1, szMsg2, szOption1, szOption2, bOpt1, bOpt2 );
824       return 0;
825   else
826       nDefOptions = SYS_BOOTMACHINE;
827       szTitle     = "";
828       szMsg1      = "";
829       szMsg2      = "";
830       nResult     = SdFinishReboot( szTitle, szMsg1, nDefOptions, szMsg2, 0 );
831       return nResult;
832   endif;
833  end;
834
835 function MyParsePath(szPath)
836   STRING szTmp,szPth;
837   NUMBER nPos;
838  begin
839    szPth = szPath;
840    listPath = ListCreate( STRINGLIST );
841
842    // Man, all I want is map. Please? :-)
843    nPos = StrFind ( szPth, ";");
844    while ( nPos > 0 )
845     StrSub ( szTmp, szPth, 0, nPos);
846     ListAddString ( listPath, szTmp, AFTER );
847     StrSub ( szTmp, szPth, nPos + 1, StrLength ( szPth) - nPos );
848     szPth = szTmp;
849     nPos = StrFind ( szPth, ";" );
850    endwhile;
851
852   return 0;
853  end;
854
855  function ForwardSlashify ( szStr , theRes )
856    NUMBER nPos;
857    STRING szTemp, szRes;
858  begin
859   // Tortuous piece of code to convert backslashes into
860   // forward ones.
861   nPos = StrFind ( szStr, "\\");
862   szRes="";
863   while ( nPos >= 0 )
864     StrSub ( szTemp, szStr, 0, nPos);
865     szRes = szRes + szTemp + "/";
866     StrSub ( szTemp, szStr, nPos + 1, StrLength ( szStr) - nPos );
867     szStr = szTemp;
868     nPos = StrFind ( szStr, "\\" );
869   endwhile;
870   StrSub ( szTemp, szStr, 0, StrLength (szStr));
871   szRes = szRes + szTemp;
872   theRes = szRes;
873   return 0;
874  end;
875
876  function CreateExecPerlScript ( szPath, szFileName )
877     NUMBER nResult, writeHandle, readHandle;
878     STRING szLine;
879  begin
880    VarSave (SRCTARGETDIR);
881    SRCDIR = szPath;
882    TARGETDIR = szPath;
883    DeleteFile ( szFileName + ".bak");
884    RenameFile ( szFileName, szFileName + ".bak");
885    VarRestore (SRCTARGETDIR);
886
887    OpenFileMode (FILE_MODE_APPEND);
888    if ( CreateFile ( writeHandle, szPath, szFileName ) < 0 ) then
889       MessageBox ("CreateFile " + szPath ^ szFileName + " failed", INFORMATION);
890    endif;
891    // append
892    WriteLine (writeHandle, "#!" + szPerlPath );
893    WriteLine (writeHandle, "$libdir='" + szLibDir + "';");
894    WriteLine (writeHandle, "$bindir='" + szBinDir + "';");
895    WriteLine (writeHandle, "$libexecdir='" + szLibExecDir + "';");
896    WriteLine (writeHandle, "$datadir='" + szDataDir + "';");
897    WriteLine (writeHandle, "$SED='sed';");
898    WriteLine (writeHandle, "$TMPDIR='C:/TEMP';");
899    WriteLine (writeHandle, "$RAWCPP='gcc -E';");
900    // For the benefit of mkdependHS, which doesn't get this prepended
901    WriteLine (writeHandle, "$INSTALLING=1;");
902
903    OpenFileMode (FILE_MODE_NORMAL);
904    if ( OpenFile ( readHandle, szPath, szFileName + ".bak") < 0 ) then
905       MessageBox ("OpenFile " + szPath ^ szFileName + ".bak failed", INFORMATION);
906    endif;
907
908    // copy the template over.
909    nResult = GetLine ( readHandle, szLine);
910    while ( nResult >= 0 )
911      WriteLine ( writeHandle, szLine);
912      nResult = GetLine ( readHandle, szLine);
913    endwhile;
914    if ( CloseFile( readHandle ) < 0 ) then
915        MessageBox ( "CloseFile " + szPath ^ szFileName + ".bak failed",
916                     INFORMATION);
917    endif;
918    if ( CloseFile( writeHandle ) < 0 ) then
919        MessageBox ( "CloseFile " + szPath ^ szFileName + " failed",
920                     INFORMATION);
921    endif;
922    // There's no way to set the 'x' bit using
923    // SetFileInfo(), but luckily it is not needed to run #! scripts
924    // under cygwin.
925    SetFileInfo ( szPath ^ szFileName, FILE_ATTRIBUTE, FILE_ATTR_NORMAL, "");     
926    // Delete the .bak file
927    DeleteFile ( szPath ^ szFileName + ".bak");
928    
929    return 0;
930  end;
931
932  function DropSuffix ( szInp, szOut )
933    NUMBER nResult, nLen;
934    STRING szTemp, szTemp2;
935  begin
936     nLen = 0;
937     szTemp2 = szInp;
938     nResult = StrFind ( szTemp2 , ".");
939     while ( nResult >= 0 )
940        nLen = nLen + nResult;
941        StrSub ( szTemp, szTemp2, nResult + 1, StrLength ( szTemp2) - nResult );
942        szTemp2 = szTemp;
943        nResult = StrFind ( szTemp2, "." );
944        if ( nResult >= 0 ) then
945           nLen = nLen + 1;  // incl the previous . if there's more.
946        endif;
947     endwhile;
948     StrSub ( szOut, szInp, 0, nLen);
949     return 0;
950  end;