(if (< (/ @installer-version 65536) 43)
		(abort "You need new installer!") )

(set cpu (database "cpu"))
(set muiver (/ (getversion "mui:libs/muimaster.library") 65536))
(set textfver (/ (getversion "sys:classes/gadgets/textfield.gadget") 65536))
(set nlistver (/ (getversion "mui:libs/mui/nlist.mcc") 65536))

(set defbrowser "WORK:IBrowse/IBrowse")

(set cpu (database "cpu"))
(set #cpu -1)
(set #badcpu 0)
(if (= cpu "68020") (set #cpu 0))
(if (= cpu "68030") (set #cpu 0))
(if (= cpu "68040") (set #cpu 2)) 
(if (= cpu "68060") (set #cpu 2))
(set fpu (database "fpu"))
(if (= #cpu 0) (if (= fpu "68881") (set #cpu 1)))
(if (< #cpu 0) ((set #badcpu 1) (set #cpu 0)))

(set #povdir (if (exists "POVRAY3:" (noreq)) ("POVRAY3:") ("") )) 

; (set #badcpu 1)
; (set muiver 0)
; (set nlistver 0)
; (set textfver 0)

(if #badcpu
	(if (= 0 (askbool (prompt "Do you have 68020 or better?")
					(default 0)
					(help "The installer detected, that you have processor worse than 68020."
							" Framsticks application requires 68020 or better.")
			))
			(abort "Framsticks can't work on your system")
	)
)

(set #missing "")

(if (< muiver 19)	(set #missing (cat #missing "\n*   MUI system v3.8 (C) Stefan Stuntz  \n  (latest version on aminet: dev/mui/mui38usr.lha")))
(if (< textfver 3) (set #missing (cat #missing "\n*   Textfield.gadget v3 (C) Mark Thomas\n  (latest version on aminet: dev/gui/textfield.lha")))
(if (< nlistver 19) (set #missing (cat #missing "\n*   NList.mcc v19 (C) Gilles Masson    \n  (latest version on aminet: dev/mui/MCC_NList0.84.lha")))

(if (<> "" #missing)
	(if (= 0 (askbool (prompt
			(cat "You dont have following libraries:\n"
				  #missing
					"\n\nDo you want to continue installation?")
				)
				(help "The listed components are required to run Framsticks.\n"
						"You can continue installation and add these libraries later.\n"
						"(all the files are available on Aminet)"
				)
			)
		)
		(abort "Some files are missing")
	)
)

;(set @default-dest "ram:")

(set #makedirhere (askdir (prompt "Where do you want to install Framsticks"
			"\n(directory 'Framsticks' will be created here)")
					(help @askdir-help)
     		       (default @default-dest)
               )  
)

(set @default-dest (tackon #makedirhere "Framsticks"))

(makedir @default-dest (infos))

(set #cpu (askchoice (choices "[2p68020" "68020+FPU" "68040" )
			 (prompt "You can install a version optimized for certain processor type. What processor do you own?")
	                 (help   #askcpu)
          		 (default #cpu)
	  )
)

(set #xtra-doc 0)
(set #xtra-examples 1)
(set #xtra-snd 2)
(set #xtra-anim 3)
(set #xtra-pov 4)

(set #extras (askoptions
					(prompt "Select which extra files would you like to install")
					(choices "[2pHTML documentation"
					"Example species" "Sounds" "Transfer Animation"
					"POV-Ray Files")
								(help 
					"Note: None of these files are required to run Framsticks. "
					"You can install it later by hand if needed.\n\n"
					"HTML Documentation - you need a HTML browser to use this\n"
					"Sounds and Transfer Animation - for your eyes and ears pleasure\n"
					"POV-Ray files - needed if you want to use POV Export function (available for registered users)\n"
								)
					(default (if (= "" #povdir) 47 63 ) )
				)
)

(set #whaticon (askchoice (choices "[2p2:1 resolution (PAL,NTSC)"
												"1:1 resolution (VGA)")
			 (prompt "Which icon should be installed?")
	                 (help "")
          		 (default 0)
	  )
)

(if (in #extras 3)
(set #whatanim (askchoice
						(prompt "Which transfer animation should be installed?")
						(choices "[2pSmall (good for PAL,NTSC)" "Big (good for high resolution)")
						(help "")
						(default #whaticon)
	  )
))

(if (in #extras 4)
 (
	(if (= "" #povdir)
		(set #povdir
			(askdir (prompt "You wanted to install POV-Ray files. "
					"Where is your POV-Ray directory?")
			(help (cat "In order to work, POV-Ray files will be copied to "
					"'include' directory of your POV-Ray installation\n\n"
					"Proceed without selection, if you don't want to install these files\n\n" @askdir-help))
			(disk) (default "")
			)
		)
	)
	(if (= "" #povdir)
		((message "\nPOV-Ray files installation cancelled!")
		 (set #extras (bitand #extras 47))
		)
	)
 )
)

(if (in #extras 0)
 (set defbrowser
	(askfile (prompt "Select your favorite HTML browser for Framsticks documentation")
			(help "The program you select will be launched when you click on documentation icon. A browser that supports frames is recommended but not necessary.")
			(default defbrowser)
	)
 )
)

(copyfiles 
	(source (select #cpu "Framsticks.020" "Framsticks.FPU" "Framsticks.040"))
	(dest @default-dest) (newname "Framsticks")
	(prompt "Copying main executable") (confirm) (help @copyfiles-help)
)

(copyfiles (source (select #whaticon "files/hires-icon.info" "files/vga-icon.info"))
	(dest @default-dest) (newname "Framsticks.info")
	(prompt "Copying program icon") (confirm) (help @copyfiles-help)
)

(copyfiles (source "framsticks.recent")
	(dest @default-dest)
	(prompt "Copying configuration file") (confirm) (help @copyfiles-help)
)

(copyfiles (source "") (pattern "#?.sim")
	(dest @default-dest)
	(prompt "Copying simulator settings") (confirm) (help @copyfiles-help)
)

(if (in #extras 0)(

(copyfiles (source "") (choices "docs") (dest @default-dest) (infos)
(prompt "Copying documentation") (confirm) (help @copyfiles-help))

(tooltype (prompt "Setting pathname of your HTML browser") (help "")
	(dest "docs/doc_index.html")
	(setdefaulttool defbrowser))

))

(if (in #extras 1)
(copyfiles (source "species") (all) (dest (tackon @default-dest "species"))
(prompt "Copying example species") (confirm) (help @copyfiles-help)
))

(if (in #extras 2)
(copyfiles (source "sounds") (all) (dest (tackon @default-dest "sounds"))
(prompt "Copying sound files") (confirm) (help @copyfiles-help)
))

(if (in #extras 3)
(copyfiles (source (select #whatanim "files/small-transferanim" "files/big-transferanim"))
(dest @default-dest) (newname "def_TransferAnimation") (infos) 
(prompt "Copying transfer animation") (confirm) (help @copyfiles-help)
))

(if (in #extras 4)
((set #povinc (tackon #povdir "include"))
(if (<> 2 (exists #povinc)) (makedir #povinc))
(copyfiles (source "files") (choices "alife.inc" "alife2.inc")
		(dest #povinc)
	(prompt "Copying POV-Ray files") (confirm) (help @copyfiles-help))
))

(set #endmessage
 "\nAuthors of Framsticks wish you a lot of fun with this program!"
)

(if (<> "" #missing)
	(set #endmessage
	(cat #endmessage "\n\n...and don't forget to install missing files...\n"
		 #missing
		"\n\nAny newer version is of course OK"
		))
)

(exit #endmessage)
