(if (= 2 (exists "REXX:" (noreq)))
  (set #defdir "REXX:")
  (set #defdir "S:")
)

;(message "Your language is "@language)
(set #ver (/ @installer-version 65536))
(set #destmsg$ "")
(set #FWCmacro "FWCalendar.rexx")
(set #AddEventmacro "FWCAddEvent.rexx")
(set #RandomFile "FWCRandom.txt")
(set #HistoryFile "FWCHistory")
(set #ImagesFile "Images")
(set #optionchoices 3)
(set #option1 "")
(set #option2 "")
(set #option3 "")
(set #option4 "")
(set #option5 "")
(set #maxoptions 7) ; 2 + number of options
;=============================================================================
; English (default) strings
(set #languagechoice 0)
(set #welcome$ (cat "Welcome to the FWCalendar installation program.\n"
                    "Select the application(s) you will be using with FWCalendar."))
(set #doabort$ "You did not select an application. Would you like to abort the installation?")
(set #doaborthelp$ "You must select an application to continue.")
(set #seldir$ "Select the destination drawer for the ARexx scripts. A new directory will NOT be created.")
(set #FWdestmsg$ " (The recommended location is the FinalWriter/Macros directory)")
(set #bothdestmsg$ " (The recommended location is a common directory of ARexx scripts)")
(set #selLanguage$ (cat "Select which country's preference file should be used. "
                        "Existing preference files will NOT be overwritten."))
(set #docDestMsg$ (cat "The documentation is in HTML format. Where should they be installed? "
                       "An \"FWCDocs\" directory WILL BE created if it doesn't already exist."))
(set #CopyMacrosMsg$ "The following macros will be copied to ")
(set #CopyPrefsMsg$ "The following files will be copied to ")
(set #copyDocsMsg$ "The document directory will be copied to ")
(set #ViewDocsMsg$ "Would you like to view the documents?")
(set #Yes$ "Yes")
(set #Skip$ "Skip this part")
(set #Proceed$ "Proceed")
(set #ViewDocsHelp$ (cat "If you would like to view the docs, press \"" #Yes$ "\", otherwise press \"" #Skip$ "\"."))
;=============================================================================
; German strings (24.06.00) by OliverMolz <OliverMolz@t-online.de>
(if (= @language "deutsch")
  (
    (set #languagechoice 1)
    (set #welcome$ (cat "Willkommen zum FWCalendar Installations-Programm.\n"
                        "Wähle die Applikation(en) mit denen Du FWCalendar benutzen möchtest."))
    (set #doabort$ "Du hast keine Applikation gewählt. Möchtest Du die Installation abbrechen?")
    (set #doaborthelp$ "Du mußt eine eine Applikation wählen um fortzufahren.")
    (set #seldir$ "Wähle den Ziel-Pfad für die ARexx-Scripte. Es wird KEIN neues Verzeichnis angelegt.")
    (set #FWdestmsg$ " (Der empfohlene Pfad ist das FinalWriter Macros Verzeichnis)")
    (set #bothdestmsg$ " (Der empfohlene Pfad ist der gewöhnliche Pfad für die ARexx Scripte)")
    (set #selLanguage$ (cat "Wähle welche Sprache und welche Preference-Datei benutzt werden soll. "
                            "Bestehende Preference-Dateien werden NICHT überschrieben."))
    (set #docDestMsg$ (cat "Die Dokumentation ist im HTML-Format. Soll diese installiert werden? "
                           "Ein \"FWCDocs\" Verzeichnis WIRD erstellt, falls dieses nicht existiert."))
    (set #CopyMacrosMsg$ "Die folgenden Makros werden kopiert ")
    (set #CopyPrefsMsg$ "Das folgende Preference-File wird kopiert ")
    (set #copyDocsMsg$ "Das Dokument-.Verzeichnis wird kopiert ")
    (set #ViewDocsMsg$ "Möchtest Du das Dok-File lesen?")
    (set #Yes$ "Ja")
    (set #Skip$ "Überspringe diesen Teil")
    (set #Proceed$ "Weiter")
    (set #ViewDocsHelp$ (cat "Wenn Du das Dok-File lesen möchtest, drücke \"" #Yes$ "\", andererseits, drucke \"" #Skip$ "\"."))
  )
)
;=============================================================================
; Spanish strings (29.11.99) by Dámaso D. Estévez <amidde@arrakis.es>
(if (= @language "español")
  (
    (set #languagechoice 3)
    (set #welcome$ (cat "Bienvenido al programa de instalación de `FWCalendar':\n"
                        "elija la(s) aplicación(es) que usarán dicho guión ARexx."))
    (set #doabort$ "No ha seleccionado ninguna aplicación.  ¿Desea abortar la instalación?")
    (set #doaborthelp$ "Ha de seleccionar obligatoriamente una aplicación para continuar.")
    (set #seldir$ "Elija el cajón de destino para los guiones ARexx (NO se creará ningún nuevo directorio).")
    (set #FWdestmsg$ " (Se recomienda el directorio FinalWriter/Macros)")
    (set #bothdestmsg$ " (Se recomienda un directorio común para los guiones ARexx)")
    (set #selLanguage$ (cat "Elija el fichero de preferencias a utilizar según su país "
                            "Los ficheros de preferencias preexistentes NO serán sobreescritos."))
    (set #docDestMsg$ (cat "La documentación se encuentra en formato HTML. ¿Dónde desea instalarla? "
                           "Un directorio \"FWCDocs\" SE CREARÁ si aún no existe."))
    (set #CopyMacrosMsg$ "Las siguientes macros se copiarán en ")
    (set #CopyPrefsMsg$ "El siguiente fichero se copiará en ")
    (set #copyDocsMsg$ "El directorio de documentación se copiará en ")
    (set #ViewDocsMsg$ "¿Le gustaría ver la documentación?")
    (set #Yes$ "Sí")
    (set #Skip$ "Saltar esta parte")
    (set #Proceed$ "Proceder")
    (set #ViewDocsHelp$ (cat "Si desea ver la documentación, presione \"" #Yes$ "\".  En caso contrario presione \"" #Skip$ "\"."))
  )
)
;=============================================================================
; Norwegian strings (22.06.00) by Truls Osmundsen (ozzy1@online.no)
(if (= @language "norsk")
  (
    (set #languagechoice 7)
    (set #welcome$ (cat "Velkommen til FWCalendar installasjonsprogram.\n"
                        "Velg de programmene du kommer til å bruke sammen med FWCalendar."))
    (set #doabort$ "Du valgte ikke noe program. Vil du stanse installasjonen?")
    (set #doaborthelp$ "Du må velge et program for å fortsette.")
    (set #seldir$ "Velg en mappe for Arexx-skriptene. En ny mappe vil IKKE bli laget.")
    (set #FWdestmsg$ " (Den vanligste plassen er FinalWriter/Macros mappen)")
    (set #bothdestmsg$ " (Den vanligste plassen er en vanlig ARexx plassering)")
    (set #selLanguage$ (cat "Velg landsutgangspunkt-fil "
                            "(som inneholder språk og fridager) som vil bli brukt. "
                            "Eksisterende filer vil IKKE bli overskrevet."))
    (set #docDestMsg$ (cat "Dokumentasjonen er i HTML format. Hvor skal de installeres? "
                           "En \"FWCDocs\" mappe VIL BLI laget om ingen allerede eksisterer."))
    (set #CopyMacrosMsg$ "Følgende Macroer vil bli kopiert til ")
    (set #CopyPrefsMsg$ "Følgende utgangspunkt-fil vil bli kopiert til ")
    (set #copyDocsMsg$ "Dokumentmappen vil bli kopiert til ")
    (set #ViewDocsMsg$ "Vil du se dokumentene?")
    (set #Yes$ "Ja")
    (set #Skip$ "Hopp over denne delen")
    (set #Proceed$ "Fortsett")
    (set #ViewDocsHelp$ (cat "Om du vil se dokumentene, trykk \"" #Yes$ "\", eller trykk \"" #Skip$ "\"."))
  )
)
;=============================================================================
; Swedish strings (00-06-22) by Börje Karlsson
(if (= @language "svenska")
  (
    (set #languagechoice 10)
    (set #welcome$ (cat "Välkommen till FWCalendar installations program.\n"
                        "Välj applikationerna Du vill använda med FWCalendar."))
    (set #doabort$ "Du valde ingen  applikation. Vill Du avsluta installationen?")
    (set #doaborthelp$ "Du måste välja en applikation för att fortsätta.")
    (set #seldir$ "Välj destinations låda för ARexx skripten. En ny LÅDA kommer inte att skapas.")
    (set #FWdestmsg$ " (Rekommenderad plats är FinalWriter/Macros låda)")
    (set #bothdestmsg$ " (Den rekommenderade platsen är en vanlig låda för ARexx skript)")
    (set #selLanguage$ (cat "Välj vilket lands preferens fil "
                            "(Innehållande översättningar och Helgdagar) som skall användas. "
                            "Existerande preferens filer kommer INTE att skrivas över."))
    (set #docDestMsg$ (cat "Dokumentationen är i HTML format. Var skall den installeras? "
                           "En \"FWCDocs\" Låda KOMMER ATT skapas om den inte redan existerar."))
    (set #CopyMacrosMsg$ "Följande makron kommer att kopieras till ")
    (set #CopyPrefsMsg$ "Följande preferens filer kommer att kopieras till ")
    (set #copyDocsMsg$ "Dokumentationen kopieras till ")
    (set #ViewDocsMsg$ "Vill Du läsa dokumentationen?")
    (set #Yes$ "Ja")
    (set #Skip$ "Hoppa över denna del")
    (set #Proceed$ "Fortsätt")
    (set #ViewDocsHelp$ (cat "Om Du vill läsa dokumentationen, tryck \"" #Yes$ "\", annars tryck \"" #Skip$ "\"."))
  )
)
;=============================================================================
(if (>= #ver 44)
  (showmedia 'PicHandle' 'FWCDocs/Images/FWCalendar.gif' 'upper_center' 'none' 0)
)

(until (> #AppChoice 0)
  (set #AppChoice
    (askoptions
      (prompt #welcome$)
      (help @askoptions-help)
      (choices "Final Writer" "PageStream")
      (default 0)
    )
  )

  (if (= #AppChoice 0)
    (
      (set #choice
        (askbool
          (prompt #doabort$)
          (help #soaborthelp$)
        )
      )
      (if (= #choice 1)
        (exit (quiet))
      )
    )
  )
);end until

(if (= #AppChoice 1)
  ;Application = Final Writer
  (
    (set #destmsg$ #FWdestmsg$)
  )
  (if (= #AppChoice 2)
    ;Application = PageStream
    (
      (if (= 2 (exists "PageStream4:Scripts" (noreq)))
        (set #defdir "PageStream4:Scripts/")
        (if (= 2 (exists "PageStream3:Scripts" (noreq)))
          (set #defdir "PageStream3:Scripts/")
          (if (= 2 (exists "PageStream:Scripts" (noreq)))
            (set #defdir "PageStream:Scripts/")
          )
        )
      )
    )
    ;Application = Both
    (
      (set #destmsg$ #bothdestmsg$)
    )
  )
)

(set @default-dest
 (askdir
  (prompt (cat #seldir$ #destmsg$))
  (help @askdir-help)
  (default #defdir)
 )
)

(set #docDir
 (askdir
  (prompt #docDestMsg$)
  (help @askdir-help)
  (default @default-dest)
 )
)

(if (< (+ (exists (tackon @default-dest "FWCalendar.prefs") (noreq)) (exists (tackon @default-dest "FWCTranslations.txt") (noreq))) 2)
 (
  (set #language
   (askchoice
    (prompt #selLanguage$)
    (choices "American" "Canadian" "Deutsch" "English" "Español" "Français" "Irish" "Italiano" "Jewish" "Norsk" "Português" "Scottish" "Suomi" "Svenska")
    (default #languagechoice)
    (help @askchoice-help)
   )
  )
  (set #language (select #language "American" "Canadian" "Deutsch" "English" "Español" "Français" "Irish" "Italiano" "Jewish" "Norsk" "Português" "Scottish" "Suomi" "Svenska"))
  (set #PrefsFile (cat #language "/FWCalendar.prefs"))
  (set #TranslationsFile (cat #language "/FWCTranslations.txt"))
 )
)

(if (= 0 (exists (tackon @default-dest "FWCalendar.prefs") (noreq)))
 (if (= 1 (exists (tackon #language "FWCalendar.prefs") (noreq)))
  (
   (set #option1 #PrefsFile)
   (set #optionchoices (+ #optionchoices 4))
  )
 )
)
(if (= 0 (exists (tackon @default-dest "FWCTranslations.txt") (noreq)))
 (if (= 1 (exists (tackon #language "FWCTranslations.txt") (noreq)))
  (
   (set #option2 #TranslationsFile)
   (set #optionchoices (+ #optionchoices 8))
  )
 )
)
(if (= 0 (exists (tackon @default-dest #RandomFile) (noreq)))
 (if (= 1 (exists #RandomFile (noreq)))
  (
   (set #option3 #RandomFile)
   (set #optionchoices (+ #optionchoices 16))
  )
 )
)
(if (= 0 (exists (tackon @default-dest (tackon #HistoryFile "01")) (noreq)))
 (if (= 1 (exists (tackon #HistoryFile "01") (noreq)))
  (
   (set #option4 #HistoryFile)
   (set #optionchoices (+ #optionchoices 32))
  )
 )
)
(if (= 0 (exists (tackon @default-dest (tackon #ImagesFile "Anniversary.iff")) (noreq)))
 (if (= 1 (exists (tackon #ImagesFile "Anniversary.iff") (noreq)))
  (
   (set #option5 #ImagesFile)
   (set #optionchoices (+ #optionchoices 64))
  )
 )
)

(if (= @user-level 2)
 (set #optionchoices
  (askoptions
   (prompt #copyPrefsMsg$ @default-dest)
   (help @copyfiles-help)
   (choices #FWCmacro #AddEventmacro #option1 #option2 #option3 #option4 #option5)
   (default #optionchoices)
  )
 )
)

(if (not (= #optionchoices 0))
 (
  (set #count 0)
  (set #bitmask 1)
  (while (< #count #maxoptions)
   (set #option (select #count #FWCmacro #AddEventmacro #option1 #option2 #option3 #option4 #option5))
   (if (> (bitand #bitmask #optionchoices) 0)
    (copyfiles
     (prompt "")
     (help "")
     (source (pathonly @icon))
     (dest @default-dest)
     (choices #option)
     (files)
    )
   )
   (set #count (+ #count 1))
   (set #bitmask (shiftleft #bitmask 1))
  )
 )
)

(copyfiles
  (prompt #copyDocsMsg$ #docDir)
  (help @copyfiles-help)
  (source (pathonly @icon))
  (dest #docDir)
  (choices "FWCDocs")
  (confirm)
)

(if
  (set #choice
    (askbool
      (prompt #ViewDocsMsg$)
      (choices "Yes" "Skip this part")
      (default 1)
      (help #ViewDocsHelp$)
    )
  )
  (
    (set #IndexCmd (tackon #docDir (cat "FWCDocs" "/SendToBrowser.rexx")))
    (rexx #IndexCmd
      (prompt #ShowDocsMsg$)
      (help #ShowDocsHelp$)
    )
  )
)

(exit)
