(welcome "AVM Suite Installation")
(transcript "Installing the AVM Suite...")

; **************************************************************************
; **************************************************************************
; **************************************************************************

(complete 20)

(set @default-dest "Work:")

(set @default-dest
   (askdir
      (prompt "Where do you want to put the AVMSuite2 DRAWER?  A Drawer named AVMSuite2 will be created here.")
      (help @askdir-help)
      (default @default-dest)
      (newpath)
   )
)

(set avmdest (tackon @default-dest "AVMSuite2"))

(makedir avmdest (infos))

(makeassign "AVM" avmdest)

; now let's ask where the mailboxes should be put

(set avmmboxdest
  (askdir
    (prompt "What directory should the mailboxes go in?  The Anonymous, Silent, ... mailboxes will be created here.")
    (help "This is where all the mailboxes will be put.")
    (default "avm:")
  )
)

(makeassign "AVMMBOX" avmmboxdest)

;make all the mailboxes -- this is non-destructive

(trap 4 (makedir "avmmbox:anonymous"))
(trap 4 (makedir "avmmbox:anonymous/logs"))
(trap 4 (makedir "avmmbox:anonymous/voices"))

(trap 4 (makedir "avmmbox:mailbox1"))
(trap 4 (makedir "avmmbox:mailbox1/logs"))
(trap 4 (makedir "avmmbox:mailbox1/voices"))

(trap 4 (makedir "avmmbox:mailbox2"))
(trap 4 (makedir "avmmbox:mailbox2/logs"))
(trap 4 (makedir "avmmbox:mailbox2/voices"))

(trap 4 (makedir "avmmbox:manual"))
(trap 4 (makedir "avmmbox:manual/logs"))
(trap 4 (makedir "avmmbox:manual/voices"))

(trap 4 (makedir "avmmbox:archive"))
(trap 4 (makedir "avmmbox:archive/logs"))
(trap 4 (makedir "avmmbox:archive/voices"))

(trap 4 (makedir "avmmbox:silent"))
(trap 4 (makedir "avmmbox:silent/logs"))
(trap 4 (makedir "avmmbox:silent/voices"))

(trap 4 (makedir "avmmbox:outgoing"))
(trap 4 (makedir "avmmbox:outgoing/logs"))
(trap 4 (makedir "avmmbox:outgoing/voices"))

(trap 4 (makedir "avmmbox:outgoingarchive"))
(trap 4 (makedir "avmmbox:outgoingarchive/logs"))
(trap 4 (makedir "avmmbox:outgoingarchive/voices"))

(set avminwbstartup (exists "sys:wbstartup/startAVM"))

(if (> avminwbstartup 0)
  (copyfiles
    (prompt "Updating sys:WBStartup/StartAVM")
    (help @copyfiles-help)
    (source (expandpath ""))
    (dest "sys:wbstartup")
    (pattern "StartAVM#?")
  )
  (message "If you use StartAVM anywhere other than sys:WBStartup, you should update it with avm:StartAVM")
)

(set previousinstallation (exists "avm:filenames.cfg"))

(execute "InstallExtra/copyoldfilenames"
 (prompt "Copying #?filenames.cfg into old directory")
)

(if (> previousinstallation 0)
  (execute "InstallExtra/RemoveConflictingFiles"
    (prompt "Removing old files")
  )
)

(if (> previousinstallation 0)
  (set useoldicons
    (askbool
      (prompt "Do you want to save your current icons?")
      (help "Say yes if you want to.")
      (default 1)
    )
  )
  (set useoldicons 0)
)

(if (= useoldicons 1)
  (execute "InstallExtra/backupoldicons"
    (prompt "Backing up old icons")
  )
)

(if (> previousinstallation 0)
  (set bool
    (askbool
      (prompt "Do you want me to backup stuff in avm:rexx?")
     (help "If you've modified them and want to keep them, say yes.")
      (default 1)
    )
  )
  (set bool 0)
)

(if (= bool 1)
  (execute "InstallExtra/backupavmrexx"
    (prompt "Backing up avm:rexx into avm:old/rexx")
  )
)

;(if (> previousinstallation 0)
;  (set bool
;    (askbool
;      (prompt "Do you want me to backup stuff in avm:source?")
;      (help "If you've modified them and want to keep them, say yes.")
;      (default 1)
;    )
;  )
;  (set bool 0)
;)

;(if (= bool 1)
;  (execute "InstallExtra/backupavmsource"
;    (prompt "Backing up avm:rexx into avm:old/source")
;  )
;)

(copyfiles
   (prompt "Copying executables, scripts, icons, and documentation...")
   (help @copyfiles-help)
        (source (expandpath ""))
   (dest avmdest)
   (pattern "~(archive|mailbox1|mailbox2|anonymous|voices|outgoing|outgoingarchive|silent|manual)")
)

(if (> previousinstallation 0)
  (set bool
    (askbool
      (prompt "Should I change your mailbox configuration to their defaults?")
      (help "This will *not* erase log files or voice files!")
      (default 0)
    )
  )
  (set bool 1)
)

(if (= bool 1)
  (
    (copyfiles
      (prompt "Fixing anonymous mailbox")
      (help @copyfiles-help)
      (source "protomailbox")
      (dest "avmmbox:anonymous")
      (pattern "(mailbox.cfg|pickup.iff)")
    )
    (copyfiles
      (prompt "Fixing manual mailbox")
      (help @copyfiles-help)
      (source "protomailbox")
      (dest "avmmbox:manual")
      (pattern "(mailbox.cfg)")
    )
    (copyfiles
      (prompt "Fixing archive mailbox")
      (help @copyfiles-help)
      (source "protomailbox")
      (dest "avmmbox:archive")
      (pattern "(mailbox.cfg)")
    )
    (copyfiles
      (prompt "Fixing silent mailbox")
      (help @copyfiles-help)
      (source "protomailbox")
      (dest "avmmbox:silent")
      (pattern "(mailbox.cfg)")
    )
    (copyfiles
      (prompt "Fixing mailbox1 mailbox")
      (help @copyfiles-help)
      (source "protomailbox")
      (dest "avmmbox:mailbox1")
      (pattern "(mailbox.cfg|pickup.iff)")
    )
    (copyfiles
      (prompt "Fixing mailbox2 mailbox")
      (help @copyfiles-help)
      (source "protomailbox")
      (dest "avmmbox:mailbox2")
      (pattern "(mailbox.cfg|pickup.iff)")
    )
    (copyfiles
      (prompt "Fixing outgoing mailbox")
      (help @copyfiles-help)
      (source "protomailbox")
      (dest "avmmbox:outgoing")
      (pattern "(mailbox.cfg)")
    )
    (copyfiles
      (prompt "Fixing outgoingarchive mailbox")
      (help @copyfiles-help)
      (source "protomailbox")
      (dest "avmmbox:outgoingarchive")
      (pattern "(mailbox.cfg)")
    )
  )
)

(makeassign "AVMREXX" "avm:rexx")
(makeassign "AVMREXXALT" "avmrexx:")
(makeassign "AVMTEMP" "t:")
(makeassign "FAXOUT" "avmmbox:outgoing/voices")
(makeassign "FAXTEMP" "t:")

(delete "avm:installer")
(delete "avm:avm-install")
(delete "avm:avm-install.info")

(makedir "avm:voices")

(complete 75)

(set voicecapable
  (askbool
    (prompt "Do you have a voice-capable modem?")
    (help "Say yes if AT+FCLASS=8, AT#CLS=8, or AT#VS4 don't return ERROR.")
    (default 1)
  )
)

(if (> previousinstallation 0)
  (set usepreviousconfig
    (askbool
      (prompt "Do you want to use your previous configuration?")
      (help "Say yes if you want to.")
      (default 1)
    )
  )
  (set usepreviousconfig 0)
)

(if (= usepreviousconfig 0)
  (
    (if (= voicecapable 1)
      (
        (set modemtype
          (askchoice
            (prompt "What modem do you have?")
            (help @askchoice-help)
            (choices
              "ZyXEL"
              "LineLink"
              "MTD Dolphin"
              "Rockwell-based Voice modem"
              "USR Sportster Vi (14.4/28.8) (h/w handshake)"
              "USR Sportster Vi (14.4/28.8) (try above first)"
              "USR Sportster Vi (14.4/28.8) (no echo)"
            )
          )
        )
        (if (= modemtype 0)
          (
            (set modemtype
              (askchoice
                (prompt "What ROM version?")
                (help @askchoice-help)
                (choices
                  "6.01"
                  "6.10"
                  "6.11"
                  "6.11a"
                  "6.12"
                  "6.13"
                  "2864 1.04"
                )
              )
            )
            (set modemtype (+ modemtype 10))
          )
        )
      )
      (
        (set modemtype
          (askchoice
            (prompt "What modem do you have?")
            (help @askchoice-help)
            (choices
              "Generic Class 2 fax/modem"
              "Generic Class 1 fax/modem"
              "AT&T DataPort Class 1"
              "AT&T DataPort Class 2"
              "Supra 144 LC (Class 1)"
              "USR modem (Class 1)"
              "USR old config (try above first)"
            )
          )
        )
        (set modemtype (+ modemtype 25))
      )
    )
  )
)

(debug modemtype)

(if (= usepreviousconfig 0)
  (
    (execute "InstallExtra/backupconfig"
      (prompt "Backing up previous configuration")
    )
    (select modemtype
      (debug "modemtype==0")
      (execute "avm:defaultscripts/useLineLink144e")
      (execute "avm:defaultscripts/useDolphin")
      (execute "avm:defaultscripts/useRockwell")
      (execute "avm:defaultscripts/useUSRVi.hwhandshake")
      (execute "avm:defaultscripts/useUSRVi")
      (execute "avm:defaultscripts/useUSRVi.noecho")
      (debug "modemtype==7")
      (debug "modemtype==8")
      (debug "modemtype==9")
      (execute "avm:defaultscripts/useZyxel6.01")
      (execute "avm:defaultscripts/useZyxel6.10")
      (execute "avm:defaultscripts/useZyxel6.11")
      (execute "avm:defaultscripts/useZyxel6.11a")
      (execute "avm:defaultscripts/useZyxel6.12")
      (execute "avm:defaultscripts/useZyxel6.13")
      (execute "avm:defaultscripts/useZyxel2864_1.04")
      (debug "modemtype==9")
      (debug "modemtype==9")
      (debug "modemtype==9")
      (debug "modemtype==9")
      (debug "modemtype==9")
      (debug "modemtype==9")
      (debug "modemtype==9")
      (debug "modemtype==9")
      (execute "avm:defaultscripts/useClass2")
      (execute "avm:defaultscripts/useClass1")
      (execute "avm:defaultscripts/useDataPortC1")
      (execute "avm:defaultscripts/useDataPortC2")
      (execute "avm:defaultscripts/useSupra144LC")
      (execute "avm:defaultscripts/useUSR")
      (execute "avm:defaultscripts/useUSROld")
    )
  )
)

(complete 80)


(if (= voicecapable 1)
  (
    (set digitizertype
       (askchoice
          (prompt "What type of digitizer do you have?")
          (help @askchoice-help)
          (choices
             "Generic/None"
             "Perfect Sound"
          )
          (default 0)
       )
    )

    (debug digitizertype)

    (if (= digitizertype 0)
       (execute "avm:defaultscripts/useGenericDigitizer")
       (if (= digitizertype 1)
          (execute "avm:defaultscripts/usePerfectSound")
          (message "Bad Stuff")
       )
    )
  )
)

(complete 85)

(set alerttype
   (askchoice
      (prompt "How do you want to be informed of new messages/faxes?")
      (help @askchoice-help)
      (choices
         "Flashing LED"
         "AmigaDOS Say Command"
                        "Prerecorded Voice"
      )
      (default 2)
   )
)

(debug alerttype)

(if (= alerttype 0)
   (execute "avm:defaultscripts/useFlashAlert")
   (if (= alerttype 1)
      (execute "avm:defaultscripts/useSayAlert")
                (if (= alerttype 2)
                     (execute "avm:defaultscripts/useSayAlertPreRec")
           (message "Bad Stuff")
                )
   )
)

(complete 90)


; **************************************************************************
; **************************************************************************
; **************************************************************************


(startup "AVM Suite"
  (prompt "Adding the required ASSIGNS to your user-startup.  Do this!  You have been warned!")
   (help @startup-help)
   (command "assign avm: \"" avmdest "\"\n")
   (command "assign avmmbox: \"" avmmboxdest "\"\n")
   (command "assign avmrexx: \"avm:rexx\"\n")
   (command "assign avmrexxalt: \"t:\" \"avmrexx:\"\n")
   (command "assign avmtemp: \"t:\"\n")
   (command "assign faxout: \"avmmbox:outgoing/voices\"\n")
   (command "assign faxtemp: \"t:\"\n")
)

(if (= voicecapable 1)
  (execute "avm:InstallExtra/renamevoicefiles"
   (prompt "Renaming old voice files, if any.")
  )
)

(execute "avm:InstallExtra/copyfaxprinter"
 (prompt "Copying faxprinter to devs:printers")
)

(if (= useoldicons 1)
  (execute "avm:InstallExtra/restoreoldicons"
   (prompt "Restoring old icons")
  )
)

(if (= voicecapable 1)
  (run "newshell con:////AVM-Install from InstallExtra/deletevfiles"
   (prompt "Deleting old voice files that were incompatible with this version.")
  )
)

(if (= voicecapable 0)
  (
    (set deleteforfaxonly
      (askbool
        (prompt "You have a fax/modem only.  Delete unneeded files?")
        (help "Say yes to delete avm:voices, avm:mailbox1, avm:mailbox2, ...")
        (default 0)
      )
    )
    (if (= deleteforfaxonly 1)
      (execute "InstallExtra/deleteforfaxonly")
    )
  )
)

(complete 100)


; **************************************************************************
; **************************************************************************
; **************************************************************************

(exit)
