;
; Script to install MidiTracker
;
; (VERY important: tooltype-values of LANGUAGE must be lower-case !!!
;  e.g. use LANGUAGE=deutsch instead of LANGUAGE=Deutsch !!!)
;


(set @default-dest "RAM:")


; Language codes:
;
;   1  English
;   2  Deutsch
;   4  Dansk
;   8  Español
;  16  Français
;  32  Italiano
;  64  Nederlands
; 128  Norsk
; 256  Português
; 512  Svenska


(set default_lang 0) ; misuse variable as a flag, for later to check



; == German strings =====================================================

(if (= @language "deutsch")
(
(set default_lang 2)

(set #bad-kick "Sie benötigen mindestens Kickstart 2.04 für ReqChange")
(set #which-language "Welche Sprachen sollen installiert werden?")

(set #intro (cat
"MidiTracker Installation\n"
"~~~~~~~~~~~~~~~~~~~~~~~~\n\n"
"Dieser Vorgang wird das MidiTracker Softwarepaket "
"auf Ihrer Festplatte installieren.\n\n"
"Um das Programm nur kurz auszuprobieren, müssen Sie es "
"nicht unbedingt installieren - starten Sie es einfach!\n\n"
"MidiTracker ist (c) 1996-1997 Sven Thoennissen"
))

(set #copy-mt-library "Kopiere miditracker.library")
(set #copy-rt-library "Kopiere reqtools.library")
(set #copy-mt-guide   "Kopiere MidiTracker.guide")
(set #install-docu    "Soll die MidiTracker Dokumentation installiert werden?")
(set #copy-synths     "Kopiere Dialog-Textdateien...")

(set #where-mt (cat
"Bitte einen Pfad für MidiTracker aussuchen. Dort wird das MidiTracker-Verzeichnis "
"erstellt."
))

(set #mt-exists (cat
"Die Datei (bzw. das Verzeichnis) \"MidiTracker\" existiert bereits.\n"
"Bitte reagieren:\n"
))

(set #rename-old-file   "Alte Datei umbenennen")
(set #delete-old-file   "Alte Datei löschen")
(set #select-new-path   "Neuen Pfad auswählen")
(set #rename-old-drawer "Altes Verzeichnis umbenennen")
(set #update-old-drawer "Ins alte Verzeichnis aktualisieren")

(set #mt-exists-help (cat
"\"Umbennen\" benennt das alte Verzeichnis um. "
"Es kann ja später immer noch gelöscht werden.\n\n"
"\"Löschen\" wird die alte Datei löschen.\n\n"
"\"Aktualisieren\" wird die Dateien im alten Verzeichnis "
"einfach überschreiben.\n\n"
"Mit \"Neuer Pfad\" können Sie ein anderes Verzeichnis für MidiTracker "
"aussuchen.\n\n"
@askchoice-help
))

(set #mt-rename "Alte Datei/Verzeichnis nach \"%s\" umbenennen")
(set #makedir "Ein Verzeichnis namens \"%s\" wird erstellt.")
(set #mt-delete "Lösche alten MidiTracker")

(set #mt-rename-help
"Wählen Sie einen neuen namen für die alte MidiTracker-Datei aus.")

(set #mt-delete-help
"Die Datei wird unwiederbringlich gelöscht. Seien Sie ganz sicher!")

(set #mt-version-help (cat
"Sie können nun diejenige Version von MidiTracker installieren, "
"die dem Prozessor in Ihrem Amiga am nächsten kommt."
))

(set #newname (cat
"Das alte MidiTracker-Verzeichnis/Datei\n\n"
"\"%s\"\n\n"
" ist in\n\n"
"\"%s\"\n\n"
"umbenannt worden."
))


(set #mainprog (cat
"Das Hauptprogramm wird nun kopiert.\n\n"
"Dieser Amiga hat einen %s Prozessor.\n\n"
"Welche Version möchten Sie installieren:\n"
))

(set #ver-68000 "68000 Version (läuft auf allen Amigas)")
(set #ver-68020 "68020 Version (benötigt mindestens 68020)")

(set #yes "Ja")
(set #no  "Nein")

(set #install-docu "Soll die Dokumentation installiert werden?")

(set #install-mtplay (cat
"Soll das Programm \"mtplay\" installiert werden?\n\n"
"(dies ist ein externes Abspielprogramm für MidiTracker-Songs)"
))

(set #where-mtplay "Wohin soll mtplay kopiert werden?")
(set #copy-mtplay "Kopiere mtplay nach %s")
(set #copy-registerform "Kopiere das Registrierungs-Formular")
(set #copy-controlsources "Kopiere MIDI-Parameter Datei")
(set #regform "Registrierung")
(set #which-iconset "Welches Piktogramm-System bevorzugen Sie?\n")
(set #copy-catalog "Kopiere Kataloge")

(set #standard-icons "Standard (4 Farben)")
(set #magicwb-icons  "MagicWB (8 Farben)")
(set #newicos-icons  "NewIcons (bis zu 256 Farben)")

(set #editor "Bitte den bevorzugten Texteditor eingeben:")

(set @askbool-help (cat
"Clicken Sie auf \"" #yes "\" oder \"" #no "\","
"um diese Frage zu beantworten."
))

(set @defaulttool-help (cat
"Alle Dialog-Textdateien werden nun \"%s\"\n"
"als voreingestellten Editor bekommen."
))

)) ; if



; == English strings ====================================================

; Imagine the case, a language has been specified in @language for which
; this script is not localized yet. English strings are set in this case.

(if (= default_lang 0)
(
(set default_lang 1)

(set #bad-kick "You must be using Kickstart 2.04+ to install MidiTracker")
(set #which-language "Which languages should be installed?")

(set #intro (cat
"MidiTracker installation\n"
"~~~~~~~~~~~~~~~~~~~~~~~~\n\n"
"This script will install the MidiTracker package "
"to your hard drive.\n\n"
"For a quick start, you don't have to install. "
"Just click the program's icon.\n\n"
"MidiTracker is (c) 1996-1997 Sven Thoennissen"
))

(set #copy-mt-library "Copying miditracker.library...")
(set #copy-rt-library "Copying reqtools.library...")
(set #copy-mt-guide   "Copying MidiTracker.guide...")
(set #copy-synths     "Copying dialog textfiles...")

(set #where-mt
"Please select the path where the MidiTracker-drawer will be created.")

(set #install-docu
"Would you like to install the MidiTracker documentation?")

(set #mt-exists (cat
"A file or drawer \"MidiTracker\" already exists.\n"
"Choose action:\n"
))

(set #rename-old-file   "Rename old file")
(set #delete-old-file   "Delete old file")
(set #select-new-path   "Select new path")
(set #rename-old-drawer "Rename old drawer")
(set #update-old-drawer "Update into old drawer")

(set #mt-exists-help (cat
"Choose \"Rename\" if you want to be safe. Old file/drawer is"
"renamed, you may delete it later.\n\n"
"\"Delete\" will kill the file immediately.\n\n"
"\"Update\" will copy the new files into the old drawer.\n\n"
"\"New path\" brings you back to path-selection menu.\n\n"
@askchoice-help
))

(set #mt-rename "Rename old file/drawer to \"%s\"")
(set #makedir "A drawer named \"%s\" is created.")
(set #mt-delete "Deleting old MidiTracker")

(set #mt-rename-help
"Choose an alternate name for your old MidiTracker-drawer.")

(set #mt-delete-help
"Deletes this file from disk. Be careful what you do!")

(set #mt-version-help (cat
"Depending on your processor type, you may choose the "
"appropriate version of MidiTracker."
))

(set #newname (cat
"The old MidiTracker file/drawer\n\n"
"\"%s\"\n\n"
"has been renamed to\n\n"
"\"%s\"."
))


(set #mainprog (cat
"Copying main program\n\n"
"Your Amiga's cpu is a %s.\n\n"
"Version to be installed:\n"
))

(set #ver-68000 "68000 version (runs on all Amigas)")
(set #ver-68020 "68020 version (needs at least 68020 cpu)")

(set #yes "Yes")
(set #no  "No" )

(set #install-docu "Do you want to install documentation?")

(set #install-mtplay (cat
"Do you want to install \"mtplay\",\n\n"
"an external player for MidiTracker-songs?"
))

(set #where-mtplay "Where do you want the mtplay-program?")
(set #copy-mtplay "Copying mtplay to %s")
(set #copy-registerform "Copying register form")
(set #regform "Register form")
(set #copy-controlsources "Copying controlsources file")
(set #which-iconset "Which is your favourite icon-set?\n")
(set #copy-catalog "Copying locale catalog")

(set #standard-icons "Standard (4 colours)")
(set #magicwb-icons  "MagicWB (8 colours)")
(set #newicos-icons  "NewIcons (up to 256 colours)")

(set #editor "Please enter your favourite text editor:")


(set @askbool-help (cat
"Please click \"" #yes "\" or \"" #no "\""
"to answer this question."
))

(set @defaulttool-help (cat
"We will now set all the textfiles'\n"
"defaulttool to \"%s\"."
))

)) ; if




;=================================================================
;============== INSTALLATION STARTS

(set oldlevel (user 2))
(message #intro)
(user oldlevel)
(welcome)


(complete 0)


; Check Kickstart version. Exit if not at least 2.0

(if (< (/ (getversion) 65536) 37)
  (abort #bad-kick)
)


; Choose languages to install (documentation + registerform)

(set lang
	(askoptions (prompt #which-language)
		(help @askoptions-help)
		(choices
			"English"
			"Deutsch"
;			"Dansk"
;			"Español"
;			"Français"
;			"Italiano"
;			"Nederlands"
;			"Norsk"
;			"Português"
;			"Svenska"
		)
		(default default_lang)
	)
)


; begin loop

(set choosing-ready 0)
(until choosing-ready
(

	; Ask user for destination dir, where a separate drawer is being created

	(user 2)
	(set mt-dest
		(askdir
			(prompt  #where-mt)
			(help    @askdir-help)
			(default @default-dest)
		)
	)
	(user oldlevel)


	; Check if drawer already exists, trigger dependent actions

	(set destination (tackon mt-dest "MidiTracker") )
	(set whattodo "update")
	(if (> (exists destination) 0 )

		(
		(if (= (exists destination) 1)
			(set whattodo
				(select
				  (askchoice
						(prompt  #mt-exists)
				    (help    #mt-exists-help)
						(choices #rename-old-file
						         #delete-old-file
						         #select-new-path)
						(default 0)
					)
					"rename" "delete" "newpath"
				)
			)

			; ELSE (destination exists, is a dir)
			(set whattodo
				(select
				  (askchoice
						(prompt  #mt-exists)
				    (help    #mt-exists-help)
						(choices #rename-old-drawer
						         #update-old-drawer
						         #select-new-path)
						(default 1)
					)
					"rename" "update" "newpath"
				)
			)
		)


		(if (= whattodo "rename")
			(
			(set new-name (tackon mt-dest "MidiTracker-old") )
			(if (rename   destination new-name
						(prompt #mt-rename new-name)
			    	(help   #mt-rename-help)
					)
				(
				(message (#newname destination new-name) )
				(set choosing-ready 1)
				)
			)
			)
		)


		(if (= whattodo "delete")
			(
			(delete   destination
				(prompt #mt-delete)
		    (help   #mt-delete-help)
			)
			(set choosing-ready 1)
			)
		)


		(if (= whattodo "update")
			(set choosing-ready 1)
		)


		)

		; ELSE (dir does not exist)
		(set choosing-ready 1)


;		(if (= whattodo "newpath")
;			(set choosing-ready 0)
;		)


	)

)
) ; end of until




; Install MidiTracker main program, depending on CPU.
; In this place, the destination directory is created.

(complete 10)

(set cpu (database "cpu") )
(if (OR (= cpu "68000") (= cpu "68010") )
	(set version-default 0)
	; ELSE
	(set version-default 1)
)

(set mainprog
	(select
		(askchoice
			(prompt  (#mainprog cpu) )
		  (help    @askchoice-help)
			(choices #ver-68000
			         #ver-68020
			)
			(default version-default)
		)
		"MidiTracker"
		"MidiTracker 68020"
	)
)

(copyfiles
	(prompt  #copy-mainprog)
	(help    @copyfiles-help)
	(source  (cat "/" mainprog) )
	(dest    destination)
  (newname "MidiTracker")
	(confirm)
	(infos)
)





; Copy miditracker.library

(complete 20)

;(copylib
;	(prompt  #copy-mt-library)
;	(help    @copylib-help)
;	(source  "/miditracker.library")
;	(dest    destination)
;	(confirm)
;)


; Copy reqtools.library to Libs:

(complete 25)

(copylib
	(prompt  #copy-rt-library)
	(help    @copylib-help)
	(source  "/libs/reqtools.library")
	(dest	   "LIBS:")
	(confirm)
)



; Copy mtplay tool

;(complete 30)

;(if (askbool
;			(prompt  #install-mtplay)
;			(help    @askbool-help)
;			(default 1)
;			(choices #yes #no)
;		)
;	(
;	(set mtplaydir
;		(askdir
;			(prompt  #where-mtplay)
;			(help    @askdir-help)
;			(default "C:")
;		)
;	)

;	(copyfiles
;		(prompt  (#copy-mtplay mtplaydir) )
;		(help    @copylib-help)
;		(source  "/mtplay")
;		(dest	   mtplaydir)
;		(confirm)
;	)

;	)
;)



; Create empty drawers

(complete 40)

(if (= (exists (tackon destination "SysEx")) 0 )
	(makedir (tackon destination "SysEx") (infos) )
)

(if (= (exists (tackon destination "Songs")) 0 )
	(makedir (tackon destination "Songs") (infos) )
)




; Copy dialog textfiles and set the default-tool

(complete 50)

(set texteditor
	(askstring
		(prompt  #editor)
	  (help    @askstring-help)
		(default "ed")
	)
)

;(if (= (exists (tackon destination "Synth")) 0 )
;	(makedir (tackon destination "Synth") (infos) )
;)

(copyfiles
	(prompt  #copy-synths)
	(help    @copylib-help)
	(source  "/Synth")
	(dest	   (tackon destination "Synth"))
  (all)
	(confirm)
)

(foreach ((tackon destination "Synth")) ("~(#?.info)")
(
(tooltype
	(prompt  #defaulttool)
	(help    (@defaulttool-help texteditor))
	(dest	   (tackon (tackon destination "Synth") @each-name))
	(setdefaulttool texteditor)
)
))




(complete 60)

; Copy MidiTracker.guide if AmigaGuide® is installed.

(if (> (getversion "Libs:amigaguide.library") 0)

	(if (askbool
				(prompt  #install-docu)
				(help    @askbool-help)
				(default 1)
				(choices #yes #no)
			)

		(
		(makedir  (tackon destination "Help")
			(prompt #makedir (tackon destination "Help") )
			(help   @makedir-help)
			(infos)
		)

		(set n 0)
		(while (set language (select n
					"english"
					"deutsch"
					"dansk"
					"español"
					"français"
					"italiano"
					"nederlands"
					"norsk"
					"português"
					"svenska"
					""))
			(
			(if (IN lang n)
				(

				(set docudest (tackon destination ("Help/%s" language) ) )
				(makedir  docudest
					(prompt #makedir docudest)
					(help   @makedir-help)
					(infos)
				)

				(copyfiles
					(prompt   #copy-docu)
					(help     @copyfiles-help)
					(source   (tackon ("/Help/%s" language) "MidiTracker.guide") )
					(dest     docudest)
					(optional nofail)
					(infos)
					(confirm)
				)

				; Modify tooltypes of guide if this is needed

				(if (< (/ (getversion) 65536) 39)
					(tooltype
						(dest (tackon docudest "MidiTracker.guide") )
						(setdefaulttool "AmigaGuide")
				  )
				)

				) ; if IN
			)

			(set n (+ n 1))
			) ; while
		)
		)

	)
)



(complete 70)

; Copy the controlsources file

(copyfiles
	(prompt  #copy-controlsources)
	(help    @copyfiles-help)
	(source  "/Controlsources" )
	(dest    destination)
	(confirm)
	(infos)
)

(tooltype
	(prompt  #defaulttool)
	(help    (@defaulttool-help texteditor))
	(dest    (tackon destination "Controlsources"))
	(setdefaulttool texteditor)
)



; Prompt & Copy the desired icon set

(complete 80)

(set iconset
	(select
		(askchoice
			(prompt  #which-iconset)
		  (help    @askchoice-help)
			(choices #standard-icons
			         #magicwb-icons
			         #newicos-icons
			)
			(default 0)
		)
		"Standard-Icons"
		"MagicWB-Icons"
		"NewIcons-Icons"
	)
)

; Copy the main program's icon

(copyfiles
	(prompt  #copy-iconset)
	(help    @copyfiles-help)
	(source  (tackon (cat "/" iconset) "MidiTracker.info") )
	(dest    destination)
)



; Copy icons: Song, Iconify. (to come: Project)

(makedir (tackon destination "Icons")
	(prompt #makedir (tackon destination "Icons") )
	(help   @makedir-help)
	(infos)
)
(copyfiles
	(prompt  #copy-iconset)
	(help    @copyfiles-help)
	(source  (cat "/" iconset) )
	(dest    (tackon destination "Icons") )
	(pattern "~(MidiTracker.info)")
)





; Copy order-form

(complete 90)

(copyfiles
	(prompt   #copy-registerform)
	(help     @copyfiles-help)
	(source   ("/Register/%s" @language) )
	(dest     destination)
	(newname	#regform)
	(optional nofail)
	(infos)
)

(tooltype
	(prompt  #defaulttool)
	(help    (@defaulttool-help texteditor))
	(dest    (tackon destination #regform))
	(setdefaulttool texteditor)
)




; Copy catalogs

(complete 95)

(set n 0)
(while (set language (select n
			"english"
			"deutsch"
			"dansk"
			"español"
			"français"
			"italiano"
			"nederlands"
			"norsk"
			"português"
			"svenska"
			""))
	(
	(if (IN lang n)
		(if (<> 0 n) ; if english, skip that bit (there is no catalog)
			(copyfiles
				(prompt   #copy-catalog)
				(help     @copyfiles-help)
				(source   (tackon ("/Catalogs/%s" language) "MidiTracker.catalog") )
				(dest     ("LOCALE:Catalogs/%s" language) )
				(optional nofail)
			)
		)
	)

	(set n (+ n 1))
	) ; while
)



(complete 100)

