;*******************************************************;
;                                                       ; 
;             LightWave 5.0 Beta Installer              ;
;                                                       ;
;                     by Todd Hayes                     ;
;                   ©1995 NewTek, Inc.                  ;
;                                                       ;
;  $VER: Lightwave Unbundled Installer 4.0 (11-09-95)   ;
;                                                       ;
;  Fixed by: tRANCETIP/dCN! (v4.0y)                     ;
;  Some modifications by MAX/DC                         ;
;                                                       ;
;                                                       ;
;*******************************************************;

;************* Initialize **************
(set @app-name "LightWave")
(set @user-level 1)
(set default_drive (if (exists "Work:" (noreq))
                       "Work:"
                       (cat (getdevice "c:") ":")))
(set @default-dest default_drive)

(makeassign "Lightwave3D" "")
(set x 0)
(while (< x 20 )
  (makeassign (cat "LightWaveDisk" x) "" )
  (set x (+ x 1) )
)

(set disk1 "Lightwave3D")
(set disk_n "LightwaveDisk")
(set LHA_FILE (cat (pathonly @icon) "prog0.lha"))


(set parts -1)
(set num_parts 10)

;****** Help Messages ******
(set toast_drive_help (cat "The LightWave 3D Installer needs to know where you "
                      "would like to install the software.  In most cases "
                      "you will want to choose the root of any drive that "
                      "has enough room to install the parts of the "
                      "software that you intend to install.  If you choose "
                      "to install to a directory called 'NewTek', you will "
                      "want to make sure that you answer 'NO' on the next "
                      "requester which will ask if you would like to install "
                      "the software inside a NewTek directory.  This option "
                      "is provided for first time installation, when there "
                      "is not usually an existing NewTek directory.  It "
                      "will create a NewTek directory for you inside the "
                      "directory that you have chosen. If you already have "
							 "a version of the Video Toaster and/or Flyer software "
							 "version 4.0 or above, then we HIGHLY recommend that "
							 "you choose to install LightWave 3D to the same directory. "
							 "To do this, select the drive/drawer containing your "
							 "NewTek directory to install Lightwave in.  For example, "
							 "if your Flyer 4.0 software is installed in your "
							 "WORK:NewTek drawer, then choose to install LightWave in "
							 "WORK: only. LightWave will automatically know to install "
							 "inside the NewTek directory."))  

(set newtek_newtek_help (cat "The LightWave 3D Installer has detected that you "
                        "have chosen to install the software in a "
                        "directory called Newtek, and have also chosen to "
                        "have the Installer create a NewTek directory "
                        "(inside the existing NewTek directory) to install "
                        "the software into.  This will result in a Newtek/"
                        "Newtek directory, which is probably not what you "
                        "wanted.  By choosing 'YES' you tell the Installer "
                        "that you did understand what you were doing and "
                        "really did want a NewTek/NewTek directory to be "
                        "created.  If you choose 'NO' then you are telling "
                        "the Installer that you would like it to install to "
                        "the existing NewTek directory without making "
                        "another NewTek directory that would be nested in "
                        "the existing NewTek directory."))
(set next_disk_help (cat "The Installer has finished reading data "
                        "from the current disk and needs to read from the "
                        "indicated disk.  Please insert the indicated disk "
                        "so that the Installer may continue."))

(set user_startup_help (cat "These commands need to be added to your User-"
                        "Startup file in order for the Video "
                        "Toaster software/hardware to function properly.  "
                        "These commands will then be automatically run at "
                        "boot up."))

;****** Function Definitions ******

(procedure SET_CD_SIZES
	(
		(set programs_size	6200000)
		(set envelopes_size	3000)
		(set images_size		2000000)
		(set motions_size		100000)
		(set objects_size		2200000)
		(set plugins_size		800000)
		(set previews_size	0)
		(set psfonts_size		2000000)
		(set scenes_size		650000)
		(set surfaces_size	20000)
		(set hiip_size			2200000)
	)
)

(procedure GETPATH
	(set newtek_dir (askdir (prompt "Please select the drive where you would "
	                                 "like to install Lightwave 3D. A new drawer "
	                                 "called 'NewTek' will be created there.")
	                         (default default_drive)
	                         (help toast_drive_help)))
	(set slash (if (= ":" (substr newtek_dir (- (strlen newtek_dir) 1) 1))
		            ""
	               "/"))
	(set newtek_dir (cat newtek_dir slash "NewTek"))
	(set slash "/")
	
	(if (= "NewTek/NewTek" (substr newtek_dir (- (strlen newtek_dir) 13) 13))
		(set newtek_dir 
			(if (askbool (prompt (cat "Are you sure that you "
	                                "want to install the LightWave 3D "
	                                "software to the " newtek_dir
	                                " directory?\n\nIf you choose "
	                                "'NO' then the LightWave 3D software "
	                                "will be installed into the "
	                                (substr newtek_dir 0 
	      	                          (- (strlen newtek_dir) 7)
	                                ) 
											  "directory instead."))
	                   (help newtek_newtek_help)	
		                (default 0))
		 	    newtek_dir
				 (substr newtek_dir 0 (- (strlen newtek_dir) 7))
			)
		)
	)

	(if (NOT (exists newtek_dir))
		(makedir newtek_dir (infos))
	)
	(set @default-dest newtek_dir)
)

(procedure GETPARTS
   (set parts (askoptions (prompt (cat "Please select the portions of the "
                          "LightWave 3D 5.0 Beta software that you would like to install"))
                          (choices (cat "Programs " 	(/ programs_size 1000) "K")
											  (cat "Envelopes " 	(/ envelopes_size 1000) "K")
                                   (cat "Images " 		(/ images_size 1000) "K")
                                   (cat "Motions " 	(/ motions_size 1000) "K")
                                   (cat "Objects " 	(/ objects_size 1000) "K")
                                   (cat "PlugIns " 	(/ plugins_size 1000) "K")
                                   (cat "Previews " 	(/ previews_size 1000) "K")
                                   (cat "PS Fonts " 	(/ psfonts_size 1000) "K")
                                   (cat "Scenes " 		(/ scenes_size 1000) "K")
                                   (cat "Surfaces " 	(/ surfaces_size 1000) "K")
                           (default parts)
                           (help parts_help)))
	)
	(CALCSIZE)
)

(procedure INSTALLCDPARTS
	(set n 0)
	(while (< n num_parts)
		((if (IN parts n)
			(select n
				(;Programs
					(copyfiles  (source  (cat disk1 ":Programs"))
									(dest 	(cat newtek_dir "/Programs"))
									(optional "force")
									(all)
					)
					(copylib (source (cat disk1 ":libs/iffparse.library"))
								(dest "libs:")
								(optional "nofail" "force")
					)
					(copylib (source (cat disk1 ":libs/rexxmathlib.library"))
								(dest "libs:")
								(optional "nofail" "force")
					)
					(copylib (source (cat disk1 ":libs/rexxsupport.library"))
								(dest "libs:")
								(optional "nofail" "force")
					)

				)
				(;Envelopes
					(copyfiles  (source  (cat disk1 ":Envelopes"))
									(dest 	(cat newtek_dir "/Envelopes"))
									(optional "force")
									(all)
					)
				)
				(;Images 
					(copyfiles  (source  (cat disk1 ":Images"))
									(dest 	(cat newtek_dir "/Images"))
									(optional "force")
									(all)
					)
				)
				(;Motions
					(copyfiles  (source  (cat disk1 ":Motions"))
									(dest 	(cat newtek_dir "/Motions"))
									(optional "force")
									(all)
					)
				)
				(;Objects
					(copyfiles  (source  (cat disk1 ":Objects"))
									(dest 	(cat newtek_dir "/Objects"))
									(optional "force")
									(all)
					)
				)
				(;PlugIns
					(if (NOT (IN parts 0))
						(copyfiles  (source  (cat disk1 ":Programs/Plug-Ins"))
										(dest 	(cat newtek_dir "/Programs/Plug-Ins"))
										(optional "force")
										(all)
						)
						(copyfiles  (source  (cat disk1 ":Programs/HIIP_Support"))
										(dest 	(cat newtek_dir "/Programs/HIIP_Support"))
										(optional "force")
										(all)
						)
					)
				)
				(;Previews
					(copyfiles  (source  (cat disk1 ":Previews"))
									(dest 	(cat newtek_dir "/Previews"))
									(optional "force")
									(all)
					)
				)
				(;PS Fonts
					(copyfiles  (source  (cat disk1 ":PsFonts"))
									(dest 	(cat newtek_dir "/PsFonts"))
									(optional "force")
									(all)
					)
				)
				(;Scenes 
					(copyfiles  (source  (cat disk1 ":Scenes"))
									(dest 	(cat newtek_dir "/Scenes"))
									(optional "force")
									(all)
					)
				)
				(;Surfaces
					(copyfiles  (source  (cat disk1 ":Surfaces"))
									(dest 	(cat newtek_dir "/Surfaces"))
									(optional "force")
									(all)
					)
				)
			)
		)
		(set n (+ n 1))
	  )
	)
)

(procedure CALCSIZE
	(set n 0)
	(set size 0)
	(while (< n num_parts)
		(
			(if (IN parts n)
				(select n
					(;Programs
						(set size (+ (+ size programs_size) hiip_size))
					)
					(;Envelopes
						(set size (+ size envelopes_size))
					)
					(;Images 
						(set size (+ size images_size))
					)
					(;Motions
						(set size (+ size motions_size))
					)
					(;Objects
						(set size (+ size objects_size))
					)
					(;PlugIns
						(set size (+ size plugins_size))
					)
					(;Previews
						(set size (+ size previews_size))
					)
					(;PS Fonts
						(set size (+ size psfonts_size))
					)
					(;Scenes 
						(set size (+ size scenes_size))
					)
					(;Surfaces
						(set size (+ size surfaces_size))
					)
				)
			)
			(set n (+ n 1))
		)
	)
)

(procedure SHOWREADME
	(if (askbool (prompt (cat "\n\nThe ReadMe file has been updated with "
											 "new features and bug fixes since the "
											 "last update.  Please read this file "
											 "before using the new software.  Would "
											 "you like to view the ReadMe file now?"))
	
					 (help (cat "The ReadMe file has been updated with "
									"new features and bug fixes since the "
									"last update.  Please read this file "
									"before using the new software."))
					 (choices "Read it Now" "Read it Later"))
		
		(run (cat "run more " newtek_dir slash "readme"))
	)
)

(procedure WARNSIZE
	(message (cat  "There is not enough space on your drive to install "
						"all of the components that you have selected.  Please "
						"deselect some options or make more space on your hard "
						"drive to finish the installation.\n\nClick proceed to "
						"continue..."))
)

(procedure DOSTARTUP
        (copyfiles (prompt "Installing ARexx-Scripts for LightWave 5.0!")
                   (source "LightWave3D:ARexx")
                   (dest   (cat newtek_dir slash "ARexx"))
                   (all)
                   (optional nofail)
        )

        (copyfiles (prompt "Installing ARexx_Examples for LightWave 5.0!")
                   (source "LightWave3D:ARexx_Examples")
                   (dest   (cat newtek_dir slash "ARexx-Examples"))
                   (all)
                   (optional nofail)
        )


	(set start_lines_1 (cat "Assign REXX: " newtek_dir slash "ARexx add\n"))
	(set start_lines_2 (cat "Assign TOASTER: " newtek_dir "\n"))
	(set start_lines_3 (cat start_lines "assign HIIP: " newtek_dir slash
                            "Programs/HIIP_Support\n"))
        (set start_lines_4 (cat "Assign 3D: " newtek_dir "\n"))
        (set total_start_lines (cat start_lines_1 start_lines_2 start_lines_3 start_lines_4))

        (run start_lines_1)
        (run start_lines_2)
        (run start_lines_3)
        (run start_lines_4)

   (startup "LightWave" (command total_start_lines)
                    (help user_startup_help)
                    (prompt (cat "\n\nThe following lines must be added to "
                                 "your user-startup file:\n\n" total_start_lines))
   )
)

(procedure MAKEDIRS
	(if (NOT (exists (cat newtek_dir "/Programs")))
   	 (makedir (cat newtek_dir "/Programs") (infos)))
	(if (NOT (exists (cat newtek_dir "/Envelopes")))
   	 (makedir (cat newtek_dir "/Envelope") (infos)))
	(if (NOT (exists (cat newtek_dir "/Images")))
   	 (makedir (cat newtek_dir "/Images") (infos)))
	(if (NOT (exists (cat newtek_dir "/Motions")))
   	 (makedir (cat newtek_dir "/Motions") (infos)))
	(if (NOT (exists (cat newtek_dir "/Objects")))
   	 (makedir (cat newtek_dir "/Objects") (infos)))
	(if (NOT (exists (cat newtek_dir "/Programs/Plug-Ins")))
   	 (makedir (cat newtek_dir "/Programs/Plug-Ins") (infos)))
	(if (NOT (exists (cat newtek_dir "/Previews")))
   	 (makedir (cat newtek_dir "/Previews") (infos)))
	(if (NOT (exists (cat newtek_dir "/PSFonts")))
   	 (makedir (cat newtek_dir "/PSFonts") (infos)))
	(if (NOT (exists (cat newtek_dir "/Scenes")))
   	 (makedir (cat newtek_dir "/Scenes") (infos)))
	(if (NOT (exists (cat newtek_dir "/Surfaces")))
   	 (makedir (cat newtek_dir "/Surfaces") (infos)))
	(if (NOT (exists (cat newtek_dir "/Programs/HIIP_Support")))
   	 (makedir (cat newtek_dir "/Programs/HIIP_Support") (infos)))
)
;****** Main Program ******

(welcome)
(complete 0)
(set current_disk 1)

(SET_CD_SIZES)

(GETPATH)
(set disk_avail (getdiskspace (cat (getdevice newtek_dir) ":")))
(set size 0)
(GETPARTS)
(while (> size disk_avail)
	(
		(WARNSIZE)
		(GETPARTS)
	)
)

(MAKEDIRS)

(INSTALLCDPARTS)

(DOSTARTUP)
(complete 95)
;(SHOWREADME)

(complete 100)

(makeassign "Lightwave3D")
(set x 0)
(while (< x 20 )
  (makeassign (cat "LightWaveDisk" x))
  (set x (+ x 1) )
)
