; MPMorph - Amiga Morphing program
; Copyright (C)  1993-96 Mark John Paddock

; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; any later version.

; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.

; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

; mpaddock@cix.compulink.co.uk

; This is the script to install MPMorph
; $VER: MPMorph-Install 4.8 (14.3.97)

(complete 1)

; determine if in place or new drawer install
(Set #InPlace
	(askchoice
		(prompt "Where do you want to install?\n\n"
				"If you have unpacked MPMorph 4.8 directly to the place you "
				"wish to run it from then select 'In Place', otherwise select 'New Drawer' "
				"to copy the relevant files to a new drawer")
		(help @askchoice-help)
		(choices "New Drawer" "In Place")
		(default 1)
	)
)

(complete 2)

; Ask for destination if not in place
(if (NOT #InPlace)
	(set #InstallDir
		(askdir
			(prompt "Where do you want to install MPMorph 4.8\n\n"
					"A new drawer named 'MPMorph' will be created in the "
					"selected directory and the MPMorph files copied there")
			(help @askprompt-help)
			(default "Work:")
		)
	)
)

(complete 3)

;Check where to install libraries
(Set #LibChoice
	(askchoice
		(prompt "Where do you want to install the libraries?\n\n"
			"You can choose to install the libraries required by MPMorph "
			"in the MPMorph directory, "
			"your LIBS: directory, or some other directory.")
		(help @askchoice-help)
		(choices "In Place" "LIBS:" "Elsewhere")
		(default 1)
	)
)

(complete 4)

(if (= #LibChoice 2)
	(Set #LibDir
		(askdir
			(prompt "Select directory in which to install the MPMorph libraries")
			(help @askdir-help)
			(default "LIBS:")
		)
	)
)

(complete 5)

; Set up directory names
(if #InPlace
	(Set #DestDir (expandpath ""))
)
(if (NOT #InPlace)
	(Set #DestDir 
  		(tackon #InstallDir "MPMorph")
	)
)
(if (= #libchoice 0)
	(Set #LibDir #DestDir)
)
(if (= #libchoice 1)
	(Set #LibDir "LIBS:")
)
(set #GuiDir
	(tackon #DestDir "Gui")
)
(set #IncludeDir
	(tackon #DestDir "include")
)
(Set #RexxDir 
	(tackon #DestDir "Rexx")
)
(Set #CursorDir 
	(tackon #DestDir "Cursor")
)
(Set #BrushDir 
	(tackon #DestDir "Brush")
)
(Set #TutDir 
	(tackon #DestDir "Tutorial")
)
(Set #HTMLDir 
	(tackon #DestDir "HTML")
)
(Set #DocsDir
	(tackon #DestDir "Docs")
)
(set @default-dest 
	#DestDir
)

; Determine machine config
(Set #Has020
	(=
		(database "cpu")
		68020
	)
)
(Set #Has030
	(=
		(database "cpu")
		68030
	)
)
(Set #Has040
	(= 
		(database "cpu")
		68040
	)
)
(Set #Has060
	(= 
		(database "cpu")
		68060
	)
)
(Set #HasFPU
	(<>
		(database "fpu")
		"NOFPU"
	)
)

(Set #CPU 0)
(if #Has020
	(Set #CPU 1)
)
(if #Has030
	(Set #CPU 1)
)
(if (AND #Has020 #HasFPU)
	(Set #CPU 2)
)
(if (AND #Has030 #HasFPU)
	(Set #CPU 2)
)
(if (AND #Has040 #HasFPU)
	(Set #CPU 3)
)
(if #Has060
	(Set #CPU 4)
)

; Check choice of program to install
(set #CPU
	(askchoice
		(prompt "Install which version?")
		(help "There are five versions of the MPRender program. "
				"The first requires just a 68000. "
				"The second requires a 68020. "
				"The third requires both a 68020 or 68030 CPU with a 68881 or 68882 FPU. "
				"The fourth requires a 68040. "
				"The last requires a 68080.\n\n"
				@askchoice-help)
		(choices
			"68000"
			"68020"
			"68020/030/68881/2"
			"68040"
			"68060"
		)
		(default #CPU)
	)
)

(if (= #CPU 4)
	(
	(Set #SrcImage "libs/MPImage.library.060")
	(Set #SrcRender "MPRender.060")
	(Set #Spatch 1)
	(Set #ImagePatch "libs/MPImage.library.881")
	(Set #RenderPatch "MPRender.881")
	)
)
(if (= #CPU 3)
	(
	(Set #SrcImage "libs/MPImage.library.040")
	(Set #SrcRender "MPRender.040")
	(Set #Spatch 1)
	(Set #ImagePatch "libs/MPImage.library.881")
	(Set #RenderPatch "MPRender.881")
	)
)
(if (= #CPU 2)
	(
	(Set #SrcImage "libs/MPImage.library.881")
	(Set #SrcRender "MPRender.881")
	(Set #Spatch 0)
	)
)
(if (= #CPU 1)
	(
	(Set #SrcImage "libs/MPImage.library.020")
	(Set #SrcRender "MPRender.020")
	(Set #Spatch 1)
	(Set #ImagePatch "libs/MPImage.library.000")
	(Set #RenderPatch "MPRender.000")
	)
)
(if (= #CPU 0)
	(
	(Set #SrcImage "libs/MPImage.library.000")
	(Set #SrcRender "MPRender.000")
	(Set #Spatch 0)
	)
)
(Set #SrcRenderI (cat #SrcRender ".inf"))
(Set #DestRender "MPRender")
(Set #DestRenderI	(cat #DestRender ".info"))
(Set #SrcGui "libs/MPGui.library")
(Set #DestGui "MPGui.library")
(Set #DestImage "MPImage.library")
(Set #Temp "t:MPMorph.temp")

(complete 6)

(if (NOT #InPlace)
	(Set #CopyGui
		(askbool
			(prompt "Copy GUI files?\n\n"
					"Select 'Yes' to copy the GUI files. "
					"These files may then be changed to allow you to configure the user interface. "
					"Select 'No' if you do not wish to change the interface.")
			(help @askbool-help)
			(default 0)
		)
	)
)

(complete 7)

(if (NOT #InPlace)
	(Set #CopyTut
		(askbool
			(prompt "Copy Tutorial files?\n\n"
					"A short tutorial and some image files are included. "
					"Select 'Yes' to copy the Tutorial files. "
					"Select 'No' if you do not wish to install the Tutorial.")
			(help @askbool-help)
			(default 1)
		)
	)
)

(complete 8)

(if (NOT #InPlace)
	(Set #CopyDoc
		(askbool
			(prompt "Copy Programmer files?\n\n"
					"Programmer docs and includes are included for MPGui.library and MPImage.library. "
					"Select 'Yes' to copy the docs/includes files. "
					"Select 'No' if you do not wish to install the docs/includes.")
			(help @askbool-help)
			(default 0)
		)
	)
)

(complete 9)

(Set #HasBrowser
	(askbool
		(prompt "Do you have a Web Browser?\n\n"
				"A Web Browser can be used to view the HTML docs.")
		(help @askbool-help)
		(default 1)
	)
)

(complete 10)

(if (AND (NOT #InPlace) #HasBrowser)
	(Set #CopyHTML
		(askbool
			(prompt "Copy .html files?\n\n"
					"Full Documentation is also included in .html format. "
					"You will need a browser to read these files. "
					"Select 'Yes' to copy the .html files. "
					"Select 'No' if you do not wish to install the .html files.")
			(help @askbool-help)
			(default 1)
		)
	)
	(Set #CopyHTML 0)
)

(complete 11)

(if (AND #HasBrowser (OR #InPlace #CopyHTML))
	(set #Browser
		(askfile
			(prompt "Where is your Browser?\n"
					"The exact location and name of your Browser is required "
					"to enable a script to be set up to view the .html documentation.")
			(help @askfile-help)
			(default "")
		)
	)
)

(complete 12)

; Create destination directory
(if (NOT #InPlace)
	(makedir
		#DestDir 
		(infos)
	)
)

(complete 13)

(if
	(askbool
		(prompt "Do you have djpeg and cjpeg?\n\n"
				"Select 'Yes' if you have cjpeg and djpeg and you wish to "
				"use them to load and save jpeg files.")
		(help @askbool-help)
	  	(default 0)
	)
	(
		(makedir
			"ENV:MPImage"
		)
		(makedir
			"ENVARC:MPImage"
		)
		(set #cjpeg
			(askstring
				(prompt "Enter your command to run cjpeg\n\n"
						'"%s" should be used to in place of the input and '
						"output files")
				(help @askstring-help)
				(default 'cjpeg "%s" >"%s"')
			)
		)
		(textfile
			(dest "ENV:MPImage/cjpeg")
			(append #cjpeg)
		)
		(textfile
			(dest "ENVARC:MPImage/cjpeg")
			(append #cjpeg)
		)
		(set #djpeg
			(askstring
				(prompt "Enter your command to run djpeg\n\n"
						'"%s" should be used to in place of the input and '
						"output files")
				(help @askstring-help)
				(default 'djpeg "%s" >"%s"')
			)
		)
		(textfile
			(dest "ENV:MPImage/djpeg")
			(append #djpeg)
		)
		(textfile
			(dest "ENVARC:MPImage/djpeg")
			(append #djpeg)
		)
	)
)

(complete 14)

(if
	(askbool
		(prompt "Do you have pngtopnm and pnmtopng?\n\n"
				"Select 'Yes' if you have pngtopnm and pnmtopng and you wish to "
				"use them to load and save PNG files.")
		(help @askbool-help)
	  	(default 0)
	)
	(
		(makedir
			"ENV:MPImage"
		)
		(makedir
			"ENVARC:MPImage"
		)
		(set #pnmtopng
			(askstring
				(prompt "Enter your command to run pnmtopng\n\n"
						'"%s" should be used to in place of the input and '
						"output files")
				(help @askstring-help)
				(default 'pnmtopng "%s" >"%s"')
			)
		)
		(textfile
			(dest "ENV:MPImage/pnmtopng")
			(append #pnmtopng)
		)
		(textfile
			(dest "ENVARC:MPImage/pnmtopng")
			(append #pnmtopng)
		)
		(set #pngtopnm
			(askstring
				(prompt "Enter your command to run pngtopnm\n\n"
						'"%s" should be used to in place of the input and '
						"output files")
				(help @askstring-help)
				(default 'pngtopnm "%s" >"%s"')
			)
		)
		(textfile
			(dest "ENV:MPImage/pngtopnm")
			(append #pngtopnm)
		)
		(textfile
			(dest "ENVARC:MPImage/pngtopnm")
			(append #pngtopnm)
		)
	)
)

(complete 20)

; Copy for in place installation
(if #InPlace
	(
	(if #Spatch
		(run
			(cat "spatch -o" #DestRender " -p" #SrcRender ".pch " #RenderPatch)
		)
		(copyfiles
			(source #SrcRender)
			(dest #DestDir)
			(newname #DestRender)
		)
	)
	(copyfiles
		(source #SrcRenderI)
		(dest #DestDir)
		(newname #DestRenderI)
	)
	(if #Spatch
		(
			(run
				(cat "spatch -o" #Temp " -p" #SrcImage ".pch " #ImagePatch)
			)
			(copylib
				(source #Temp)
				(dest #LibDir)
				(newname #DestImage)
			)
			(delete #temp)
		)
		(copylib
			(source #SrcImage)
			(dest #LibDir)
			(newname #DestImage)
		)
	)
	(copylib
		(source #SrcGui)
		(dest #LibDir)
		(newname #DestGui)
	)
	)
)


; Copy and rename for new drawer, delete old versions if present
(if (NOT #InPlace)
	(copyfiles
		(prompt "Copying Non CPU specific files")
  		(help @copyfiles-help)
		(source "")
		(dest #DestDir)
		(choices "MPMorph" "EditPrefs" "MPImage" "MPMorph-prefs" "MPRender-prefs"
					"RunMPGui" "ConvertMPImage" "EdgePoints" "RunMPIndex" 
					"Docs.Index"
					"MPMorph-rexx" "MPRender-rexx" "EditPrefs-rexx"
					"MPMorph.guide" "MPImage.guide"
					"MPRender.guide" "RunMPIndex.guide" "EdgePoints.guide"
					"Preview.guide" "EditPrefs.guide" "Tutorial.guide"
					"MPGui.guide" "Readme.unix")
		(infos)
		(confirm)
	)
)

(complete 30)

; Copy for new drawer
(if (NOT #InPlace)
	(
		(if #Spatch
			(
				(run
					(cat "spatch -o" #Temp " -p" #SrcRender ".pch " #RenderPatch)
				)
				(copyfiles
					(source #Temp)
					(dest #DestDir)
					(newname #DestRender)
				)
			)
			(copyfiles
				(source #SrcRender)
				(dest #DestDir)
				(newname #DestRender)
			)
		)
		(copyfiles
			(source #SrcRenderI)
			(dest #DestDir)
			(newname #DestRenderI)
		)
		(if #Spatch
			(
				(run
					(cat "spatch -o" #Temp " -p" #SrcImage ".pch " #ImagePatch)
				)
				(copylib
					(source #Temp)
					(dest #LibDir)
					(newname #DestImage)
				)
				(delete #temp)
			)
			(copylib
				(source #SrcImage)
				(dest #LibDir)
				(newname #DestImage)
			)
		)
		(copylib
			(source #SrcGui)
			(dest #LibDir)
			(newname #DestGui)
		)
	)
)

(complete 40)

(if (AND (NOT #InPlace) #CopyHTML)
	(
		(makedir #HTMLDir)
		(complete 41)
		(copyfiles
			(prompt "Copying .html files")
			(help @copyfiles-help)
			(source "HTML")
			(dest #HTMLDir)
			(all)
		)
		(complete 47)
		(copyfiles
			(prompt "Copying View_HTML icon")
			(help @copyfiles-help)
			(source "")
			(dest #DestDir)
			(choices "View_HTML.info")
		)
		(complete 48)
		(copyfiles
			(prompt "Copying Main HTML file")
			(help @copyfiles-help)
			(source "")
			(dest #DestDir)
			(choices "MPMorph.html")
		)
	)
)

(complete 49)

(set #MPhtml
	(tackon #DestDir "MPMorph.html")
)

(if #HasBrowser
	(textfile
		 (dest (tackon #DestDir "View_HTML"))
		 (append #Browser ' "file://localhost/' #MPhtml'"')
	)
)

(complete 50)

(makedir "ENVARC:MPMorph")

(complete 51)

(copyfiles
	(prompt "Copying Icons to ENVARC:")
	(help @copyfiles-help)
	(source "")
	(dest "ENVARC:MPMorph")
	(choices "ENV/MPMorph/def_points.info"
				"ENV/MPMorph/def_pic.info"
				"ENV/MPMorph/def_prefs.info")
	(confirm)
)

(complete 60)

(makedir "ENV:MPMorph")

(complete 61)

(copyfiles
	(prompt "Copying Icons to ENV:")
	(help @copyfiles-help)
	(source "")
	(dest "ENV:MPMorph")
	(choices "ENV/MPMorph/def_points.info"
				"ENV/MPMorph/def_pic.info"
				"ENV/MPMorph/def_prefs.info")
	(confirm)
)

;
;(startup "MPMorph"
;	(prompt "Adding assign MPMorph: to " DestDir " in s:user-startup")
;	(help @startup-help)
;	(command "Assign MPMorph: " DestDir)
;)
;
;(makeassign "MPMorph" DestDir)

(complete 70)

(if #InPlace
	(
		(complete 100)
		(exit)
	)
)

(makedir
	#RexxDir
)

(complete 75)

(copyfiles
	(prompt "Copying example Rexx scripts")
	(help @copyfiles-help)
	(source "Rexx")
	(dest #RexxDir)
	(all)
	(confirm)
)

(complete 80)

(if #CopyGui
	(
		(makedir #CursorDir)
		(copyfiles
			(prompt "Copying Pointer files")
			(help @copyfiles-help)
			(source "Cursor")
			(dest #CursorDir)
			(all)
			(confirm)
		)
		(complete 55)
		(makedir #BrushDir)
		(copyfiles
			(prompt "Copying Gadget files")
			(help @copyfiles-help)
			(source "Brush")
			(dest #BrushDir)
			(all)
			(confirm)
		)
	)
)

(complete 85)

(if #CopyTut
	(
		(makedir #TutDir)
		(copyfiles
			(prompt "Copying Tutorial files")
			(help @copyfiles-help)
			(source "Tutorial")
			(dest #TutDir)
			(all)
			(confirm)
		)
	)
)

(complete 90)

(copyfiles
	(prompt "Copying gui scripts")
	(help @copyfiles-help)
	(source "Gui")
	(dest #GuiDir)
	(all)
)

(complete 95)

(if #CopyDoc
	(
		(makedir #DocsDir)
		(copyfiles
			(prompt "Copying Docs")
			(help @copyfiles-help)
			(source "Docs")
			(dest #DocsDir)
			(all)
		)
		(makedir #IncludeDir)
		(copyfiles
			(prompt "Copying Includes")
			(help @copyfiles-help)
			(source "Include")
			(dest #IncludeDir)
			(all)
		)
	)
)

(complete 100)
