;**************************************************
;
;$VER: MAC Lite Emulation Installer v1.0 (24 Jun 1996)
;
; Title:
;    EMPLANT's MAC Lite Emulation Software Installer
; 
; Description:
;    The Commodore Installer Script for EMPLANT's
;    MAC emulation module software.
;
; 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 mode 0)				;default to 32 bit mode

(set EMPLANT_dir (getassign "EMPLANT"))
(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_c "MacII:MAC_EMU/c/")
(set Src_devs "MacII:MAC_EMU/devs/")
(set Src_fonts "MacII:MAC_EMU/fonts/")
(set Src_libs "MacII:MAC_EMU/libs/")
(set Src_docs "MacII:MAC_EMU/Documentation/")
(set Src_ExtIO "MacII:MAC_EMU/Ext_IO/")
(set Src_ROMS "MacII:MAC_EMU/ROM_Images/")
(set Src_Video "MacII:MAC_EMU/Video_Drivers/")
(set Src_main "MacII:MAC_EMU/")

(if  (<> EMPLANT_dir nothing)
     (if  (askbool
               (prompt "\n\n\nSome version of the MAC emulation software "
               "already exists in your drawer named: \n\n"
               quote EMPLANT_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 is_update false)
               (set EMPLANT_dir
               (askdir
                    (prompt "Where would you like the updated software "
                    "installed?\n"
                    "'EMPLANT' will be automatically appended.")
                    (help @askdir-help)
                    (default @default-dest)
               )
               )

               (set EMPLANT_dir
               (tackon EMPLANT_dir "EMPLANT")
               )

               (makedir EMPLANT_dir
               (infos)
               )
          )
     )
)

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

          (set EMPLANT_dir
          (tackon EMPLANT_dir "EMPLANT")
          )

          (makedir EMPLANT_dir
          (infos)
          )
     )
)

          (set EMU_Dir
          (tackon EMPLANT_dir "MACLite")
          )

          (makedir EMU_dir
          (infos)
          )

(set @default-dest EMU_dir)

(complete 5)

; ask user to locate SYS:C directory

(set c_dir
     (askdir
          (prompt "Please locate your C: directory.")
          (help @askdir-help)
          (default c_dir)
     )
)
   
(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 to your C: "
     "directory.\n\n\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_c)
     (dest c_dir)
     (pattern "#?")
     (confirm)
)

(complete 10)

; ask user to locate LIBS: directory

(set libs_dir
     (askdir
          (prompt "Please locate your LIBS: directory.")
          (help @askdir-help)
          (default libs_dir)
          (newpath)
     )
)

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

(copyfiles
     (prompt "Select file(s) to be copied into your LIBS: directory:")
     (help "\n\n\n\n\nThis will copy the JAM library into your "
     "system's LIBS: directory.\n\n\n\n\n\n\n"
     @copylib-help)
     (source Src_libs)
     (dest libs_dir)
     (pattern "(#?.library#?)")
     (confirm)
)

(complete 20)

; ask user to locate DEVS: directory

(set devs_dir
     (askdir
          (prompt "Please locate your DEVS: directory")
          (help @askdir-help)
          (default devs_dir)
     )
)
 
(working omp "...Please Wait...")  

(copyfiles
     (prompt "Select file(s) to be copied into your DEVS: directory:")
     (help "\n\n\n\n\nThis will copy the device drivers for the use "
     "with EMPLANT's various I/O ports.\n\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_devs)
     (dest DEVS_dir)
     (pattern "#?")
     (confirm)
)

(complete 30)

; ask user to locate FONTS: directory

(set Fonts_dir
     (askdir
          (prompt "Please locate your FONTS: directory")
          (help @askdir-help)
          (default fonts_dir)
          (newpath)
     )
)

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

(copyfiles
     (prompt "Select file(s) to be copied into your FONTS: directory:")
     (help "\n\n\n\n\nThis will copy over any fonts needed for the "
     "emulation.\n\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_fonts)
     (dest fonts_dir)
     (pattern "(SCAIV#?)")
     (fonts)
     (confirm)
)

(complete 40)

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

; Copy utilities
   
(set EMPLANT_dir
     (copyfiles
          (prompt "Select files to be copied to the EMPLANT: directory:")
          (help "\n\n\n\n\nThis will copy all of the utilities for the "
          "EMPLANT hardware and the MAC emulation.\n\n\n\n\n\n\n"
          @copyfiles-help)
          (source Src_main)
          (dest EMPLANT_dir)
          (pattern "(HardFile#?|ROMINFO#?|MAC_HDSetup#?)")
          (confirm)
     )
)

(complete 50)

; Copy over the MAC EMULATION programs

(working omp "...Please Wait...")
   
(set EMU_dir
     (copyfiles
          (prompt "Select files to be copied to the EMPLANT:MAC/ 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 EMU_dir)
          (pattern "(MACLite#?|Lite.dat)")
          (confirm)
     )
)

;copy AppIcon

(copyfiles
     (source Src_Main)
     (dest EMU_dir)
     (pattern "(EMP_AppIcon.info)")
)

(complete 55)

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

(makedir VideoDrvr_dir
(infos)
)

(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 "
     "'\EMPLANT:MAC/Video_Drivers\' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_video)
     (dest VideoDrvr_dir)
     (pattern "(#?)")
     (confirm)
)

(complete 60)

;create ExtIO directory

(set ExtIODrvr_dir
(cat EMU_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 MAC external I/O drivers must reside in your "
     "'\EMPLANT:MAC/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 EMU_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 various documentation and "
     "IFF pictures to your documentation directory.  ALL MAC emulation "
     "documentation should reside in your "
     "'\EMPLANT:MAC/Documenation\' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_docs)
     (dest Docs_dir)
     (pattern "#?")
     (confirm)
)

(complete 75)

;create ROM_Images directory

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

(makedir ROM_dir
(infos)
)

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

(copyfiles
     (prompt "Select ROM Image(s) and Related Files:")
     (help "\n\n\n\n\nThis will copy your ROM image(s) from your "
     "original installation (if applicable).  ALL ROM image files "
     "must be in your '\EMPLANT:MAC/ROM_Images\' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_ROMS)
     (dest ROM_dir)
     (pattern "#?")
     (confirm)
)

(complete 80)


; add custom EMPLANT setup caller to Startup-Sequence if 'AssignEMPLANT'
; does not exist yet

(if  (not (exists "s:AssignEMPLANT"))
     (if  (askbool
               (prompt "\nIn order for MAC emulation to work correctly, "
               "the FIRST line in your STARTUP-SEQUENCE must be\n\n"
               "'execute >NIL: s:SetupEMPLANT'\n\n"
               "and the LAST line of your USER-STARTUP must be:\n\n"
               "'execute >NIL: s:AssignEMPLANT'\n\n"
               "These lines can be automatically added by this installer "
               "script.  Do you wish to proceed?\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 EMPLANT \n")
                    (append "assign t: ram: \n")
                    (append "execute >NIL: s:SetupEMPLANT \n")
                    (append ";END EMPLANT \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 EMPLANT \n")
                    (append "execute >NIL: s:AssignEMPLANT \n")
                    (append ";END EMPLANT \n")
                    )
                    (rename "s:user-startup" "s:user-startup.old")
                    (copyfiles
                    (help @copyfiles-help)
                    (source "ram:user-startup")
                    (dest "s:")
                    )
                    (delete "ram:user-startup")
               )
          )
          )
     )
     )
)

;create mini-script files
      
(delete "s:SetupEMPLANT")
(textfile
(dest "s:SetupEMPLANT")
(append "RsrvCold >NIL: \n")
)
(delete "s:AssignEMPLANT")
(textfile
(dest "s:AssignEMPLANT")
(append "Assign EMPLANT: " EMPLANT_dir "\n")
)


(complete 100)

(message "\n\n\n\n"
"A T T E N T I O N ! ! !\n\n"
"You must turn off the power to your Amiga before attempting "
"to run the emulation.  Simply rebooting will NOT work, you "
"MUST physically turn off of the Amiga with its power switch. "
"No exceptions."
)          

(exit)
