; Installation script for NEMAC IV Version 1.0

(complete 0)
(set disk0 "NEMAC_4_Disk_1:i")
(set instarc "NEMAC_4_Disk_1:inst_arc.lha")
(set dtem "T:NEMAC/i")
(set lhcom (cat (cat "NEMAC_4_Disk_1:lhx/lhx x " instarc) " T:NEMAC/"))
(set diskx "NEMAC_4_Disk_%ld")
(set idir "i")
(set nemacname "NEMAC_4")
(set nemacdirn "NEMAC_4")
(set nemacdocd "Deutsch-LiesMich.guide")
(set nemacdoce "English-ReadMe.guide")
(set nemacrmfd "Deutsch-LiesMichErst.txt")
(set nemacrmfe "English-ReadMeFirst.txt")
(set nemacconf ".config")
(set mazename "maze.cld")
(set mazex "maze.00")
(set mazebase "maze")
(set mazecnt 8)
(set nemacappend "append")

(set langtext "Please select your language to run the Installer.\n\nBitte wählen Sie Ihre Sprache für den Installer aus.\n")

(set language (askchoice (prompt langtext) (help "So what did I say?") (choices "English" "Deutsch")))

(if language
	(
		(set t2 "Ich habe die folgende Systemkonfiguration gefunden:\n\n")
		(set t3 "\nSie benötigen Amiga OS 2.0 oder besser, um dieses Programm starten zu können.\n")
		(set t4 "\nDas Programm benötigt eine MC68020 CPU oder besser.\n")
		(set t5 "\nDas Programm benötigt mindestens 1.7MB freien Speicher. Ich nehme an, daß Sie eine Applikation laufen haben...\n")
		(set t6 "Die Installation wird abgebrochen.")
		(set t7 "Systemkonfiguration erlaubt nicht das Laufenlassen des Spiels.")
		(set t8 "\nDie Konfiguration ist ausreichend.")
		(set t9 "Ich beginne jetzt mit der Installation.\nMöchten sie ...")
		(set t10 "Bitte wählen Sie, welche Dokumentation Sie kopieren möchten.")
		(set t11 "Bitte wählen aus, wo das Verzeichnis \"NEMAC_4\" angelegt werden soll.")
		(set t12 "Bitte wählen Sie nun aus, wo das Verzeichnis \"NEMAC_4\" angelegt werden soll.\n\nSollten Sie eine bestehende ")
		(set t12 (cat t12 "Version updaten wollen (zum Beispiel eine Demoversion, um die saved_games zu behalten), so wechseln "))
		(set t12 (cat t12 "Sie bitte einfach in das verzeichnis, in dem sich das Verzeichnis \"NEMAC_4\" befindet."))
		(set t13 "Erstelle Verzeichnis \"Docs\"...")
		(set t14 "Erstelle das Verzeichnis \"NEMAC_4\"...")
		(set t15 "Die Installation beginnt jetzt.")
		(set t17 "Kopiere Programm...")
		(set t18 "Kopiere Dokumentation")		
		(set t19 "Kopiere .config-File")
		(set t20 "Ihre maze.cld-Version ist neuer!\n\nIch habe sie nicht kopiert.")
		(set t21 "Bitte Diskette # %ld einlegen")
		(set t22 "Kopiere \"maze\"-Teil # %ld")
		(set t23 "Kopiere \"append\" nach T:")
		(set t25 "Lesen Sie bitte unbedingt vor dem ersten Start die komplette Dokumentation durch!\n\nIn diesem File sind viele wichtige ")
		(set t25 (cat t25 "Hinweise, die Sie benötigen werden, um das Spiel zu spielen!"))
		(set t26 "Ein Fehler trat beim Zusammenfügen des maze.cld auf. Bitte überprüfen Sie, ob Sie genügend freien Platz auf der Partition ")
		(set t26 (cat t26 "haben und ob alle Teilfiles korrekt kopiert wurden."))
		(set t27 "Das Archiv wird in T: entpackt.")
		(set t28 "Die \"Maze\"-Teile werden nun zusammengefügt. Sollte hier ein Fehler auftreten (Speicherplatz) so beheben Sie bitte den Fehler ")
		(set t28 (cat t28 "und installieren Sie erneut."))
		(set t29 "Die kopierten Files werden aus dem RAM entfernt.")
		(set cht1 "normal installieren")
		(set cht2 "Eine bestehende Installation (Demo) updaten.")

		(set h2 "Es wird die Dokumentation in der ausgewählten Sprache kopiert. Sie finden Sie im Verzeichnis \"doc\" als amigaguide-File.")
		(set h3 "Ihre Systemkonfiguration wird überprüft, ob sie ausreicht, um das Spiel starten zu können.")
		(set h4 "Um eine bestehende NEMAC IV Installation zu updaten, müssen Sie das korrekte Verzeichnis angeben.\n\n")
		(set h4 (cat h4 "Wenn Sie trotzdem weitermachen und sich im falschen Verzeichnis befinden, wird automatisch eine Vollinstallation"))
		(set h4 (cat h4 " in diesem Verzeichnis durchgeführt."))

	)
	(
		(set t2 "I found the following system configuration:\n\n")
		(set t3 "\nYou need Amiga OS 2.0 or better to run the program.\n")
		(set t4 "\nThe program requires a MC68020 CPU or better.\n")
		(set t5 "\nThe program requires a minimum of 1.7MB free RAM to run. Assuming that a application is running...\n")
		(set t6 "Installation is aborted.")
		(set t7 "System configuration doesn't allow running the game.")
		(set t8 "\nYour configuration is suitable.")
		(set t9 "Installation starts now.\nDo you want to ...")
		(set t10 "Please select the documentation language you prefer.") 
		(set t11 "Please choose the location where the directory \"NEMAC_4\" will be created.")	
		(set t12 "Please select now the directory where the directory \"NEMAC_4\" should be created.\n\nIf you already have a version of NEMAC IV and ")
		(set t12 (cat t12 "and want to update this version "))
		(set t12 (cat t12 "(for example a demo to keep the saved_games), then please select the directory where the directory \"NEMAC_4\" is located.")) 
		(set t13 "Creating directory \"Docs\"...")
		(set t14 "Creating directory \"NEMAC_4\"...")
		(set t15 "The installation starts now.")
		(set t17 "Copying program...")
		(set t18 "Copying documentation")
		(set t19 "Copying .config-file")
		(set t20 "Your maze.cld-version is newer.\n\nI haven't copied it.")
		(set t21 "Please insert disk # %ld")
		(set t22 "Copying \"maze\"-part # %ld")
		(set t23 "Copying \"append\" to T:")
		(set t25 "We strongly recommend you to read the complete documentation before starting!\n\nIn this file there are many important ")
		(set t25 (cat t25 "hints that you may need to play the game..."))
		(set t26 "An error occured joining the maze.cld file. Pleas make sure you have enough free space on your partition and that all partial maze ")
		(set t26 (cat t26 "were copied into the directory."))
		(set t27 "The archive is unpacked in T:")
		(set t29 "The copied files are now removed from your memory.")
		(set t28 "The \"maze\"-parts are now joined together. If any error occurs (diskspace), please install completely again.")
		(set cht1 "install normally")
		(set cht2 "update an existing installation (demo)")

		(set h2 "The documentation in the selected language will be copied into the directory \"doc\" as amigaguide-File.")
		(set h3 "You system configuration is checked to see you can run the game.")
		(set h4 "For updating an existing NEMAC IV installation, you have to select the proper directory.\n\n")
		(set h4 (cat h4 "If you continue although you are in a wrong directory, I will automatically do a complete installation."))           

	)
)
		
(set cputype (+ (database ("cpu"))))
(set chipmem (+ (database ("graphics-mem"))))
(set totalmem (+ (database ("total-mem"))))
(set fastmem (- totalmem chipmem))
(set osversion (/ (getversion) 65536))

(set showos ">3.1")
(if (< osversion 39) (set showos "2.0"))
(if (< osversion 36) (set showos "<2.0"))
(if (= osversion 39) (set showos "3.0"))
(if (= osversion 40) (set showos "3.1"))

(set text1 ("OS Version  :  %s\nCPU  :  %ld\nChip Memory  :  %ld\nFast Memory  :  %ld\n" showos cputype chipmem fastmem))

(set text (cat t2 text1))
(set abortcheck 0)
(if (< osversion 36)
	(	
		(set text (cat text t3))
	 	(set abortcheck 1)
	 )
)


(if (< cputype 68020)
	(	(set text (cat text t4))
	 	(set abortcheck 1)
	 ))

(set memfree (if (< chipmem fastmem) fastmem chipmem))
(if (< memfree 1700000) (set text (cat text t5)))

(if abortcheck
	(
		(set text (cat text t6))
		(message text (help h3))
		(abort t7)
	)
)		

(complete 5)
(set text (cat text t8))
(message text (help h3))

(set doclang (askoptions (prompt t10) (help h2) (choices "English" "Deutsch") (default (+ language 1))))

(message t12)
(set dirname (askdir (prompt (if update t12 t11)) (help @askdir-help) (default @default-dest) (disk)))
(set @default-dest dirname)

(message t15)
(complete 9)
(run lhcom (prompt t27))
(complete 10)
(set ddir (tackon dirname nemacdirn))
(if (exists ddir)
	(set nop 1)
	(makedir ddir (prompt t14) (help @makedir-help) (infos)))  

(set ddir (tackon dirname nemacdirn))
(set nemac4name (tackon dtem nemacname))

(copylib (prompt t17) (source nemac4name) (dest ddir) (infos) (help @copylib-help))

(complete 20)

(set docdir (tackon ddir "Docs"))
(if doclang
	(if (exists docdir)
		(set nop 1)
		(makedir docdir (prompt t13) (help @makedir-help) (infos))
	)
)

(set docd (tackon ddir "Docs/"))
(set bdoce (tackon dtem nemacdoce))
(set bdocd (tackon dtem nemacdocd))

(if (BITAND doclang 1)	
	(copyfiles (prompt t18) (source bdoce) (dest docd) (infos) (help @copyfiles-help))
)

(if (BITAND doclang 2)	
	(copyfiles (prompt t18) (source bdocd) (dest docd) (infos) (help @copylib-help))
)

(complete 30)

(if (exists (tackon ddir nemacconf))
	(rename (tackon ddir nemacconf) (cat ".old_" nemacconf)))

(copyfiles (prompt t19) (source (tackon dtem nemacconf)) (dest ddir) (infos) (help @copyfiles-help))

(set wok 0)
(set cnt 1)
(set cmmaze (tackon ddir mazename))
(set diskmaze (tackon dtem (cat mazex "1")))

(set docop 1)
(if (exists cmmaze)
	(if (earlier diskmaze cmmaze) (set docop 0)))
(if docop
(
	(while (= wok 0)
	(
		(set acdisk (diskx cnt))
		(set acmaze ("%s%ld" mazex cnt))
		(if (= cnt 1) (set nop 1)
			(askdisk (dest acdisk) (prompt (t21 cnt)) (help @askdisk-help)))
		(set acdir (tackon (cat acdisk ":") idir))
		(copyfiles
			(prompt (t22 cnt))
			(source (tackon acdir acmaze))
			(dest ddir)
			(infos)
			(help @copyfiles-help))
			
		(if (= cnt mazecnt) (set wok 1))
		(set cnt (+ cnt 1))
		
		(set com1 (* 60 (- cnt 1)))
		(set com1 (/ com1 mazecnt))
		(set com1 (+ com1 30))
		(complete com1)
	))
	
	(set cmdl ("T:NEMAC/i/%s %s %ld %ld %s" nemacappend (tackon ddir mazebase) mazecnt 3 (tackon ddir mazename)))
	(message t28)
	(if (run cmdl) (abort t26))
	(complete 95)
)	
(message t20))

(delete (tackon dtem nemacconf) (prompt t29))
(delete (tackon dtem nemacdocd) (prompt t29))
(delete (tackon dtem nemacdoce) (prompt t29))
(delete (tackon dtem (cat nemacdoce ".info")) (prompt t29))
(delete (tackon dtem (cat nemacdocd ".info")) (prompt t29))
(delete (tackon dtem nemacappend) (prompt t29))
(delete (tackon dtem nemacname) (prompt t29))
(delete (tackon dtem (cat nemacname ".info")) (prompt t29))
(delete dtem (prompt t29))

(complete 95)
(message t25)
(complete 100)



