; get a location

(set @default-dest "SYS:")

(set my_help 
   (cat
      "Performing this installation will create TWO new drawers.  One named '68040', and one named 'HDTools'. \n"
      "These drawers will be created in the area that you specify using the given path selector. \n"
      "It will also copy two files to your currently assigned 'LIBS:' area.\n"
      "\n\n"
      @askdir-help
   )
)

(set sver1
   (getversion "c:SetPatch")
)

(set sver2
   (getversion "PPI_040:c/SetPatch")
)

(set sver3
   (getversion "PPI_040:c2/SetPatch")
)

(set osversion
   (/ (getversion "libs:version.library") 65535)
)

(set model
   (askchoice
      (prompt "What model of Progressive Peripherals\n accelerator do you have?\n\n\n")
      (choices "PPS 040/500" "PPS 040/2000" "PPS 040/3000"  "Mercury" "Zeus")
      (help @askchoice-help)
   )
)

(set dest_a
   (askdir
      (prompt "Where should the 68040 drawer be installed?")
      (help my_help)
      (default @default-dest)
   )
)

; Tell the Installer program where the user wants the data
(set @default-dest dest_a)
;
(askdisk
   (prompt "Please insert the disk labeled \"PPI_040\".")
   (help   @askdisk-help)
   (dest "PPI_040")
   (newname "PPI_040")
)

(set dest_b dest_a)

(set dest_a
   (tackon dest_a "68040")
)

(makedir dest_a
   (infos)
)

(working)

(delete "libs:pps040.library")

(set dest_z dest_a)
(set dest_z 
   (tackon dest_z "AddMem")
)
(delete dest_z
   (infos)
)

(set dest_z dest_a)
(set dest_z 
   (tackon dest_z "FP040")
)
(delete dest_z
   (infos)
)

(set dest_z dest_a)
(set dest_z 
   (tackon dest_z "FastSYS")
)
(delete dest_z
   (infos)
)


(set dest_z "SYS:WBStartup/FP040")
(delete dest_z
   (infos)
)

(set dest_z "SYS:WBStartup/FASTSYS")
(delete dest_z
   (infos)
)

(set dest_z "SYS:WBStartup/ADDMEM")
(delete dest_z
   (infos)
)

(copyfiles
   (all)
   (help @copyfiles-help)
   (source "PPI_040:68040")
   (dest dest_a)
)


(copyfiles
   (all)
   (help @copyfiles-help)
   (source "PPI_040:Libs")
   (dest "libs:")
)

(if (> osversion 37) 
   (
      (if (< osversion 39) 
         (
            (copyfiles
               (help @copyfiles-help)
               (source "PPI_040:C2/CPU")
               (dest "C:")
            )
            ; Check SetPatch for 2.1
            (if (> (/ sver1 65535) 38)
               (
                  (message "WARNING: You are running a version of setpatch that is not meant for "
                           "OS Version 2.1.  This will most likely cause a problem with the 68040, "
                           "or other hardware or software.  You should install a 2.1 version "
                           "of setpatch!")
               )
            )
            (if (< (/ sver1 65535) 38)
               (
                  (message "WARNING: You are running a version of setpatch that is not meant for "
                           "OS Version 2.1.  This will most likely cause a problem with the 68040, "
                           "or other hardware or software.  You should install a 2.1 version "
                           "of setpatch!")
               )
            )

            (if 
               (askbool 
                  (prompt "You are running a 2.1 system.  Some versions of 38.xx setpatch "
                        "do not properly patch the system for 68040 processors. \n"
                        " Versions that are known not to work are: \n"
                        "38.1, 38.3, 38.4, and 38.7\n\n"
                        "We recommend that you use version 38.31.  Do you wish to install this "
                        "version now?")
                  (help @askbool-help)
               )
               (
                  (copyfiles
                     (help @copyfiles-help)
                     (source "PPI_040:C2/SetPatch")
                     (dest "C:")
                  )
               )
            )
         )
      )

   )
   (
      (copyfiles
         (help @copyfiles-help)
         (source "PPI_040:C/CPU")
         (dest "C:")
      )
      ; Check SetPatch for 2.0
      (if (> (/ sver1 65535) 37)
         (
            (message "WARNING: You are running a version of setpatch that is not meant for "
                     "OS Version 2.0x.  This will most likely cause a problem with the 68040, "
                     "or other hardware or software.  You should install a 2.04/2.05 version "
                     "of setpatch!")
         )
      )

      (if (< (/ sver1 65535) 37)
         (
            (message "WARNING: You are running a version of setpatch that is not meant for "
                     "OS Version 2.0x.  This will most likely cause a problem with the 68040, "
                     "or other hardware or software.  You should install a 2.04/2.05 version "
                     "of setpatch!")
         )
      )

      (if 
         (askbool 
            (prompt "You are running a 2.04/2.05 system.  Some versions of 37.xx setpatch "
                  "do not properly patch the system for 68040 processors. \n"
                  " Versions that are known not to work are: \n"
                  "37.10\n\n"
                  "We recommend that you use version 37.34.  Do you wish to install this "
                  "version now?")
            (help @askbool-help)
         )
         (
            (copyfiles
               (help @copyfiles-help)
               (source "PPI_040:C/SetPatch")
               (dest "C:")
            )
         )
      )

   )
)

(if ( = model 4)
   (
      (set dest_b
         (askdir
            (prompt "Where should the HDTools drawer be installed?")
            (help my_help)
            (default dest_b)
         )
      )
      (set dest_b
         (tackon dest_b "HDTools")
      )
      (copyfiles
         (all)
         (help @copyfiles-help)
         (source "PPI_040:HDTools")
         (dest dest_b)
      )
      (makedir dest_b
         (infos)
      )
   )
)

(set dest_a
   (tackon dest_a "Init040")
)

(set ver 
   (/ (getversion "libs:version.library") 65536)
)

(if
   (askbool
      (prompt "\n\nShould the 'Init040' line be added to your 's:Startup-Sequence' file ?")
      (help @askbool-help)
   )
   (
      (if (= @pretend 0)
         (
            (if (> ver 36)
               (
                  (textfile 
                     (dest "ram:Startup-Sequence")
                     (append "\""dest_a"\"" " >NIL: \n\n")
                     (include "s:startup-sequence")
                  )

                  (rename "s:Startup-Sequence" "s:Start-Old")
   
                  (copyfiles
                     (help @copyfiles-help)
                     (source "ram:Startup-Sequence")
                     (dest "s:")
                  )
               )
               (
                  (textfile 
                     (dest "ram:Startup-Sequence")
                     (append "c:SetPatch >NIL:\n")
                     (append "\""dest_a"\"" " >NIL: \n\n")
                     (include "s:startup-sequence")
                  )
   
                  (rename "s:Startup-Sequence" "s:Start-Old")
   
                  (copyfiles
                     (help @copyfiles-help)
                     (source "ram:Startup-Sequence")
                     (dest "s:")
                  )
               )
            )         
         )
      )
   )
   (
      (message 
         (cat
            "The following line should be added to your 's:Startup-Sequence' file...\n"
            dest_a " >NIL:\n\n"
         )
      )
   )
)


(set @default-dest "")

;
