(procedure check-one-file-version
 (set fpath (tackon @default-dest fname))
 (if (exists fpath) (
  (set amiwin-version (getversion fpath))
  (if (not(= amiwin-version fversion))
   (abort (cat "Your file " fname " does not have the correct version\n"));
  )
 ))
) 

(procedure check-amiwin-version
 (set amiwin-version (getversion (tackon @default-dest "bin/AmiWin")))
 (if (not(= amiwin-version 131088))
  (abort "You do not have AmiWin 2.16 installed.\n");
 )

 (working)
 (set n 0)
 (while (set fname (select n
  "bin/mkfontdir" "bin/oclock" "bin/twm" "bin/xauth" "bin/xcalc"
  "bin/xclock" "bin/xdpyinfo" "bin/xhost" "bin/xkill" "bin/xlsclients"
  "bin/xset" "bin/xsetroot" "bin/xwininfo" "libs/xau.library"
  "libs/xaw.library" "libs/xfont.library" "libs/xice.library"
  "libs/xlib.library" "libs/xmu1.library" "libs/xmu2.library"
  "libs/xsm.library" "libs/xt.library" "libs/xtrans.library"
  "xle/mitmisc.xle" "xle/multibuf.xle" "xle/shape.xle"
  "xle/sync.xle" "xsd/aga-1.xsd" "xsd/aga-8.xsd" "xsd/rtg-1.xsd"
  "xtp/amitcp.xtp" "xtp/as225.xtp" "")) (
  (set fversion (select n
   131088 131072 131086 131072 131088
   131072 131084 131084 131084 131086
   131084 131084 131084 131072
   131088 131088 131083
   131086 131083 131086
   131072 131088 131083
   131072 131072 131072
   131072 131086 131088 131086
   131072 131072))
  (check-one-file-version)
  (set n (+ n 1))
 ))
)

(procedure select-destination-directory
 (set @default-dest
  (askdir
   (prompt "Select the directory where you have "
    "installed AmiWin 2.16 demo. The default is "
    "probably correct.")
   (help "Please specify the directory where you have "
    "installed AmiWin 2.16 demo. 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.22demo")

(complete 0)

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

(select-destination-directory)

(check-amiwin-version)

(complete 10)

(copyfiles
 (source (tackon source-dir "x11/Help"))
 (dest (tackon @default-dest "Help"))
 (all)
)

(complete 12)

(if (not (exists (tackon @default-dest "xsr")))
 (makedir (tackon @default-dest "xsr"))
)

(copyfiles
 (source (tackon source-dir "x11/xsr"))
 (dest (tackon @default-dest "xsr"))
 (all)
)

(complete 14)

(copyfiles
 (source (tackon source-dir "x11/libs/xdmcpintl.library"))
 (dest (tackon @default-dest "libs"))
)

(complete 16)

(if (not (exists (tackon @default-dest "man")))
 (makedir (tackon @default-dest "man"))
)

(copyfiles
 (source (tackon source-dir "x11/man"))
 (dest (tackon @default-dest "man"))
 (all)
)

(complete 18)

(copyfiles
 (source (tackon source-dir "x11/xle/amiwinmisc.xle"))
 (dest (tackon @default-dest "xle"))
)

(complete 20)

(copyfiles
 (source (tackon source-dir "x11/xle/lbx.xle"))
 (dest (tackon @default-dest "xle"))
)

(complete 22)

(copyfiles
 (source (tackon source-dir "x11/xsd/cybergraphx-8.xsd"))
 (dest (tackon @default-dest "xsd"))
)

(complete 24)

(copyfiles
 (source (tackon source-dir "x11/xsd/graffity-8.xsd"))
 (dest (tackon @default-dest "xsd"))
)

(complete 26)

(copyfiles
 (source (tackon source-dir "x11/xsd/hrg-8.xsd"))
 (dest (tackon @default-dest "xsd"))
)

(complete 28)

(copyfiles
 (source (tackon source-dir "x11/xsd/picasso-l-8.xsd"))
 (dest (tackon @default-dest "xsd"))
)

(complete 30)

(copyfiles
 (source (tackon source-dir "x11/xsd/retina-8.xsd"))
 (dest (tackon @default-dest "xsd"))
)

(complete 32)

(copyfiles
 (source (tackon source-dir "x11/xsk/is.xsk"))
 (dest (tackon @default-dest "xsk"))
)

(complete 34)

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

(complete 36)

(set n 0)
(while (set srcfile (select n
 "mkfontdir" "oclock" "twm" "xauth" "xcalc" "xclock" "xdpyinfo"
 "xhost" "xkill" "xlsclients" "xset" "xsetroot" "xwininfo"
 "xau.library" "xaw.library" "xfont.library" "xice.library"
 "xlib.library" "xmu1.library" "xmu2.library" "xsm.library"
 "xt.library" "xtrans.library" "mitmisc.xle" "multibuf.xle"
 "shape.xle" "sync.xle" "aga-1.xsd" "aga-8.xsd" "rtg-1.xsd"
 "amitcp.xtp" "as225.xtp" "")) (
 (set reldir (select n
  "bin" "bin" "bin" "bin" "bin" "bin" "bin" "bin"
  "bin" "bin" "bin" "bin" "bin" "libs" "libs" "libs"
  "libs" "libs" "libs" "libs" "libs" "libs" "libs"
  "xle" "xle" "xle" "xle" "xsd" "xsd" "xsd" "xtp" "xtp"))

 (set srcdir (tackon @default-dest reldir))

 (if (exists (tackon srcdir srcfile)) (
  (set pchfile (tackon (tackon (tackon source-dir "x11") reldir) (select n
   "mkfontdir.pch" "oclock.pch" "twm.pch" "xauth.pch" "xcalc.pch"
   "xclock.pch" "xdpyinfo.pch" "xhost.pch" "xkill.pch"
   "xlsclients.pch" "xset.pch" "xsetroot.pch" "xwininfo.pch"
   "xau.pch" "xaw.pch" "xfont.pch" "xice.pch" "xlib.pch"
   "xmu1.pch" "xmu2.pch" "xsm.pch" "xt.pch" "xtrans.pch"
   "mitmisc.pch" "multibuf.pch" "shape.pch" "sync.pch"
   "aga-1.pch" "aga-8.pch" "rtg-1.pch" "amitcp.pch"
   "as225.pch")
    ))
   (patchonefile)
 ))
 (set n (+ n 1))
 (complete (+ 36 (* n 2)))
))

(exit "Installation of the update from AmiWin 2.16 demo to "
 "AmiWin 2.22 demo is finished.")
