; This piece installs the Eagleplayer (TM) to your hard disk
; © 1992-1997 DEFECT Softworks, All rights reserved.
; only to be distributed within the Eagleplayer package
;
; Written by Henryk Richter
; Date: 10/Oct/97

(set #EP_Version (cat "2.01"))					;Eagleplayer Version
(set #Space (cat "2.6 "))						;Megabytes needed for
                                                ;installation.
(set KickVersion (/ (getversion) 65536))
(debug "Kickversion:" Kickversion)

;=========================== English texts ==================================
(set #which-disk
(cat "In which drawer shall I install Eagleplayer?\n"
     "(a directory named Eagleplayer2 will be created there)"
))

(Set #intro
(cat "This procedurce lets you install the full Eagleplayer Version "
     #EP_Version
     " on your hard drive. \n\n"
     " You will be asked for the location where you want to install"
     " it and the preferred icon set. The rest will be done by this"
     " script for you.\n\n"
     "For installing of this "
     "package you need about "
     #Space
     "MBytes free space on your harddisk. \n"
))

(set #askicons
(cat "Which Iconset do you like to be installed ?"
))

(set #askicons-help
(cat "Just select one of the items shown for the preferred look "
     "of Eagleplayer`s icons.\n"
     "Standard:   4 colour system standard icons\n"
     "MagicWB:    8 colour Red-Brown style icons\n"
     "NewIcons:   multicolour iso-style icons (needs NewIcons to be running)\n"
     "AristIcons: multicolour icons with a very special look (needs NewIcons to be running)\n"
))

(set #userstart
(cat "Installer will modify your s:user-startup "
     "file. The following lines need to be added "
     "to make Eagleplayer work properly:\n\n"
))

(set #reinstall
(cat "Eagleplayer2: Assign found, do you wish to update "
     "your installation or specify a new directory ? "
))

(set #Update
(cat "Update"
))

(set #NewDir
(cat "New Directory"
))

(set #weiter
(cat "Go ahead"
))

(set #skipit
(cat "Skip this part"
))

;=========================== Deutsche Texte =================================
(if (= @language "deutsch")
(

(set #which-disk
(cat "Wo soll der Eagleplayer installiert werden ? "
     "(es wird dort ein Verzeichnis Namens 'Eagleplayer2' angelegt)"
))

(Set #intro
(cat "Dieser Vorgang ermöglicht es Ihnen, das komplette Eagleplayer-Paket "
     #EP_Version
     " samt den benötigten Bibliotheken auf Ihrer Harddisk zu installieren.\n\n"
     " Zur Installation des kompletten Paketes werden etwa "
     #Space
     " MBytes freier Platz auf der Festplatte benötigt.\n\n"
     "Alles, was Sie zur Installation beitragen müssen, ist sind die Angaben, "
     "wo Sie den Eagleplayer installieren möchten, sowie die von Ihnen bevorzugten "
     "Piktogramme."
))

(set #askicons
(cat "Welche Art von Piktogrammen möchten Sie verwenden ?"
))

(set #askicons-help
(cat "Sie brauchen lediglich eine der Optionen mit der Maus anzuwählen, "
     "welche Art von Icons Sie für den Eagleplayer bevorzugen\n"
     "Standard:   4 farbige system standard icons\n"
     "MagicWB:    8 farbige Rot-Braun-Grau icons\n"
     "NewIcons:   mehrfarbige iso-look icons (erfordert NewIcons)\n"
     "AristIcons: mehrfarbige icons mit einem sehr eigenständigen look (erfordert NewIcons)\n"
))

(set #Reinstall
(cat "Das Installscript hat ein bestehendes `Eagleplayer2:` Assign gefunden, "
     "wollen Sie die bestehende Installation auf den aktuellen Stand bringen "
     "oder ein neues Verzeichnis für diese Version wählen ?"
))

(set #Update
(cat "Aktualisieren"
))

(set #NewDir
(cat "Neues Verzeichnis"
))

(set #userstart
(cat "Der Installer wird Ihre s:user-startup - Datei "
     "um folgende Einträge erweitern, die zum korrekten Betrieb "
     "des Eagleplayers notwendig werden:\n\n"
))

(set #weiter
(cat "weiter"
))

(set #skipit
(cat "diesen Teil überspringen"
))


)
)

;============================== Welcome the User ===========================

(complete 0)

;(welcome)
(message #intro)

;====== get target directory where the Eagleplayer is to be installed =====
;=================== ask for the Iconset to install ================================

    (set yo (exists ("Eagleplayer2:") (noreq)))
	(debug "Eagleplayer2 gefunden: " yo)

	(if (<> yo 0)
	 (
	  (set newdir (askbool (prompt #Reinstall)
	                       (help @askbool-help)
	                       (choices #Update #NewDir)
	              )
	  )
	 )
	)

	(if (or (= yo 0) (= newdir 0))
		(
			(set target (askdir	(prompt #which-disk)
							(help @askdir-help)
							(default "Work:")
							(disk)
						)
			)

			(set icons 1)
			(set icons (askchoice (choices "Standard" "MagicWB" "NewIcons" "AristIcons (NI)")
									(prompt (cat "\n" #askicons "\n"))
									(help   #askicons-help)
									(default icons)
						)
			)
			
			(debug "Icons:" icons)

			(set @default-dest (tackon target "Eagleplayer2"))
			(set update 0)
			(set epdrawer target)
		)
		(
			(set update 1)
			(set target "Eagleplayer2:")
			(set @default-dest "Eagleplayer2:")
		)
	)

	(debug "Ziel:" target)

;=================== is this a registered Eagleplayer ? ============================

    (set keypresent (exists ("Eagleplayer.key"))
    )
    (debug "Wir haben als Keyfile:" keypresent)

;========================== create directories =================================

	(if (= update 0)
	 (
	  (debug "kein Assign, also ein Verzeichnis anlegen bzw. überprüfen")

	  ;a file called Eagleplayer2 existing ?
	  (set yo (exists (tackon target "Eagleplayer2")))

	  (if (= yo 1)
	   (
	    (delete (tackon target "Eagleplayer2") (force))
	    (set yo 0)
	   )
	  )

	  ;no directory called Eagleplayer2 existing ?
	  (if (= yo 0)
	   (
	    (makedir (tackon target "Eagleplayer2"))
	    (set target (tackon target "Eagleplayer2"))
		(makeassign "Eagleplayer2" target)
	   )
	  )

	  ;a directory called Eagleplayer2 existing ?
	  (if (= yo 2)
	    (set target (tackon target "Eagleplayer2"))
		(makeassign "Eagleplayer2" target)
	  )
	 )
	)
	
	(complete 2)

;================= Copy Eagleplayer and Keyfile ==============================

    (copyfiles (source ("Eagleplayer"))
               (dest target)
               (optional "force" "nofail")
    )

    (copyfiles (source ("Eagleplayer.readme"))
               (dest target)
               (optional "force" "nofail")
    )

	(if (= 1 keypresent)
	 (
		(copyfiles (source ("Eagleplayer.key"))
					(dest target)
					(optional "force" "nofail")
		)
	 )
	)

	(complete 8)

;=========== copy Players,Engines, Catalogs, Docs, Goodies, Developer, Rexxscripts ==

    (copyfiles (source ("Eagleplayers"))
               (dest (tackon target "Eagleplayers"))
               (all)
               (optional "force" "nofail")
    )

	(complete 40)

    (copyfiles (source ("Engines"))
               (dest (tackon target "Engines"))
               (all)
               (optional "force" "nofail")
    )

	(complete 55)

    (copyfiles (source ("Catalogs"))
               (dest (tackon target "Catalogs"))
               (all)
               (optional "force" "nofail")
    )

	(complete 57)

    (copyfiles (source ("Help"))
               (dest (tackon target "Help"))
               (all)
               (optional "force" "nofail")
    )

	(complete 90)

    (copyfiles (source ("Rexx"))
               (dest (tackon target "Rexx"))
               (all)
               (optional "force" "nofail")
    )

	(complete 91)

    (copyfiles (source ("Goodies"))
               (dest (tackon target "Goodies"))
               (all)
               (optional "force" "nofail")
    )

	(complete 92)

    (copyfiles (source ("Developer"))
               (dest (tackon target "Developer"))
               (all)
               (optional "force" "nofail")
    )

	(complete 93)

;====================== copy Configs if needed ===============================

	(set yo (exists (tackon target "configs")))
	(if (= yo 2)
	 (
	    (copyfiles (source ("Configs/Eagleplayer.batch"))
	               (dest (tackon target "Configs"))
	               (optional "force" "nofail")
	    )
	 )
	 (
	    (copyfiles (source ("Configs"))
	               (dest (tackon target "Configs"))
	               (all)
	               (optional "force")
	    )
	 )
	)

	(complete 94)

;================= copy Icons on first installation ==========================

	(if (= update 0)
	 (

		(if (= icons 0)
		 (
		 ;copy Standard Icons
		  (set icondir "Icons/Standard")
		 )
		)
		(if (= icons 1)
		 (
		 ;copy MWB Icons
		  (set icondir "Icons/MagicWB")
		 )
		)
		(if (= icons 2)
		 (
		 ;copy NewIcons
		  (set icondir "Icons/NewIcons")
		 )
		)
		(if (= icons 3)
		 (
		 ;copy AristIcons
		  (set icondir "Icons/AristIcons")
		 )
		)

		(debug "Icondir: " icondir)

	    (copyfiles (source (cat icondir ".info"))
	               (dest epdrawer)
	               (optional "nofail" "force")
	               (newname "Eagleplayer2.info")
	    )

		(copyfiles (source icondir)
					(dest target)
					(optional "nofail" "force")
					(all)
					(files)
		)

		(copyfiles (source (tackon icondir "help/english.info"))
					(dest (tackon target "help"))
					(optional "nofail" "force")
		)

		(copyfiles (source (tackon icondir "help/EP_Main.guide.info"))
					(dest (tackon target "help/english"))
					(optional "nofail" "force")
		)

		(set yo (exists (tackon target "help/deutsch/EP_Main.guide") (noreq))
		)

		(debug "Exists liefert bei help/deutsch" yo)

		(if (= yo 1)
		 (
			(copyfiles (source (tackon icondir "help/deutsch.info"))
						(dest (tackon target "help"))
						(optional "nofail" "force")
			)

			(copyfiles (source (tackon icondir "help/EP_Main.guide.info"))
						(dest (tackon target "help/deutsch"))
						(optional "nofail" "force")
			)
		 )
		)

		(delete (tackon target "help/EP_Main.guide.info"))

	 )
	)

	(complete 98)

;====== delete corrupt XFD Slaves and obsolete players if present ============

	(set yo (exists ("libs:xfd/XFD_FIMP_LHLib_XPK.Slave") (noreq))
	)
	(if (= yo 1)
	 (delete "libs:xfd/XFD_FIMP_LHLib_XPK.Slave" (optional force))
	)

	(set yo (exists ("libs:xfd/XFD_ATN!_LHLib_XPK.Slave") (noreq))
	)
	(if (= yo 1)
	 (delete "libs:xfd/XFD_ATN!_LHLib_XPK.Slave" (optional force))
	)

	(complete 99)

;============== create nessesary Assign in User-Startup ======================

	(set myassign
	 (cat
	  "assign Eagleplayer2: "
	  (expandpath target)
	 )
	)

	(debug "das Assign:" myassign)

	(set makeass (askbool (prompt #userstart
	                              myassign
	                      )
	                      (help @askbool-help)
	                      (choices #weiter #skipit)
	             )
	)

	(if (= makeass 1)
	 (
	  (user 1)

	  (startup "Eagleplayer2"
	           (command myassign)
			   (prompt #userstart
				       myassign
	           )
			   (help @startup-help)
      )

      (user 3)

     )
    )

	(complete 100)

;========================== done =============================================
(exit)
