; $VER: Installation script for FMdriver 1.10
; © Stefan Robl
; Created with GoldED 6.1.4


; check if we are running under correct OS
(if (< (/ (getversion) 65536) 39) 
    (
        (abort "Incorrect OS version (software requires OS 39 or better )!")
    )
)

; error handling
(onerror
    (if (> @ioerr 0)
        (
            (message
                ("An error has occurred during installation. Please check the log file to understand the error.")
            )
        )
    )
    (exit (quiet))
)

(welcome)


(set @default-dest
    (askdir
        (prompt "Please choose the installation path for the FMdriver programs:\n(a new folder named \"FrameMachine\" will be created there)")
        (help "Installation creates a new folder \"FrameMachine\" for FMBaseConfig and FMTV in the path you specify.")
        (default @default-dest)
    )
)

(set #fmdir (tackon @default-dest "FrameMachine"))


(set #cputype
    (askoptions
        (prompt "Which CPU type(s) do you want to have supported?")
        (help "Select the type of CPU you want to have supported.\nIf you have no PPC-accelerator card, 68k is your choice.\nIf you have a PPC-board, there is no need to install the 68k-versions, too.")
        (choices
            " 68k (68020 or better)"
            " PPC (PPC603e or better, WarpOS required)"
        )
        (default (+ 1 2))
    )
)

(if (= #cputype 0)
  (abort "No CPU-type selected.\n\nInstallation aborted!")
)



(set #video-format
    (askchoice
        (prompt "What type of video format has your Amiga as default?")
        (help "If your Amiga is in Europe, you normally have to choose PAL")
        (choices
            "PAL"
            "NTSC"
        )
        (default 0)
    )
)



(set #fmfiles
    (askoptions
        (prompt "What files shall be installed?")
        (help "FMdriver.guide: Online documentation (AmigaGuide format) for the FMdriver programs\n\nFMBaseConfig: Config program for FM display settings\n\nFMInit: Tool for the WB and CLI which initializes the FrameMachine\n\nFMTV: Watch TV on your Workbench!\n\nFMRecorder: Records and converts anims\n\nFMGrab: CLI tool for grabbing single images\n\nFMRecord/FMRecordDec: like FMRecorder, but for the CLI")
        (choices
            " FMdriver.guide - online documentation"
            " FMBaseConfig"
            " FMInit"
            " FMTV"
            " FMRecorder"
            " FMGrab (CLI tool)"
            " FMRecord / FM RecordDec (CLI tool)"
        )
        (default (+ 1 2 4 8 16 32 64))
    )
)

(if (= #fmfiles 0)
  (abort "No FMdriver application(s) selected.\n\nInstallation aborted!")
)


(COMPLETE 0) ; makedir FrameMachine
(makedir (tackon @default-dest "FrameMachine") (infos))


(COMPLETE 10) ; wizard.library
(copylib 
    (prompt "Copying wizard.library to LIBS:")
    (help "The \"wizard.library\" is needed for the applications using a GUI.\nIt is the free distributable part of Haage&Partners StormWIZARD system.")
    (source "libs/wizard.library")
    (dest "LIBS:")
    (optional nofail force askuser)
    (confirm)
)


(COMPLETE 20) ; XILINX-files
(copyfiles 
    (prompt "Copying XILIX-files to DEVS:")
    (help "These files are needed to configure the FrameMachinehardware.\nThey are loaded on driver-open into the reconfigurable Xilinx-Units on the FrameMachine.\nYou have to copy both files to \"DEVS:\", otherwise the driver cannot work!")
    (source "devs/")
    (dest "DEVS:")
    (pattern "XILINX#?")
    (optional nofail force askuser)
    (confirm)
)


(COMPLETE 70) ; PAL/NTSC settings
(if (= #video-format 0)
    ( ; PAL
        (copyfiles
            (prompt "Copying PAL-settings to DEVS:")
            (help @copy-files)
            (source "devs/FrameMachine.settings.PAL")
            (newname "FrameMachine.settings")
            (dest "DEVS:")
            (optional nofail force)
        )
    )
    ; else
    ( ; NTSC
        (copyfiles
            (prompt "Copying NTSC-settings to DEVS:")
            (help @copy-files)
            (source "devs/FrameMachine.settings.NTSC")
            (newname "FrameMachine.settings")
            (dest "DEVS:")
            (optional nofail force)
        )
    )
)


(COMPLETE 30)
(if (BITAND #fmfiles 1) ; FMdriver.guide
  (
    (copyfiles
      (prompt "Copying Guide-documentation...")
      (help @copy-files)
      (source "FMdriver.guide")
      (dest #fmdir)
      (infos)
      (optional nofail force)
      (confirm)
  )
  )
)


(COMPLETE 40)
(if (BITAND #fmfiles 2) ; FMBaseConfig
  (
    (if (BITAND #cputype 1)
      (copyfiles
        (prompt "Copying FMBaseConfig_68k...")
        (help @copy-files)
        (source "FMBaseConfig_68k")
        (dest #fmdir)
        (infos)
        (optional nofail force)
        (confirm)
      )
    )
    (if (BITAND #cputype 2)
      (copyfiles
        (prompt "Copying FMBaseConfig_PPC...")
        (help @copy-files)
        (source "FMBaseConfig_PPC")
        (dest #fmdir)
        (infos)
        (optional nofail force)
        (confirm)
      )
    )
  )
)


(COMPLETE 50)
(if (BITAND #fmfiles 4) ; FMInit
  (copyfiles
    (prompt "Copying FMInit...")
    (help @copy-files)
    (source "FMInit")
    (dest #fmdir)
    (infos)
    (optional nofail force)
    (confirm)
  )
)


(COMPLETE 60)
(if (BITAND #fmfiles 8) ; FMTV
  (
    (if (BITAND #cputype 1)
      (copyfiles
        (prompt "Copying FMTV_68k...")
        (help @copy-files)
        (source "FMTV_68k")
        (dest #fmdir)
        (infos)
        (optional nofail force)
        (confirm)
      )
    )
    (if (BITAND #cputype 2)
      (copyfiles
        (prompt "Copying FMTV_PPC...")
        (help @copy-files)
        (source "FMTV_PPC")
        (dest #fmdir)
        (infos)
        (optional nofail force)
        (confirm)
      )
    )
  )
)


(COMPLETE 70)
(if (BITAND #fmfiles 16) ; FMRecorder
  (
    (if (BITAND #cputype 1)
      (copyfiles
        (prompt "Copying FMRecorder_68k...")
        (help @copy-files)
        (source "FMRecorder_68k")
        (dest #fmdir)
        (infos)
        (optional nofail force)
        (confirm)
      )
    )
    (if (BITAND #cputype 2)
      (copyfiles
        (prompt "Copying FMRecorder_PPC...")
        (help @copy-files)
        (source "FMRecorder_PPC")
        (dest #fmdir)
        (infos)
        (optional nofail force)
        (confirm)
      )
    )
  )
)


(COMPLETE 80)
(if (BITAND #fmfiles 32) ; FMGrab
  (
    (if (BITAND #cputype 1)
      (copyfiles
        (prompt "Copying FMGrab_68k...")
        (help @copy-files)
        (source "FMGrab_68k")
        (dest #fmdir)
        (optional nofail force)
        (confirm)
      )
    )
    (if (BITAND #cputype 2)
      (copyfiles
        (prompt "Copying FMGrab_PPC...")
        (help @copy-files)
        (source "FMGrab_PPC")
        (dest #fmdir)
        (optional nofail force)
        (confirm)
      )
    )
  )
)


(COMPLETE 90)
(if (BITAND #fmfiles 64) ; FMRecord
  (
    (copyfiles
      (prompt "Copying FMRecord...")
      (help @copy-files)
      (source "FMRecord")
      (dest #fmdir)
      (optional nofail force)
      (confirm)
    )
    (if (BITAND #cputype 1)
      (copyfiles
        (prompt "Copying FMRecordDec_68k...")
        (help @copy-files)
        (source "FMRecordDec_68k")
        (dest #fmdir)
        (optional nofail force)
        (confirm)
      )
    )
    (if (BITAND #cputype 2)
      (copyfiles
        (prompt "Copying FMRecordDec_PPC...")
        (help @copy-files)
        (source "FMRecordDec_PPC")
        (dest #fmdir)
        (optional nofail force)
        (confirm)
      )
    )
  )
)


(COMPLETE 100)

(exit)

