;
; Install Fiasco 2.01 Patch
; Patches Fiasco Release Version 2.0 to Release Version 2.01
; Copyright © 1997 Nils Bandener
; $VER: PatchFiasco 5.9 (29.3.97)
;

(procedure applypatch
    ;
    ; Expected parameters:
    ;
    ; apfile = Name of file to patch
    ; appch  = Name of patch file
    ;

    (working (#patching-s apfile))

    (if (=
           (run ("\"%s\" \"-p%s\" -ot:Fiasco_New \"%s\"" spatch appch apfile))

         0)
    (
        (delete apfile)
        (copyfiles (source "T:Fiasco_New")
                   (dest (pathonly apfile)))

        (rename (tackon (pathonly apfile) "Fiasco_New") apfile)
    )
    (
        (abort (#patch-could-not-be-applied apfile))
    ))
)

(procedure applyldocpatch

    (set apfile (tackon ldocdir "Fiasco.guide"))

    (if (exists apfile)
    (
        (if (askbool (prompt (#want-to-patch apfile))
                     (choices #yes #no)
                     (help #patch-doc-help)
                     (default 1))
        (
            (set appch (tackon srcdir ("Doc_guide_%s.pch" ldoclang)))

            (applypatch)
        ))
    ))

    (set apfile (tackon ldocdir "Fiasco.dvi"))

    (if (exists apfile)
    (
        (if (askbool (prompt (#want-to-patch apfile))
                     (choices #yes #no)
                     (help #patch-doc-help)
                     (default 1))
        (
            (set appch (tackon srcdir ("Doc_dvi_%s.pch" ldoclang)))

            (applypatch)
        ))
    ))
)

(if (= @language "deutsch")
(
    (set #yes "Ja")

    (set #no "Nein")

    (set #patching-s "Patche \"%s\"...")

    (set #patch-could-not-be-applied "Patch konnte nicht auf \"%s\" angewendet werden.")

    (set #want-to-patch "Wollen Sie %s patchen?")

    (set #patch-doc-help "Diese Prozedur aktualisiert das Dokument der Fiasco 2.0-Distribution auf die 2.01-Version. Dieses Script sichert ab, daß der richtige Patch angewendet wird.")

    (set #select-fiasco-dir "Bitte wählen Sie das Verzeichnis aus, in dem sich Fiasco 2.0 befindet.")

    (set #select-fiasco-dir-help "Benutzen Sie diesen Requester, um das Verzeichnis anzugeben, in dem Fiasco 2.0 abgelegt ist.")

    (set #fiasco-dir-does-not-exist "Das ausgewählte Verzeichnis existiert nicht!")

    (set #fiasco-dir-not-ok "Das ausgewählte Verzeichnis enthält nicht die Fiasco-Haupt-Datei!")

    (set #version-not-ok "Sie haben nicht Fiasco Version 2.0 installiert!\nDie installierte Fiasco-Haupt-Datei sollte Version 5.416 haben, Sie haben Version %ld.%ld.")

    (set #patch-fiasco-main "Wollen Sie die Fiasco-Haupt-Datei patchen?")

    (set #patch-fiasco-main-help "Diese Prozedur aktualisiert die ausführbare Datei von Fiasco Relase Version 2.0 auf die Version 2.01.")

    (set #unknown-file "Kann Patch nicht anwenden:\nDie Datei %s ist dem Installer-Script unbekannt.")

    (set #install-aminet-db "Wollen Sie die neue `Aminet'-Datenbank installieren?")

    (set #install-aminet-db-help "Installier eine neue Beispiel-Datenbank für Fiasco, die zum Verwalten von Aminet-Datei-Indizes mit Fiasco benutzt werden kann.")

    (set #install-converttolist "Wollen Sie das neue ARexx-Script converttolistview.rexx installieren?")

    (set #install-converttolist-help "Installier ein neues ARexx-Script für Fiasco, das Daten in mehreren Feldern in ein Listview-Feld umwandelt.")

    (set #patch-german-catalog "Wollen Sie den deutschen Fiasco.catalog patchen?")

    (set #patch-german-catalog-help "Diese Prozedur aktualisiert den Deutsch/Fiasco.catalog von Fiasco 2.0 auf die 2.01-Version. Dies behebt ein paar Probleme mit Tastatur-Shortcuts in bestimmten Requestern.")

    (set #install-swedish-catalog "Wollen Sie den Schwedischen Catalog für Fiasco installieren?")

    (set #install-swedish-catalog-help "Installiert den neuen schwedischen Catalog für Fiasco. Damit können Sie Fiasco in Schwedisch betreiben.")

    (set #examining-s "Untersuche %s ...")
)
(
    (set #yes "Yes")

    (set #no "No")

    (set #patching-s "Patching \"%s\"...")

    (set #patch-could-not-be-applied "Patch could not be applied to \"%s\".")

    (set #want-to-patch "Do you want to patch %s?")

    (set #patch-doc-help "This procedure updates the document from the Fiasco 2.0 distribution to the 2.01 version. This script makes sure, that the correct patch will be applied")

    (set #select-fiasco-dir "Please select the directory where you have installed Fiasco 2.0")

    (set #select-fiasco-dir-help "Use this requester to select the directory Fiasco release version 2.0 is located.")

    (set #fiasco-dir-does-not-exist "The selected directory does not exist!")

    (set #fiasco-dir-not-ok "The selected directory does not contain the Fiasco main executable!")

    (set #version-not-ok "You do not have Fiasco 2.0 installed!\nThe installed Fiasco main executable should have version 5.416, you have version %ld.%ld.")

    (set #patch-fiasco-main "Do you want to patch the main Fiasco executable?")

    (set #patch-fiasco-main-help "This procedure will change the Fiasco release version 2.0 main file to the 2.01 version.")

    (set #unknown-file "Unable to apply patch:\nThe file %s is unkown to this installer script.")

    (set #install-aminet-db "Do you want to install the new `Aminet' Database?")

    (set #install-aminet-db-help "Installs a new example database for Fiasco, that can be used to store Aminet file indices with Fiasco.")

    (set #install-converttolist "Do you want to install the new ARexx script converttolistview.rexx?")

    (set #install-converttolist-help "Installs a new ARexx support script for Fiasco, that converts data in several single fields to one listview field.")

    (set #patch-german-catalog "Do you want to patch the German Fiasco.catalog?")

    (set #patch-german-catalog-help "This procedure changes the Fiasco release version 2.0 Deutsch/Fiasco.catalog to its 2.01 version. This fixes some problems with shortcuts in some Fiasco requesters.")

    (set #install-swedish-catalog "Do you want to install the Swedish catalog for Fiasco?")

    (set #install-swedish-catalog-help "Installs the new Swedish catalog for Fiasco. If you have installed it, you may use Fiasco in Swedish language.")

    (set #examining-s "Examining %s...")
))

(set srcdir (tackon (pathonly @icon) "data"))

(set spatch (tackon (pathonly @icon) "spatch"))

(set destok 0)

(while (not destok)
(
    (set @default-dest
        (askdir (prompt #select-fiasco-dir)
                (default "Work:")
                (help #select-fiasco-dir-help)))

    (if (exists @default-dest)
    (
        (if (= (exists (tackon @default-dest "Fiasco")) 1)
        (
            (set destok 1)
        )
        (
            (message #fiasco-dir-not-ok)
        ))
    )
    (
        (message #fiasco-dir-does-not-exist)
    ))
))

(complete 5)

(set exver (getversion (tackon @default-dest "Fiasco")))
(set fver (+ (*  5 65536) 455))

(if (<> exver (+ (* 5 65536) 416))
(
    (set ver (/ exver 65536))
    (set rev (- exver (* ver 65536)))

    (abort (#version-not-ok ver rev))
))

(if (askbool (prompt #patch-fiasco-main)
             (choices #yes #no)
             (help #patch-fiasco-main-help)
             (default 1))
(
    (set appch (tackon srcdir "Fiasco.pch"))
    (set apfile (tackon @default-dest "Fiasco"))

    (applypatch)
))

(complete 15)

(set docdir (tackon @default-dest "Documentation"))

(if (exists docdir)
(
    (set apfile (tackon docdir "Fiasco.dvi"))

    (if (exists apfile)
    (
        (if (askbool (prompt (#want-to-patch apfile))
                     (choices #yes #no)
                     (help #patch-doc-help)
                     (default 1))
        (
            (working (#examining-s apfile))

            (set sum (getsum apfile))

            (complete 30)

            (if (= sum 764810407)
            (
                (set lang "English")
                (set appch (tackon srcdir "Doc_dvi_eng.pch"))
            )
            (
                (if (= sum -297370585)
                (
                    (set lang "Deutsch")
                    (set appch (tackon srcdir "Doc_dvi_deu.pch"))
                )
                (
                    (message (#unknown-file apfile))
                    (set appch "")
                ))
            ))

            (if (<> appch "")
            (
                (applypatch)
            ))

            (complete 40)
        ))
    ))

    (set apfile (tackon docdir "Fiasco.guide"))

    (if (exists apfile)
    (
        (if (askbool (prompt (#want-to-patch apfile))
                     (choices #yes #no)
                     (help #patch-doc-help)
                     (default 1))
        (
            (working (#examining-s apfile))

            (set sum (getsum apfile))

            (complete 55)

            (if (= sum -220819350)
            (
                (set lang "English")
                (set appch (tackon srcdir "Doc_guide_eng.pch"))
            )
            (
                (if (= sum 825961463)
                (
                    (set lang "Deutsch")
                    (set appch (tackon srcdir "Doc_guide_deu.pch"))
                )
                (
                    (message (#unknown-file apfile))
                    (set appch "")
                ))
            ))

            (if (<> appch "")
            (
                (applypatch)
            ))

            (complete 65)
        ))
    ))

    (set ldocdir (tackon docdir "English"))
    (set ldoclang "eng")

    (applyldocpatch)

    (complete 75)

    (set ldocdir (tackon docdir "Deutsch"))
    (set ldoclang "deu")

    (applyldocpatch)

    (complete 85)
))

(set dbdir (tackon @default-dest "Databases"))

(if (exists dbdir)
(
    (if (askbool (prompt #install-aminet-db)
                 (choices #yes #no)
                 (help #install-aminet-db-help)
                 (default 1) )
    (
        (makedir (tackon dbdir "Aminet") (infos))

        (copyfiles (source (tackon srcdir "Aminet"))
                   (dest (tackon dbdir "Aminet"))
                   (infos)
                   (all))
    ))

))

(complete 90)

(set rexxdir (tackon @default-dest "ARexx"))

(if (exists rexxdir)
(
    (if (askbool (prompt #install-converttolist)
                 (choices #yes #no)
                 (help #install-dovnerttolist-help)
                 (default 1))
    (
        (copyfiles (source (tackon srcdir "converttolistview.rexx"))
                   (dest rexxdir)
                   (infos))
    ))
))

(complete 92)

(set catalogdir (tackon @default-dest "catalogs"))

(if (not (exists catalogdir))
(
    (set catalogdir "sys:locale/catalogs")
))

(if (exists catalogdir)
(
    (if (exists (tackon catalogdir "Deutsch/Fiasco.catalog"))
    (
        (if (askbool (prompt #patch-german-catalog)
                     (choices #yes #no)
                     (help #patch-german-catalog-help)
                     (default 1))
        (
            (set apfile (tackon catalogdir "Deutsch/Fiasco.catalog"))
            (set appch (tackon srcdir "Cat_Deu.pch"))

            (applypatch)
        ))
    ))

    (complete 96)

    (if (askbool (prompt #install-swedish-catalog)
                 (choices #yes #no)
                 (help #install-swedisch-catalog-help)
                 (default 0))
    (
        (copyfiles (source (tackon srcdir "Fiasco_sve.catalog"))
                   (dest (tackon catalogdir "Svenska")))

        (rename (tackon catalogdir "Svenska/Fiasco_sve.catalog")
                (tackon catalogdir "Svenska/Fiasco.catalog"))
    ))
))

(complete 99)

(if (not (exists (tackon @default-dest "Fiasco.key")))
(
    (copyfiles (source (tackon (pathonly @icon) "RegForm.txt"))
               (dest @default-dest)
               (infos))
))

(copyfiles (source (tackon (pathonly @icon) "MailingList.txt"))
           (dest @default-dest)
           (infos))

(complete 100)
