;**************************************************
;
;$VER: MAC II/x/cx Emulation Installer v1.3 (29 jul 1993)
;
; Title:
;    EMPLANT's MAC II/x/cx Emulation Software Installer
; 
; Description:
;    The Commodore Installer Script for EMPLANT's
;    MAC II/x/cx emulation module software.
;
; Author:
;    Brian Walz & Jim Drew
;
;**************************************************

; some useful variables
   (set true 1)
   (set false 0)
   (set on true)
   (set off false)
   (set yes true)
   (set no false)
   (set is_a_file 1)
   (set is_a_dir 2)
   (set quote "\"")
   (set newline "\n")
   (set nothing "")
   (set WB2 (< 2293760 (getversion "exec.library" (resident)))) ; true if under 2.0

; set up our delete options
   (delopts "AskUser" "OkNoDelete" "Force")


;****************************************
;***** FIGURE OUT WHERE STUFF GOES ******
;****************************************

; now figure out the initial defaults for a bunch of things
     (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:EMPLANT/c/")
     (set Src_s "MacII:EMPLANT/s/")
     (set Src_libs "MacII:EMPLANT/libs/")
     (set Src_fonts "MacII:EMPLANT/fonts/")
     (set Src_devs "MacII:EMPLANT/devs/")
     (set Src_main "MacII:EMPLANT/")
     (set Src_docs "MacII:EMPLANT/Documentation/")
     (set Src_Video "MacII:EMPLANT/Video_Drivers/")
     (set Src_Logo "MacII:EMPLANT/Logos/")
     (set Src_ExtIO "MacII:EMPLANT/Ext_IO/")

; see if we are doing an update
   (if (<> EMPLANT_dir nothing)
      (if (askbool
            (prompt "\n\n\nSome version of the MAC II/x/cx 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 II/x/cx emulation software installed "
               "on your system.  If this is wrong or you want the update installed "
               "elsewhere, select 'NO', otherwise select 'YES'."
            )
            (default 1)
         )
         ( ; the then clause
            (set is_update true) 
         )
         ( ; the else clause
            (set is_update false)
            (set EMPLANT_dir
               (askdir
                  (prompt "Where would you like the updated software installed?")
                  (help @askdir-help)
                  (default @default-dest)
               )
            )
            (set EMPLANT_dir
               (tackon EMPLANT_dir "EMPLANT")
            )
            (makedir EMPLANT_dir
            (infos)
            )
           
         )
      )
   )

; if EMPLANT_dir is still nothing then where do they want it?
   (if (= EMPLANT_dir nothing)
      ( ; then clause
        (set EMPLANT_dir
           (askdir
              (prompt "Where would you like the software installed?")
              (help @askdir-help)
              (default @default-dest)
           )
        )
        (set EMPLANT_dir
           (tackon EMPLANT_dir "EMPLANT")
        )
        (makedir EMPLANT_dir
        (infos)
        )
      )
   )

; tell the user of our progress
   (complete 5)

; lets make sure the C: stuff goes there
   (set c_dir
      (askdir
         (prompt "Where would you like the C: files installed?")
         (help @askdir-help)
         (default c_dir)
      )
   )
   
; first copy over the c: stuff
   (working omp "Scanning C: directory on distribution disk...")
   
   (set c_dir
      (copyfiles
         (prompt "Select file(s) to be copied into your C: directory:")
         (help "\n\nThis will copy RsrvMem37ii "
            "to your system's C: directory.\n\n"
            @copyfiles-help
         )
         (source Src_c)
         (dest c_dir)
         (pattern "#?MEM#?")
         (confirm)
      )
   )
   
; tell the user of our progress
   (complete 10)


; lets make sure the Libs: stuff goes there
   (set libs_dir
      (askdir
         (prompt "Where would you like the LIBS: files installed?")
         (help @askdir-help)
         (default libs_dir)
         (newpath)
      )
   )

; copy over the libs: stuff
   (working omp "Scanning LIBS: directory on distribution disk...")
   
   (copyfiles
      (prompt "Select file(s) to be copied into your LIBS: directory:")
      (help "\n\nThis will copy the EMPLANT, SYBIL, and "
         "JAM libraries into your system's LIBS: directory.\n\n"
         @copylib-help
      )
      (source Src_libs)
      (dest libs_dir)
      (pattern "(EMPLANT#?|SYBIL#?|JAM#?)")
      (confirm)
     )

; tell the user of our progress
    (complete 20)

; lets make sure the Devs: stuff goes there
   (set DEVS_dir
      (askdir
         (prompt "Where would you like the DEVS: files installed?")
         (help @askdir-help)
         (default DEVS_dir)
      )
   )
   
; first copy over the DEVS: stuff
   (working omp "Scanning DEVS: directory on distribution disk...")
   
   (set DEVS_dir
      (copyfiles
         (prompt "Select file(s) to be copied into your DEVS: directory:")
         (help "\n\nThis will copy the device drivers for the use with "
            "EMPLANT's various ports.\n\n"
            @copyfiles-help
         )
         (source Src_devs)
         (dest DEVS_dir)
         (pattern "EMP#?")
         (confirm)
      )
   )

; tell the user of our progress
    (complete 30)

; Lets make sure the Fonts go there
   (set Fonts_dir
      (askdir
         (prompt "Where would you like the font installed?")
         (help @askdir-help)
         (default fonts_dir)
         (newpath)
      )
   )

; copy over the fonts
   (working omp "Scanning FONTS: on distribution disk...")

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

; tell the user of our progress
    (complete 40)

  
; Copy over the EMPLANT programs
   (working omp "Scanning for Utilities and ReadMe files...")
   
   (set EMPLANT_dir
      (copyfiles
         (prompt "Select various files to be copied to the EMPLANT: directory:")
         (help "\n\nThis will copy the utilities and some various "
            "readme files.\n\n"
            @copyfiles-help
         )
         (source Src_main)
         (dest EMPLANT_dir)
         (pattern "(Conv#?|Diag#?|Dump#?|Hard#?|MacII|Soft#?|Rominfo|Read#?|InitRet#?|MAC_HDSetup#?|VBRMover#?|HardFileSetup#?|#?.info)")
         (confirm)
      )
   )
   
; tell the user of our progress
   (complete 50)


; Ask user where to put Video Drivers
  (Set VideoDrvr_dir
     (askdir
        (prompt "Where do you want to install the Video Drivers? "
           "'Video_Drivers' will be automatically appended.")
        (help @askdir-help)
        (default EMPLANT_dir)
     )
  )

   (set VideoDrvr_dir
      (tackon VideoDrvr_dir "Video_Drivers")
   )
 
   (makedir VideoDrvr_dir
      (infos)
   )

; Copy over Video Drivers
   (Working omp "Scanning for Video Drivers on distribution disk...")

   (copyfiles
      (prompt "Select file(s) to be copied into your Video_Drivers directory:")
      (help "\n\nThis will copy the video drivers to your "
         "system.  If you do not already have a drawer for them, "
         "one will be created for you.\n\n"
         @copyfiles-help
      )
      (source Src_video)
      (dest VideoDrvr_dir)
      (pattern "(#?video#?)")
      (confirm)
   )

; tell the user of our progress
    (complete 60)


; Ask user where to put External I/O Drivers
  (Set ExtIODrvr_dir
     (askdir
        (prompt "Where do you want to install the External I/O Driver(s)? "
           "'Ext_IO' will be automatically appended.")
        (help @askdir-help)
        (default EMPLANT_dir)
     )
  )

   (set ExtIODrvr_dir
      (tackon ExtIODrvr_dir "Ext_IO")
   )
 
   (makedir ExtIODrvr_dir
      (infos)
   )

; Copy over External I/O Drivers
   (Working omp "Scanning for External I/O Drivers on distribution disk...")

   (copyfiles
      (prompt "Select file(s) to be copied into your Ext_IO directory:")
      (help "\n\nThis will copy the External I/I drivers to your "
         "system.  If you do not already have a drawer for them, "
         "one will be created for you.\n\n"
         @copyfiles-help
      )
      (source Src_ExtIO)
      (dest ExtIODrvr_dir)
      (pattern "(#?)")
      (confirm)
   )

; tell the user of our progress
    (complete 70)


; Ask user where to put logos
  (Set Logos_dir
     (askdir
        (prompt "Where do you want to install the logos? "
           "'Logos' will be automatically appended.")
        (help @askdir-help)
        (default EMPLANT_dir)
     )
  )

   (set Logos_dir
      (tackon Logos_dir "Logos")
   )
 
   (makedir Logos_dir
      (infos)
   )

; Copy over logos
   (Working omp "Scanning for logos on distribution disk...")

   (copyfiles
      (prompt "Select file(s) to be copied into your Logos directory:")
      (help "\n\nThis will copy the logos to your "
         "system.  If you do not already have a drawer for them, "
         "one will be created for you.\n\n"
         @copyfiles-help
      )
      (source Src_logo)
      (dest logos_dir)
      (pattern "(#?logo#?)")
      (confirm)
   )

; tell the user of our progress
    (complete 80)

; Ask where to put Documentation
  (set Docs_dir
     (askdir
        (prompt "Where do you want the Documentation installed? "
           "'Documentation' will be automatically appended.")
        (help @askdir-help)
        (default EMPLANT_dir)
     )
  )

  (set Docs_dir
     (tackon Docs_dir "Documentation")
  )

  (makedir Docs_dir
     (infos)
  )

; copy over Documentation
   (working omp "Scanning for Documentation...")

   (copyfiles
      (prompt "Copying Documentation Files...")
      (help "\n\nThis will copy the EMPLANT & emulation documentation to your "
         "system.  If you do not already have a drawer for them, "
         "one will be created for you.\n\n"
         @copyfiles-help
      )
      (source Src_docs)
      (dest Docs_dir)
      (pattern "#?")
      (confirm)
    )

; tell the user of our progress
    (complete 90)

; create a drawer for ROM images
   (set ROM_dir
      (askdir
         (prompt "Where do you want the drawer for your ROM image(s)? "
             "'ROM_Images' will be automatically appended.")
         (help
            "\n\nThis will create a drawer for you to store any ROM "
            "images you make for EMPLANT.\n\n"
            @askdir-help
         )
         (default EMPLANT_dir)
      ) 
   )

   (set ROM_dir
      (tackon ROM_dir "ROM_Images")
   )

   (makedir ROM_dir
      (infos)
   )

; tell the user of our progress
    (complete 95)

; add custom EMPLANT setup caller to Startup-Sequence
 (if (not (exists "s:AssignEMPLANT"))
   (if (askbool
          (prompt "\nIn order for MAC II/x/cx 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)
              (
                  (
                      (textfile
                         (dest "ram:startup-sequence")
                         (append "execute >NIL: s:SetupEMPLANT \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 "execute >NIL: s:AssignEMPLANT \n")
                      )
                      (rename "s:user-startup" "s:user-startup.old")
                      (copyfiles
                         (help @copyfiles-help)
                         (source "ram:user-startup")
                         (dest "s:")
                      )
                      (delete "ram:user-startup")
                   )
                 )
               )
             )
           )
         )
 
                      (delete "s:SetupEMPLANT")
                      (textfile
                         (dest "s:SetupEMPLANT")
                         (append "RsrvMem37ii >NIL: \n")
                      )
                      (delete "s:AssignEMPLANT")
                      (textfile
                         (dest "s:AssignEMPLANT")
                         (append "Assign EMPLANT: " EMPLANT_dir "\n")
                      )

; tell the user of our progress
   (complete 100)

   ; now for the real exit
   (exit)
