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

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

(complete 20)

(set @default-dest "Work:AVMSuite")

(set avmdest
   (askdir
      (prompt "Where do you want to put the AVM Suite?")
      (help @askdir-help)
      (default @default-dest)
      (newpath)
   )
)

(set @default-dest avmdest)

(makedir avmdest (infos))

(makeassign "AVM" avmdest)

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

(execute "copyoldfilenames"
 (prompt "Copying old filenames.cfg to oldfilenames.cfg")
)

(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 "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 "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 "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 "~(mailbox.cfg|mailbox1|mailbox2|anonymous)")
)

(if (> previousinstallation 0)
  (set bool
    (askbool
      (prompt "Should I overwrite your mailbox.cfgs?")
      (help "If you've never used AVM, say yes.")
      (default 0)
    )
  )
  (set bool 1)
)

(if (= bool 1)
  (copyfiles
    (prompt "Copying mailbox.cfg")
    (help @copyfiles-help)
    (source (expandpath ""))
    (dest avmdest)
    (pattern "mailbox.cfg")
  )
)

(if (= bool 1)
  (copyfiles
    (prompt "Copying anonymous mailbox")
    (help @copyfiles-help)
    (source (expandpath ""))
    (dest avmdest)
    (pattern "anonymous")
  )
)

(if (= bool 1)
  (copyfiles
    (prompt "Copying mailbox1 mailbox")
    (help @copyfiles-help)
    (source (expandpath ""))
    (dest avmdest)
    (pattern "mailbox1")
  )
)

(if (= bool 1)
  (copyfiles
    (prompt "Copying mailbox2 mailbox")
    (help @copyfiles-help)
    (source (expandpath ""))
    (dest avmdest)
    (pattern "mailbox2")
  )
)

(makeassign "AVMREXX" "avm:rexx")
(makeassign "AVMTEMP" "t:")

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

(makedir "avm:voices")

(complete 75)

(set modemtype
   (askchoice
      (prompt "What modem and ROM version do you have?")
      (help @askchoice-help)
      (choices
         "Use previous files"
         "LineLink 144e"
         "MTD Dolphin"
         "ZyXEL 6.01"
         "ZyXEL 6.10"
         "ZyXEL 6.11"
         "ZyXEL 6.11a"
         "Rockwell based Voice modem"
         "ZyXEL 6.12"
         "Non-Voice Class 2 Fax modem"
         "Non-Voice Class 1 Fax modem"
      )
      (default 0)
   )
)

(debug modemtype)

(if (> modemtype 0)
  (execute "backupconfig"
    (prompt "Backing up previous configuration")
  )
)

(if (= modemtype 0)
  (execute "avm:defaultscripts/usePrevious")
  (if (= modemtype 1)
    (execute "avm:defaultscripts/useLineLink144e")
    (if (= modemtype 2)
      (execute "avm:defaultscripts/useDolphin")
      (if (= modemtype 3)
        (execute "avm:defaultscripts/useZyXEL6.01")
        (if (= modemtype 4)
          (execute "avm:defaultscripts/useZyXEL6.10")
          (if (= modemtype 5)
            (execute "avm:defaultscripts/useZyXEL6.11")
            (if (= modemtype 6)
              (execute "avm:defaultscripts/useZyXEL6.11a")
              (if (= modemtype 7)
                (execute "avm:defaultscripts/useRockwell")
                (if (= modemtype 8)
                  (execute "avm:defaultscripts/useZyXEL6.12")
                  (if (= modemtype 9)
                    (execute "avm:defaultscripts/useClass2")
                    (if (= modemtype 10)
                      (execute "avm:defaultscripts/useClass1")
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  )
)

(complete 80)

(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?")
      (help @askchoice-help)
      (choices
         "Flashing LED"
         "AmigaDOS Say Command"
                        "Prerecorded Voice"
      )
      (default 0)
   )
)

(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.")
   (help @startup-help)
   (command "assign avm: \"" avmdest "\"\n")
   (command "assign avmrexx: \"avm:rexx\"\n")
   (command "assign avmtemp: \"t:\"\n")
   (command "assign faxout: \"avm:outgoing/voices\"\n")
   (command "assign faxtemp: \"t:\"\n")
)

(execute "avm:renamevoicefiles"
 (prompt "Renaming old voice files, if any.")
)

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

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

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

(complete 100)


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

(exit)
