;;----------------------------------------------------------------------------
;;
;; Update-1.6 - NewsRog 1.x -> 1.6 update script
;;
;; Copyright © 1998 ShadowWorks Software, All Right reserved.
;;
;; Use following Icon tooltypes / Command line options:
;; APPNAME=NewsRog
;; MINUSER=AVERAGE
;;----------------------------------------------------------------------------


;;-- declare procedures ------------------------------------------------------

(procedure P_NRExists testdir
  (and (exists (tackon testdir "NewsRog"))
       (exists (tackon testdir "MUI/S5697_NNews.mcc"))
       (exists (tackon testdir "MUI/S5697_AppBase.mcc"))
       (exists (tackon testdir "MUI/S5697_NPost.mcc"))))

(procedure P_Abort abtmsg
   (transcript abtmsg)
   (abort abtmsg))

;;-- initialization ----------------------------------------------------------

(complete 0)
(set locale 0)
(set @default-dest "RAM:")
(set @app-name "NewsRog")

;;------------------------------ english messages ----------------------------

(if (not (= @language "english"))
   (P_Abort #halted))

(if (= @language "english")
 (

   (set #welcome           (cat "Welcome to the " @app-name " 1.x->1.6 Update "
                                "process."))
   (set #bad-MUI 	   (cat "You need at least MUI 3.8 to use " @app-name))
   (set #bad-OS            (cat "You need at least OS 3.0 to use " @app-name
                                "2.0."))
   (set #bad-NewsRog       (cat "You must have " @app-name " 1.0-1.4b installed "
                                 "to use this update script."))

   (set #dir-choice 	   (cat "Select the directory where " @app-name
                                " is currently installed."))
   
   (set #copy 		   (cat "Copying " @app-name "..."))

   (set #copy-edit	   (cat "Copying TextEditor class..."))

   (set #reinst-prompt     (cat "The " @app-name " directory was last "
                                "installed in %s.  Do you wish to update "
                                "NewsRog in this location?"))

   (set #shutdown-prompt   (cat "If NewsRog is running, it must be stopped "
                                "before this update.  Continue?"))

   (set #badarch           (cat "Bad archive.  File paths and empty directories "
                                "must be preserved when unarchiving: "))

   (set #nopd              (cat "This script only updates the commercial "
                                "version of NewsRog."))

   (set #halted            (cat "Installation halted."))

   (set #badabpatch        (cat "A shared library patch could not be "
                                "installed.  Make sure that a valid "
                                "commercial version of NewsRog has been "
                                "properly installed before applying this "
                                "patch."))

   (set #badabcksum        (cat "The file S5697_AppBase.mcc has an improper "
                                "checksum.  Please contact ShadowWorks "
                                "Software technical support for assistance."))
))


;=============================================================================
; Installation procedure
;=============================================================================

; -- check for existance of MUI: ---------------------------------------------

(welcome #welcome)

(if (< (exists "MUI:") 2)
    (P_Abort #bad-MUI))

(if (< (getversion "exec.library" (resident)) 2555904)
    (P_Abort #bad-OS))

(if (not (askbool (prompt #shutdown-prompt)
                  (help   @askbool-help)
                  (default 1)))
    (P_Abort #halted))

; -- check for proper archive ------------------------------------------------

(set scriptdir (pathonly @icon))

(set #n 0)
(while (set thisfile (select #n 
			"MUI/S5697_NPost.mcc"
			"MUI/S5697_NPostList.mcc"
			"MUI/S5697_NTCPList.mcc"
			"MUI/S5697_NTCP.mcc"
			"MUI/S5697_NServerList.mcc"
			"MUI/S5697_NServer.mcc"
			"MUI/S5697_NNews.mcc"
			"MUI/S5697_NArticleMgr.mcc"
			"MUI/S5697_NGroup.mcc"
			"MUI/S5697_NGroupList.mcc"
			"MUI/S5697_NArticleView.mcc"
			"MUI/S5697_NArticle.mcc"
			"MUI/S5697_NDF_TextStyles.mcc"
			"MUI/S5697_NDF_ScrollHdrs.mcc"
			"MUI/S5697_NDF_Rewrap.mcc"
			"MUI/S5697_NDF_HideSig.mcc"
			"MUI/S5697_NDF_HLPatt.mcc"
			"MUI/S5697_NDF_MIME.mcc"
			"MUI/S5697_NDF_EMail.mcc"
			"MUI/S5697_NDF_URL.mcc"
			"MUI/S5697_NDF_UUDecode.mcc"
			"MUI/S5697_NDF_Substitute.mcc"
			"MUI/S5697_NSF_New.mcc"
			"MUI/S5697_FileActs.mcc"
			"MUI/S5697_DTImg.mcc"
			"MUI/S5697_CText.mcc"
			"MUI/S5697_AttrVal4.mcc"
			"MUI/S5697_NHdrList.mcc"
			"MUI/S5697_VarList.mcc"
			"MUI/S5697_ListCol.mcc"
			"MUI/S5697_ListSearch.mcc"
			"MUI/S5697_NSFList.mcc"
			"MUI/S5697_Classlist.mcc"
			"MUI/S5697_NSF_AgeRange.mcc"
			"MUI/S5697_NSF_SizeRange.mcc"
			"MUI/S5697_NSF_HeaderMatch.mcc"
			"MUI/S5697_NSF_MatchThread.mcc"
			"MUI/S5697_NSF_MatchThreadBase.mcc"
			"MUI/S5697_NSF_InGroup.mcc"
			"MUI/S5697_NDF_TrimSpace.mcc"
			"MUI/S5697_NDF_ROT13.mcc"
			"MUI/S5697_NDF_HLQuotes.mcc"
			"MUI/S5697_NAF_Decode.mcc"
			"MUI/S5697_Support.library"
			"Distrib/S5697_AppBase.1.0.pch"
			"Distrib/S5697_AppBase.1.2.pch"
			"Distrib/S5697_AppBase.1.4.pch"
			"Distrib/S5697_AppBase.1.5.pch"
			"Docs/English/NR-Reference.html"
			"Docs/English/NR-Tutorial.html"
			"Docs/English/NR-Req.html"
			"Docs/English/NR-FAQ.html"
			"Docs/English/NR-Credits.html"
			"Docs/English/NR-History.html"
			"Docs/English/Reference/NR-Ref-CmdLine.html"
			"Docs/English/Reference/NR-Ref-Kbd.html"
			"Docs/English/Reference/NR-Ref-ARexx.html"
			"Docs/English/Reference/NR-Ref-HideSig.html"
			"Docs/English/Reference/NR-Ref-HLPatt.html"
			"Docs/English/Reference/NR-Ref-HLQuotes.html"
			"Docs/English/Reference/NR-Ref-SaveTxt.html"
			"Docs/English/Reference/NR-Ref-Decode.html"
			"Docs/English/Reference/NR-Ref-ActFlt.html"
			"Docs/English/Reference/NR-Ref-DspFlt.html"
			"Docs/English/Reference/NR-Ref-SelFlt.html"
			"Docs/English/Reference/NR-Ref-Vars.html"
			"Docs/English/Reference/NR-Ref-TextStyles.html"
			"Docs/English/Reference/NR-Ref-AgeRange.html"
			"Docs/English/Reference/NR-Ref-MatchThreadBase.html"
			"Docs/English/Reference/NR-Ref-LineRange.html"
			"Docs/English/Reference/NR-Ref-ScrollHdrs.html"
			"Docs/English/Reference/NR-Ref-Substitute.html"
			"Docs/English/Reference/NR-Ref-ROT13.html"
			"Docs/English/Reference/NR-Ref-EMail.html"
			"Docs/English/Reference/NR-Ref-URL.html"
			"Docs/English/Tutorials/NR-Tut-InitConfig.html"
			"Docs/English/Tutorials/NR-Tut-DspFlt.html"
			"Docs/English/Tutorials/NR-Tut-MM.html"
			"Docs/English/Tutorials/NR-Tut-Reading.html"
			"Docs/English/Tutorials/NR-Tut-Group.html"
			"Docs/English/Tutorials/NR-Tut-Posts.html"
			"Docs/English/Tutorials/NR-Tut-Config.html"
			"Docs/English/Tutorials/NR-Tut-Servers.html"
			"Docs/English/Tutorials/NR-Tut-FAQMgr.html"
			"Docs/English/Tutorials/NR-Tut-SelFlt.html"
			"Docs/English/Tutorials/NR-Tut-Groups.html"
			"Docs/English/Graphics/Window-SGList.GIF"
			"Docs/English/Graphics/NR-Tut-Group-Stats.GIF"
			"Docs/English/Graphics/NR-Tut-Groups-Opts.GIF"
			"Docs/English/Graphics/NR-Ref-AgeRange-UI.GIF"
			"Docs/English/Graphics/NR-Ref-ScrollHdrs-UI.GIF"
			"Docs/English/Graphics/NR-Ref-ScrollHdrs-Ex1.GIF"
			"Docs/English/Graphics/NR-Ref-ScrollHdrs-Ex2.GIF"
			"Docs/English/Graphics/NR-Ref-SizeRange-UI.GIF"
			"Docs/English/Graphics/NR-Ref-New-UI.GIF"
			"Docs/English/Graphics/NR-Ref-EMail-UI.GIF"
			"Docs/English/Graphics/NR-Ref-URL-UI.GIF"
			"Docs/English/Graphics/NR-Ref-HLPatt-UI.GIF"
			"Docs/English/Graphics/NR-Ref-HLPatt-Ex.GIF"
			"Docs/English/Graphics/NR-Ref-Substitute-UI.GIF"
			"Docs/English/Graphics/NR-Ref-Substitute-Ex1.GIF"
			"Docs/English/Graphics/NR-Ref-Substitute-Ex2.GIF"
			"Docs/English/Graphics/NR-Tut-HLight.GIF"
			"Docs/English/Graphics/NR-Tut-Groups-Opts.GIF"
			"Docs/English/Graphics/NR-Tut-Groups-BatchDL.GIF"
			"Docs/English/Graphics/NR-Tut-Groups-BatchProg.GIF"
			"Docs/English/Graphics/Button-FAQ.GIF"
			"Docs/English/Graphics/Button-HLight.GIF"
			"Docs/English/Graphics/Button-eb_Bold.GIF"
			"Docs/English/Graphics/Button-eb_Copy.GIF"
			"Docs/English/Graphics/Button-eb_Cut.GIF"
			"Docs/English/Graphics/Button-eb_Insert.GIF"
			"Docs/English/Graphics/Button-eb_Italic.GIF"
			"Docs/English/Graphics/Button-eb_Paste.GIF"
			"Docs/English/Graphics/Button-eb_Save.GIF"
			"Docs/English/Graphics/Button-eb_Uline.GIF"
			"Docs/English/Graphics/Button-eb_Undo.GIF"
			"Docs/English/Graphics/Window-PostEdit.GIF"
			"Docs/English/Graphics/Window-Groups.GIF"
			"Docs/English/Graphics/Window-Grp-ALSrch.GIF"
			"Docs/English/Graphics/Window-Servers.GIF"
			"Docs/English/Graphics/Window-FAQMgr.GIF"
			"Docs/English/Graphics/Window-Cfg-Hdrs.GIF"
			"Docs/English/Graphics/Toolbar-B3.jpg"
			"TextEditor.mcc"
			"Images/IFF.HLight"
			"Images/IFF.FAQ"
			"Images/IFF.eb_Bold"
			"Images/IFF.eb_Copy"
			"Images/IFF.eb_Cut"
			"Images/IFF.eb_Insert"
			"Images/IFF.eb_Italic"
			"Images/IFF.eb_Paste"
			"Images/IFF.eb_Save"
			"Images/IFF.eb_Uline"
			"Images/IFF.eb_Undo"
			"Images/IFF.eb_Redo"
			"Images/IFF.eb_Copy_G"
			"Images/IFF.eb_Cut_G"
			"Images/IFF.eb_Undo_G"
			"Images/IFF.eb_Redo_G"
			"Images/NRLogo.L.TC"
			"Images/NRLogo.L.R8"
			"Images/NRLogo.S.TC"
			"Images/NRLogo.S.R8"
			"Images/NRLogo.S.R4"
                        ""))
  ((set #n (+ #n 1))
   (if (not (exists (tackon scriptdir thisfile)))
       (P_Abort (cat #badarch thisfile)))))

; -- select our install dir --------------------------------------------------

(set LastDir "")
(set NR-Dir  "")

(if (exists "ENV:NewsRog/NR-Dir")
    ((set LastDir (getenv "NewsRog/NR-Dir"))
     (if (not (exists (tackon LastDir "NewsRog/NewsRog")))
         (set LastDir ""))))

(complete 10)
(if LastDir
    (if (askbool (prompt  (#reinst-prompt LastDir))
                 (help    @askbool-help)
                 (default 1))
        (set NR-Dir (tackon LastDir "NewsRog"))))

(if (= NR-Dir "")
    (set NR-Dir
         (askdir (prompt #dir-choice)
                 (help "")
                 (default "SYS:Utilities")
                 (newpath))))

(set @default-dest NR-Dir)

(if (not (P_NRExists NR-Dir))
    (set NR-Dir (tackon NR-Dir @app-name)))

; -- check for NewsRog installation ------------------------------------------

(if (not (P_NRExists NR-Dir))
    (P_Abort #bad-NewsRog))

(set @default-dest NR-Dir)

(if (or (not (exists (tackon NR-Dir "NewsRog.key"))))
    (P_Abort #nopd))

(complete 20)

(set @default-dest NR-Dir)

; -- flush libs from memory --------------------------------------------------

(run (tackon NR-Dir "C/FlushLibs"))

; -- patch the old versions of AppBase.mcc -----------------------------------

(set absum (getsum (tackon NR-Dir "MUI/S5697_AppBase.mcc")))
(set abpatch "")

(if (= absum 1002760635)  (set abpatch "Distrib/S5697_AppBase.1.0.pch"))
(if (= absum -1629425022) (set abpatch "Distrib/S5697_AppBase.1.2.pch"))
(if (= absum -216674447)  (set abpatch "Distrib/S5697_AppBase.1.4.pch"))
(if (= absum -216543375)  (set abpatch "Distrib/S5697_AppBase.1.5.pch"))

(if (not (= abpatch ""))
    ((if (<> (run (cat "C/spatch " "-ot:NR1.6TMP \"-p"
                       (tackon scriptdir abpatch)
                       "\" " (tackon NR-Dir "MUI/S5697_AppBase.mcc")))
             0)
         (P_Abort #badabpatch))

     (copyfiles (prompt #copy) (help   @copyfiles-help)
                (source "t:NR1.6TMP")
                (dest (tackon NR-Dir "MUI")) (newname "S5697_AppBase.mcc"))

     (delete "t:NR1.6TMP")))


(if (not (= (getsum (tackon NR-Dir "MUI/S5697_AppBase.mcc")) -1896684850))
    (P_Abort #badabcksum))

; -- copy the new files ------------------------------------------------------

(copyfiles
 (prompt #copy) (help @copyfiles-help)
 (infos)
 (source scriptdir) (dest NR-Dir)
 (choices "NewsRog" "MUI" "Readme_1.6.txt" "RegInfo" "Filters" "Docs"))

(copyfiles
 (prompt #copy) (help   @copyfiles-help)
 (infos)
 (source scriptdir) (dest NR-Dir) (optional "nofail")
 (choices "Images"))

(copylib
 (prompt #copy-edit)
 (help @copylib-help)
 (source "TextEditor.mcc")
 (dest "MUI:libs/mui"))

(copylib
 (prompt #copy-edit)
 (help @copylib-help)
 (source "TextEditor.mcp")
 (dest "MUI:libs/mui"))

(if (exists (tackon NR-Dir "MUI/TextEditor.mcc"))
    (delete (tackon NR-Dir "MUI/TextEditor.mcc")))

; -- create missing ServerGroups directory -----------------------------------

(makedir (tackon NR-Dir "ServerGroups"))

; -- create filters directory ------------------------------------------------

(makedir (tackon NR-Dir "Filters"))

; -- move MUI environment ----------------------------------------------------

(if (exists "ENV:MUI/NEWSROG.1.prefs")
    (rename "ENV:MUI/NEWSROG.1.prefs" "ENV:MUI/NEWSROG.prefs"))

(if (exists "ENVARC:MUI/NEWSROG.1.prefs")
    (rename "ENVARC:MUI/NEWSROG.1.prefs" "ENVARC:MUI/NEWSROG.prefs"))

(complete 80)

(run (cat "run sys:utilities/multiview " (tackon NR-Dir "Readme_1.6.txt")))

; -- cleanup -----------------------------------------------------------------

(complete 100)

(exit)
