; $VER: V42PrinterInstall 42.3 (31.1.95)
; Script to install V42 printer.device

;===============================================================
; Set up text strings
;===============================================================

(set #introduction
    (cat "\n\nThis program lets you install V42 of the printer.device "
         "onto a hard drive.\nV42 of the printer.device provides "
         "multi-threaded multi-printer support, printer management, "
         "and printing to files.\n\n"
         "Please refer to the documentation and software for "
         "distribution and copyright information."))

(set #ask-old
    (cat "Do you wish to save the V3x printer files?"))

(set #ask-old-help
    (cat "Answering YES will make the install save the old printer "
         "related files to a specified directory.  Otherwise, the files "
         "will be deleted.\n\n"))

(set #where-old
    (cat "In which directory should the OLD printer files be placed?"))

(set #where-old-help
    (cat "This section lets you choose on which hard drive directory the "
         "old printer.device related files should go.\n\n"
         @askdir-help))

(set #where-device
    (cat "In which directory should the V42 printer.device be installed?"))

(set #where-device-help
    (cat "This section lets you choose on which hard drive directory the "
         "V42 printer.device will be installed.  This should normally go "
         "to the same directory as the V3x printer.device.\n\n"
         @askdir-help))

(set #where-handler
    (cat "In which directory should the V42 printer-handler be installed?"))

(set #where-handler-help
    (cat "This section lets you choose on which hard drive directory the "
         "V42 printer-handler will be installed.  This should normally go "
         "to the same directory as the V3x dos handlers.\n\n"
         @askdir-help))

(set #where-dosdriver
    (cat "In which directory should the V42 PRT: mountlist be installed?"))

(set #where-dosdriver-help
    (cat "This section lets you choose on which hard drive directory the "
         "V42 PRT: mountlist will be installed.  This should normally go "
         "to the same directory as the V3x mountlists.\n\n"
         @askdir-help))

(set #where-prefs
    (cat "In which directory should the V42 Printer prefs be installed?"))

(set #where-prefs-help
    (cat "This section lets you choose on which hard drive directory the "
         "V42 Printer prefs will be installed.  This should normally go "
         "to the same directory as the V3x preferences programs.\n\n"
         @askdir-help))

(set #where-prtmgr
    (cat "In which directory should the V42 Printer Manager be installed?"))

(set #where-prtmgr-help
    (cat "This section lets you choose on which hard drive directory the "
         "V42 Printer Manager will be installed.\n\n"
         @askdir-help))

(set #ask-postscript
    (cat "Do you wish to patch to PostScript driver to allow multiple "
         "postscript printers?"))

(set #ask-postscript-help
    (cat "Answering YES will make the install patch the PostScript "
         "driver.  Version 39.1 of the driver is required.\n\n"))

(set #where-postscript
    (cat "In which directory should the V42 PostScript driver be installed?"))

(set #where-postscript-help
    (cat "This section lets you choose on which hard drive directory the "
         "V42 PostScript driver will be installed.  This should normally go "
         "to the same directory as the V3x printer drivers.\n\n"
         @askdir-help))

(set #where-v39postscript
    (cat "Please locate the V39.1 PostScript driver."))

(set #where-v39postscript-help
    (cat "The V39.1 PostScript driver is required for the V42.1 patch.\n\n"
         @askdir-help))

(set #which-ports
    (cat "Which printer ports do you wish to have installed?"))

(set #ask-prt
    (cat "In order to use the new PRT: handler, "
         "the following commands are needed.  "
         "Do you want them added to your startup?\n\n"
         "assign PRT: dismount\nmount PRT:\n\n"
         "NOTE: PRT: will not be mounted until you reboot."))

(set #ask-prt-help
    (cat "The listed commands are required to dismount the old PRT: and "
         "mount the new PRT: using the installed mountlist.  "
         "If you request it, the installer will add the necessary commands "
         "to your user-startup script, which is run when your machine boots.  "
         "If you decide not to allow the installer to make these changes, "
         "you will need to make them yourself."))

;===============================================================
; Introduction
;===============================================================

(complete 0)
(message #introduction)
(set old-level @user-level)

;===============================================================
; Get information from the user
;===============================================================

(set yn-saveold (askbool (prompt #ask-old)
    (help #ask-old-help)
    (default 1)))

(if (= yn-saveold 1)
(
   (set target-old (askdir (prompt #where-old)
       (help @askdir-help)
       (default "SYS:Old")
       (disk)))
))

(set target-device (askdir (prompt #where-device)
    (help #where-device-help)
    (default "DEVS:")
    (disk)))

(set yn-postscript (askbool (prompt #ask-postscript)
    (help #ask-postscript-help)
    (default 1)))

(if (= yn-postscript 1)
(
   (set target-postscript (askdir (prompt #where-postscript)
       (help #where-postscript-help)
       (default "PRINTERS:")
       (disk)))
))

(set target-handler (askdir (prompt #where-handler)
    (help #where-handler-help)
    (default "L:")
    (disk)))

(set target-dosdriver (askdir (prompt #where-dosdriver)
    (help #where-dosdriver-help)
    (default "DEVS:DosDrivers")
    (disk)))

(set target-prefs (askdir (prompt #where-prefs)
    (help #where-prefs-help)
    (default "SYS:Prefs")
    (disk)))

(set target-prtmgr (askdir (prompt #where-prtmgr)
    (help #where-prtmgr-help)
    (default "SYS:System")
    (disk)))

(set list-ports (askoptions (prompt #which-ports)
    (choices "Amiga Internal Parallel"
             "Amiga Internal Serial"
             "Print to File"
             "No Output Device"
             "Envoy")
    (help)))

(set @default-dest "RAM:")

;===============================================================
; Save the old files if requested
;===============================================================

(if (= yn-saveold 1)
(
   (if (exists (tackon target-device "printer.device"))
   (
       (set result (run (cat "Version " (tackon target-device "printer.device")
                             " FILE VERSION 42")))
       (if (> result 0)
       (
           (copyfiles (source (tackon target-device "printer.device")) (dest target-old))
       ))
   ))
   (complete 4)

   (if (exists (tackon target-prefs "Printer"))
   (
       (set result (run (cat "Version " (tackon target-prefs "Printer")
                             " FILE VERSION 42")))
       (if (> result 0)
       (
           (copyfiles (source (tackon target-prefs "Printer")) (dest target-old))
           (complete 8)

           (if (exists (tackon target-prefs "Printer.info"))
           (
               (copyfiles (source (tackon target-prefs "Printer.info")) (dest target-old))
           ))
           (complete 12)

           (if (exists (tackon target-prefs "PrinterGfx"))
           (
               (copyfiles (source (tackon target-prefs "PrinterGfx")) (dest target-old))
           ))
           (complete 16)

           (if (exists (tackon target-prefs "PrinterGfx.info"))
           (
               (copyfiles (source (tackon target-prefs "PrinterGfx.info")) (dest target-old))
           ))
       ))
   ))
))
(complete 20)

;===============================================================
; Delete the V39 files
;===============================================================

(if (exists (tackon target-device "printer.device"))
(
    (delete (tackon target-device "printer.device"))
))
(complete 24)

(if (exists (tackon target-prefs "Printer"))
(
    (delete (tackon target-prefs "Printer"))
))
(complete 28)

(if (exists (tackon target-prefs "Printer.info"))
(
    (delete (tackon target-prefs "Printer.info"))
))
(complete 32)

(if (exists (tackon target-prefs "PrinterGfx"))
(
    (delete (tackon target-prefs "PrinterGfx"))
))
(complete 36)

(if (exists (tackon target-prefs "PrinterGfx.info"))
(
    (delete (tackon target-prefs "PrinterGfx.info"))
))
(complete 40)

;===============================================================
; Install the V42 files
;===============================================================

(copyfiles (source "printer.device") (dest target-device))
(complete 44)

(if (= yn-postscript 1)
(
   (user 2)
   (set file-v39postscript (askfile (prompt #where-v39postscript)
                    (help #where-v39postscript-help)
                    (default "PRINTERS:PostScript")))
   (user old-level)
   (set result (run (cat "patches/SPatch -o"  (tackon target-postscript "PostScript")
                         " -ppatches/PostScript.pch " file-v39postscript)))
   (if (> result 0)
   (
       (abort)
   ))
))
(complete 48)

(copyfiles (source "printer-handler") (dest target-handler))
(complete 52)

(copyfiles (source "PRT") (dest target-dosdriver))
(complete 58)

(copyfiles (source "Printer") (dest target-prefs))
(complete 60)

(copyfiles (source "Printer.info") (dest target-prefs))
(complete 64)

(copyfiles (source "PrtMgr") (dest target-prtmgr))
(complete 68)

(copyfiles (source "PrtMgr.info") (dest target-prtmgr))
(complete 72)

(if (not (exists (tackon target-device "PrinterPorts")))
(
   (makedir (tackon target-device "PrinterPorts") (infos))
))
(complete 76)

(if (in list-ports 0)
(
   (copyfiles (source "PrinterPorts/Parallel 0.info") (dest (tackon target-device "PrinterPorts")))
))
(complete 80)

(if (in list-ports 1)
(
   (copyfiles (source "PrinterPorts/Serial 0.info") (dest (tackon target-device "PrinterPorts")))
))
(complete 84)

(if (in list-ports 2)
(
   (copyfiles (source "PrinterPorts/File.info") (dest (tackon target-device "PrinterPorts")))
))
(complete 88)

(if (in list-ports 3)
(
   (copyfiles (source "PrinterPorts/No Port.info") (dest (tackon target-device "PrinterPorts")))
))
(complete 92)

(if (in list-ports 4)
(
   (copyfiles (source "PrinterPorts/Envoy.info") (dest (tackon target-device "PrinterPorts")))
))
(complete 96)

;===============================================================
; Modify the User-Startup to mount PRT:
;===============================================================

(startup "V42 printer.device" (prompt #ask-prt)
        (command "assign PRT: dismount\nmount PRT:\n")
        (help #ask-prt-help))
(complete 100)