;-----------------------------------------------------------------------------
; Script to install P96Speed v0.13ß+ 
;
; $VER: InstallP96Speed 1.1 (07.10.97)
;
; - original script done by Jens Langner (deck@rcs.urz.tu-dresden.de)
;
;-----------------------------------------------------------------------------

;=============================================================================
; Configuration defaults
;=============================================================================

(set #Name					"P96Speed")
(set #MinSysVersion			36)
(set #LibsDefaultPath		"SYS:Libs")
(set #MainPath			    "P96Speed")
(set #MainDefaultPath		"Work:")

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

(if
	(= @language "english")
	(
	; startup message
        (set #StartUpMsg     "Do you want to read the documentations now ?")
        (set #StartUpMsgHelp "You should read the documentations now to check if your system is compatible with P96Speed!")
		
	; Errors
		(set #Err-Bad-Kick "You need at least KickStart 2.0 to run P96Speed!")
		(set #Err-Bad-CPU "You need at least a Motorola M68000 CPU to run P96Speed")

	; Warnings

	; Message
		(set #Message
			(cat
				"\nThank you very much for choosing P96Speed as your Speedcomparsion system.\n\n\n"
				"P96Speed is the new GFX benchmark program for ALL graphicsystems.\n\n\nInstallscript ©`97 by Jens Langner\n\n"
			)
		)

	; Install/Update
		(set #InstallMode "Do you want to install or uninstall P96Speed?")
		(set #InstallModeHelp
			(cat
				"Choosing Install will install P96Speed with all needed libraries,"
				"if you click uninstall, this script will remove your installed P96Speed version."
			)
		)
		(set #Install "Install")

        (set #UnPrg   "Main programs & Docs")
        (set #UnLib   "Libraries")

		(set #Uninstall     "Uninstall an installed version")
        (set #UninstallSel  "What do you want to uninstall ?")
        (set #UninstallSelHelp
            (cat
                "Here you can select what you want to remove from your P96Speed installation."
            )
        )
        (set #AskUninstall  "Do you really want to uninstall the selected areas?")
        (set #AskUnyes      "Yes!")
        (set #AskUnno       "No!")
        (set #AskUninstallHelp
            (cat
                "If the installer will find any backups of a old installation before P96Speed,"
                "it will reinstall them."
            )
        )

        (set #InstEnd
            (cat "\nThe installation is finished now and the installer hopefully copied all packages to the right place.\n"
                 "If you still got any problems, please check the following Webpages for help:\n\n"
                 "http://www.villagetronic.com/amiga/\n\nor mail to: Jens Langner <deck@rcs.urz.tu-dresden.de>\n\n"
                 "Thank you very much for choosing P96Speed\n\nYour P96Speed Author...."
            )
        )
        (set #UniEnd
            (cat "\nThe uninstall procedure is finished now and hopefully all selected packages are correctly removed.\n"
                 "If you got any problems, please check the following Webpages for help:\n\n"
                 "http://www.villagetronic.com/amiga/\n\nor mail to: Jens Langner <deck@rcs.urz.tu-dresden.de>\n\n"
                 "Thank you very much for trying P96Speed. And we hope you soon will install it again.\n\nYour P96Speed Author...."
            )
        )

	; Libs
		(set #AskLibPath    "Where do you want to have the P96Speed library files installed?")
		(set #AskLibPathUp  "Where do you have the P96Speed library files installed?")
		(set #AskLibPathHelp
			(cat
				"If you are not absolutely sure what to choose, choose \""
				#LibsDefaultPath "\"!"
			)
		)
		(set #AskLibPathLibs #LibsDefaultPath)
		(set #AskLibPathUser "Select another location")

		(set #SelectLibDir "Choose a directory for the P96Speed library files.")
		(set #SelectLibDirUp "Choose the directory where you installed the files.")
		(set #SelectLibDirHelp
			(cat
				"This directory MUST be a part of your LIBS: assign!"
				"It has to be part of libs: before the monitors are launched."
				"Therefore, it is usually best to install them in SYS:libs."
			)
		)

	; Main
		(set #AskMainPath   "Where do you want to have the Main program files installed?")
		(set #AskMainPathUp "Where are the program files installed?")
		(set #AskMainPathHelp
			(cat
				"If you are not absolutely sure what to choose, choose \"SYS:"
				#MainPath "\"!"
			)
		)
		(set #AskMainPathDevs (cat "SYS:" #MainPath))
		(set #AskMainPathUser "Select another location")

		(set #SelectMainDir     "Where do you want to have the main program files installed?\nA drawer named P96Speed will be created there.")
		(set #SelectMainDirUp   "Where do you have the support files installed?")
		(set #SelectMainDirHelp
			(cat
				"A new drawer named P96Speed will be created to hold the files."
				"An appropriate assign will be added to your user-startup file later."
			)
		)

	; Copy
		(set #P96SpeedHomeDir       "Creating drawer for applications and scripts.")
		(set #P96SpeedHomeDirHelp   "The drawer created now holds the applications and the update and uninstall scripts.")
		(set #CopyGTLayout          "Installing gtlayout.library.")
		(set #CopyGTLayoutHelp      "This library is needed for P96Speed.\nAuthor: Olaf 'Olsen' Barthel")
		(set #CopyIdentify          "Installing identify.library.")
		(set #CopyIdentifyHelp      "This library is needed for P96Speed.\nAuthor: Richard Koerber")
	
		(set #CopyMain              "Installing Main program.")
		(set #CopyMainHelp          "Here the main program will be installed to its path.")
		(set #CopyMainDoc           "Installing the documentation")
		(set #CopyMainDocHelp       "Here the documentation will be installed to its path.")

	; Install
		(set #Msg-Installing "Installing P96Speed files!")

	)
)

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

(if
	(= @language "deutsch")
	(
	; startup message
        (set #StartUpMsg     "Möchten Sie nun die Dokumentation lesen ?")
        (set #StartUpMsgHelp "Sie sollten nun die Dokumentation lesen um zu kontrollieren ob Ihr System mit P96Speed kompatible ist!")
		
	; Errors
		(set #Err-Bad-Kick "Sie benötigen mindestens KickStart 2.0 für P96Speed!")
		(set #Err-Bad-CPU "Sie benötigen mindestens eine Motorola M68000 CPU für P96Speed!")

	; Warnings

	; Message
		(set #Message
			(cat
				"\nVielen Dank, daß Sie P96Speed installieren wollen.\n\n\n"
				"P96Speed ist das neue Grafik Benchmarkprogramm für ALLE Grafiksysteme.\n\n\nInstallskript ©`97 - Jens Langner\n\n"
			)
		)

	; Install/Update
		(set #InstallMode "Wollen Sie P96Speed installieren oder entfernen?")
		(set #InstallModeHelp
			(cat
				"Wenn Sie Installieren wählen, wird P96Speed mit allen Libraries installiert,"
				"wenn Sie Enfernen wählen, können Sie auswählen was Sie deinstallieren wollen."
			)
		)
		(set #Install "Installation")

        (set #UnPrg   "Hauptprogramm mit Dokumentation")
        (set #UnLib   "Zusatzbibliotheken")

		(set #Uninstall     "Bestehende Installation entfernen")
        (set #UninstallSel  "Was möchten Sie entfernen ?")
        (set #UninstallSelHelp
            (cat
                "Sie können nun wählen welche Teile der Installation Sie löschen möchten."
            )
        )
        (set #AskUninstall  "Möchten Sie wirklich die von Ihnen gewählten Bereiche löschen?")
        (set #AskUnyes      "Ja!")
        (set #AskUnno       "Nein!")
        (set #AskUninstallHelp
            (cat
                "Wenn der Installer irgendwelche gesicherten Dateiene finden sollte, die vor"
                "der P96Speed existierten, wird er diese an den alten Platz zurückkopieren."
            )
        )

        (set #InstEnd
            (cat "\nDie Installation ist nun abgeschlossen und der Installer hat hoffentlich alles an den richtigen Platz kopiert.\n"
                 "Wenn Sie dennoch Probleme haben sollten, finden Sie auf folgenden WebSeiten Hilfe:\n\n"
                 "http://www.villagetronic.com/amiga/\n\noder schreiben Sie an: Jens Langner <deck@rcs.urz.tu-dresden.de>\n\n"
                 "Danke das Sie P96Speed gewählt haben.\n\nIhr P96Speed Author...."
            )
        )
        (set #UniEnd
            (cat "\nDie Deinstallation is nun abgeschlossen und hoffentlich sind alle gewählten Pakete korrekt entfernt worden.\n"
                 "Wenn Sie Probleme haben sollten, finden Sie auf folgenden WebSeiten Hilfe:\n\n"
                 "http://www.villagetronic.com/amiga/\n\noder schreiben Sie an: Jens Langner <deck@rcs.urz.tu-dresden.de>\n\n"
                 "Danke das Sie P96Speed benutzt haben. Wir hoffen Sie wählen es einmal wieder.\n\n"
                 "Ihr P96Speed Author...."
            )
        )

	; Libs
		(set #AskLibPath    "Wo sollen die Zusatzbibliotheken für P96Speed installiert werden?")
		(set #AskLibPathUp  "Wo sind die Zusatzbibliotheken von P96Speed installiert?")
		(set #AskLibPathHelp
			(cat
				"Die Funktionsbibliotheken müssen in das Verzeichnis kopiert werden, auf welches "
				"der Assign Libs: während des Startvorgangs (vor User-Startup!) zeigt. "
                "Im Zweifelsfall nehmen Sie einfach " #LibsDefaultPath "!"
			)
		)
		(set #AskLibPathLibs #LibsDefaultPath)
		(set #AskLibPathUser "Einen anderen Ort wählen")

		(set #SelectLibDir      "Wählen Sie ein Verzeichnis für die Zusatzbibliotheken von P96Speed.")
		(set #SelectLibDirUp    "Wählen Sie das Verzeichnis mit den Zusatzbibliotheken von P96Speed.")
		(set #SelectLibDirHelp
			(cat
				"Dieses Verzeichnis MUSS ein Teil Ihrer LIBS: Zuweisung sein!"
				"Am Besten, die Dateien in SYS:Libs installieren."
			)
		)

	; Main
		(set #AskMainPath   "Wo soll das Hauptprogramm und die Dokumentation installiert werden?")
		(set #AskMainPathUp "Wo ist das Hauptprogramm mit der Dokumentation installiert?")
		(set #AskMainPathHelp
			(cat
				"Wenn Sie sich nicht absolut sicher sind, wählen Sie \"SYS:"
				#MainPath "\"!"
			)
		)
		(set #AskMainPathDevs (cat "SYS:" #MainPath))
		(set #AskMainPathUser "Einen anderen Ort wählen")

		(set #SelectMainDir     "Wo soll das Hauptprogramm und die Dokuemntation installiert werden?\nEin neues Verzeichnis mit Namen P96Speed wird dort installiert.")
		(set #SelectMainDirUp   "Wo ist das Hauptprogramm mit der Dokumentation installiert worden?")
		(set #SelectMainDirHelp
			(cat
				"Dort wird das Hauptprogramm 'P96Speed' mit samt der Dokumentation installiert."
			)
		)

	; Copy
		(set #P96SpeedHomeDir       "P96Speed Stammverzeichnis wird angelegt.")
		(set #P96SpeedHomeDirHelp   "Das angelegte Verzeichnis beherbergt das Zubehör.")
		(set #CopyGTLayout          "Installation der GTLayout.library.")
		(set #CopyGTLayoutHelp      "Diese Bibliothek wird für das GUI von P96Speed benötigt.\nAuthor: Olaf 'Olsen' Barthel")
		(set #CopyIdentify          "Installation der Identify.library.")
		(set #CopyIdentifyHelp      "Diese Bibliothek wird für die Systemerkennung von P96Speed benötigt.\nAuthor: Richard Koerber")
	
		(set #CopyMain              "Installation des Hauptprogrammes.")
		(set #CopyMainHelp          "In diesem Schritt wird das Hauptprogramm installiert.")
		(set #CopyMainDoc           "Installation der Dokumentation.")
		(set #CopyMainDocHelp       "In diesem Schritt wird die Dokumentation installiert.")

	; Install
		(set #Msg-Installing "Installiere P96Speed System!")

	)
)


;=============================================================================
; Procedures
;=============================================================================

(procedure GetLibPath

	(if
		(askbool
            (if (= #_installmode 0) (prompt #AskLibPath))
            (if (= #_installmode 1) (prompt #AskLibPathUp))
			(help #AskLibPathHelp)
			(choices #AskLibPathLibs #AskLibPathUser)
		)
		(set #_libpath #LibsDefaultPath)
		(set #_libpath
			(askdir
                (if (= #_installmode 0) (prompt #SelectLibDir))
                (if (= #_installmode 1) (prompt #SelectLibDir))
				(help #SelectLibDirHelp)
				(default #LibsDefaultPath)
                (disk)
			)
		)
	)
)

(procedure GetMainPath

   	(if
    	(askbool
            (if (= #_installmode 0) (prompt #AskMainPath))
            (if (= #_installmode 1) (prompt #AskMainPathUp))
		    (help #AskMainPathHelp)
   			(choices #AskMainPathDevs #AskMainPathUser)
    	)
	    ((if (= #_installmode 0) (set #_mainpathroot "SYS:"))
	    (if (= #_installmode 1) (set #_mainpathroot (cat "SYS:" #MainPath))))
    	(set #_mainpathroot
	    	(askdir
                (if (= #_installmode 0) (prompt #SelectMainDir))
                (if (= #_installmode 1) (prompt #SelectMainDirUp))
    			(help #SelectMainDirHelp)
	    		(default #MainDefaultPath)
		    	(newpath)
                (disk)
	    	)
    	)
    )
    (if (= #_installmode 0) (set #_mainpath (tackon #_mainpathroot #MainPath)))
    (if (= #_installmode 1) (set #_mainpath (cat #_mainpathroot)))

)

(procedure CopyLibs

  	; copy gtlayout.library
	(copylib
    	(prompt #CopyGTLayout)
		(help #CopyGTLayoutHelp)
		(source "libs/gtlayout.library")
		(dest #_libpath)
		(confirm)
	)

	; copy identify.library
	(copylib
		(prompt #CopyIdent)
		(help #CopyIdentHelp)
		(source "libs/identify.library")
		(dest #_libpath)
		(confirm)
	)

)

(procedure CopyMain

    (copyfiles
        (prompt #CopyMain)
        (help #CopyMainHelp)
        (source "")
        (dest #_mainpath)
        (infos)
        (all)
    )

)

;=============================================================================
; Install ...
;=============================================================================

(message #Message)

(if
	(< (getversion) (* #MinSysVersion 65536))
	(abort #Err-Bad-Kick)
)

(set #_installmode
    (askchoice
        (prompt #InstallMode)
        (help #InstallModeHelp "\n\n" @askoptions-help)
        (choices
            #Install
            #Uninstall
        )
        (default 0)
    )
)

(welcome)

;*********************

(if
	(= #_installmode 0)
	(
        ;*******************
        ; adviceing user

        (set #_olduserlevel @user-level)
        (user 1)
        (if
        	(askbool
		        (prompt	#StartupMsg)
        		(help		#StartupMsgHelp)
        	)
        	(
        		(if
		        	(= @language "english")
        			(
		        		(run "Copy P96Speed.guide RAM:" (safe))
				        (run "SYS:Utilities/MultiView RAM:P96Speed.guide" (safe))
        			)
		        )
        		(if
		        	(= @language "deutsch")
        			(
		        		(run "Copy P96Speed.guide RAM:" (safe))
				        (run "SYS:Utilities/MultiView RAM:P96Speed.guide" (safe))
        			)
		        )
        	)
        )
        (user #_olduserlevel)

		;*********************
		; install
	

		;*********************
		; get paths


        (GetLibPath)
        (GetMainPath)

		;*********************
		; finally install...

		(working #Msg-Installing)

		(set @default-dest #_mainpath)

		; make applications directory
		(if
			(= 0 (exists #_mainpath))
			(makedir #_mainpath
				(prompt #P96SpeedHomeDir)
				(help #P96SpeedHomeDirHelp)
				(confirm)
			)
		)

        ; Copy MainPrg & Doc

        (CopyMain)

        ; Copy Libraries

        (CopyLibs)

    (message #InstEnd)
	)
)

(if
	(= #_installmode 1)
	(
    

	(set #_uninstall
		(askoptions
   			(prompt #UninstallSel)
			(help #UninstallSelHelp)
			(choices
                #UnPrg
                #UnLib
			)
			(default 1)
		)
	)

	(if
		(askbool
            (prompt #AskUninstall)
	    	(help #AskUninstallHelp)
			(choices #AskUnyes #AskUnno)
		)
		(set #_uninstallyes 0)
		(set #_uninstallyes 1)
	)
    
    (if (= #_uninstallyes 0)(
        (if (BITAND #_uninstall 1)             (GetMainPath))
        (if (BITAND #_uninstall 2)             (GetLibPath))

        (if (BITAND #_uninstall 1)             (run (cat 'delete "' #_mainpath '" "' #_mainpath '.info" ALL')))
        (if (BITAND #_uninstall 2)             (delete (tackon #_libpath "gtlayout.library") (tackon #_libpath "identify.library"))))
    )
    (message #UniEnd)
    )
)
