; $Id: Install-Patch,v 1.2 93/02/23 12:08:51 lee Exp $
;
; v 1.2b 93/03/16 -- Slight modification to work as a script on disk 4 of the ADPro
;                    2.3.0 disk set.  Jeff (ASDG).
;
; This is the 4.6 patch install script for DeluxePaint AGA 
; © 1993 Electronic Arts Inc. All Rights Reserved
;
; The order in which the user is requested to things is
; as follows:
;
; 1) Input the DPaintIV Install Disk 1
; 2) Input a Destination Disk (to clone DPaintIV Install Disk)
; 3) Input 4.6 Patch Disk for patch data
; 4) Input Destination Disk to receive patched data
;
(set @default-dest "Work:")

; due to a problem with spatch command line parsing, the name of 
; the patch disk should not contain spaces.
;(set PATCH_NAME   "DPaint_4.6_Patch")
(set PATCH_NAME   "ADPro_D4")
(set PATCH_VOLUME (cat PATCH_NAME ":"))

(set SOURCE_NAME "DPaintIV Install Disk 1")
(set SOURCE_VOLUME (cat SOURCE_NAME ":"))

(set DEST_NAME "DPaint 4.6 Install Disk")
(set DEST_VOLUME (cat DEST_NAME ":"))

(set ASSIGN   "DPaintIV")
(set PROGNAME "DPaint")
(set UNPACKER "lharc")
(set RUNWIN "NIL:")


(set PATCHER   (cat PATCH_VOLUME "spatch"))
(set PATCHFILE (cat PATCH_VOLUME "DPaint.pch"))

(set LHARC_EXTRACT_HELP
  (cat
	"The Installer will use LHARC to extract the DPaint program. "
        "from its archive on the original install disk."
  )
)

(set LHARC_ADD_HELP
  (cat
	"The Installer will use LHARC to add the patched version DPaint "
        "to its archive on your new install disk."
  )
)

(set PATCH_HELP
  (cat 
       "The Installer will use the SPATCH utility from SAS/C to make "
       "changes to a copy of your original DPaint program."
  )
)

(set RENAME_HELP
   (cat "The Installer will rename the floppy disk you provided "
        "from \""DEST_NAME"\" to \"" SOURCE_NAME "\" so it can replace "
        "your original disk in the DPaint installation process."
   )
)

(set INIT_HELP
	(cat
  		"The DPaint 4.6 patch requires your original 4.5 install "
                "disk and an installed version of DPaint 4.5.  The patch "
                "will copy the original program file to ram, modify it, "
                "and copy the modified version to the directory where you "
                "have installed DPaint 4.5.\n\n"

                "Your original DPaint 4.5 install disk will NOT "
                "be changed in any way.\n\n"

                "Please make sure your original DPaint 4.5 Install Disk "
                "is WRITE-PROTECTED and that you have your registration "
                "number handy."
	)
)

(set DIR_HELP
     (cat  "The patch looks for the installed version of DPaint and "
           "replaces the original program file with the patched "
           "version.\n\n"

           "Please specify the volume and directory where you "
           "currently have DPaint 4.5 installed."
     )
)

(set BACKUP_HELP
     (cat "If you select \"Yes,\" the installer will copy the currently "
          "installed version of \"DPaint\" to a "Backup" directory. "
          "If you select \"No,\" the installer will simply replace or "
          "overwrite the installed version with the patched version."
     )
)
 
(procedure ask_sourcedisk
	(askdisk
		(prompt ("Please insert the disk labeled \"%s\"." SrcDiskE))
		(help @askdisk-help)
		(dest SrcDiskE)
	)

	(set SrcDiskE (cat SrcDiskE ":"))
)

; Destination disk confirmation.
;  DstDiskE: The disk to insert
(procedure ask_destdisk
	(askdisk
		(prompt ("Please insert the disk labeled \"%s\"." DstDiskE))
		(help @askdisk-help)
		(dest DstDiskE)
	)

	(set DstDiskE (cat DstDiskE ":"))
)

(set osversion (/ (getversion) 65536))
(if (< osversion 37)
	(abort	"DeluxePaint requires AmigaDOS 2.04 or later to run.")
)

; Make sure the user has the appropriate disks ready
(
	(if	(askbool
			(prompt "You will need your original \"DPaintIV Install "
                                "Disk 1\" and an installed version of DPaint 4.5. Your "
                                "original \"DPaintIV Install Disk 1\" will NOT be "
                                "modified in any way but your installed version "
                                "WILL be updated to version 4.6.\n\n"
               
                                "If you haven't already installed DPaint 4.5 "
                                "please do so before running this patch.\n\n"

                                "Please have your registration number handy; "
                                "you will be asked to register your copy "
                                "of DPaint 4.6"
			)
			(help INIT_HELP)
			(choices "Proceed" "Cancel")
			(default 1)
		)

                (set dummy 1)
		(abort "User aborted installation.")
	)
)

; copy the necessary patch files to ram
(
        (set SrcDiskE PATCH_NAME)
        (ask_sourcedisk)

	(copyfiles
		(prompt "")
		(help "")
		(source (tackon SrcDiskE UNPACKER))
		(dest "ram:")
	)

        (set UNPACKER  (tackon "ram:" UNPACKER))
)


; copy the original program file
(
       (set SrcDiskE SOURCE_NAME)
       (ask_sourcedisk)
        
       ; make sure file isn't already there due to some previous attemp   
       (delete "ram:DPaint")

       (working ("Extracting DPaint 4.5 program file"))
       (set archive (tackon SrcDiskE "dpaint.lzh"))
       (set result 
            (run ("%s x \"%s\" ram: dpaint* > %s" UNPACKER archive RUNWIN)
                 (help LHARC_EXTRACT_HELP)
                 (prompt ("Extract original DPaint 4.5 program file?"))
                 (confirm)
            )
       )
       (if result (abort "Error while extracting program"))
)


(
   (set SrcDiskE PATCH_NAME)
   (ask_sourcedisk)

   (working ("Patching DPaint program file"))

   ;  make sure file isn't already there due to some previous attempt
   (delete "ram:patched")

   (set result 
      (run 
         ("\"%s\" -p%s -oram:patched ram:dpaint > %s" PATCHER PATCHFILE RUNWIN)
         (help PATCH_HELP)
         (prompt ("Patch DPaint 4.5 program file?"))
         (confirm)
      )
   )

   (delete "ram:dpaint")
   (if result (abort "Error while patching program"))
   (rename "ram:patched" "ram:dpaint")
)

; see if this is really an update

(set dpaint_dest (getassign ASSIGN "a"))

; if update, be sure they want program in same place

(if dpaint_dest
    (if (not
            (askbool
                (prompt "Your current copy of DPaintIV appears to be located in the drawer named \""
                         dpaint_dest
                         "\". Do you want the update installed in that drawer?"
                )
                (help   DIR_HELP)
                (default 1)
            )
        )

        (set dpaint_dest        ; if user wants in different place
                     (askdir
                          (prompt "In which disk or drawer should the "
                                  "4.6 patch be installed?"
                          )
                          (help (cat DIR_HELP "\n\n" @askdir-help))
                          (default @default-dest)
                      )
        )
    )

; Update not found, so get a location for program

    (set dpaint_dest
        (askdir
            (prompt "Please select the directory where you "
                    "have DPaint 4.5 installed. "
            )
            (help (cat DIR_HELP "\n\n" @askdir-help))
            (default @default-dest)
        )
    )
)

; OK, we know where we'll be installing, so let's make it permanent
(set @default-dest dpaint_dest)

(set ProgramFile (tackon dpaint_dest "DPaint"))

(if (exists ProgramFile)
    (
       (if (askbool 
               (prompt "Make backup of currently installed program file?")
               (help BACKUP_HELP)
               (default 1)
            )

            ; Note: we copy the file to a backup directory instead of 
            ; to a backup file name so the icons won't overlap
            (copyfiles 
                 (source ProgramFile)
                 (dest (tackon dpaint_dest "Backup"))
                 (help BACKUP_HELP)
                 (infos)
            )
       )
    )
)

(if (exists (tackon ProgramFile ".info"))
    ; use the existing .info file
    (
      (delete "ram:DPaint.info")
      (copyfiles
        (prompt "")
        (help "")
        (source "ram:DPaint")
        (dest dpaint_dest)
        (confirm)
      )
    )

    ; copy the .info file from ram:
    (copyfiles
        (prompt "")
        (help "")
        (source "ram:DPaint")
        (dest dpaint_dest)
        (confirm)
        (infos)
    )
)

(delete UNPACKER)
(delete "ram:dpaint")
(delete "ram:dpaint.info")

; Ask if the user would like to register
; his/herself by running the main program

(if (askbool
       (prompt "Would you like to run and personalize your "
               "copy of DPaint 4.6?")
       (help
                "DPaint 4.6 must be personalized when using for "
                "the first time. You may choose to run DPaint 4.6 "
                "later, at which time you will be asked to personalized your copy."
       )
       (default 1)
    )

   (run
       ("run >NIL: <NIL: \"%s\"" ProgramFile)
       (help RUNHELP)
       (prompt "Run DPaint 4.6")
       (confirm)
   )
)

(exit)