;**************************************************
;
;$VER: PCx Emulation Installer v1.0 (02 Dec 1996)
;
; Title:
;    PCx Emulation Software Installer
; 
; Description:
;    The Commodore Installer Script for PCx
;
; 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 PCx_dir (getassign "PCx"))
(set c_dir (getassign "C"))
(set libs_dir (getassign "LIBS"))
(set devs_dir (getassign "DEVS"))
(set s_dir (getassign "S"))
(set MSHF_dir (getassign "MSHF"))

(set Src_c "OurPC:PC_EMU/c/")
(set Src_s "OurPC:PC_EMU/s/")
(set Src_libs "OurPC:PC_EMU/libs/")
(set Src_devs "OurPC:PC_EMU/devs/")
(set Src_main "OurPC:PC_EMU/")
(set Src_docs "OurPC:PC_EMU/Documentation/")
(set Src_BIOS "OurPC:PC_EMU/BIOS/")
(set Src_Video "OurPC:PC_EMU/DisplayDrivers/")
(set Src_Utils "OurPC:PC_UTILS/")

(if  (<> PCx_dir nothing)
     (if  (askbool
               (prompt "\n\n\nA previous installation of PCx has been "
               "detected in the root drawer: \n\n"
               quote PCx_dir quote
               "\n\nDo you want the update installed into this drawer?")
               (help
               "\n\n\nThe installer has determined that you already have a "
               "some version of a the PCx emulation 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 PCx_dir
               (askdir
                    (prompt "Where would you like the updated software "
                    "installed?\n"
                    "The directory 'PCx' will automatically created")
                    (help @askdir-help)
                    (default @default-dest)
               )
               )

               (set PCx_dir
               (tackon PCx_dir "PCx")
               )

               (makedir PCx_dir
               (infos)
               )
          )
     )
)

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

          (set PCx_dir
          (tackon PCx_dir "PCx")
          )

          (makedir PCx_dir
          (infos)
          )
     )
)

(set @default-dest PCx_dir)

(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 necessary "
     "libraries 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 30)

; 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 PCx's various I/O ports.\n\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_devs)
     (dest DEVS_dir)
     (pattern "#?")
     (confirm)
)

(complete 40)

;create Utils directory

(set Utils_dir
(cat PCx_dir)
)
(set Utils_dir
(tackon Utils_dir "PC_UTILS")
)

(makedir Utils_dir
;(infos)
)

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

(copyfiles
     (prompt "Select PC driver file(s) to be copied:")
     (help "\n\n\n\nThis will copy various PC drivers"
     ".\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_Utils)
     (dest Utils_dir)
     (pattern "#?")
     (confirm)
)

(complete 50)

; Copy over the PCx EMULATION programs

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

(complete 60)

;create Utils directory

(set HF_dir
(cat PCx_dir)
)
(set HF_dir
(tackon HF_dir "HardFiles")
)

(makedir HF_dir
;(infos)
)

(complete 65)

;create DisplayDrivers directory
   
(set DisplayDrvr_dir
(cat PCx_dir)
)
(set DisplayDrvr_dir
(tackon DisplayDrvr_dir "DisplayDrivers")
)

(makedir DisplayDrvr_dir
;(infos)
)

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

(copyfiles
     (prompt "Select file(s) to be copied into your DisplayDrivers directory:")
     (help "\n\n\n\n\nThis will copy the video drivers to the proper "
     "directory.  ALL PCx display drivers must reside in your "
     "'PCx:DisplayDrivers' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_video)
     (dest DisplayDrvr_dir)
     (pattern "(#?)")
     (confirm)
)

(complete 70)

;create Documentation directory

(set Docs_dir
(cat PCx_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 PCx "
     "documentation should reside in your "
     "'PCx:Documenation' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_docs)
     (dest Docs_dir)
     (pattern "#?")
     (confirm)
)

(complete 80)

;create BIOS directory

(set BIOS_dir
(cat PCx_dir)
)
(set BIOS_dir
(tackon BIOS_dir "BIOS")
)

(makedir BIOS_dir
;(infos)
)

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

(copyfiles
     (prompt "Select BIOS Image(s) and Related Files:")
     (help "\n\n\n\n\nThis will copy the native BIOS. "
     "ALL BIOS files "
     "must be in your 'PCx:BIOS' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_BIOS)
     (dest BIOS_dir)
     (pattern "#?")
     (confirm)
)

(complete 90)

; alter user-startup for assignment of PCx:

(if  (not (<> MSHF_dir nothing))
     (if (askbool
               (prompt "\nIn order for PCx to work, two assignments "
               "must be made to the s:user-startup file.  These "
               "assignments are:\n\n"
               "'assign PCx: <device>:'\n\n"
               "'assign MSHF: PCx:HardFiles'\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:user-startup")
                    (include "s:user-startup")
                    (append ";BEGIN PCx \n")
                    (append "assign PCx: " PCx_dir "\n")
                    (append "assign MSHF: PCx:HardFiles/ \n")
                    (append ";END PCx \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)

(message "\n\n\n\n\n\n"
"Installation of emulation software is complete."
)

(exit)
