//
//      PowerViewsInstallation script.
//      (c) 1992, Microtek International Inc. All rights reserved.
//
//      Begin program with variable declaration
//
// Define some predefined constants. Can be used for number only
//
#define MAX_SIZE         145

// ---->

#define BASE_FILE_SIZE   4200000
#define ALT_FILE_SIZE    0
#define TWO_DISKS        TRUE           // false for single disk, true for 2

declare // Must use declare keyword to start variable declaration

        string  szText[ MAX_SIZE ], szTemp[ MAX_SIZE ]; // Declare string vars
        string  szDefPath[ MAX_SIZE ], szResultPath[ MAX_SIZE ];
        string  szDisk[50];
        string  szErrMsg [ 255 ], szErrFile [ 100 ];
        string  szREADME [ 100 ], szPath[ 200 ];
        string  szCommand[ 200 ], szWinDir[ 50 ];
        string  szReadFile[ 30], szTbird[ 30], szSetup[30],szInstall[80];
        string  szPgrp[ 40 ];
        number  nSpace;
        number  nFile;

program /* Must use program keyword to start the statements */


Start:
       Disable( BACKGROUND );
       // Set the color of the background to be BLUE
       SetColor( BACKGROUND, RGB( 0,0,64 ) );
       SetColor( STATUSBAR, RED );
       SetFont( FONT_TITLE, STYLE_NORMAL, "Helv" );

       StrCopy( szInstall, "Installing MP/SLD");

       SetTitle( szInstall, 45, RGB(255,255,255) );
       SetStatusWindow( 1, szInstall );

       // In Info Window to display the file1.lis
       SetInfoWindow( "Information ", "file1.lis" );

// ---> Initialize the parameters
       StrCopy( szPgrp, "MICEpack/SLD" );
       StrCopy( szReadFile, "readme.txt" );
       StrCopy( szTbird, "mp186.exe mp186.ima"); 
       StrCopy( szSetup, "mpset.exe" );

       nSpace = BASE_FILE_SIZE + ALT_FILE_SIZE;

       // Enable various objects.
       Enable( BITMAPFADE );    // All bitmaps will fade into the screen.
       Enable( INDVFILESTATUS ); // Shows all filenames when copied.
       Disable( HELP );        //
       Enable( EXIT );         // Exit Button
//       Enable( PAUSE );        // Pause Button
       Enable( STATUS );       // Status , % Complete Bar Window
       Enable( TEXT );         // Info Windows
       Enable( FEEDBACK_FULL); // Feedback window enabled
       Enable( BACKGROUND );
       Delay( 2 );

       // Determine target location for files
       StrCopy( szWinDir, TARGETDIR );

       GetDisk( TARGETDIR, szDisk );
       StrCopy( szDefPath, szDisk );
// ----->
       StrConcat( szDefPath, "\\mp186" ); // Note: the double slashes

TargetLoc:
       // Increment % Complete Bar to 1 %, & display message
       SetStatusWindow( 1, szInstall );

       // Want to ask user for a path to install PowerViews
       StrCopy( szText, "Please enter the desired location for MICEpack/SLD." );
       AskPath( szText, szDefPath, szResultPath );
       if LAST_RESULT = FALSE then call ConfirmCancel; endif;
       StrCompare( szResultPath, SRCDIR );
       if LAST_RESULT = 0 then
           MessageBox( "The target location must be different than the source.\nPlease specify a different location.",WARNING );
           goto TargetLoc;
       endif;

       GetDisk( szResultPath, szDisk );

       // If correct disk entered, then BeginInstall;
       ExistsDisk( szDisk );
       if LAST_RESULT != 0 then
          // Invalid disk entered, reprompt
          StrCopy( szText, szResultPath );
          StrConcat( szText, "- is an invalid disk, press Ok to return to the path selection");
          MessageBox( szText, WARNING );
          goto TargetLoc;
       endif;

BeginInstall:
       SetStatusWindow( 2 , szInstall );
       GetDisk( szResultPath, szDisk );

       // Check to see if enough space is free on the destination.
       // GetDiskSpace returns free space in LAST_RESULT.
       GetDiskSpace( szDisk );
       if LAST_RESULT < nSpace then
          StrCopy( szText, "Not enough space on ");
          StrConcat( szText, szDisk );
          StrConcat( szText, "-Please press OK to try another target disk");
          MessageBox( szText, WARNING );
          goto TargetLoc;
       endif;

EnoughSpace:
       SetStatusWindow( 3 , szInstall );

       // Check to see if Directory Exists
       // ExistsDir returns value in LAST_RESULT
       ExistsDir( szResultPath );
       if LAST_RESULT = 0 goto AlreadyExistDir;
       CreateDir( szResultPath );
       if LAST_RESULT = 0 goto CheckSubDir;
       StrCopy( szText, "Unable to create specified path -");
       StrConcat( szText, szResultPath );
       StrConcat( szText, "\nPlease enter a correct path like C:\\DIRECTRY");
       MessageBox( szText, WARNING );
       goto TargetLoc;

AlreadyExistDir:
       AskYesNo( "Directory already exists; files will be added to directory. Are you sure?", NO );
       if LAST_RESULT = NO goto TargetLoc;

CheckSubDir:

       StrCopy( szPath, szResultPath );
       StrConcat( szPath, "\\SAMP186" );
       ExistsDir( szPath );
       if LAST_RESULT = 0 goto Dir186Exists;
       CreateDir( szPath );
       if LAST_RESULT = 0 goto Dir186Exists;
       StrCopy( szText, "Unable to create specified path -");
       StrConcat( szText, szPath );
       StrConcat( szText, "\nPlease enter a correct path like C:\\DIRECTRY");
       MessageBox( szText, WARNING );
       goto TargetLoc;
Dir186Exists:


       // avoid moto samples, tek notes for Intel phase 1
       goto EnterDiskAgain;

       StrCopy( szPath, szResultPath );
       StrConcat( szPath, "\\SAMP332" );
       ExistsDir( szPath );
       if LAST_RESULT = 0 goto Dir332Exists;
       CreateDir( szPath );
       if LAST_RESULT = 0 goto Dir332Exists;
       StrCopy( szText, "Unable to create specified path -");
       StrConcat( szText, szPath );
       StrConcat( szText, "\nPlease enter a correct path like C:\\DIRECTRY");
       MessageBox( szText, WARNING );
       goto TargetLoc;
Dir332Exists:

       StrCopy( szPath, szResultPath );
       StrConcat( szPath, "\\SAMPCP32" );
       ExistsDir( szPath );
       if LAST_RESULT = 0 goto DirCP32Exists;
       CreateDir( szPath );
       if LAST_RESULT = 0 goto DirCP32Exists;
       StrCopy( szText, "Unable to create specified path -");
       StrConcat( szText, szPath );
       StrConcat( szText, "\nPlease enter a correct path like C:\\DIRECTRY");
       MessageBox( szText, WARNING );
       goto TargetLoc;
DirCP32Exists:

       StrCopy( szPath, szResultPath );
       StrConcat( szPath, "\\SAMPHC16" );
       ExistsDir( szPath );
       if LAST_RESULT = 0 goto DirHC16Exists;
       CreateDir( szPath );
       if LAST_RESULT = 0 goto DirHC16Exists;
       StrCopy( szText, "Unable to create specified path -");
       StrConcat( szText, szPath );
       StrConcat( szText, "\nPlease enter a correct path like C:\\DIRECTRY");
       MessageBox( szText, WARNING );
       goto TargetLoc;
DirHC16Exists:

       StrCopy( szPath, szResultPath );
       StrConcat( szPath, "\\TEKNOTES" );
       ExistsDir( szPath );
       if LAST_RESULT = 0 goto DirTekExists;
       CreateDir( szPath );
       if LAST_RESULT = 0 goto DirTekExists;
       StrCopy( szText, "Unable to create specified path -");
       StrConcat( szText, szPath );
       StrConcat( szText, "\nPlease enter a correct path like C:\\DIRECTRY");
       MessageBox( szText, WARNING );
       goto TargetLoc;
DirTekExists:

EnterDiskAgain:
       SetStatusWindow( 4, szInstall );
       StrCopy( TARGETDIR, szResultPath );

       // Ask user to enter a disk in drive.
       // Check to see if compress.exe file exists on this disk
       // If it does, then it must the right disk.
       StrCopy( szText, "Please enter the source path for MICEpack/SLD disk 1.");
// ----->
       EnterDisk( szText, "mp186.ex$");

       if LAST_RESULT != TRUE then
          call ConfirmCancel;  // Call to confirm cancel
          goto EnterDiskAgain;       // returned, therefore continue
       endif;
       
       call FileTransfer1;

CheckDisk: 
       if TWO_DISKS = TRUE then  // prompt user to insert disk 2
          StrCopy( szText, "Please enter the source path for MICEpack/SLD disk 2.");
          EnterDisk( szText, "dll3.li$");
          if LAST_RESULT != TRUE then
             call ConfirmCancel;  // Call to confirm cancel
             goto CheckDisk;       // returned, therefore continue
          endif;
       endif;     

       call FileTransfer2;
        
// transfer sample files into Samples directory

       StrConcat( TARGETDIR, "\\SAMP186" );
       call Copy186Samples;      // transfer the sample files
       StrCopy( TARGETDIR, szResultPath );

       // avoid moto samples, tek notes for Intel phase 1
       goto DoneWithSamples;

       StrConcat( TARGETDIR, "\\SAMP332" );
       call Copy332Samples;      // transfer the sample files
       StrCopy( TARGETDIR, szResultPath );
       StrConcat( TARGETDIR, "\\SAMPCP32" );
       call CopyCP32Samples;      // transfer the sample files
       StrCopy( TARGETDIR, szResultPath );
       StrConcat( TARGETDIR, "\\SAMPHC16" );
       call CopyHC16Samples;      // transfer the sample files
       StrCopy( TARGETDIR, szResultPath );
       StrConcat( TARGETDIR, "\\TEKNOTES" );
       call CopyTekNotes;      // transfer the sample files


       // avoid samples, tek notes for Intel phase 1
DoneWithSamples:

// copy 'mp186.ini' to Windows directory
       StrCopy (TARGETDIR, szWinDir);
// first make a backup of the old mp186.ini if there is one
       StrCopy( szPath, SRCDIR ); // save SRCDIR
       StrCopy( SRCDIR, TARGETDIR );
       CopyFile( "mp186.ini", "mp186.bak"); // don't care if it fails
       if LAST_RESULT = 0 then
           StrCopy( szErrMsg, "Your old mp186.ini file in " );
           StrConcat( szErrMsg, TARGETDIR );
           StrConcat( szErrMsg, " has been copied to mp186.bak. " );
           StrConcat( szErrMsg, "You may wish to merge your old settings with" );
           StrConcat( szErrMsg, " the additional information in the new file." );
           MessageBox( szErrMsg,INFORMATION );
       endif;
       StrCopy( SRCDIR, szPath ); // restore SRCDIR
       CopyFile( "mp186.ini", "mp186.ini");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "mp186.ini" );
          call CopyError;
       endif;
      
Complete:
       StrCopy ( TARGETDIR, szResultPath );
       // Now create a program group & icons

       SetStatusWindow(  98, "Creating Program Group & Icons");
       Delay( 1 );
       AppCommand( PROGMAN, CMD_RESTORE );

       StrCopy( szPath, TARGETDIR );
       AppendToPath( szPath, szTbird );  // mp186.exe
// x.yz in next line used for automatting PV builds do not use or change
       AddProgItem( szPgrp, "MP/SLD 2.2", szPath, "" );
//       Delay( 2 );

       // Add an icon for README
       StrCopy( szPath, "notepad.exe " );
       StrConcat( szPath, TARGETDIR );
       AppendToPath( szPath, szReadFile);
       AddProgItem( szPgrp, "MP/SLD ReadMe", szPath, "" );

       // Add an icon for HELP
       StrCopy( szPath, "winhelp.exe " );
       StrConcat( szPath, TARGETDIR );
       AppendToPath( szPath, "pwrviews.hlp");
       AddProgItem( szPgrp, "MP/SLD Help", szPath, "" );
       
       StrCopy( szPath, TARGETDIR );
       AppendToPath( szPath, szSetup );  // mp186.exe
       AddProgItem( szPgrp, "MP Setup", szPath, "" );
       
       AppCommand( PROGMAN, CMD_PUSHDOWN );

       SetStatusWindow( 100, "Installation complete..." );

       Delay( 2 ); //Artificial Delay

       AskYesNo( "Would you like to view the README file ?", TRUE );
       if LAST_RESULT = YES then
          StrCopy( szREADME, TARGETDIR );
          AppendToPath( szREADME, szReadFile );
          LaunchApp("notepad.exe", szREADME );
       endif;

       StrCopy( szREADME, TARGETDIR );
       AppendToPath( szREADME, szSetup );
       LaunchApp(szREADME, "" );

       exit;  //Exit installation program.

//---------------------------------------------------------------------
//
//    FileTransfer1
//
//    Descrip:  This procedure will transfer all the files that are
//              required for the PowerViews product.
//
//
//---------------------------------------------------------------------
FileTransfer1:

       StatusUpdate( OFF, 4 );
       SetStatusWindow( 4, "Copying file ... readme.txt" );
       CopyFile( szReadFile, szReadFile );
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, szReadFile );
          call CopyError;
       endif;
       SetStatusWindow( 4, "Copying file ... include.me" );
       CopyFile( "include.me", "include.me" );
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "include.me" );
          call CopyError;
       endif;
                     
       SetStatusWindow( 5, "Copying file ... problem.txt" );
       StatusUpdate( OFF, 5);
       CopyFile( "problem.txt", "problem.txt");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "problem.txt" );
          call CopyError;
       endif;

       SetStatusWindow( 6, "Decompressing... mp186.ex$" );
       StatusUpdate( ON, 13);
       DeCompress( "mp186.ex$", "mp186.exe" );
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "mp186.exe" );
          call CopyError;
       endif;

       SetStatusWindow( 13, "Decompressing... mp186.im$" );
       StatusUpdate( ON, 45);
       DeCompress( "mp186.im$", "mp186.ima" );
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "mp186.ima" );
          call CopyError;
       endif;

       SetStatusWindow( 45, "Decompressing... pwrviews.hl$" );
       StatusUpdate( ON, 55);
       DeCompress( "pwrviews.hl$", "pwrviews.hlp" );
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "pwrviews.hlp" );
          call CopyError;
       endif;

       SetStatusWindow( 55, "Decompressing ... cfg.li$" );
       StatusUpdate( ON, 56);     
       DeCompress( "cfg.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "cfg.li$" );
          call CopyError;
       endif;
                                  
       SetStatusWindow( 56, "Decompressing ... dll1.li$" );
       StatusUpdate( ON, 61);     
       DeCompress( "dll1.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "dll1.li$" );
          call CopyError;
       endif;

       SetStatusWindow( 61, "Decompressing ... dll2.li$" );
       StatusUpdate( ON, 71);     
       DeCompress( "dll2.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "dll2.li$" );
          call CopyError;
       endif;

       return;

//---------------------------------------------------------------------
//
//    FileTransfer2
//
//    Descrip:  This procedure will transfer all the files in the
//              disk 2 that are required for the PowerViews product.
//
//---------------------------------------------------------------------
FileTransfer2:

       SetStatusWindow( 71, "Decompressing ... dll3.li$" );
       StatusUpdate( ON, 79);     
       DeCompress( "dll3.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "dll3.li$" );
          call CopyError;
       endif;

       SetStatusWindow( 80, "Decompressing ... dll4.li$" );
       StatusUpdate( ON, 94);     
       DeCompress( "dll4.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "dll4.li$" );
          call CopyError;
       endif;


       return;

//---------------------------------------------------------------------
//
//    Copy 332 Sample Files
//
//    Descrip:  This procedure will transfer all the sample files to 
//              subdirectory-SAMP332 of PowerViews directory.
//
//
//---------------------------------------------------------------------
Copy332Samples:

       SetStatusWindow( 94, "Decompressing file ... samp332.li$" );
       StatusUpdate( ON, 95);
       DeCompress( "samp332.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "samp332.li$" );
          call CopyError;
       endif;

       return;

//---------------------------------------------------------------------
//
//    Copy CP32 Sample Files
//
//    Descrip:  This procedure will transfer all the sample files to 
//              subdirectory-SAMPCP32 of PowerViews directory.
//
//
//---------------------------------------------------------------------
CopyCP32Samples:

       SetStatusWindow( 95, "Decompressing file ... sampcp32.li$" );
       StatusUpdate( ON, 96);
       DeCompress( "sampcp32.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "sampcp32.li$" );
          call CopyError;
       endif;

       return;

//---------------------------------------------------------------------
//
//    Copy HC16 Sample Files
//
//    Descrip:  This procedure will transfer all the sample files to 
//              subdirectory-SAMPHC16 of PowerViews directory.
//
//
//---------------------------------------------------------------------
CopyHC16Samples:

       SetStatusWindow( 96, "Decompressing file ... samphc16.li$" );
       StatusUpdate( ON, 97);
       DeCompress( "samphc16.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "samphc16.li$" );
          call CopyError;
       endif;

       return;

//---------------------------------------------------------------------
//
//    Copy Technical Notes
//
//    Descrip:  This procedure will transfer all the note files to 
//              subdirectory-TEKNOTES of PowerViews directory.
//
//
//---------------------------------------------------------------------
CopyTekNotes:

       SetStatusWindow( 97, "Decompressing file ... teknotes.li$" );
       StatusUpdate( ON, 98);
       DeCompress( "teknotes.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "teknotes.li$" );
          call CopyError;
       endif;

       return;

//---------------------------------------------------------------------
//
//    Copy 186 Sample Files
//
//    Descrip:  This procedure will transfer all the sample files to 
//              subdirectory-SAMP186 of PowerViews directory.
//
//
//---------------------------------------------------------------------
Copy186Samples:

       SetStatusWindow( 98, "Decompressing file ... samp186.li$" );
       StatusUpdate( ON, 99);
       DeCompress( "samp186.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "samp186.li$" );
          call CopyError;
       endif;

       return;

//---------------------------------------------------------------------
//
//    ConfirmCancel
//
//    Descrip:  This procedure will confirm with the users if they want
//              to terminate the installation of the PowerViews product.
//
//
//---------------------------------------------------------------------
ConfirmCancel:

          AskYesNo( "Are you sure you want to CANCEL installation ?", FALSE );

          if LAST_RESULT = FALSE then return; endif;

          exit;

//---------------------------------------------------------------------
//
//    CopyError
//
//    Descrip:  This procedure will display an error when PowerViews is
//              unable to decompress or copy a file.
//
//
//---------------------------------------------------------------------
CopyError:

        StrCopy( szErrMsg, "Unable to copy or decompress file: ");
        StrConcat( szErrMsg, szErrFile);
        MessageBox( szErrMsg, SEVERE );

        return;

