; NewIcons 3.0 Updater Script
; $Ver: 39.1 (14-Jul-96)
; Written by Phil Vedovatti
; Brought to you by the NewIcons Team

(set @default-dest "SYS:C")

(set cpu (database "cpu"))
(set cpu020 (and (<> cpu "68000") (<> cpu "68010")))
(set v39 (>= (/ (getversion "exec.library" (resident)) 65536) 39))

(set #bad-kick
   (cat "\n\nSorry! You must have Workbench 2.0 or"
        "higher to to use this package."))

(set #hello-message
   (cat "\n\nThank you for updating NewIcons, the revolutionary"
        "\nGraphical User Interface system for the Amiga."
        "\nPlease read the documentation to get the most out"
        "\nof this package.  Nothing will be deleted from your"
        "\nsystem with this installation program.  Your old WB"
        "\nicons will still be there, even though it won't look"
        "\nlike it on your screen.  If you don't understand any"
        "\npart of the installation, click on the \"Help\" gadget"
        "\nfound throughout the installation for more information."
        "\n\nCLICK TO PROCEED"))

(set #install-which
   (cat "\nWhich part(s) of the NewIcons System would"
        "\nyou like to update onto your hard drive?\n"))

(set #install-library
   (cat "\n\nInstalling NewIcon.library to LIBS:."))

(set #install-library-help
   (cat "\n\nThis library is required to use NewIcons."))

(set #install-newicons
   (cat "\n\nCopying the NewIcons executable file"
        "\n and support files to C:"))

(set #install-newicons-help
   (cat "\n\nThis section installs NewIcons, InjectBrush"
        "\nand PatchOpenWB to your C: directory."))

(set #tools-dest
   (cat "\nWhich drawer would you like the NewIcon"
        "\nmanipulation utilities to be installed?"
        "\nA drawer will NOT be created."))

(set #install-prefs
   (cat "\nInstalling NewIconsPrefs to your"
        "\nSys:prefs directory."))

(set #install-prefs-help
   (cat "\nUse this program to configure NewIcons!"))

(set #run-prefs
   (cat "\nStarting NewIconsPrefs so you can configure"
        "\nNewicons right away. The effect will not be"
        "\nevident until you reboot."
        "\nBe sure to save your changes."))

(set #startup-change
   (cat "\nNewIcons V3.0 requires a change in"
        "\nyour user startup to launch it.  Shall I add"
        "\n\n'Run <NIL: >NIL: c:NewIcons'"
        "\n\nto your S:user-startup file?"
        "\n\n(You may need to remove the old line manually"
        "\nif you didn't originally install NewIcons"
        "\nusing the Installer utility.)"))

(set #install-deficons
   (cat "\n\nInstalling the DefIcons daemon to your"
        "\nC: directory, and copying default icons"
        "\nto your Envarc:sys directory."))

(set #install-deficons-help
   (cat "\nThis sections installs the Deficons program"
        "\nand copies the required def_icons to your"
        "\nENVARC: directory."))

(set #move-olddefs-dir
   (cat "The installer will move your old default"
        "\nicons to another location for safe keeping."
        "\nWhere would you like me to create a directory"
        "\nto put them in?"))

(set #move-olddefs-help
   (cat "\nThis section copies your old default icons to"
        "\na safe place instead of overwriting them."
        "\nShould you wish to deinstall Deficons, you"
        "\nWill have them available to restore."))

(set #move-olddefs
   (cat "Moving your old default icons to \n"
        destdir))

(set #install-envarc
   (cat "\nCopying the default icons and brainfile"
        "\nto ENVARC: so DefIcons can use them.\n"))

(set #install-envarc-help
   (cat "\n\nThis section install the icons that DefIcons"
        "\nwill use to display icon images for files that"
        "\ndon't have icons already attached to them."))

(set #startup-deficons
   (cat "\n\nAdding a line to your S:user-Startup file"
        "\nto launch DefIcons whenever the system"
        "\nis booted up."))

(set #powb-message
   (cat "\n\nIf you have installed NewIcons, you must "
           "add a line to your S:Startup-Sequence:\n\n"
           "C:PatchOpenWB\n"
           "\nto fix a bug in the 3.x operating system!"
           "\n\n Make sure to place the line after Setpatch"
           "\nand before IPrefs."))

(set #docs-dest
   (cat "Where would you like the NewIcons Documentation"
        "\nGuide to be installed?"))


(set #exit-message
   (cat "Please reboot your system to fully activate\n"
        "the new NewIcons System."
        "\n\n\nWe hope you enjoy this package!"))


; ClassAct installation procedure V 1.5 (12.5.96) by Osma Ahvenlampi

; percentage of the size of included ClassAct classes versus the whole
; distribution (ie. total "complete" percentage after ClassAct is installed)

(set classact-complete 70)

; ClassAct installer scripts
(set #classdest-prompt "Please select the directory where you want the ClassAct classes installed.\n(See help for details)")
(set #classdest-help (cat "ClassAct is a GUI toolkit consisting of shared BOOPSI classes.\n\nSome programs require some or all of the ClassAct classes installed on your system. "
    (if v39 (cat "OS 3.0 has a standard directory for BOOPSI classes, the SYS:Classes directory. It is recommended that you install ClassAct there.")
            (cat "OS 2.0 does not have a standard place for disk resident BOOPSI classes. On OS 3.0 these classes are stored in the SYS:Classes directory. It is recommended that you create this directory and install ClassAct there.\nThis directory must be added in the LIBS: assign. This can be done by placing the command\nAssign >NIL: LIBS: SYS:Classes ADD\nto User-Startup. This installer will do this for you.")
        )
    )
)
(set #classes-020 "Do you want to use the OS 3.0, 020 optimised version of ClassAct?")
(set #help-020 "Some ClassAct libraries have versions optimised for use on 020 or better equipped OS 3.0 or later machines. If your Amiga is such equipped, you should install these. The 68000/2.0 versions will also work, but are slightly slower.")
(set #noclasses-message "The directory you selected for your ClassAct classes is not a part of the LIBS: assign.\n\nIt is necessary to add this assign so that the classes will be found properly.")
(set #creating-dir "Creating directory ")
(set #usbackup-prompt "User-Startup will now be backed up.")
(set #usbackup-help "This installer will next make a modification in User-Startup. Before doing this the old User-Startup will be backed up to S:User-Startup.old")
(set #adding-1 "Adding ")
(set #adding-2 " to LIBS: assign\n")
(set #adding-help "This is necessary so that the custom classes can be found.")
(set #junod-button "It seems you have a late Commodore 'V42' button.gadget installed on your system.\n\nClassAct's button.gadget is far more capable than this gadget, and we recommend that you replace it. The ClassAct button.gadget is backwards compatible to the Commodore gadget. Do you wish to back up the Commodore gadget and replace it with the ClassAct version?")
(set #junod-backed "The Commodore 'V42' button.gadget has been backed up with the name button.gadget.v42.\n\nThe ClassAct button.gadget will be installed in its place.")
(set #junod-kept "The Commodore 'V42' button.gadget was not replaced with the more capable ClassAct version.\n\nPrograms depending on the availability of ClassAct-only features will be likely to work wrong.")
(set #caprefs-message "CAPrefs is a small utility that sets some user preferences for ClassAct applications. These include the bevel style (Thin/Gadtools/Xen), window backfills, and group label details.\n\nPlease use the ClassAct GUI prefs editor to alter the default settings provided. ClassAct prefs will be installed in your system Prefs drawer.\n\n")
(set #caprefs-startup-1 "Adding the command\n\n")
(set #caprefs-startup-2 "\n\nTo your s:User-Startup.")

(procedure install-classact
(debug "classact")
; call this procedure to copy the classes included in the Classes directory
; in your distribution dir.
	(if (exists "Classes") ; The archive contains a ClassAct library update.
	(
		(set comp-dest  (/ (* classact-complete 5) 10))
		(set comp-libs  (/ (* classact-complete 5) 10))
		(set comp-dirs  (/ (* classact-complete 6) 10))
		(set comp-junod (/ (* classact-complete 6) 10))
		(set comp-020   (/ (* classact-complete 7) 10))
		(set comp-gad   (/ (* classact-complete 7) 10))
		(set comp-im    (/ (* classact-complete 8) 10))
		(set comp-prefs (/ (* classact-complete 9) 10))

		; has the user installed ClassAct in CLASSACT: ?
		(set @classact-dest (getassign "CLASSACT" "A"))
		(if (= @classact-dest "") (set @classact-dest "SYS:Classes"))

		; is ClassAct already in SYS:Classes ?
		(if (or (not (exists (tackon @classact-dest "Gadgets/layout.gadget") (noreq)))
		        (= @user-level 2))
		    ; no, ask where it should be placed
		    (set @classact-dest
		        (askdir
		            (prompt #classdest-prompt)
		            (help #classdest-help)
		            (default @classact-dest)
		            (newpath)
		        )
		    )
		)

		(complete comp-dest)

		(if (<> (run (cat "C/CheckAssign LIBS: " @classact-dest)) 0)
		    (
		        (message #noclasses-message)
		        (if (not (exists @classact-dest))
			        (makedir @classact-dest (prompt (cat #creating-dir @classact-dest)))
			    )
		        (set @addassign (cat "Assign >NIL: LIBS: " @classact-dest " ADD\n"))
		        (startup "CLASSACT"
		        	(command @addassign)
		            (prompt (cat #adding-1 @classact-dest #adding-2))
		            (help #adding-help)
		        )
		        (run (@addassign))
		    )
		)

		(complete comp-libs)

		(set @classact-gadgets (tackon @classact-dest "Gadgets"))
		(set @classact-images (tackon @classact-dest "Images"))

		(if (not (exists @classact-gadgets (noreq)))
		    (makedir @classact-images
		        (prompt (cat #creating-dir @classact-gadgets))
		    )
		)

		(if (not (exists @classact-images (noreq)))
		    (makedir @classact-images
		        (prompt (cat #creating-dir @classact-images))
		    )
		)

		(complete comp-dirs)

		(if (exists "SYS:Classes/Gadgets/button.gadget")
		    (if (< 40 (/ (getversion "SYS:Classes/Gadgets/button.gadget") 65536))
		        (if (askbool (prompt #junod-button) (help @askbool-help) (default 1))
		            (
		                (rename "SYS:Classes/Gadgets/button.gadget" "SYS:Classes/Gadgets/button.gadget.v42")
		                (message #junod-backed)
		            )
		            (message #junod-kept)
		        )
		    )
		)

		(complete comp-junod)

		(if (exists "Classes/Gadgets/layout.gadget.020")
			(set classes-020 (askbool (prompt #classes-020) (help #help-020) (default (and cpu020 v39))))
			(set classes-020 0)
		)

		(complete comp-020)

		(foreach "Classes/Gadgets" "#?.gadget"
			(
				(set thislib (tackon "Classes/Gadgets" @each-name))
				(if (and classes-020 (exists (cat thislib ".020")))
					(set thislib (cat thislib ".020"))
				)
			    (copylib (source thislib)
			        (dest @classact-gadgets)
			        (newname @each-name)
			        (prompt (cat #installing @each-name))
			        (help #classdest-help)
			        (optional "force" "askuser")
			    )
		    )
		)

		(complete comp-gad)

		(foreach "Classes/Images" "#?.image"
			(
				(set thislib (tackon "Classes/Images" @each-name))
				(if (and classes-020 (exists (cat thislib ".020")))
					(set thislib (cat thislib ".020"))
				)
			    (copylib (source thislib)
			        (dest @classact-images)
			        (newname @each-name)
			        (prompt (cat #installing @each-name))
			        (help #classdest-help)
			        (optional "force" "askuser")
			    )
		    )
		)

		(complete comp-im)

		(foreach "Classes" "#?.class"
			(
				(set thislib (tackon "Classes" @each-name))
				(if (and classes-020 (exists (cat thislib ".020")))
					(set thislib (cat thislib ".020"))
				)
			    (copylib (source thislib)
			        (dest @classact-dest)
			        (newname @each-name)
			        (prompt (cat #installing @each-name))
			        (help #classdest-help)
			        (optional "force" "askuser")
			    )
		    )
		)
	)
	)
	(if (exists "Prefs/ClassAct") ; The archive contains ClassAct prefs tools
	(
		(message #caprefs-message)

		(copylib (source "Prefs/CAPrefs")
			(dest "C:")
			(prompt (cat #installing "CAPrefs"))
		)
		(copylib (source "Prefs/ClassAct")
			(dest "SYS:Prefs")
			(prompt (cat #installing "ClassAct Prefs"))
			(infos)
		)

		(complete comp-prefs)

		(if (not (exists "ENVARC:ClassAct" (noreq)))
			(
				(makedir "ENVARC:ClassAct"
					(prompt (cat #creating-dir "ENVARC:ClassAct"))
				)
				(textfile (dest "ENVARC:ClassAct/ClassAct")
					(append "")
				)
			)
		)

		(set caprefs-cmd "C:CAPrefs >NIL:\n")

		(startup "CAPREFS"
			(prompt (cat #caprefs-startup-1 caprefs-cmd #caprefs-startup-2))
			(help #caprefs-message)
			(command caprefs-cmd)
		)
	)
	)

	(complete classact-complete)
)




; ------------------------------
; Check Kickstart Version
; ------------------------------


 (if (< (getversion "LIBS:version.library") (* 37 65536))
        (abort #bad-kick)
 )

(message #hello-message)


; ------------------------------
; What should I install?
; ------------------------------
(complete 0)
(set InstallOpt
      (askoptions (prompt #install-which)
                  (help @askoptions-help)
                  (choices "NewIcons" "DefIcons" "Documentation")
      )
)


; ------------------------------
; Install NewIcon.library
; ------------------------------

(complete 10)
(if ((patmatch (database "cpu") ("68000|68010")
     )
    )
      (copylib
           (source "/libs/000/newicon.library")
           (dest "libs:")
           (prompt #install-library)
           (help #install-library-help)
           (confirm)
      )

      (if (>= (getversion "LIBS:version.library") (* 39 65536)
          )

           (copylib
                (source "/libs/020-V39/newicon.library")
                (dest "libs:")
                (prompt #install-library)
                (help #install-library-help)
                (confirm)
           )
           (copylib
                (source "/libs/000/newicon.library")
                (dest "libs:")
                (prompt #install-library)
                (help #install-library-help)
                (confirm)
           )
      )
)

;--------------------------------------------------------
; Install NewIcons, icon images, and icon support files
;--------------------------------------------------------

(complete 20)
(if (BITAND InstallOpt 1)

   ((complete 25)

   (copylib
      (prompt #install-newicons)
      (source "/C/NewIcons")
      (dest "c:")
      (help #install-newicons-help)
   )

   (copylib
      (source "/C/InjectBrush")
      (dest "c:")
   )

   (copylib
      (source "/C/PatchOpenWB")
      (dest "c:")
   )

   (complete 30)

   (set destdir
      (askdir
            (prompt #tools-dest)
            (help @askdir-help)
            (default "Sys:Utilities")
      )
   )

   (copyfiles
      (source "/Utilities/CopyNewIcon")
      (dest destdir)
      (infos)
   )

   (copyfiles
      (source "/Utilities/CreateDefaultIcon")
      (dest destdir)
      (infos)
   )

   (copyfiles
      (source "/Utilities/KillNewIcon")
      (dest destdir)
      (infos)
   )

   (complete 35)

   (startup "NewIcons"
      (prompt #startup-change)
      (command "Run <NIL: >NIL: c:NewIcons")
      (help @startup-help)
   )


   (copylib
      (prompt #install-prefs)
      (source "/prefs/NewIconsPrefs")
      (dest "Sys:prefs")
      (help #install-prefs-help)
      (confirm)
      (infos)
   )




;------------------------------
;Install ClassAct classes
;------------------------------

;   (message #install-classes
;      (help #install-classes-help)
;   )
   (install-classact)
  )
)
;------------------------------
;Install Deficons
;------------------------------
(complete 75)
(if (BITAND InstallOpt 2)


  ((set destdir
      (askdir
           (prompt #move-olddefs-dir)
           (help #move-olddefs-help)
           (default "Sys:Storage")
      )
   )

   (set destdir
      (tackon destdir "Old_Def_icons")
   )

   (makedir destdir
   )

   (complete 80)

   (copyfiles
      (prompt #move-olddefs)
      (source "Envarc:sys")
      (dest destdir)
      (pattern "def#?")
      (help #move-olddefs-help)
   )

   (copylib
      (prompt #install-deficons)
      (source "/C/DefIcons")
      (dest "C:")
      (help #install-deficons-help)
      (confirm)
   )

   (copyfiles
      (prompt #install-envarc)
      (source "/envarc")
      (dest "ENVARC:")
      (all)
      (infos)
      (help #install-envarc-help)
   )

   (startup "DefIcons"
      (prompt #startup-deficons)
      (command "DefIcons")
      (help @startup-help)
   )
  )
)


;------------------------------
;Install Documentation
;------------------------------
(complete 90)
(if (BITAND InstallOpt 4)

   ((set destdir
      (askdir
            (prompt #docs-dest)
            (help @askdir-help)
            (default "Help:")
      )
    )
    (copyfiles
      (source "/NewIcons.guide")
      (dest destdir)
      (infos)
    )
   )
)


;------------------------------
;Run NIPrefs
;------------------------------

(complete 95)
(run "/prefs/NewIconsPrefs"
      (prompt #run-prefs)
      (help "This lets you configure NewIcons.")
      (confirm)
      (safe)
)

(run "Sys:Utilities/Multiview /NewIcons.guide"
      (safe)
)
(complete 99)
(message #powb-message)
(complete 100)
(exit #exit-message)