;
;         IMPACT! Installer
;
;         by Andrew Frerking
;       ©1994 Dynamic Realities
;
; $VER: IMPACT! Installer 1.0b (6-13-95)
;

(set @appname "IMPACT!")


(set default_dir (if (exists "Work:Toaster" (noreq))
                     ("Work:Toaster")
                     ("SYS:")))

(set minmuiversion 10)
(set installmui 0)
(set exitmessage "You may now run IMPACT!")

;************** Help Text **************

(set help_find_area (cat "The installer needs to know where to install "
                         "IMPACT!  The default is your Video Toaster Drawer.  There "
                         "will be a directory called 'IMPACT!' created here.  If you already "
                         "have an older version of IMPACT! installed, select the same path "
                         "(minus the 'IMPACT!' part of the path) and the new version of IMPACT! "
                         "will be installed over the old and outdated one"))

(set help_insert_disk (cat "The Installer needs this disk to be inserted "
                           "to continue the installation process."))

;************** Main **************

(complete 0)
(welcome)


(set impact_dir (askdir (prompt "Please locate the area where "
                                "you wish to install IMPACT!  There will be "
                                "a directory called IMPACT! created here.")
                        (default default_dir)
                        (help help_find_area)))

(set @default-dest impact_dir)

(set tempdir (if (= ":" (substr impact_dir (- (strlen impact_dir) 1) 1))
                 impact_dir
                 (cat impact_dir "/")))

;(if (exists (cat impact_dir "IMPACT!"))
;    (protect (cat impact_dir "IMPACT!") "+w +d" all))

(working "\n\nDecompressing IMPACT! to " impact_dir)
(run ("c/lx x impact!.lha \"%s\"" tempdir))

(complete 50)


; Check for existance of 'muimaster.library' in Sys:Libs drawer
(if (exists "sys:libs/muimaster.library" (noreq))
    (delete "sys:libs/muimaster.library"
        (help "If you select 'Proceed', the old version will be deleted and the current version "
              "of 'muimaster.library' will be installed in the correct location (in the 'MUI:libs' "
              "drawer).  If you skip this part, IMPACT! will probably not work correctly and future "
              "versions of MUI will have problems.")
        (prompt "A older version of 'muimaster.library' was found in your 'Sys:Libs' path.  "
                "This could royally mess up how IMPACT! runs, so can we delete it and replace "
                "it with a current version in the correct location?")
        (confirm)
        (optional force)
    )
)

; Get MUI library version (if exists)
(set muiver (/ (getversion "libs:muimaster.library") 65536))

; Install MUI
(if (OR (NOT (exists "MUI:" (noreq)))   ;install if MUI assign does not exists
        (< muiver minmuiversion))       ;or if the library version found is less than this one 

    ; Ask user if they really want to install MUI
    (if (= (askbool (prompt "IMPACT! needs the interface tool called 'Magic User Interface' "
                            "(MUI) to be installed on your system.  If you had MUI installed "
                            "previously, it was found to be an outdated version and a new "
                            "version needs to be installed (it will be installed in the same "
                            "location).  Can we proceed and install this version of MUI?")
                    (help "Select 'YES' to install or 'NO' to skip.")) 1)

        (

        (set exitmessage "Please reboot your computer before running IMPACT!")

        ; Get the MUI path if exists or put in the IMPACT! drawer
        (if (exists "MUI:" (noreq))
            (set mui_dir (expandpath (cat (getassign "MUI") "/")))
            (set mui_dir (tackon impact_dir "IMPACT!")))
        (complete 60)

        (working "\n\nDecompressing MUI to " mui_dir)
        (run ("c/lx x mui.lha \"%s/\"" mui_dir))

        (complete 80)

        ; This is the full MUI path
        (set destination (tackon mui_dir "MUI"))

        ; Add this stuff to the user-startup
        (startup "MUI"
	        (prompt "Some required commands will be added to your \"s:user-startup\" file.")
            (help @startup-help)
    	    (command "if exists \"" destination "\"\n")
	        (command "   assign MUI: \"" destination "\"\n")
	        (command "   if exists MUI:Libs\n")
    	    (command "      assign add LIBS: MUI:Libs\n")
	        (command "   endif\n")
	        (command "   if exists MUI:Locale\n")
	        (command "      assign add LOCALE: MUI:Locale\n")
	        (command "   endif\n")
	        (command "   version >nil: exec.library 39\n")
	        (command "   if not warn\n")
	        (command "      if exists MUI:Docs\n")
	        (command "         if exists HELP:dummy ; do not remove\n")
	        (command "         endif                ; this entry!\n")
	        (command "         assign add HELP: MUI:Docs\n")
	        (command "      endif\n")
	        (command "   endif\n")
	        (command "endif"))

        ) ;End of if condition
    ) ;End of if statement
) ;End of if statement


; If defaults for MUI already exist, ask user if we should copy the defaults
(set copydefaults (if (exists "env:mui")
                      (askbool (prompt "Do you wish us to copy the default screen and IMPACT! "
                                       "settings?  If you do, any existing settings you may have had "
                                       "from a previous version of IMPACT! or MUI will be "
                                       "overwritten.  If you don't, you may have to change IMPACT!'s "
                                       "screenmode later.")
                               (help "Select 'YES' to install or 'NO' to skip."))
                      1))

; Copy the defaults
(if (= copydefaults 1)
    (

    (set exitmessage "Please reboot your computer before running IMPACT!")

    ; Ask user what mode they want IMPACT! to start on initially
    (set screenmode (askchoice
                        (help @askchoice-help)
                        (prompt "What screenmode would you like IMPACT! to start initially on?  "
                                "This choice can be changed later using the MUI program located in "
                                "the MUI drawer.  If you have a third party graphics board, select "
                                "Workbench and change it later with MUI.")
                        (choices "Workbench Screen"
                                 "NTSC"
                                 "DBLNTSC (AGA)"
                                 "PAL"
                                 "DBLPAL (AGA)"
                                 "MULTISCAN")))

    ; Copy the appropriate screenmode default
    (select screenmode (copyfiles (source "Defaults/Workbench")
                                  (dest "ENVARC:mui")
                                  (all)
                                  (optional force))

                       (copyfiles (source "Defaults/NTSC")
                                  (dest "ENVARC:mui")
                                  (all)
                                  (optional force))

                       (copyfiles (source "Defaults/DBLNTSC")
                                  (dest "ENVARC:mui")
                                  (all)
                                  (optional force))

                       (copyfiles (source "Defaults/PAL")
                                  (dest "ENVARC:mui")
                                  (all)
                                  (optional force))

                       (copyfiles (source "Defaults/DBLPAL")
                                  (dest "ENVARC:mui")
                                  (all)
                                  (optional force))

                       (copyfiles (source "Defaults/MULTISCAN")
                                  (dest "ENVARC:mui")
                                  (all)
                                  (optional force)))
    ) ;End of if condition
) ;End of if statement


(complete 100)
(exit exitmessage)
