; Installer Script for KingFisher Release 2
; Copyright © 1994,1995 Udo Schuermann
; All rights reserved
; $VER: Install-KingFisher 2.8 (6.3.95)
;
;
; Installer and Installer project icon
; (c) Copyright 1991-93 Commodore-Amiga, Inc.  All Rights Reserved.
; Reproduced and distributed under license from Commodore.
; 
; INSTALLER SOFTWARE IS PROVIDED "AS-IS" AND SUBJECT TO CHANGE;
; NO WARRANTIES ARE MADE.  ALL USE IS AT YOUR OWN RISK.  NO LIABILITY
; OR RESPONSIBILITY IS ASSUMED.


(procedure install-language (
  (set catDest ("Catalogs/%s" language))
  (if (not (exists catDest))
    (makedir catDest (safe)))
  (copyfiles
    (source (tackon "KFINST:" catDest))
    (dest (tackon DESTIN catDest))
    (all))
))

; Main entry point
(set dosver (/ (getversion "dos.library" (resident)) 65536))
(if (< dosver 37)
    ((user 1)
     (message
	"KingFisher Release 2 requires at least Kickstart 2.04 but your "
	"system's Kickstart (ROM software) is too old to support "
	"KingFisher!\n\nIt is suggested that you abort the installation and "
	"upgrade your system, as KingFisher Release 2 cannot be made to "
	"function until you do.")))

(if (exists "Developer")
  (set defaultopts %010110111)
  (set defaultopts %000111111))
(if (not (exists "LIBS:amigaguide.library"))
  (set defaultopts (BITOR defaultopts %100000000)))

(set opts
  (askoptions
    (help (cat
	"Select all items from the list which you would like to have "
	"installed.  If you are upgrading an existing installation "
	"to a newer version, you should make the same choices as you "
	"did for your primary installation.\n\n"
	"NOTES:\n"
	"AmigaGuide.library will not be installed if you already "
	"have a copy of it in your LIBS: directory.\n\n"
	"The Developer Kit is only included in special order packages "
	"direct from the software's author."))
    (default defaultopts)
    (prompt (cat
	"Which portions of the KingFisher Release 2 software would you like "
	"to have installed?"))
    (choices
	"KingFisher Release 2     (~165K)"
	"RexxFisher + Examples     (~35K)"
	"Online Documentation     (~200K)"
	"Language Catalogs     (~6K each)"
	"Miscellaneous files       (~10K)"
	"1000 Fish Database       (~1.5M)"
	"Other Databases            (n/a)"
	"Developer Kit            (~200K)"
	"AmigaGuide.library V34    (~65K)"
	)))

(if (AND (in opts 7) (not (exists "Developer"))) (
   (set opts (BITXOR opts %010000000))
   (message
	"Because of diskspace limitations, the Developer Kit is not "
	"included on this disk.\n\n"
	"If you are interested in developing your own client software "
	"for the KFServer, please request the KingFisher Development Kit "
	"from the author.\n\n"
	"See the documentation for ordering information!")))

(if (in opts 8)
  ((set opts (BITXOR opts %100000000))
   (if (exists "LIBS:amigaguide.library")
     (message
	"You already have a copy of AmigaGuide.library installed in "
	"your LIBS: directory.  The version that ships with KingFisher "
	"will not be used to overwrite your existing copy.")
     (message
	"AmigaGuide.library is no longer shipped with KingFisher due "
	"to lack of space on the floppy disk.  AmigaGuide can be "
	"obtained from other sources, such as Aminet or local BBSs, "
	"however.  AmigaGuide merely provides context sensitive help "
	"for KingFisher but is not required to operate the program."))))

(if (= opts 0) (
  (complete 100)
  (message "Looks like the Installer has nothing to do...")
  (exit)))

(if (= @user-level 0)
  (set defaultcats 255)
  (set defaultcats 0))

(if (in opts 3)
  ((set catalogs
     (askoptions
       (help @askoptions-help)
       (default defaultcats)
       (prompt	"You may choose one or more language catalogs to be "
		"installed with KingFisher.  If your language of choice "
		"does not appear here, perhaps you are interested in "
		"creating a translation?")
       (choices "Dansk"
		"Deutsch"
		"Español"
; n/a		"Français"
; n/a		"Italiano"
		"Nederlands"
; n/a		"Norsk"
; n/a		"Português"
		"Suomi"
		"Svenska"
      )))
   (set CATCOUNT 0)
   (if (in catalogs 0) (set CATCOUNT (+ CATCOUNT 1)))
   (if (in catalogs 1) (set CATCOUNT (+ CATCOUNT 1)))
   (if (in catalogs 2) (set CATCOUNT (+ CATCOUNT 1)))
   (if (in catalogs 3) (set CATCOUNT (+ CATCOUNT 1)))
   (if (in catalogs 4) (set CATCOUNT (+ CATCOUNT 1)))
   (if (in catalogs 5) (set CATCOUNT (+ CATCOUNT 1)))
   (if (in catalogs 6) (set CATCOUNT (+ CATCOUNT 1)))
   (if (in catalogs 7) (set CATCOUNT (+ CATCOUNT 1)))
  )
  (set catalogs 0))

(set MINSPC 0)
(if (in opts 0) (set MINSPC (+ MINSPC 165)))
(if (in opts 1) (set MINSPC (+ MINSPC 35)))
(if (in opts 2) (set MINSPC (+ MINSPC 200)))
(if (in opts 3) (set MINSPC (+ MINSPC (* CATCOUNT 8))))
(if (in opts 4) (set MINSPC (+ MINSPC 10)))
(if (in opts 5) (set MINSPC (+ MINSPC 1480)))
(if (in opts 7) (set MINSPC (+ MINSPC 200)))
(if (in opts 8) (set MINSPC (+ MINSPC 65)))

(set DISKFREE 0)
(while (< DISKFREE MINSPC)
  (set DESTIN (tackon
    (askdir
      (prompt (cat
		"Where do you wish to install KingFisher Release 2?\n(A "
		"drawer named `KingFisher2' will be created there.)  Do "
		"not attempt to install KingFisher Release 2 to the same "
		"directory as KingFisher 1.x!")
      (help @askdir-help)
      (default "SYS:")))
    "KingFisher2"))
  (makeassign "KFINST" "" (safe))
  (set @default-dest DESTIN)
  (set @execute-dir DESTIN)
  (set DISKFREE (/ (getdiskspace ("%s:" (getdevice DESTIN))) 1024))
  (if (< DISKFREE MINSPC)
    ((if (= @user-level 0) (user 1))
     (if (askbool
	(prompt (cat
		("\nPlease note:\n\nThe selected volume reports only %ldK of " DISKFREE)
		("diskspace, whereas you should have at least %ldK free!\n\n" MINSPC)
		"Are you sure you wish to proceed with installation to this volume?"))
	(choices "Yes, proceed" "No, try another")
	(default "No, try another")
	(help @askbool-help))
	(set DISKFREE MINSPC)))))

(if (in opts 2)
  (if (< dosver 39)
     (set WrapIt
       (askbool
	  (prompt (cat
		"*** ATTENTION - READ THIS!  ***\n\n"
		"The KingFisher2.guide documentation that ships with "
		"KingFisher Release 2 is formatted with long lines to "
		"provide Kickstart 3.x users with more readable, "
		"paragraph oriented documentation.\n"
		"This format causes trouble for AmigaGuide under "
		"Kickstart 2.x wherefore a special 'WrapGuide' tool "
		"is supplied to fix the .guide file for use with "
		("your installed version of AmigaDOS V%ld\n\n" dosver)
		"You are STRONGLY URGED to have Installer apply "
		"the WrapGuide operation to the documentation!!"))
	  (choices "WrapGuide" "Skip it")
	  (default "WrapGuide")
	  (help @askbool-help)))
     (set WrapIt
       (askbool
	  (prompt (cat
		"The KingFisher2.guide documentation that ships with "
		"KingFisher Release 2 is formatted with long lines to "
		"provide Kickstart 3.x users with more readable, "
		"paragraph oriented documentation.\n"
		"If you have pressing reasons to convert this file "
		"to a version that will not cause trouble with Kickstart "
		"2.x, then you may choose to have the Installer apply "
		"the supplied 'WrapGuide' tool to the file.\n\n"
		"For best performance under your installed version of "
		("AmigaDOS %ld, it is recommended to skip this step!" dosver)))
	  (choices "WrapGuide" "Skip it")
	  (default "Skip it")
	  (help @askbool-help)))))

(if (= @user-level 0)
    ((user 1)
     (message ("KingFisher Release 2 will be installed to\n\n%s" DESTIN))))

(if (not (exists DESTIN))
    (makedir DESTIN (infos) (safe)))

(copyfiles
 (source "KFINST:gunzip")
 (dest "ram:"))

(complete 0)

(set total (* MINSPC 1024)) (set copied 0)

(foreach "KFINST:" "#?.gz" (
  (set ALWAYS 0)
  (set ONLYNEW 0)

  (if (in opts 0)
    (if (patmatch "(KingFisher|KFServer).gz" @each-name)
      (set ALWAYS 1)
      (if (patmatch "(KingFisher.info|KFServer.prefs).gz" @each-name)
        (set ONLYNEW 1))))

  (if (in opts 1)
    (if (patmatch "RexxFisher#?.gz" @each-name)
      (set ALWAYS 1)
      (if (patmatch "#?.kfrx(%|.info).gz" @each-name)
        (set ONLYNEW 1))))

  (if (in opts 2)
    (if (patmatch "#?(.guide|IFF).gz" @each-name)
      (set ALWAYS 1)
      (if (patmatch "#?(.guide|IFF).info.gz" @each-name)
        (set ONLYNEW 1))))

  (if (in opts 4)
    (if (patmatch "#?.pi.gz" @each-name)
      (set ALWAYS 1)
      (if (patmatch "#?.(format|search).gz" @each-name)
        (set ONLYNEW 1))))

  (if (in opts 5)
    (if (patmatch "1000Fish#?.gz" @each-name)
      (set ONLYNEW 1)))

  (if (in opts 8)
    (if (patmatch "amigaguide.library.gz" @each-name)
      (set ONLYNEW 1)))

  (if ALWAYS (
    (set thisfile (substr @each-name 0 (- (strlen @each-name) 3)))
    (copyfiles
	(source (tackon "KFINST:" @each-name))
	(dest DESTIN))
    (working ("\nInstalling KingFisher Release 2\n\n%s" thisfile))
    (run ("stack 50000\nram:gunzip >NIL: <NIL: -fN \"%s\"" (tackon DESTIN @each-name)))
    (set copied (+ copied (getsize (tackon DESTIN thisfile))))
    (if (> copied total) (set total copied))
    (complete (/ (* copied 100) total))))

  (if ONLYNEW (
    (set thisfile (substr @each-name 0 (- (strlen @each-name) 3)))
    (if (not (exists (tackon DESTIN thisfile))) (
      (copyfiles
	(source (tackon "KFINST:" @each-name))
	(dest DESTIN))
      (working ("\nInstalling KingFisher Release 2\n\n%s" thisfile))
      (run ("stack 50000\nram:gunzip >NIL: <NIL: -fN \"%s\"" (tackon DESTIN @each-name)))))
    (set copied (+ copied (getsize (tackon DESTIN thisfile))))
    (if (> copied total) (set total copied))
    (complete (/ (* copied 100) total))))
))

(if (in opts 8) (
  (working "Processing changes to AmigaGuide.library")
  (if (exists (tackon DESTIN "amigaguide.library")) (
    (if (not (exists "LIBS:amigaguide.library"))
      (copylib
	(source (tackon DESTIN "amigaguide.library"))
	(dest "LIBS:")))
    (delete (tackon DESTIN "amigaguide.library"))))))

(if (<> catalogs 0) (
  (working "\nInstalling Language Catalogs")
  (if (not (exists (tackon DESTIN "Catalogs")))
      (makedir (tackon DESTIN "Catalogs") (safe)))
;   note that the bit numbers 0, 1, 2, 3, 4, 5... will change when
;   more catalogs become available and lines above are uncommented
  (if (in catalogs 0)
     ((set language "Dansk")
      (install-language)))
  (if (in catalogs 1)
     ((set language "Deutsch")
      (install-language)))
  (if (in catalogs 2)
     ((set language "Español")
      (install-language)))
  (if (in catalogs 3)
     ((set language "Nederlands")
      (install-language)))
  (if (in catalogs 4)
     ((set language "Suomi")
      (install-language)))
  (if (in catalogs 5)
     ((set language "Svenska")
      (install-language)))

;   And finally, let's uncompress all the .gz Catalog files...
  (run "stack 50000\nram:gunzip >NIL: <NIL: -rfN Catalogs")))

(working "\nFixing icon tooltypes ...")
(tooltype
  (dest DESTIN)
  (noposition))

; setup the SERVERNAME to the installation directory
(tooltype
  (dest (tackon DESTIN "KingFisher"))
  (settooltype "(SERVERNAME" (cat (tackon DESTIN "KFServer") ")")))
; Make Kickstart-dependent alterations

(if (in opts 2)
  ((if (> dosver 38)
    ((working "Adjusting KingFisher2.guide icon for MultiView")
     (tooltype
       (dest (tackon DESTIN "KingFisher2.guide"))
       (setdefaulttool "MultiView"))))
   (if (or (< dosver 39) WrapIt)
     ((working "\nWord-wrapping KingFisher2.guide\nfor use with AmigaGuide V34")
      (run ("stack 50000\nKFINST:WrapGuide %s 65" (tackon DESTIN "KingFisher2.guide")))))))

(if (in opts 7) (
  (working "Installing KingFisher Developer Kit")
  (copyfiles (source "KFINST:Developer") (dest (tackon DESTIN "Developer")) (all))
  (run ("stack 50000\nram:gunzip >NIL: <NIL: -rfN Developer"))))

(complete 100)

(delete "ram:gunzip")

(if (in opts 6)
  (message
	"Adding other databases...\n\n"
	"This function is not yet implemented.  Please refer to the "
	"documentation for instructions on how to add other databases "
	"so that the KFServer can serve them to clients such as KingFisher "
        "and RexxFisher."))

(makeassign "KFINST")
(exit)
