(procedure check-amiwin-version
 (set amiwin-version (getversion (tackon @default-dest "bin/AmiWin")))
 (if (not(= amiwin-version 131086))
  (abort "You do not have AmiWin 2.14 installed.\n");
 )
 (set amiwin-version (getversion (tackon @default-dest "bin/mkfontdir")))
 (if (not(= amiwin-version 131072))
  (abort "Your file mkfontdir does not have the correct version\n");
 )
 (set amiwin-version (getversion (tackon @default-dest "libs/xfont.library")))
 (if (not(= amiwin-version 131086))
  (abort "Your xfont.libray does not have the correct version\n");
 )
)

(procedure select-destination-directory
 (set @default-dest
  (askdir
   (prompt "Select the directory where you have "
    "installed AmiWin 2.14 reg. The default is "
    "probably correct.")
   (help "Please specify the directory where you have "
    "installed AmiWin 2.14 reg. The default is "
    "the X11: directory, i.e. the likely place of "
    "your AmiWin installation.")
   (default "X11:")
  )
 )
)  

(procedure patchonefile
 (copyfiles
  (source (tackon srcdir srcfile))
  (dest "T:")
  (newname "oldfile")
 )

 (working)
 (run (cat "\"" (tackon source-dir "bin/spatch") "\" -oT:newfile \"-p" pchfile "\" T:oldfile"))

 (copyfiles
  (source "T:newfile")
  (dest srcdir)
  (newname srcfile)
 )

 (delete "T:oldfile")
 (delete "T:newfile")
)

;;;; Start

(set app-name "AmiWin 2.16reg")

(complete 0)

(set source-dir (if (= 1 (exists @icon)) (pathonly (expandpath @icon))
 (expandpath @icon))
)

(select-destination-directory)

(check-amiwin-version)


(set srcdir (tackon @default-dest "bin"))
(set srcfile "AmiWin")
(set pchfile (tackon source-dir "x11/bin/AmiWin.pch"))
(patchonefile)


(complete 5)

(set srcdir (tackon @default-dest "bin"))
(set srcfile "xcalc")

(if (exists (tackon srcdir srcfile)) (
 (set pchfile (tackon source-dir "x11/bin/xcalc.pch"))
 (patchonefile)
))

(complete 10)

(set srcdir (tackon @default-dest "help"))
(set srcfile "AmiWin.dvi")
(if (exists (tackon srcdir srcfile)) (
 (set pchfile (tackon source-dir "x11/help/AmiWin_dvi.pch"))
 (patchonefile)
))

(complete 15)

(set srcdir (tackon @default-dest "help"))
(set srcfile "AmiWin.guide")
(if (exists (tackon srcdir srcfile)) (
 (set pchfile (tackon source-dir "x11/help/AmiWin_guide.pch"))
 (patchonefile)
))

(complete 20)

(set srcdir (tackon @default-dest "help"))
(set srcfile "AmiWin.ps")
(if (exists (tackon srcdir srcfile)) (
 (set pchfile (tackon source-dir "x11/help/AmiWin_ps.pch"))
 (patchonefile)
))

(complete 25)

(set srcdir (tackon @default-dest "libs"))
(set srcfile "xfont.library")
(set pchfile (tackon source-dir "x11/libs/xfont.pch"))
(patchonefile)

(complete 30)

(set srcdir (tackon @default-dest "libs"))
(set srcfile "xt.library")
(if (exists (tackon srcdir srcfile)) (
 (set pchfile (tackon source-dir "x11/libs/xt.pch"))
 (patchonefile)
))

(complete 35)

(set srcdir (tackon @default-dest "libs"))
(set srcfile "xaw.library")
(if (exists (tackon srcdir srcfile)) (
 (set pchfile (tackon source-dir "x11/libs/xaw.pch"))
 (patchonefile)
))

(complete 40)

(set srcdir (tackon @default-dest "libs"))
(set srcfile "xaw3d.library")
(if (exists (tackon srcdir srcfile)) (
 (set pchfile (tackon source-dir "x11/libs/xaw3d.pch"))
 (patchonefile)
))

(complete 45)

(set srcdir (tackon @default-dest "libs"))
(set srcfile "xpm.library")
(if (exists (tackon srcdir srcfile)) (
 (set pchfile (tackon source-dir "x11/libs/xpm.pch"))
 (patchonefile)
))

(complete 50)

(set srcdir (tackon @default-dest "bin"))
(set srcfile "fvwm")
(if (exists (tackon srcdir srcfile)) (
 (set pchfile (tackon source-dir "x11/bin/fvwm.pch"))
 (patchonefile)
))

(complete 55)

(set srcdir (tackon @default-dest "bin"))
(set srcfile "mkfontdir")
(if (exists (tackon srcdir srcfile)) (
 (set pchfile (tackon source-dir "x11/bin/mkfontdir.pch"))
 (patchonefile)
))

(complete 60)

(set srcdir (tackon @default-dest "bin"))
(set srcfile "xdaliclock")
(if (exists (tackon srcdir srcfile)) (
 (set pchfile (tackon source-dir "x11/bin/xdaliclock.pch"))
 (patchonefile)
))

(complete 65)

(copyfiles
 (source (tackon source-dir "x11/bin/AWDecrypt"))
 (dest "x11:bin")
)

(complete 70)

(if (askbool
 (prompt "Would you like to install the new display drivers "
  "for the HRG-System (Merlin, Domino and VisionA) ?")
 (help "This release of AmiWin contains new drivers for the "
  "three graphics boards Merlin, Domino and VisionA running "
  "with their native graphics software. If you want to install "
  "these drivers, please click 'Yes'.")
 (choices "Yes" "No")
 )
 (

  (copyfiles
   (source (tackon source-dir "x11/xsd/hrg-8.xsd.000"))
   (dest "x11:xsd")
  )

  (complete 75)

  (copyfiles
   (source (tackon source-dir "x11/xsd/hrg-8.xsd.030"))
   (dest "x11:xsd")
  )

  (complete 80)

  (copyfiles
   (source (tackon source-dir "x11/xsd/hrg-15.xsd.000"))
   (dest "x11:xsd")
  )

  (complete 85)

  (copyfiles
   (source (tackon source-dir "x11/xsd/hrg-15.xsd.030"))
   (dest "x11:xsd")
  )

  (complete 90)

  (if(askchoice (
    (prompt "Please select for which CPU you want the "
     "HRG drivers to be installed:")
    (help "The HRG drivers can be installed in a version that can "
     "be run on any cpu (->68000), or in a version that "
     "requires a 68030 or higher and a 68881 or higher."
    )
    (choices "68000"
     "68030/68881")
    (default 0)
   ))
   (
    (copyfiles
     (source (tackon source-dir "x11/xsd/hrg-15.xsd.030"))
     (dest "x11:xsd")
     (newname "hrg-15.xsd")
    )

    (complete 95)

    (copyfiles
     (source (tackon source-dir "x11/xsd/hrg-8.xsd.030"))
     (dest "x11:xsd")
     (newname "hrg-8.xsd")
    )
   )
   (
    (copyfiles
     (source (tackon source-dir "x11/xsd/hrg-15.xsd.000"))
     (dest "x11:xsd")
     (newname "hrg-15.xsd")
    )

    (complete 95)

    (copyfiles
     (source (tackon source-dir "x11/xsd/hrg-8.xsd.000"))
     (dest "x11:xsd")
     (newname "hrg-8.xsd")
    )
   )
  )
  (message "To activate the HRG-System drivers, you have to "
   "modify the configuration file 'ENV:AMIWIN/AWOPTIONS'. "
   "Please change the option '-xsd' to either "
   "'-xsd hrg-8' for the 8-bit driver or to '-xsd hrg-15' "
   "for the 15/16-bit driver."
  )
 )
)

(complete 100)

(exit "Installation of the update from AmiWin 2.14 reg to "
 "AmiWin 2.16 reg is finished.")
