; this is an install script for SBase4 Professional
; the following two tooltypes should be on the invokation project icon:
;         MINUSER=AVERAGE
;         APPNAME=SBase4pro
;         PRETEND=FALSE
;
;


(copyfiles
   (source "Install_SBase4pro:lharc")
   (dest "ram:")
   (infos)
)
(copyfiles
   (source "Install_SBase4pro:Disk.info")
   (dest "ram:")
   (infos)
)
(copyfiles
   (source "Install_SBase4pro:SBase4.sort")
   (dest "s:")
)

(onerror
   (delete "ram:lharc" (safe))
   (delete "ram:Disk.info" (safe))
)

(set installlevel 3)

(if (IN installlevel 0)
   (
      (set length_ok 1)

      (set serialno "")

      (while length_ok
         (set serialno
            (askstring
               (prompt "Please enter your serial no. which is printed on"
                       " your installation disk.")
               (help @askstring-help)
               (default serialno)
            )
         )
         (if (= (strlen serialno) 8)
            (set length_ok 0)
            (message "Improper serial no.")
         )
      )

      (set length_ok 1)

      (set name "")

      (while length_ok
         (set name
            (askstring
               (prompt "Please enter your name.  This must be at least 6"
                       " characters long, and less than 40 characters long.")
               (help @askstring-help)
               (default name)
            )
         )
         (if (< (strlen name) 6)
            (message "name must be at least 6 characters long")
            (if (> (strlen name) 39)
               (message "name must be less than 40 characters long")
               (set length_ok 0)
            )
         )
      )

      (set length_ok 1)

      (set org "")

      (while length_ok
         (set org
            (askstring
               (prompt "Please enter your organization.  This must be at least 6"
                       " characters long, and less than 40 characters long.")
               (help @askstring-help)
               (default org)
            )
         )
         (if (< (strlen org) 6)
            (message "organization must be at least 6 characters long")
            (if (> (strlen org) 39)
               (message "organization must be less than 40 characters long")
               (set length_ok 0)
            )
         )
      )
   )
)

(set sb_install
   (askbool
      (prompt "Do you wish to install to Floppy or Hard Disk?")
      (help "If you install to Floppy, it will generate two"
            " floppys.  If you install to Hard Disk, then all files"
            " will be placed in"
            " one directory on your hard drive.")
      (choices "Floppy" "Hard Disk")
      (default 1)
   )
)

(if sb_install
   (  ; --- floppy install **************************************
      (set disk_ready 0)
      (if (= installlevel 3)
         (set disk_ready
            (askbool
               (prompt "To install to floppy disks requires two formatted"
                       " floppys labeled \"SBase4pro:\", and \"SBase4:\"."
                       "  If you do not have these ready"
                       " then please exit this installation procedure, prepare"
                       " them, and re-start the installation.")
               (help "SBase4pro: will hold all program files except for"
                     " the form designer.  SBase4: will be used for the"
                     " form designer program and some extra examples.")
               (choices "Continue" "Exit")
               (default 1)
            )
         )
      )
      (if disk_ready
         (
            (if (IN installlevel 0)
               (
                  (set @default-dest "SBase4")
                  (copyfiles
                     (source "Install_SBase4pro:prog.lzh")
                     (dest "ram:")
                  )
                  (copyfiles
                     (source "Install_SBase4pro:registersb")
                     (dest "ram:")
                  )
                  (askdisk
                     (prompt "Please insert the diskette labeled \"SBase4pro\""
                             " in any drive.")
                     (help @askdisk-help)
                     (dest  "SBase4pro")
                  )
                  (copyfiles
                     (source "ram:Disk.info")
                     (dest "SBase4pro:")
                     (infos)
                  )
                  (working
                             "Preparing SBase4pro disk.\n"
                             "\n**********\n"
                             "This could take several minutes so please be patient!\n"
                             "**********"
                  )

                  (if (run (cat "ram:lharc >nil: -m -n x ram:prog.lzh SBase4pro:"))
                     (abort "Program files Decompression failed")
                  )
                  (delete "ram:prog.lzh")
                  (if (run (cat "ram:registersb SBase4pro:SBase4pro \"" name "\" \"" org "\" \"" serialno "\""))
                     (abort "Program Registration failed")
                  )
                  (delete "ram:registersb")

                  (askdisk
                     (prompt "Please insert the diskette labeled \"Install...\""
                             " in any drive.")
                     (help @askdisk-help)
                     (dest  "SBase4pro")
                  )
                  (copyfiles
                     (source "Install_SBase4pro:printers.lzh")
                     (dest "ram:")
                  )
                  (askdisk
                     (prompt "Please insert the diskette labeled \"SBase4pro\""
                             " in any drive.")
                     (help @askdisk-help)
                     (dest  "SBase4pro")
                  )
                  (if (run (cat "ram:lharc >nil: -m -n x ram:printers.lzh SBase4pro:"))
                     (abort "Printer files Decompression failed")
                  )
                  (delete "ram:printers.lzh")

                  (askdisk
                     (prompt "Please insert the diskette labeled \"Install...\""
                             " in any drive.")
                     (help @askdisk-help)
                     (dest  "SBase4pro")
                  )
                  (copyfiles
                     (source "Install_SBase4pro:sbfd.lzh")
                     (dest "ram:")
                  )
                  (askdisk
                     (prompt "Please insert the diskette labeled \"SBase4\""
                             " in any drive.")
                     (help @askdisk-help)
                     (dest  "SBase4")
                  )
                  (copyfiles
                     (source "ram:Disk.info")
                     (dest "SBase4:")
                     (infos)
                  )
                  (working
                             "Preparing SBase4 form designer disk.\n"
                             "\n**********\n"
                             "This could take several minutes so please be patient!\n"
                             "**********"
                  )
                  (if (run (cat "ram:lharc >nil: -m -n x ram:sbfd.lzh SBase4:"))
                     (abort "Program files Decompression failed")
                  )
                  (delete "ram:sbfd.lzh")
               )
            )
            (complete 50)
            (if (IN installlevel 1)
               (
                  (askdisk
                     (prompt "Please insert the diskette labeled \"Install_SBase4pro:\""
                             " in any drive.")
                     (help @askdisk-help)
                     (dest  "Install_SBase4pro")
                  )
                  (copyfiles
                     (source "Install_SBase4pro:examples.lzh")
                     (dest "ram:")
                  )
                  (askdisk
                     (prompt "Please insert the diskette labeled \"SBase4:\""
                             " in any drive.")
                     (help @askdisk-help)
                     (dest  "SBase4")
                  )
                  (working
                             "Preparing Examples.\n"
                             "\n**********\n"
                             "This could take several minutes so please be patient!\n"
                             "**********"
                  )
                  (if (run (cat "ram:lharc >nil: -m -n x ram:examples.lzh SBase4:"))
                     (abort "Examples files Decompression failed")
                  )
                  (delete "ram:examples.lzh")
               )
            )
         )
         (abort "User Request")
      )
   )
   (  ; --- hard disk install ***********************************


      (set sb_dest (tackon @default-dest "SBase4"))

      (set sb_dest
         (askdir
            (prompt "Where would you like to install SBase4pro?"
            )
            (help   "The suggested path is on your volume with the"
                    " most available space.  If you wish it to be"
                    " elsewhere, simply change the name.  If the drawer does"
                    " not exist, it will be added to the indicated"
                    " volume, along with an icon.  Some examples will be"
                    " installed to the same location."
            )
            (newpath)
            (default sb_dest)
         )
      )

      (makedir sb_dest (infos))
      (makeassign "SBase4" sb_dest)
      (makeassign "SBase4xx" sb_dest)

      (set @default-dest sb_dest)
      (if (IN installlevel 0)
         (
            (copyfiles
               (source "Install_SBase4pro:registersb")
               (dest "ram:")
            )
            (working
                       "Preparing SBase4 program files.\n"
                       "\n**********\n"
                       "This could take several minutes so please be patient!\n"
                       "**********"
            )
            (if (run (cat "ram:lharc >nil: -m -n x Install_SBase4pro:prog.lzh SBase4xx:"))
               (abort "Program files Decompression failed")
            )
            (delete "ram:prog.lzh")
            (if (run (cat "ram:lharc >nil: -m -n x Install_SBase4pro:sbfd.lzh SBase4xx:"))
               (abort "Program files Decompression failed")
            )
            (delete "ram:sbfd.lzh")
            (if (run (cat "ram:registersb \"" (tackon sb_dest "SBase4pro") "\" \"" name "\" \"" org "\" \"" serialno "\""))
               (abort "Program Registration failed")
            )
            (delete "ram:registersb")
            (if (run (cat "ram:lharc >nil: -m -n x Install_SBase4pro:printers.lzh S:"))
               (abort "Printer files Decompression failed")
            )
            (delete "ram:printers.lzh")

            (if (= (exists "sys:wbstartup" (noreq)) 2)
               (
                  (
                     (textfile
                        (prompt "Creating the SBase4 Assignment file in sys:WBstartup\n"
                        )
                        (help "This file is required to assign SBase4: to the drawer"
                              " which contains SBase.  It is placed into sys:WBstartup"
                              " so it will be executed when workbench is started up."
                              " If you do not use workbench, then you will have to"
                              " add this to your user-startup file, or do it manually."
                        )
                        (dest "sys:WBstartup/AssignSB")
                        (append "echo \"SBase4 Assign Initialization\"\n")
                        (append "assign SBase4: \"" sb_dest "\"\n")
                     )
                     (copyfiles
                        (source "Install_SBase4pro:icons/AssignSB.info")
                        (dest "sys:WBstartup")
                     )
                  )
               )
               (
                  (startup "SBase4"
                     (prompt "add assignment to user-startup")
                     (help "This file is required to assign SBase4: to the drawer"
                           " which contains SBase."
                     )
                     (command "assign SBase4: \"" sb_dest "\"\n")
                  )
               )
            )
         )
      )
      (complete 50)
      (if (IN installlevel 1)
         (
            (askdisk
               (prompt "Please insert the diskette labeled \"Install_SBase4pro:\""
                       " in any drive.")
               (help @askdisk-help)
               (dest  "Install_SBase4pro")
            )
            (working
                       "Preparing Examples.\n"
                       "\n**********\n"
                       "This could take several minutes so please be patient!\n"
                       "**********"
            )
            (if (run (cat "ram:lharc >nil: -m -n x Install_SBase4pro:examples.lzh SBase4xx:"))
               (abort "Examples Decompression failed")
            )
            (delete "ram:examples.lzh")
         )
      )
   )
)

(delete "ram:lharc" (safe))
(makeassign "SBase4xx")

(complete 100)

(exit)
