; Installation script for AmigaWriter-Filter
;
; ©2000 by Rüdiger Hanke

(set #FILTERPATH "SoftLogik:Filters")
(set #INSTALLPATH "install_data")
(set #DOCFILTER (cat #FILTERPATH "/AmigaWriter.dfilter"))
(set #TEXTFILTER (cat #FILTERPATH "/AmigaWriter.tfilter"))
(set #INST_DOCFILTER (cat #INSTALLPATH "/AmigaWriter.dfilter"))
(set #INST_TEXTFILTER (cat #INSTALLPATH "/AmigaWriter.tfilter"))

(set #INSTALL_TFILTER 1)
(set #INSTALL_DFILTER 1)

(set @app-name "AmigaWriter-Filter")
(set @default-dest (cat "" #FILTERSPATH))

; First check some stuff
(if (patmatch "68000|68010" (database "cpu"))
   (
		(abort "Sorry, but you need an 68020+ processor.")
   )
)

(if (<> 2 (exists #FILTERPATH (noreq)))
   (
      (abort "Your PageStream installation is incomplete!\n\nThis is a filter for Soft-Logik's DTP program PageStream.\n"
             "PageStream must be installed correctly on your computer.\n\nPlease install PageStream properly, then run the install script again.")
   )
)

(if (or (<> 1 (exists #INST_DOCFILTER (noreq)))
        (<> 1 (exists #INST_TEXTFILTER (noreq))))
   (
      (abort "Incomplete installation package!\n\nThe installer could not find some required files.\n"
             "Be sure to download the original AmigaWriter-Filter distribution\nfrom Aminet or http://www.muenster.de/~tomjoad/.")
   )
)

; Ask what to install if user != novice
(if (<> @user-level 0)
   (
      (set #RESULT   (askoptions (prompt "Please select which filter(s) you'd like to install:")
                     (choices "Document filter" "Text filter")
                     (help "Select the filters you would like to install.\n\nDocument filter:\n"
                           "With the document filter, you can load AmigaWriter documents in PageStream "
                           "via the \"Open\" menu item as if they were PageStream-native documents. Page sizes, boxes, images, "
                           "links between boxes etc. will all be imported.\n\n"
                           "Text filter:\nThe text filters imports the main flowtext of your AmigaWriter "
                           "document via the \"Insert text\" menu item into the current column.\n\n"
                           "Both filters can co-exist and unless you absolutely don't need one of them, "
                           "there is no reason to install only one.")))

      (if (not (bitand 1 #RESULT))
         (
            (set #INSTALL_DFILTER   0)
         )
      )

      (if (not (bitand 2 #RESULT))
         (
            (set #INSTALL_TFILTER   0)
         )
      )
   )
)

; Install
(if (<> 0 #INSTALL_DFILTER)
   (
		; Check version number
		(set #VER_FILTER (getversion #DOCFILTER))
		(set #VER_VER (/ #VER_FILTER 65536))
		(set #VER_REV (- #VER_FILTER (* #VER_VER 65536)))

		(set #VER_NEWFILTER (getversion #INST_DOCFILTER))
		(set #VER_NEWVER (/ #VER_NEWFILTER 65536))
		(set #VER_NEWREV (- #VER_NEWFILTER (* #VER_NEWVER 65536)))

		(if (or (> #VER_VER #VER_NEWVER) (and (= #VER_VER #VER_NEWVER) (>= #VER_REV #VER_NEWREV)))
			(
				(message "The document filter installed on your system is a later "
							"version than the one to install.\n\nThe document filter will not be installed.")
			)
			(
				; Copy document filter to filter path
				(copyfiles  (source  #INST_DOCFILTER)
								(dest    #FILTERPATH)
								(prompt  "Installing document filter..."))
			)
		)
   )
)

(if (<> 0 #INSTALL_TFILTER)
   (
		; Check version number
		(set #VER_FILTER (getversion #TEXTFILTER))
		(set #VER_VER (/ #VER_FILTER 65536))
		(set #VER_REV (- #VER_FILTER (* #VER_VER 65536)))

		(set #VER_NEWFILTER (getversion #INST_TEXTFILTER))
		(set #VER_NEWVER (/ #VER_NEWFILTER 65536))
		(set #VER_NEWREV (- #VER_NEWFILTER (* #VER_NEWVER 65536)))

		(if (or (> #VER_VER #VER_NEWVER) (and (= #VER_VER #VER_NEWVER) (>= #VER_REV #VER_NEWREV)))
			(
				(message "The text filter installed on your system is a later "
							"version than the one to install.\n\nThe text filter will not be installed.")
			)
			(
				; Copy text filter to filter path
				(copyfiles  (source  #INST_TEXTFILTER)
								(dest    #FILTERPATH)
								(prompt  "Installing text filter..."))
			)
		)
   )
)

