//
//      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( szSetup, "mpsetup.exe" );
       StrCopy( szTbird, "micepack.exe mpppc.ima"); 

       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, "\\mpppc" ); // 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, "\\SAMPLE" );
       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, "micepack.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, "\\SAMPLE" );
       call Copy306Samples;      // transfer the sample files
       StrCopy( TARGETDIR, szResultPath );
       StrConcat( TARGETDIR, "\\TEKNOTES" );
       call CopyTekNotes;      // transfer the sample files

// copy 'micepack.ini' to Windows directory
       StrCopy (TARGETDIR, szWinDir);
// first make a backup of the old micepack.ini if there is one
       StrCopy( szPath, SRCDIR ); // save SRCDIR
       StrCopy( SRCDIR, TARGETDIR );
       CopyFile( "micepack.ini", "micepack.bak"); // don't care if it fails
       if LAST_RESULT = 0 then
           StrCopy( szErrMsg, "Your old micepack.ini file in " );
           StrConcat( szErrMsg, TARGETDIR );
           StrConcat( szErrMsg, " has been copied to micepack.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( "micepack.ini", "micepack.ini");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "micepack.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 );  // micepack.exe
// x.yz in next line used for automatting PV builds do not use or change
       AddProgItem( szPgrp, "MP/SLD-PPC V0.9", szPath, "" );
//       Delay( 2 );
       
       StrCopy( szPath, TARGETDIR );
       AppendToPath( szPath, szSetup );  // mpsetup.exe
       AddProgItem( szPgrp, "MP/Setup-PPC", szPath, "" );

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

       // Add an icon for HELP
       StrCopy( szPath, "winhelp.exe " );
       StrConcat( szPath, TARGETDIR );
       AppendToPath( szPath, "pwrviews.hlp");
       AddProgItem( szPgrp, "MP/SLD-PPC Help", 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, szSetup );
          LaunchApp(szREADME, "" );
          StrCopy( szREADME, TARGETDIR );
          AppendToPath( szREADME, szReadFile );
          LaunchApp("notepad.exe", szREADME );
       else
          StrCopy( szREADME, TARGETDIR );
          AppendToPath( szREADME, szSetup );
          LaunchApp(szREADME, "" );
       endif;

       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... micepack.ex$" );
       StatusUpdate( ON, 10);
       DeCompress( "micepack.ex$", "micepack.exe" );
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "micepack.exe" );
          call CopyError;
       endif;

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

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

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

       SetStatusWindow( 50, "Decompressing ... dll2.li$" );
       StatusUpdate( ON, 57);     
       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( 57, "Decompressing ... dll3.li$" );
       StatusUpdate( ON, 67);     
       DeCompress( "dll3.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "dll3.li$" );
          call CopyError;
       endif;

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

       return;

//---------------------------------------------------------------------
//
//    Copy 306 Sample Files
//
//    Descrip:  This procedure will transfer all the sample files to 
//              subdirectory-SAMP306 of PowerViews directory.
//
//
//---------------------------------------------------------------------
Copy306Samples:

       SetStatusWindow( 97, "Decompressing file ... samples.li$" );
       StatusUpdate( ON, 98);
       DeCompress( "samples.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "samples.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( 98, "Decompressing file ... teknotes.li$" );
       StatusUpdate( ON, 98);
       DeCompress( "teknotes.li$", "");
       if LAST_RESULT < 0 then
          StrCopy( szErrFile, "teknotes.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;

