/*
 * Project: CurvFit
 */

@DefineProject
        @Name = "CurvFit"
        @ShowName(1, "CurvFit (tm): Power, Lorentz, Exp. Series",,2,40,15,@RGB(255, 255,0))
        @Version = "3.34"
	@Immediate = 1
	@Verify
	@Terse
	@Requires @HardDisk
	@Subdir = "\\OD-Tools"
	@OutDrive = C
	@Group = "i"
@EndProject

@NumberOfDisks = 1

@DefineVars
  @Integer @Win = @eval( 100 * @WindowsMajor + @WindowsMinor)
  @Integer @Red          = @RGB(255,0,0) //DEFINE COLOR RED
  @Integer @Green        = @RGB(0,255,0) //DEFINE COLOR GREEN
  @Integer @Blue         = @RGB(0,0,255) //DEFINE COLOR BLUE
  @Integer @Black        = @RGB(0,0,0)   //DEFINE COLOR BLACK
  @Integer @RetVal = 0
  @Integer @ErrorFlag = 0
  @Qstring @LineRead = ""
    // We have read the entire file when this 
    // variable equals (-1).
  @Integer @EOF = 0  
  @Integer @Found = @False
  @Qstring @MyDrive = "@OutDrive"
  @Qstring @ODpath = ""
  @Qstring @PM2= ""
  @Qstring @PMlist= ""
  @Qstring @RefLine="CF-01-000010"
       @Integer @NewHandle = 0
       @Integer @Status = 0
       @Integer @Disposition = 0
@EndVars
@BackgroundMode(3,@Blue,@Black)

// prototype all user-defined script functions
@DefineProto
    @Void @Message(@In @Integer @iTypeOfMessage,
	@In @Qstring @qMessageText)

    @Integer @DesktopCreateTopLevel(
	@In @Qstring @ObjectName, 
	@In @Integer @Common)

    @Integer @DesktopCreateItem(
	@In @Qstring @ExecutableFileName,
	@In @Qstring @Description, 
	@In @Qstring @IconFileName,
	@In @Integer @IconIndex)
@EndProto

// this is the message function from example 2 in this lesson
@DefineFunc @Void @Message(
    @In @Integer @iTypeOfMessage, 
    @In @Qstring @qMessageText)

    @If(@iTypeOfMessage == 0)
	@Display
	    Message: @qMessageText
	    @Pause
	@EndDisplay

    @ElseIf(@iTypeOfMessage == 1)
	@Display
	    Warning: @qMessageText
	    @Pause
	@EndDisplay
    
    @Else
	@Display
	    Error: @qMessageText
	    @Pause
	@EndDisplay
	@Abort
    @EndIf
    @Return()
@EndFunc
 
@DefineFunc @Integer @DesktopCreateTopLevel(
    @In @Qstring @ObjectName, 
    @In @Integer @Common)
 
    // Do a little error check to make sure the group name is valid, 
    // and that the @Common parameter is in the correct range 
    // of zero through one.  Note that we are using the @Message() 
    // function created in Example 2.

    @If(@StrLen("@ObjectName") > 25)
	@Message(2, "The 1st Parameter to @@DesktopCreateTopLevel() 
	should be a string less than 26 chars")
    @EndIf
 
    @If(@Common > 1 || @Common < 0)
	@Message(2, "The 2nd Parameter to @@DesktopCreateTopLevel() 
	should be either a 0 or a 1")
    @EndIf
 
    @If(@Platform == 3)    // Windows 3.XX, Windows 95, or Windows NT
	@If(@SubPlatform == 3)
	    // Windows NT. Since NT supports Common vs Private groups, 
	    // pass-in the @Common formal parameter
	       @PM2 = "[CreateGroup(@ObjectName,@Common)]"
	// not sure if this will work on NT ...  @ErrorFlag = 1
	@Else
	    // Windows 3.XX or Windows 95, ignore @Common parameter
	    @PM2 = "[CreateGroup(@ObjectName)]"
	@EndIf
	@RetVal= @ProgramManager( "@PM2")
	@If(@RetVal != 0)
	  @Message(2, "The @@ProgramManager() command as called from the 
	   function @@DesktopCreateTopLevel() failed to execute properly.
           Note for developer ... @@PM2 = @PM2 & @@SubPlatForm =
           @SubPlatForm")
	@EndIf
    @EndIf

    @Return(1)
@EndFunc // @DesktopCreateTopLevel()

// Now, we'll create the second function who's purpose is to add a 
// menu item to a Windows 95 "Start | Programs | XXXXX" menu 
// (the "XXXXX" indicates the name of the menu created using the 
// @DesktopCreateTopLevel() function).  This function does a lot of error 
// checking on the parameters to make sure they have reasonable values.

@DefineFunc @Integer @DesktopCreateItem(
    @In @Qstring @ExecutableFileName,
    @In @Qstring @Description, 
    @In @Qstring @IconFileName,
    @In @Integer @IconIndex)

    // make sure @ItemName isn't too long
    @If(@StrLen("@Description") > 25)
	@Message(2, "The 1st Parameter to @@DesktopCreateItem() should 
	be a string less than 26 chars")
    @EndIf
 
    // there isn't much error checking we can do on the 
    // 2nd parameter except to make sure that it was specified
    @If(@StrLen("@ExecutableFileName") <= 0)
	@Message(2, "The 2nd Parameter to @@DesktopCreateItem() is required")
    @EndIf

    // if the @IconFileName was specified, make sure it exists
    @If(@StrLen("@IconFileName") > 0)
	@If(@Exists("@IconFileName") < 1)
	    @Message(2, "The 3rd parameter to @@DesktopCreateItem(), 
	    \"@IconFileName\" specifies a file that does not exist.")
	@EndIf
    @EndIf

    // there isn't really any error checking we can do 
    // for the @IconIndex var, so we skip it.
 
    // if execution gets here, then all parameters seem reasonable, 
    // so actually call the @ProgramManager() and have it execute the 
    // command.  If the return value from the  @ProgramManager() call 
    // is invalid, then we'll tell the end-user such.

    @PM2="[AddItem(@ExecutableFileName,@Description,@IconFileName,@IconIndex)]"
    @PMlist = "@PMlist@PM2"
    @Return(1)
@EndFunc // @DesktopCreateItem()

@Display
  @Move(11,18)
				     OD-Tools

	Math/Engineering software programs developed with the 
	use of a calculus based language, Fortran Calculus.
  @Pause
@EndDisplay

@Display
  @Move(11,5)
                               CurvFit (tm)

     CurvFit (tm) is a curvefitting program.  Power, Exponential, and
     Lorentzian series are available models to try to match your data.
     CurvFit is an example of Calculus level programming... ie. minutes
     to solve, days or years to understand solution and what it implies
     (e.g. wrong model, sampling rate error, etc.)
  @Pause
@EndDisplay

@Display
  @Move(11,5)
				    ODEcalc (tm)

     Solves an ODE with bounds (BVP) or initial conditions (IVP).
     ODE may be non-linear, implicit, && any order.  ODEcalc (tm) 
     is an example of rapid software development that is due to
     a Fortran Calculus.
  @Pause
@EndDisplay

@Display
  @Move(13,2)
				Installing 

	  @Name (tm) v. @Version ... a shareware program.
  @Pause
@EndDisplay

@Display
  @Move(6,2)
	  Hardware and software requirements for @Name are:
	  ==============================
		    Computer:  386+ IBM PC/AT with Math Co-processor
     Hard Disc storage:  4 Mb
		 OS Version:  DOS 3.3+
                    Windows:  3.1x/95/98
  @Pause
@EndDisplay

@GetOutDrive
	@LocalWindow( 7, 34)
	@Suppress A
	@Suppress B
  //    @Suppress( 0, 1)  // Suppressed B drive only ... not A & B, why?
  //    @Suppress( 0,16)  // Suppresses CD-ROMs ( and Zip drives!! )
	@Cls
	     Select the disk drive where you wish to install @Name?
@EndOutDrive

@DlgCtrlSize(0, 8, 5, 9, 25)
// 'GetSubDir' has a bug in Windows 3.1 as of 5/98 ... won't show default name!
// @GetSubdir
//         Next specify the disk destination subdirectory.  The subdirectory
//         is the location on your disk where the @Name (tm) system will
//         be installed.
// 
//         Specify path without the drive letter.
// @EndSubdir

//
//      INSTALL will now prompt the end-user for the different parts of
//      the software they wish to install.
//
@DlgCtrlSize(0,-1,-1,0,0)
@DlgCtrlSize(0, 8, 10, 11, 60)
@If( @ErrorFlag == 0)
  @ClearGroup(I)
  @SetGroup(A)
  @GetGroups
    @CheckBox
      Select the parts of @Name (tm) you wish to place on your
      computer system:

      @Set a = "All files"
      @Set o = "@Name (tm) files"
      @Set c = "'Base' files (includes graphics) ... all OD-Tools use these"
      
      //  I = User's Guide, Register info, etc. for NON-qualifying computers
  @EndGroups

  @Display
      @If ('A' [! @Group && 'C' [! @Group && 'O' [! @Group)

		 You didn't select anything to install.

		 Will terminate installation.
	  @Pause
	  @Abort
      @EndIf
  @EndDisplay
@Else
  @ErrorFlag = 1
  @SetGroup(I)
@Endif  // System meets minimum requirements?

@DesktopCreateTopLevel("Calculus Tools", 1)

// @ShowBMP( 0, 20, 20, "Equat5a.bmp", 2)

// @WinDrive:@WinDir\\
@DefineDisk
  @Label = "Disk #1"
  @BeginLib cFit.ode
                @F p @S 1308 @O         CurvFit\FILE_ID.DIZ
                @F q @S 34176 @O        CurvFit\MANUAL.WRI
                @F r @S 36115 @O        CurvFit\MANUAL.rtf
                @F s @S 1636 @O         CurvFit\README.txt
                @F t @S 7259 @O         CurvFit\REGISTER.txt
                @F u @S 2045 @O         CurvFit\VENDOR.txt
                @F v @S 766 @O          CurvFit\readme.ICO
                @F w @S 995 @O          CurvFit\List-Fit.pif
      @If( 'A' [= @Group || 'O' [= @Group)
                @F 0 @S 1435 @O         CurvFit\User\EX-mod1.0
                @F 1 @S 1156 @O         CurvFit\User\EX-mod1.1
                @F 2 @S 1186 @O         CurvFit\User\EX-mod1.3
                @F 3 @S 1183 @O         CurvFit\User\EX-mod1.5
                @F 4 @S 3278 @O         CurvFit\User\EX-MOD1.100
                @F 5 @S 8754 @O         CurvFit\User\EX-MOD1.300
                @F 6 @S 14307 @O        CurvFit\User\EX-MOD1.500
                @F 7 @S 1369 @O         CurvFit\User\EX-mod2.0
                @F 8 @S 1256 @O         CurvFit\User\EX-mod2.1
                @F 9 @S 1267 @O         CurvFit\User\EX-mod2.2
                @F A @S 1292 @O         CurvFit\User\EX-mod2.3
                @F B @S 1260 @O         CurvFit\User\EX-mod2.4
                @F C @S 1271 @O         CurvFit\User\EX-mod2.5
                @F D @S 3026 @O         CurvFit\User\EX-MOD2.100
                @F E @S 3091 @O         CurvFit\User\EX-MOD2.110
                @F F @S 5526 @O         CurvFit\User\EX-MOD2.200
                @F G @S 1270 @O         CurvFit\User\EX-mod3.0
                @F H @S 1251 @O         CurvFit\User\EX-mod3.1
                @F I @S 1245 @O         CurvFit\User\EX-mod3.3
                @F J @S 3195 @O         CurvFit\User\EX-MOD3.100
                @F K @S 8512 @O         CurvFit\User\EX-MOD3.300
                @F L @S 1238 @O         CurvFit\User\EX-mod4.0
                @F m @S 1173 @O         CurvFit\User\EX-mod4.1
                @F n @S 1248 @O         CurvFit\User\EX-mod4.2
                @F o @S 2785 @O         CurvFit\User\EX-SINE.100
                @F x @S 2995 @O         CurvFit\demo.BAT
                @F y @S 2602 @O         CurvFit\demo2.BAT
                @F z @S 766 @O          CurvFit\Fit-win.ICO
                @F 00 @S 63641 @O       CurvFit\FIT-win.EXE
                @F 10 @S 7488 @O        CurvFit\obj3d.dll
                @F 20 @S 5310 @O        CurvFit\RUN-FIT.BAT
                @F 30 @S 569 @O         CurvFit\FIT.INC
                @F 40 @S 21905 @O       CurvFit\FIT4user.FC
                @F 50 @S 394663 @O      CurvFit\FIT.EXE
                @F 60 @S 846 @O         CurvFit\startup.grp
                @F 70 @S 273 @O         Go-Fit.Bat
      @EndIf
  @EndLib
  @BeginLib base.ode
      @If( 'A' [= @Group || 'C' [= @Group)
		@F 0 @S 548336 @O       @WinDrive:@WinDir\rlzrun20\rlzrun20.rts
                @F 1 @S 440640 @O       @WinDrive:@WinDir\cable.dll
		@F 2 @S 43270 @O        Trouble\TUNE.EXE
		@F 3 @S 7878 @O         Trouble\WHATMEM.EXE
		@F 4 @S 118302 @O       Trouble\386SETUP.EXE
		@F 5 @S 9769 @O         Sharewar\LICENSE
		@F 6 @S 110460 @O       Sharewar\LIST.DOC
		@F 7 @S 10515 @O        LIST.com
		@F 8 @S 1357 @O         Sharewar\Mailer
		@F 9 @S 9999 @O         Sharewar\Programs
                @F A @S 40432 @O        F77L3.eer
                @F b @S 251614 @O       Graphit.exe
                @F c @S 42714 @O        od-Wrap.exe
                @F d @S 181 @O          List.bat
                @F e @S 766 @O          List.ico
                @F f @S 615 @O          go.bat
                @F g @S 269 @O          go-ODE.bat
                @F h @S 3632 @O         Ask.exe
                @F i @S 72 @O           DOSstart.bat
                @F j @S 695 @O          Kill-CD.bat
                @F k @S 49 @O           Kill-CDw.bat
                @F l @S 505 @O          Autoexec.bat
                @F m @S 1774 @O         Config-3.SYS
                @F n @S 1084 @O         Config-9.SYS
                @F o @S 311339 @O       od-PLT.EXE
      @EndIf
  @EndLib
@EndDisk

@ODpath = "@OutDrive:@SubDir"
@If( 'A' [= @Group || 'C' [= @Group || 'O' [= @Group)
  @If( @ErrorFlag == 0 )
    @ClearOption( 5)
    @If( @Spawn( "Subst g: c:\\") != 0)
      @SetOption( 5)
    @Else
      @RetVal = @Spawn( "Subst g: /d > nul")  // ? = " > nul"
    @EndIf

    @SetAutoexec
      @OverWrite
      @SetReplace("od-tools", "@ODpath")
    @EndAutoexec

    @SetConfig
      @OverWrite
      @Buffers = 30
      @Files = 30
      @If( 5 [= @Option)
	@LastDrive = g
      @Endif
    @EndConfig
  @Endif
@EndIf
  
@SetEnv("od-Tools", "@ODpath")

//  @EraseBMP( 0)
@Finish
  @ChDrive( @StartUpDrive)
  @ChDir( "@StartUpDir")
  @Copy("cFit*.xml", "@ODpath\\*.*")
  @If( 'A' [= @Group)
    /*
     * For tracking purpose, add Reference number to several files
     */
    @If( @Exists("disk.id") )
      @RetVal = @ReadLine("disk.id", @LineRead)
      @RetVal = @ReadLine(, @LineRead)
      @RetVal = @ReadLine(, @LineRead)
      @RetVal = @ReadLine(, @LineRead)
    @Endif
    @If( "@LineRead" == "" || @RetVal == -1)  // Empty or EOF
      @LineRead = "@RefLine"
    @EndIf
    @Write("@ODpath\\curvFit\\VENDOR.txt", "at", "          @LineRead\n")
    @Write("@ODpath\\curvFit\\register.txt", "at", "      @LineRead\n")
  @EndIf
  @If ('A' [! @Group && 'C' [! @Group && 'O' [! @Group && @ErrorFlag == 0)
    @CLS
		 Information files installed.

		 Read users guide in their sub-directory.

		 Will terminate installation.
    @Pause
    @Abort
  @EndIf
  @ChDrive( @OutDrive)
  @ChDir( "@SubDir")
  @If( @ErrorFlag == 1 )
     @Cls
     @move( 4, 5)
     Copied information files, only.  Your system did NOT pass INSTALL's
     verification for the following @Name system requirements:

	 ©============================================©
	 ©   Hardware / software requirements that failed are:      ©
	 ©============================================©
                                Non Windows 3.1x/95/98
     @Pause
  @Else
  /*
   * Modifying the file AutoExec.bat file with the last drive
   * found on this PC station.
   */
    @If( @Exists("AutoExec.bat") )
      @Write("AutoExec.bat", "at", "set RAMdsk=@MyDrive:\n")
    @Endif
  /*
   * Copy README.TXT file into both directories
   */
    @If( 'A' [= @Group || 'O' [= @Group)
      @Copy("@ODpath\\curvFit\\README.txt", "@ODpath")
    @Endif
  /*
   * Check to see if 'temp' directory exists for temp. plot files
   */
    @If( @DirExists("@ODpath\\temp") != 1)
      @MkDir("@ODpath\\temp")
    @Endif
  /*
   * Copy Graphit.exe file into both directories
   */
    @If( @Exists("Graphit.exe") )
      @If( 'A' [= @Group || 'O' [= @Group)
        @copy("@WinDrive:@WinDir\\DOSstart.bat", "@WinDrive:@WinDir\\DOSstart.ode")
        @copy("@ODpath\\f77l3.err", "@ODpath\\curvFit")
        @copy("@ODpath\\graphit.exe", "@ODpath\\curvFit")
      @Endif
    @Else
      @If( 'A' [= @Group)
	@Cls
	@move( 4, 5)
     
	     ©=====================================©
	     ©  @Name (tm) directory STRUCTURE error!     ©
	     ©=====================================©
     
     Graphit.exe file is missing from @ODpath directory.  This 
     file is necessary to install @Name.  Please re-install 
     Optimal Designs's BASE directory files in your '\OD-Tools'
     directory.
	@Pause                               
	@Abort
      @EndIf
    @EndIf
  /*
   * Copy DOSstart.bat file to *.ODE for backup and setup new DOSstart.bat
   */
    @If( @Exists("@WinDrive:@WinDir\\DOSstart.bat") )
      @If( 'A' [= @Group || 'O' [= @Group)
        @If( @Exists( "@WinDrive:@WinDir\\DOSstart.ode") <= 0) // not exists then
          @copy("@WinDrive:@WinDir\\DOSstart.bat", "@WinDrive:@WinDir\\DOSstart.ode")
        @EndIf
        @delete("@WinDrive:@WinDir\\DOSstart.bat")
        @copy("@ODpath\\DOSstart.bat", "@WinDrive:@WinDir\\DOSstart.bat")
        @copy("@WinDrive:@WinDir\\DOSstart.ODE", "@WinDrive:@WinDir\\kill-CDw.bat")
      @Endif
    @Else
      @If(@Platform == 3)  // Windows 3.XX, Windows 95, or Windows NT
        @If(@Win >= 400)  // Windows 95/98/ ( NT ?)
          @If( 'A' [= @Group)
            @Cls
            @move( 4, 5)
     
             ©=====================================©
             ©    Key Windows (@Win) file is missing error!     ©
             ©=====================================©
     
     @WinDrive:@WinDir\\DOSstart.bat file is missing.  This file is necessary
     to install @Name.  Please make sure that your Windows file
     @WinDrive:@WinDir\\DOSstart.bat exists then re-install @Name.
            @Pause                               
            @Abort
          @EndIf
        @EndIf
      @EndIf
    @EndIf
    //
    // now try out the two functions (from wInstall manual)
    @If( 'A' [= @Group || 'C' [= @Group)
      @DesktopCreateItem("@ODpath\\curvFit\\List-Fit.pif","List CurvFit output","@ODpath\\list.ico", 0)
    @EndIf
  @EndIf
  
  
  @If(@Platform == 3)  // Windows 3.X, Windows 95, or Windows NT
     @If(@Win < 400)  // DOS, Win16, OS/2
        @If( 'A' [= @Group)
          @Cls
          @move( 4, 5)

           ©=============================================©
           ©    Windows 3.1X users ... CD-ROM software conflict!!!    ©
           ©=============================================©

         A conflict with Microsoft's CD-ROM driver called msCDex.exe
         exists.  In order for this software to work you -must- remove
         any line containing msCDex.exe from your CONFIG.SYS and
         AUTOEXEC.bat.  Add "Rem " at the beginning of each line
         containing "msCDex" should do the trick.

         A better way would be to prompt you each time you started this
         PC.  To do this you would insert the following lines before
         line with msCDex.exe in your Autoexec.bat or Config.sys.
           @ODpath\ask "Want CD-ROM (Y/N)"YN
           if ErrorLevel = 1  <-- (attach your msCDex line here.)
         Then each time prompted you could say -No- when using od_Tools
         software or -Yes- otherwise.
          @Pause
        @EndIf
        @DesktopCreateItem("@ODpath\\curvFit\\manual.wri","CurvFit Manual","@ODpath\\curvFit\\readme.ico", 0)
	@Status = @WinRegCreateKey(
		     @HKeyLocalMachine, 
                     "Software\\Optimal Designs Enterprise\\CurvFit (tm)", 
		     @NewHandle)
	@Disposition = 99   // Not defined in Install 4.00 for Win16 OSes.
     @Else  // Windows 95/98/NT
        @DesktopCreateItem("@ODpath\\curvFit\\manual.rtf","CurvFit Manual","@ODpath\\curvFit\\readme.ico", 0)
	@Status = @WinRegCreateKeyEx(
		     @HKeyLocalMachine, 
                     "Software\\Optimal Designs Enterprise\\CurvFit (tm)", 
		     "Test Class",
		     0,      // no special options
		     4,      // permission to create sub keys
		     @Null, // default security
		     @NewHandle,
		     @Disposition)
     @EndIf
     @If(@Status == 0)       // It worked properly
/*      @CLS
           @If(@Disposition == 1)
		 The key was created successfully.
	   @ElseIf(@Disposition == 2)
		 The pre-existing key was opened successfully.
	   @Else
		 The key was successfully opened, but the value
		 of @Disposition is undocumented.
	   @EndIf

	    @@WinRegCreateKey() return value: @Status
	    @@NewHandle: @NewHandle
	    @@Disposition: @Disposition
	
	    @Pause
*/      // Now associate a text value with this key
	@If(@Win < 400)  // DOS, Win16, OS/2
	   @Status = @WinRegSetValue(@NewHandle,
                     "Software\\Optimal Designs Enterprise\\CurvFit (tm)", 
                     "@Version")
        @Else  // Windows 95/98/ ( NT ?)
	   @Status = @WinRegSetValueEx(@NewHandle,
                     "Software\\Optimal Designs Enterprise\\CurvFit (tm)", 
		     1, // string type -or- 4 for 32-bit word
                     "@Version",             // String "data"
		     4)                 // size of "data" string + 1
	@EndIf
		
	// Now close key (it is dangerous to leave a key open)
	@Status = @WinRegCloseKey(@NewHandle)
	@If(@Status != 0)
	   @CLS
              Error: The Registry key was NOT closed successfully.
	
	      @Pause
	@EndIf
     @Else    // Some type of error occurred.
	   @CLS
             Error: The Registry key was not created.
	
	     @Pause
     @EndIf
  @EndIf

  
  @If( 'A' [= @Group || 'O' [= @Group)
    @DesktopCreateItem("@ODpath\\curvFit\\Fit-Win.exe", "CurvFit Program", "@ODpath\\curvFit\\Fit-Win.ico", 0)
  @EndIf
  @RetVal= @ProgramManager( "@PMlist")
  @If(@RetVal != 0)
      @Message(2, "The @@ProgramManager() command as called from the 
	 function @@DesktopCreateItem() failed to execute properly.")
  @EndIf
  @If( @NDP == 0)    //Math co-processor available ?
    @CLS
			=== Warning ===
	   An 80x87 chip is required for @Name (tm) to run.

	   If you do have a 80x87 (Math co-processor) chip,
	   disregard this warning message.

       @Pause
  @EndIf
  @If( @ErrorFlag == 0 )
    @CLS
    Installation is complete.
    
    Please view the README.TXT && MANUAL.??? files for more 
    information.

    Share @Name (tm) with your friends.

    Register @Name (tm) program, if program is helpful.

    Re-boot your system, if your -ConFig.SYS- file was modified.
    @Pause
    @Reboot("Rebooting your machine.", 0)
  @EndIf
  @ChDrive( @OutDrive)
  @ChDir( "@SubDir")
@EndFinish
/* End-of-file */
