;**************************************************
;
;$VER: FUSION v2.1 (11/16/97)
;
; Title:
;    FUSION's Software Installer
; 
; Description:
;    The Commodore Installer Script for FUSION
;
; Installer script by Jim Drew
;
;**************************************************

(set true 1)
(set false 0)
(set quote "\"")
(set nothing "")
(set WB2 (< 2293760 (getversion "exec.library" (resident)))) ; true if under 2.0

(set FUSION_dir (getassign "FUSION"))
(set c_dir (getassign "C"))
(set libs_dir (getassign "LIBS"))
(set fonts_dir (getassign "FONTS"))
(set devs_dir (getassign "DEVS"))
(set s_dir (getassign "S"))

(set Src_root "")
(set Src_c "INSTALL/c/")
(set Src_s "INSTALL/s/")
(set Src_libs "INSTALL/libs/")
(set Src_devs "INSTALL/devs/")
(set Src_utils "INSTALL/utils/")
(set Src_ICP "INSTALL/ICP/")
(set Src_main "INSTALL/")
(set Src_docs "INSTALL/Documentation/")
(set Src_ROMS "INSTALL/ROM_Images/")
(set Src_Video "INSTALL/Video_Drivers/")
(set Src_ExtIO "INSTALL/Ext_IO/")
(set Temp_dir "ram:t/")

(set MSG_CopyDevs1 "\n\nCopying needed device ")
(set MSG_CopyDevs2 " to DEVS:")

; start with not updated software!

(set is_update false)

(if  (<> FUSION_dir nothing)
     (if  (askbool
               (prompt "\n\n\nSome version of FUSION already exists in"
               " your drawer named: \n\n"
               quote FUSION_dir quote
               "\n\nDo you want the update installed over it?")
               (help
               "\n\n\nThe installer has determined that you already have a "
               "some version of the MAC emulation software installed "
               "on your system.  If this is wrong or you want the update "
               "installed elsewhere, select 'NO', otherwise select 'YES'."
               )
               (default 1)
          )
               (set is_update true) 

;else ask where to put software

               (
               (set FUSION_dir
               (askdir
                    (prompt "Where would you like the updated software "
                    "installed?\n"
                    "The directory 'FUSION' will be created automatically.\n")
                    (help @askdir-help)
                    (default @default-dest)
               )
               )

               (set FUSION_dir
               (tackon FUSION_dir "FUSION")
               )

               (makedir FUSION_dir
               (infos)
               )
          )
     )
)

; FUSION: was not previously assigned, so ask where to make it
(if  (= FUSION_dir nothing)
          (
          (set FUSION_dir
               (askdir
                    (prompt "Where would you like the software installed?\n"
                    "The directory 'FUSION' will be created automatically.\n")
                    (help @askdir-help)
                    (default @default-dest)
               )
          )

          (set FUSION_dir
          (tackon FUSION_dir "FUSION")
          )


          (makedir FUSION_dir
          (infos)
          )
     )
)

(set @default-dest FUSION_dir)

(complete 5)

(working omp "...Please Wait...")

(copyfiles
     (prompt "Select file(s) to be copied into your C: directory:")
     (help "\n\n\n\n\nThis will copy RsrvCold and RsrvWarm to your C: "
     "directory.\n\n\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_c)
     (dest c_dir)
     (pattern "#?")
     (confirm)
)
   
(complete 10)

(working omp "...Please Wait...")

; copy amia.device

(copylib
   (source (tackon Src_devs "amia.device"))
   (dest "DEVS:")
   (prompt MSG_CopyDevs1 "amia.device" MSG_CopyDevs2)
   (help @copylib-help)
   (confirm)
)

(complete 15)

; copy mscd.device

(copylib
   (source (tackon Src_devs "mscd.device"))
   (dest "DEVS:")
   (prompt MSG_CopyDevs1 "mscd.device" MSG_CopyDevs2)
   (help @copylib-help)
   (confirm)
)

(complete 20)

; copy mshf.device

(copylib
   (source (tackon Src_devs "mshf.device"))
   (dest "DEVS:")
   (prompt MSG_CopyDevs1 "mshf.device" MSG_CopyDevs2)
   (help @copylib-help)
   (confirm)
)

(complete 25)

;copy multi-os.device

(copylib
   (source (tackon Src_devs "multi-os.device"))
   (dest "DEVS:")
   (prompt MSG_CopyDevs1 "'multi-os.device'" MSG_CopyDevs2)
   (help @copylib-help)
   (confirm)
)

(complete 30)

(working omp "...Please Wait...")

;create utilties directory
(set Utils_dir
(cat FUSION_dir)
)
(set Utils_dir
(tackon Utils_dir "Utils")
)

(makedir Utils_dir
;(infos)
)
   
(copyfiles
    (prompt "Select files to be copied to the FUSION:Utils directory:")
    (help "\n\n\n\n\nThis will copy all of the utilities for "
    "FUSION.\n\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_utils)
     (dest Utils_dir)
     (pattern "(ROMUtil#?)")
     (confirm)
)


(complete 40)

; Copy FUSION emulation

(working omp "...Please Wait...")
   
(set FUSION_dir
     (copyfiles
          (prompt "Select files to be copied to the FUSION: directory:")
          (help "\n\n\n\n\n\nThis will copy the MAC emulation's main "
          "programs.\n\n\n\n\n\n\n"
          @copyfiles-help)
          (source Src_main)
          (dest FUSION_dir)
          (pattern "(#?FUSION#?|.key|.dat)")
          (confirm)
     )
)

(working "Extracting data file...")
(Set lha (tackon Src_root "lhex "))
(run (cat lha '-qfw ' quote FUSION_dir quote " x " (tackon Src_main "dat.lha"))
)


;copy AppIcon

(complete 50)

(copyfiles
     (source Src_Main)
     (dest FUSION_dir)
     (pattern "(DEF_AppIcon.info)")
)

(complete 55)

;create Video_Drivers directory
   
(set VideoDrvr_dir
(cat FUSION_dir)
)
(set VideoDrvr_dir
(tackon VideoDrvr_dir "Video_Drivers")
)

(makedir VideoDrvr_dir
;(infos)
)

(working "Extracting video drivers...")
(Set lha (tackon Src_root "lhex "))
(run (cat lha '-qfw ' quote Temp_dir quote " x " (tackon Src_video "videodrivers.lha"))
)

(working omp "...Please Wait...")

(copyfiles
     (prompt "Select file(s) to be copied into your Video_Drivers directory:")
     (help "\n\n\n\n\nThis will copy the video drivers to the proper "
     "directory.  ALL MAC video drivers must reside in your "
     "'FUSION:Video_Drivers' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Temp_dir)
     (dest VideoDrvr_dir)
     (pattern "(#?)")
     (confirm)
)

(complete 60)

;create ExtIO directory

(set ExtIODrvr_dir
(cat FUSION_dir)
)
(set ExtIODrvr_dir
(tackon ExtIODrvr_dir "Ext_IO")
)
 
(makedir ExtIODrvr_dir
;(infos)
)

(working omp "...Please Wait...")

(copyfiles
(prompt "Select file(s) to be copied into your Ext_IO directory:")
     (help "\n\n\n\n\nThis will copy the external I/O drivers to the proper "
     "directory.  ALL external I/O drivers must reside in your "
     "'FUSION:Ext_IO' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_ExtIO)
     (dest ExtIODrvr_dir)
     (pattern "(#?)")
     (confirm)
)

(complete 70)

;create Documentation directory

(set Docs_dir
(cat FUSION_dir)
)
(set Docs_dir
(tackon Docs_dir "Documentation")
)

(makedir Docs_dir
(infos)
)

(working omp "...Please Wait...")

(copyfiles
     (prompt "Select file(s) to be copied Documentation directory:")
     (help "\n\n\n\nThis will copy the AmigaGuide documentation for "
     "FUSION.  ALL emulation documentation should reside in your "
     "'FUSION:Documenation' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_docs)
     (dest Docs_dir)
     (pattern "#?")
     (confirm)
)

(complete 80)

;create ROM_Images directory

(set ROM_dir
(cat FUSION_dir)
)
(set ROM_dir
(tackon ROM_dir "ROM_Images")
)

(makedir ROM_dir
;(infos)
)

(complete 85)

;create ICP directory
   
(set ICP_dir
(cat FUSION_dir)
)
(set ICP_dir
(tackon ICP_dir "ICP")
)

(makedir ICP_dir
(infos)
)

(working omp "...Please Wait...")

(copyfiles
     (prompt "Select files to be copied into your ICP directory:")
     (help "\n\n\n\n\nThis will copy the InterCommunication Port "
     "programs.  ALL ICP related programs should reside in your "
     "'FUSION:ICP' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_ICP)
     (dest ICP_dir)
     (pattern "(#?)")
     (confirm)
)

;create HardFiles directory
   
(set HF_dir
(cat FUSION_dir)
)
(set HF_dir
(tackon HF_dir "HardFiles")
)

(makedir HF_dir
;(infos)
)

(complete 90)

; add RsrvWarm to Startup-Sequence if this is not an update

(if  (= is_update false)
     (if  (askbool
               (prompt "\nIn order for MAC emulation to work correctly, "
               "the FIRST line in your STARTUP-SEQUENCE must be\n\n"
               "'RsrvWarm >NIL:'\n\n"
               "and somewhere in the USER-STARTUP must be an assigment"
               " for 'FUSION:'\n\n"
               "These lines can be added for you automatically by this "
               "installer.  Would you like these lines added?\n\n")
               (help @askbool-help)
               )

               (
                    (if (= @pretend 0)
                    (
                        (
                        (if  (not  (exists "s:user-startup"))
                             (textfile
                             (dest "s:user-startup")
                             (append ";user-startup \n\n")
                         )
                    )
                    (textfile
                    (dest "ram:startup-sequence")
                    (append ";BEGIN FUSION Setup (must be before Setpatch!)\n")
                    (append "RsrvWarm >NIL:\n")
                    (append ";END FUSION Setup \n\n")
                    (include "s:startup-sequence")
                    )
                    (rename "s:startup-sequence" "s:startup-sequence.old")
                    (copyfiles
                    (help @copyfiles-help)
                    (source "ram:startup-sequence")
                    (dest "s:")
                    )
                    (delete "ram:startup-sequence")

                    (textfile
                    (dest "ram:user-startup")
                    (include "s:user-startup")
                    (append ";BEGIN FUSION assignment\n")
                    (append "assign FUSION: " FUSION_dir)
                    (append "\nassign MSHF: " HF_dir)
                    (append "\n;END FUSION assignment\n")
                    )
                    (rename "s:user-startup" "s:user-startup.old")
                    (copyfiles
                    (help @copyfiles-help)
                    (source "ram:user-startup")
                    (dest "s:")
                    )
                    (delete "ram:user-startup")
               )
          )
          )
     )
     )
)

(complete 100)

(exit)
